**** Merged r40732-r40872 from MCS ****
[mono.git] / mcs / gmcs / ecore.cs
old mode 100755 (executable)
new mode 100644 (file)
index def1304..baf528b
@@ -51,20 +51,15 @@ namespace Mono.CSharp {
                // Returns a method group.
                MethodGroup             = 4,
 
-               // Allows SimpleNames to be returned.
-               // This is used by MemberAccess to construct long names that can not be
-               // partially resolved (namespace-qualified names for example).
-               SimpleName              = 8,
-
                // Mask of all the expression class flags.
-               MaskExprClass           = 15,
+               MaskExprClass           = 7,
 
                // Disable control flow analysis while resolving the expression.
                // This is used when resolving the instance expression of a field expression.
-               DisableFlowAnalysis     = 16,
+               DisableFlowAnalysis     = 8,
 
                // Set if this is resolving the first part of a MemberAccess.
-               Intermediate            = 32
+               Intermediate            = 16
        }
 
        //
@@ -235,9 +230,9 @@ namespace Mono.CSharp {
                        //
                        if (ma == MethodAttributes.Private) {
                                Type declaring_type = mi.DeclaringType;
-                                       
+
                                if (invocation_type != declaring_type)
-                                       return TypeManager.IsNestedFamilyAccessible (invocation_type, declaring_type);
+                                       return TypeManager.IsNestedChildOf (invocation_type, declaring_type);
 
                                return true;
                        }
@@ -304,15 +299,14 @@ namespace Mono.CSharp {
 
                public virtual Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
-                       return DoResolve (ec);
+                       return null;
                }
 
                //
-               // This is used if the expression should be resolved as a type.
-               // the default implementation fails.   Use this method in
-               // those participants in the SimpleName chain system.
+               // This is used if the expression should be resolved as a type or namespace name.
+               // the default implementation fails.   
                //
-               public virtual Expression ResolveAsTypeStep (EmitContext ec)
+               public virtual FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        return null;
                }
@@ -326,14 +320,23 @@ namespace Mono.CSharp {
                {
                        int errors = Report.Errors;
 
-                       TypeExpr te = ResolveAsTypeStep (ec) as TypeExpr;
+                       FullNamedExpression fne = ResolveAsTypeStep (ec);
 
-                       if ((te == null) || (te.eclass != ExprClass.Type) || (te.Type == null)) {
+                       if (fne == null) {
                                if (errors == Report.Errors)
                                        Report.Error (246, Location, "Cannot find type '{0}'", ToString ());
                                return null;
                        }
 
+                       if (fne.eclass != ExprClass.Type) {
+                               if (errors == Report.Errors)
+                                       Report.Error (118, Location, "'{0}' denotes a '{1}', where a type was expected",
+                                                     fne.FullName, fne.ExprClassName ());
+                               return null;
+                       }
+
+                       TypeExpr te = fne as TypeExpr;
+
                        if (!te.CheckAccessLevel (ec.DeclSpace)) {
                                Report.Error (122, Location, "'{0}' is inaccessible due to its protection level", te.Name);
                                return null;
@@ -372,19 +375,7 @@ namespace Mono.CSharp {
                        if (e == null)
                                return null;
 
-                       if (e is SimpleName){
-                               SimpleName s = (SimpleName) e;
-
-                               if ((flags & ResolveFlags.SimpleName) == 0) {
-                                       MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
-                                                           ec.DeclSpace.Name, loc);
-                                       return null;
-                               }
-
-                               return s;
-                       }
-
-                       if ((e is TypeExpr) || (e is ComposedCast)) {
+                       if ((e is TypeExpr) || (e is ComposedCast) || (e is Namespace)) {
                                if ((flags & ResolveFlags.Type) == 0) {
                                        e.Error_UnexpectedKind (flags, loc);
                                        return null;
@@ -395,6 +386,7 @@ namespace Mono.CSharp {
 
                        switch (e.eclass) {
                        case ExprClass.Type:
+                       case ExprClass.Namespace:
                                if ((flags & ResolveFlags.VariableOrValue) == 0) {
                                        e.Error_UnexpectedKind (flags, loc);
                                        return null;
@@ -431,11 +423,12 @@ namespace Mono.CSharp {
                                                     " ExprClass is Invalid after resolve");
                        }
 
-                       if (e.type == null)
+                       if (e.type == null && !(e is Namespace)) {
                                throw new Exception (
                                        "Expression " + e.GetType () +
                                        " did not set its type after Resolve\n" +
                                        "called from: " + this.GetType ());
+                       }
 
                        return e;
                }
@@ -458,16 +451,16 @@ namespace Mono.CSharp {
                /// </remarks>
                public Expression ResolveLValue (EmitContext ec, Expression right_side)
                {
+                       int errors = Report.Errors;
                        Expression e = DoResolveLValue (ec, right_side);
 
-                       if (e != null){
-                               if (e is SimpleName){
-                                       SimpleName s = (SimpleName) e;
-                                       MemberLookupFailed (ec, null, ec.ContainerType, s.Name,
-                                                           ec.DeclSpace.Name, loc);
-                                       return null;
-                               }
+                       if (e == null) {
+                               if (errors == Report.Errors)
+                                       Report.Error (131, Location, "The left-hand side of an assignment or mutating operation must be a variable, property or indexer");
+                               return null;
+                       }
 
+                       if (e != null){
                                if (e.eclass == ExprClass.Invalid)
                                        throw new Exception ("Expression " + e +
                                                             " ExprClass is Invalid after resolve");
@@ -588,8 +581,7 @@ namespace Mono.CSharp {
                        return null;
                }
 
-
-               private static ArrayList almostMatchedMembers = new ArrayList (4);
+               protected static ArrayList almostMatchedMembers = new ArrayList (4);
 
                //
                // FIXME: Probably implement a cache for (t,name,current_access_set)?
@@ -741,16 +733,28 @@ namespace Mono.CSharp {
                                if (qualifier_type != ec.ContainerType) {
                                        // Although a derived class can access protected members of
                                        // its base class it cannot do so through an instance of the
-                                       // base class (CS1540).  If the qualifier_type is a parent of the
+                                       // base class (CS1540).  If the qualifier_type is a base of the
                                        // ec.ContainerType and the lookup succeeds with the latter one,
                                        // then we are in this situation.
-                                       foreach (MemberInfo m in almostMatchedMembers)
+                                       for (int i = 0; i < almostMatchedMembers.Count; ++i) {
+                                               MemberInfo m = (MemberInfo) almostMatchedMembers [i];
+                                               for (int j = 0; j < i; ++j) {
+                                                       if (m == almostMatchedMembers [j]) {
+                                                               m = null;
+                                                               break;
+                                                       }
+                                               }
+                                               if (m == null)
+                                                       continue;
+
+                                               Report.SymbolRelatedToPreviousError (m);
                                                Report.Error (1540, loc, 
                                                              "Cannot access protected member `{0}' via a qualifier of type `{1}';"
                                                              + " the qualifier must be of type `{2}' (or derived from it)", 
                                                              TypeManager.GetFullNameSignature (m),
                                                              TypeManager.CSharpName (qualifier_type),
                                                              TypeManager.CSharpName (ec.ContainerType));
+                                       }
                                        return;
                                }
                                almostMatchedMembers.Clear ();
@@ -786,13 +790,15 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (name == ".ctor" && TypeManager.FindMembers (qualifier_type, MemberTypes.Constructor,
+                               BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, null).Count == 0)
+                       {
+                               Report.Error (143, loc, String.Format ("The type '{0}' has no constructors defined", TypeManager.CSharpName (queried_type)));
+                               return;
+                       }
 
-
-                       if (qualifier_type != null)
+                       if (qualifier_type != null) {
                                Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", TypeManager.CSharpName (qualifier_type) + "." + name);
-                       else if (name == ".ctor") {
-                               Report.Error (143, loc, String.Format ("The type {0} has no constructors defined",
-                                                                      TypeManager.CSharpName (queried_type)));
                        } else {
                                Report.Error (122, loc, "'{0}' is inaccessible due to its protection level", name);
                }
@@ -809,7 +815,7 @@ namespace Mono.CSharp {
                ///   Returns an expression that can be used to invoke operator true
                ///   on the expression if it exists.
                /// </summary>
-               static public StaticCallExpr GetOperatorTrue (EmitContext ec, Expression e, Location loc)
+               static public Expression GetOperatorTrue (EmitContext ec, Expression e, Location loc)
                {
                        return GetOperatorTrueOrFalse (ec, e, true, loc);
                }
@@ -818,16 +824,19 @@ namespace Mono.CSharp {
                ///   Returns an expression that can be used to invoke operator false
                ///   on the expression if it exists.
                /// </summary>
-               static public StaticCallExpr GetOperatorFalse (EmitContext ec, Expression e, Location loc)
+               static public Expression GetOperatorFalse (EmitContext ec, Expression e, Location loc)
                {
                        return GetOperatorTrueOrFalse (ec, e, false, loc);
                }
 
-               static StaticCallExpr GetOperatorTrueOrFalse (EmitContext ec, Expression e, bool is_true, Location loc)
+               static Expression GetOperatorTrueOrFalse (EmitContext ec, Expression e, bool is_true, Location loc)
                {
                        MethodBase method;
                        Expression operator_group;
 
+                       if (TypeManager.IsNullableType (e.Type))
+                               return new Nullable.OperatorTrueOrFalse (e, is_true, loc).Resolve (ec);
+
                        operator_group = MethodLookup (ec, e.Type, is_true ? "op_True" : "op_False", loc);
                        if (operator_group == null)
                                return null;
@@ -853,30 +862,28 @@ namespace Mono.CSharp {
                        if (e == null)
                                return null;
 
-                       Expression converted = e;
-                       if (e.Type != TypeManager.bool_type)
-                               converted = Convert.ImplicitConversion (ec, e, TypeManager.bool_type, new Location (-1));
+                       if (e.Type == TypeManager.bool_type)
+                               return e;
+
+                       Expression converted = Convert.ImplicitConversion (ec, e, TypeManager.bool_type, new Location (-1));
+
+                       if (converted != null)
+                               return converted;
 
                        //
                        // If no implicit conversion to bool exists, try using `operator true'
                        //
-                       if (converted == null){
-                               Expression operator_true = Expression.GetOperatorTrue (ec, e, loc);
-                               if (operator_true == null){
-                                       Report.Error (
-                                               31, loc, "Can not convert the expression to a boolean");
-                                       return null;
-                               }
-                               e = operator_true;
-                       } else
-                               e = converted;
-
-                       return e;
+                       Expression operator_true = Expression.GetOperatorTrue (ec, e, loc);
+                       if (operator_true == null){
+                               Report.Error (31, loc, "Can not convert the expression to a boolean");
+                               return null;
+                       }
+                       return operator_true;
                }
                
-               static string ExprClassName (ExprClass c)
+               public string ExprClassName ()
                {
-                       switch (c){
+                       switch (eclass){
                        case ExprClass.Invalid:
                                return "Invalid";
                        case ExprClass.Value:
@@ -906,11 +913,7 @@ namespace Mono.CSharp {
                /// </summary>
                public void Error_UnexpectedKind (string expected, Location loc)
                {
-                       string kind = "Unknown";
-                       
-                       kind = ExprClassName (eclass);
-
-                       Report.Error (118, loc, "Expression denotes a `" + kind +
+                       Report.Error (118, loc, "Expression denotes a `" + ExprClassName () +
                               "' where a `" + expected + "' was expected");
                }
 
@@ -929,9 +932,6 @@ namespace Mono.CSharp {
                        if ((flags & ResolveFlags.MethodGroup) != 0)
                                valid.Add ("method group");
 
-                       if ((flags & ResolveFlags.SimpleName) != 0)
-                               valid.Add ("simple name");
-
                        if (valid.Count == 0)
                                valid.Add ("unknown");
 
@@ -944,9 +944,7 @@ namespace Mono.CSharp {
                                sb.Append (valid [i]);
                        }
 
-                       string kind = ExprClassName (eclass);
-
-                       Error (119, "Expression denotes a `" + kind + "' where " +
+                       Report.Error (119, loc, "Expression denotes a `" + ExprClassName () + "' where " +
                               "a `" + sb.ToString () + "' was expected");
                }
                
@@ -1024,7 +1022,7 @@ namespace Mono.CSharp {
                                }
 
                                s = v.ToString ();
-                       } else if (c is UIntConstant){
+                       } else if (c is UIntConstant){
                                uint v = ((UIntConstant) c).Value;
 
                                if (target_type == TypeManager.int32_type){
@@ -1050,7 +1048,7 @@ namespace Mono.CSharp {
                                else if (target_type == TypeManager.uint64_type)
                                        return (ulong) v;
                                s = v.ToString ();
-                       } else if (c is LongConstant){ 
+                       } else if (c is LongConstant){ 
                                long v = ((LongConstant) c).Value;
 
                                if (target_type == TypeManager.int32_type){
@@ -1079,7 +1077,7 @@ namespace Mono.CSharp {
                                                return (ulong) v;
                                }
                                s = v.ToString ();
-                       } else if (c is ULongConstant){
+                       } else if (c is ULongConstant){
                                ulong v = ((ULongConstant) c).Value;
 
                                if (target_type == TypeManager.int32_type){
@@ -1446,6 +1444,7 @@ namespace Mono.CSharp {
                public EmptyCast (Expression child, Type return_type)
                {
                        eclass = child.eclass;
+                       loc = child.Location;
                        type = return_type;
                        this.child = child;
                }
@@ -1501,6 +1500,12 @@ namespace Mono.CSharp {
                        child.Emit (ec);
                }
 
+               public override bool IsDefaultValue {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
                public override bool IsNegative {
                        get {
                                return false;
@@ -1637,7 +1642,13 @@ namespace Mono.CSharp {
                {
                        return Child.ConvertToInt ();
                }
-               
+
+               public override bool IsDefaultValue {
+                       get {
+                               return Child.IsDefaultValue;
+                       }
+               }
+
                public override bool IsZeroInteger {
                        get { return Child.IsZeroInteger; }
                }
@@ -2005,54 +2016,17 @@ namespace Mono.CSharp {
        }
        
        /// <summary>
-       ///   SimpleName expressions are initially formed of a single
-       ///   word and it only happens at the beginning of the expression.
+       ///   SimpleName expressions are formed of a single word and only happen at the beginning 
+       ///   of a dotted-name.
        /// </summary>
-       ///
-       /// <remarks>
-       ///   The expression will try to be bound to a Field, a Method
-       ///   group or a Property.  If those fail we pass the name to our
-       ///   caller and the SimpleName is compounded to perform a type
-       ///   lookup.  The idea behind this process is that we want to avoid
-       ///   creating a namespace map from the assemblies, as that requires
-       ///   the GetExportedTypes function to be called and a hashtable to
-       ///   be constructed which reduces startup time.  If later we find
-       ///   that this is slower, we should create a `NamespaceExpr' expression
-       ///   that fully participates in the resolution process. 
-       ///   
-       ///   For example `System.Console.WriteLine' is decomposed into
-       ///   MemberAccess (MemberAccess (SimpleName ("System"), "Console"), "WriteLine")
-       ///   
-       ///   The first SimpleName wont produce a match on its own, so it will
-       ///   be turned into:
-       ///   MemberAccess (SimpleName ("System.Console"), "WriteLine").
-       ///   
-       ///   System.Console will produce a TypeExpr match.
-       ///   
-       ///   The downside of this is that we might be hitting `LookupType' too many
-       ///   times with this scheme.
-       /// </remarks>
        public class SimpleName : Expression {
                public string Name;
                public readonly TypeArguments Arguments;
 
-               //
-               // If true, then we are a simple name, not composed with a ".
-               //
-               bool is_base;
-
-               public SimpleName (string a, string b, Location l)
-               {
-                       Name = String.Concat (a, ".", b);
-                       loc = l;
-                       is_base = false;
-               }
-               
                public SimpleName (string name, Location l)
                {
                        Name = name;
                        loc = l;
-                       is_base = true;
                }
 
                public SimpleName (string name, TypeArguments args, Location l)
@@ -2060,7 +2034,6 @@ namespace Mono.CSharp {
                        Name = name;
                        Arguments = args;
                        loc = l;
-                       is_base = true;
                }
 
                public static void Error_ObjectRefRequired (EmitContext ec, Location l, string name)
@@ -2111,60 +2084,23 @@ namespace Mono.CSharp {
                        return SimpleNameResolve (ec, null, true, intermediate);
                }
 
-               public override Expression ResolveAsTypeStep (EmitContext ec)
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        DeclSpace ds = ec.DeclSpace;
-                       NamespaceEntry ns = ds.NamespaceEntry;
-                       Type t;
-                       IAlias alias_value;
-
-                       //
-                       // Since we are cheating: we only do the Alias lookup for
-                       // namespaces if the name does not include any dots in it
-                       //
-                       if (ns != null && is_base)
-                               alias_value = ns.LookupAlias (Name);
-                       else
-                               alias_value = null;
+                       FullNamedExpression dt;
 
-                       TypeParameterExpr generic_type = ds.LookupGeneric (Name, loc);
-                       if (generic_type != null)
-                               return generic_type.ResolveAsTypeTerminal (ec);
+                       dt = ds.LookupGeneric (Name, loc);
+                       if (dt != null)
+                               return dt.ResolveAsTypeStep (ec);
 
-                       if (ec.ResolvingTypeTree){
-                               int errors = Report.Errors;
-                               Type dt = ds.FindType (loc, Name);
-                               
-                               if (Report.Errors != errors)
-                                       return null;
-                               
-                               if (dt != null)
-                                       return new TypeExpression (dt, loc);
-
-                               if (alias_value != null){
-                                       if (alias_value.IsType)
-                                               return alias_value.ResolveAsType (ec);
-                                       if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
-                                               return new TypeExpression (t, loc);
-                               }
-                       }
-
-                       if ((t = RootContext.LookupType (ds, Name, true, loc)) != null)
-                               return new TypeExpression (t, loc);
-
-                       if (alias_value != null) {
-                               if (alias_value.IsType)
-                                       return alias_value.ResolveAsType (ec);
-                               if ((t = RootContext.LookupType (ds, alias_value.Name, true, loc)) != null)
-                                       return new TypeExpression (t, loc);
-                               
-                               // we have alias value, but it isn't Type, so try if it's namespace
-                               return new SimpleName (alias_value.Name, loc);
-                       }
+                       int errors = Report.Errors;
+                       dt = ec.ResolvingTypeTree 
+                               ? ds.FindType (loc, Name)
+                               : ds.LookupType (Name, loc, /*silent=*/ true, /*ignore_cs0104=*/ false);
+                       if (Report.Errors != errors)
+                               return null;
 
-                       // No match, maybe our parent can compose us
-                       // into something meaningful.
-                       return this;
+                       return dt;
                }
 
                Expression SimpleNameResolve (EmitContext ec, Expression right_side,
@@ -2176,12 +2112,9 @@ namespace Mono.CSharp {
 
                        Block current_block = ec.CurrentBlock;
                        if (current_block != null){
-                               //LocalInfo vi = current_block.GetLocalInfo (Name);
-                               if (is_base &&
-                                   current_block.IsVariableNameUsedInChildBlock(Name)) {
+                               if (current_block.IsVariableNameUsedInChildBlock (Name)) {
                                        Report.Error (135, Location,
-                                                     "'{0}' has a different meaning in a " +
-                                                     "child block", Name);
+                                                     "'{0}' has a different meaning in a child block", Name);
                                        return null;
                                }
                        }
@@ -2246,6 +2179,8 @@ namespace Mono.CSharp {
                        //
 
                        DeclSpace lookup_ds = ec.DeclSpace;
+                       Type almost_matched_type = null;
+                       ArrayList almost_matched = null;
                        do {
                                if (lookup_ds.TypeBuilder == null)
                                        break;
@@ -2254,6 +2189,11 @@ namespace Mono.CSharp {
                                if (e != null)
                                        break;
 
+                               if (almost_matched == null && almostMatchedMembers.Count > 0) {
+                                       almost_matched_type = lookup_ds.TypeBuilder;
+                                       almost_matched = (ArrayList) almostMatchedMembers.Clone ();
+                               }
+
                                lookup_ds =lookup_ds.Parent;
                        } while (lookup_ds != null);
 
@@ -2261,32 +2201,20 @@ namespace Mono.CSharp {
                                e = MemberLookup (ec, ec.ContainerType, Name, loc);
 
                        if (e == null) {
-                               //
-                               // Since we are cheating (is_base is our hint
-                               // that we are the beginning of the name): we
-                               // only do the Alias lookup for namespaces if
-                               // the name does not include any dots in it
-                               //
-                               NamespaceEntry ns = ec.DeclSpace.NamespaceEntry;
-                               if (is_base && ns != null){
-                                       IAlias alias_value = ns.LookupAlias (Name);
-                                       if (alias_value != null){
-                                               if (alias_value.IsType)
-                                                       return alias_value.ResolveAsType (ec);
-
-                                               Name = alias_value.Name;
-                                               Type t;
-
-                                               if ((t = TypeManager.LookupType (Name)) != null)
-                                                       return new TypeExpression (t, loc);
-                                       
-                                               // No match, maybe our parent can compose us
-                                               // into something meaningful.
-                                               return this;
-                                       }
+                               if (almost_matched == null && almostMatchedMembers.Count > 0) {
+                                       almost_matched_type = ec.ContainerType;
+                                       almost_matched = (ArrayList) almostMatchedMembers.Clone ();
                                }
+                               e = ResolveAsTypeStep (ec);
+                       }
 
-                               return ResolveAsTypeStep (ec);
+                       if (e == null) {
+                               if (almost_matched != null)
+                                       almostMatchedMembers = almost_matched;
+                               if (almost_matched_type == null)
+                                       almost_matched_type = ec.ContainerType;
+                               MemberLookupFailed (ec, null, almost_matched_type, ((SimpleName) this).Name, ec.DeclSpace.Name, loc);
+                               return null;
                        }
 
                        if (e is TypeExpr)
@@ -2357,12 +2285,27 @@ namespace Mono.CSharp {
                        return Name;
                }
        }
+
+       /// <summary>
+       ///   Represents a namespace or a type.  The name of the class was inspired by
+       ///   section 10.8.1 (Fully Qualified Names).
+       /// </summary>
+       public abstract class FullNamedExpression : Expression {
+               public override FullNamedExpression ResolveAsTypeStep (EmitContext ec)
+               {
+                       return this;
+               }
+
+               public abstract string FullName {
+                       get;
+               }
+       }
        
        /// <summary>
        ///   Fully resolved expression that evaluates to a type
        /// </summary>
-       public abstract class TypeExpr : Expression, IAlias {
-               override public Expression ResolveAsTypeStep (EmitContext ec)
+       public abstract class TypeExpr : FullNamedExpression {
+               override public FullNamedExpression ResolveAsTypeStep (EmitContext ec)
                {
                        TypeExpr t = DoResolveAsTypeStep (ec);
                        if (t == null)
@@ -2429,6 +2372,15 @@ namespace Mono.CSharp {
 
                protected abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
 
+               public virtual Type ResolveType (EmitContext ec)
+               {
+                       TypeExpr t = ResolveAsTypeTerminal (ec);
+                       if (t == null)
+                               return null;
+
+                       return t.Type;
+               }
+
                public abstract string Name {
                        get;
                }
@@ -2451,18 +2403,9 @@ namespace Mono.CSharp {
                {
                        return Name;
                }
-
-               bool IAlias.IsType {
-                       get { return true; }
-               }
-
-               TypeExpr IAlias.ResolveAsType (EmitContext ec)
-               {
-                       return ResolveAsTypeTerminal (ec);
-               }
        }
 
-       public class TypeExpression : TypeExpr, IAlias {
+       public class TypeExpression : TypeExpr {
                public TypeExpression (Type t, Location l)
                {
                        Type = t;
@@ -2481,7 +2424,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               string IAlias.Name {
+               public override string FullName {
                        get {
                                return Type.FullName != null ? Type.FullName : Type.Name;
                        }
@@ -2504,10 +2447,13 @@ namespace Mono.CSharp {
                protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
                        if (type == null) {
-                               type = RootContext.LookupType (
-                                       ec.DeclSpace, name, false, Location.Null);
-                               if (type == null)
+                               FullNamedExpression t = ec.DeclSpace.LookupType (
+                                       name, Location.Null, /*silent=*/ false, /*ignore_cs0104=*/ false);
+                               if (t == null)
                                        return null;
+                               if (!(t is TypeExpr))
+                                       return null;
+                               type = ((TypeExpr) t).ResolveType (ec);
                        }
 
                        return this;
@@ -2518,6 +2464,12 @@ namespace Mono.CSharp {
                                return name;
                        }
                }
+
+               public override string FullName {
+                       get {
+                               return name;
+                       }
+               }
        }
 
        /// <summary>
@@ -2530,13 +2482,13 @@ namespace Mono.CSharp {
                { }
        }
 
-       public class TypeAliasExpression : TypeExpr, IAlias {
-               IAlias alias;
+       public class TypeAliasExpression : TypeExpr {
+               FullNamedExpression alias;
                TypeExpr texpr;
                TypeArguments args;
                string name;
 
-               public TypeAliasExpression (IAlias alias, TypeArguments args, Location l)
+               public TypeAliasExpression (FullNamedExpression alias, TypeArguments args, Location l)
                {
                        this.alias = alias;
                        this.args = args;
@@ -2544,18 +2496,22 @@ namespace Mono.CSharp {
 
                        eclass = ExprClass.Type;
                        if (args != null)
-                               name = alias.Name + "<" + args.ToString () + ">";
+                               name = alias.FullName + "<" + args.ToString () + ">";
                        else
-                               name = alias.Name;
+                               name = alias.FullName;
                }
 
                public override string Name {
+                       get { return alias.FullName; }
+               }
+
+               public override string FullName {
                        get { return name; }
                }
 
                protected override TypeExpr DoResolveAsTypeStep (EmitContext ec)
                {
-                       texpr = alias.ResolveAsType (ec);
+                       texpr = alias.ResolveAsTypeTerminal (ec);
                        if (texpr == null)
                                return null;
 
@@ -3091,7 +3047,15 @@ namespace Mono.CSharp {
                                if (is_volatile)
                                        ig.Emit (OpCodes.Volatile);
 
-                               ig.Emit (OpCodes.Ldfld, FieldInfo);
+                               IFixedBuffer ff = AttributeTester.GetFixedBuffer (FieldInfo);
+                               if (ff != null)
+                               {
+                                       ig.Emit (OpCodes.Ldflda, FieldInfo);
+                                       ig.Emit (OpCodes.Ldflda, ff.Element);
+                               }
+                               else {
+                                       ig.Emit (OpCodes.Ldfld, FieldInfo);
+                               }
                        }
 
                        if (leave_copy) {
@@ -3260,6 +3224,8 @@ namespace Mono.CSharp {
                LocalTemporary temp;
                bool prepared;
 
+               internal static PtrHashtable AccessorTable = new PtrHashtable (); 
+
                public PropertyExpr (EmitContext ec, PropertyInfo pi, Location l)
                {
                        PropertyInfo = pi;
@@ -3343,10 +3309,10 @@ namespace Mono.CSharp {
                                PropertyInfo pi = (PropertyInfo) group [0];
 
                                if (getter == null)
-                                       getter = pi.GetGetMethod (true);;
+                                       getter = pi.GetGetMethod (true);
 
                                if (setter == null)
-                                       setter = pi.GetSetMethod (true);;
+                                       setter = pi.GetSetMethod (true);
 
                                MethodInfo accessor = getter != null ? getter : setter;
 
@@ -3363,7 +3329,15 @@ namespace Mono.CSharp {
                {
                        FindAccessors (ec.ContainerType);
 
-                       is_static = getter != null ? getter.IsStatic : setter.IsStatic;
+                       if (getter != null) {
+                               AccessorTable [getter] = PropertyInfo;
+                               is_static = getter.IsStatic;
+                       }
+
+                       if (setter != null) {
+                               AccessorTable [setter] = PropertyInfo;
+                               is_static = setter.IsStatic;
+                       }
                }
 
                bool InstanceResolve (EmitContext ec, bool must_do_cs1540_check)
@@ -3697,6 +3671,11 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public override Expression DoResolveLValue (EmitContext ec, Expression right_side)
+               {
+                       return DoResolve (ec);
+               }
+
                public override Expression DoResolve (EmitContext ec)
                {
                        if (instance_expr != null) {
@@ -3723,7 +3702,7 @@ namespace Mono.CSharp {
                public override void Emit (EmitContext ec)
                {
                        if (instance_expr is This)
-                               Report.Error (79, loc, "The event `{0}' can only appear on the left hand side of += or -=, try calling the actual delegate");
+                               Report.Error (79, loc, "The event `{0}' can only appear on the left hand side of += or -=, try calling the actual delegate", Name);
                        else
                                Report.Error (70, loc, "The event `{0}' can only appear on the left hand side of += or -= "+
                                              "(except on the defining type)", Name);