* typemanager.cs: Property.GetGetMethod() does not return the method if it
[mono.git] / mcs / mbas / ecore.cs
index 554c800c9cce67d3c4d4983b3b7e504c9e1f005c..428aa286ef98bbbc0ef5b27fc4d07b2df23be2a2 100644 (file)
@@ -8,7 +8,7 @@
 //
 //
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
        using System;
        using System.Collections;
        using System.Diagnostics;
@@ -82,7 +82,7 @@ namespace Mono.CSharp {
                ///   The AddressOf method should generate code that loads
                ///   the address of the object and leaves it on the stack.
                ///
-               ///   The `mode' argument is used to notify the expression
+               ///   The 'mode' argument is used to notify the expression
                ///   of whether this will be used to read from the address or
                ///   write to the address.
                ///
@@ -108,7 +108,7 @@ namespace Mono.CSharp {
                bool IsAssigned (EmitContext ec, Location loc);
 
                /// <summary>
-               ///   Checks whether field `name' in this struct has been assigned.
+               ///   Checks whether field 'name' in this struct has been assigned.
                /// </summary>
                bool IsFieldAssigned (EmitContext ec, string name, Location loc);
 
@@ -122,7 +122,7 @@ namespace Mono.CSharp {
                void SetAssigned (EmitContext ec);
 
                /// <summary>
-               ///   Tells the flow analysis code that field `name' in this struct
+               ///   Tells the flow analysis code that field 'name' in this struct
                ///   has already been assigned atthe current code position.
                /// </summary>
                void SetFieldAssigned (EmitContext ec, string name);
@@ -230,7 +230,7 @@ namespace Mono.CSharp {
 
                /// <summary>
                ///   Utility wrapper routine for Warning, only prints the warning if
-               ///   warnings of level `level' are enabled.
+               ///   warnings of level 'level' are enabled.
                /// </summary>
                public void Warning (int warning, int level, string s)
                {
@@ -241,8 +241,8 @@ namespace Mono.CSharp {
                static public void Error_CannotConvertType (Location loc, Type source, Type target)
                {
                        Report.Error (30, loc, "Cannot convert type '" +
-                                     TypeManager.CSharpName (source) + "' to '" +
-                                     TypeManager.CSharpName (target) + "'");
+                                     TypeManager.MonoBASIC_Name (source) + "' to '" +
+                                     TypeManager.MonoBASIC_Name (target) + "'");
                }
 
                /// <summary>
@@ -268,7 +268,7 @@ namespace Mono.CSharp {
                ///   There are two side effects expected from calling
                ///   Resolve(): the the field variable "eclass" should
                ///   be set to any value of the enumeration
-               ///   `ExprClass' and the type variable should be set
+               ///   'ExprClass' and the type variable should be set
                ///   to a valid type (this is the type of the
                ///   expression).
                /// </remarks>
@@ -302,14 +302,16 @@ namespace Mono.CSharp {
                        bool old_do_flow_analysis = ec.DoFlowAnalysis;
                        if ((flags & ResolveFlags.DisableFlowAnalysis) != 0)
                                ec.DoFlowAnalysis = false;
-
+                       
                        Expression e;
-                       if (this is SimpleName)
-                               e = ((SimpleName) this).DoResolveAllowStatic (ec);
-                       else 
-                               e = DoResolve (ec);
-
-                       ec.DoFlowAnalysis = old_do_flow_analysis;
+                       try {
+                               if (this is SimpleName)
+                                       e = ((SimpleName) this).DoResolveAllowStatic (ec);
+                               else 
+                                       e = DoResolve (ec);
+                       } finally {
+                               ec.DoFlowAnalysis = old_do_flow_analysis;
+                       }
 
                        if (e == null)
                                return null;
@@ -323,17 +325,17 @@ namespace Mono.CSharp {
                                                ec.ContainerType, ec.ContainerType, AllMemberTypes,
                                                AllBindingFlags | BindingFlags.NonPublic, s.Name);
                                        if (lookup != null)
-                                               Error (122, "`" + s.Name + "' " +
+                                               Error (30390, "'" + s.Name + "' " +
                                                       "is inaccessible because of its protection level");
                                        else
-                                               Error (103, "The name `" + s.Name + "' could not be " +
-                                                      "found in `" + ec.DeclSpace.Name + "'");
+                                               Error (30451, "The name '" + s.Name + "' could not be " +
+                                                      "found in '" + ec.DeclSpace.Name + "'");
                                        return null;
                                }
 
                                return s;
                        }
-
+                       
                        if ((e is TypeExpr) || (e is ComposedCast)) {
                                if ((flags & ResolveFlags.Type) == 0) {
                                        e.Error118 (flags);
@@ -353,8 +355,12 @@ namespace Mono.CSharp {
 
                        case ExprClass.MethodGroup:
                                if ((flags & ResolveFlags.MethodGroup) == 0) {
-                                       ((MethodGroupExpr) e).ReportUsageError ();
-                                       return null;
+                                       MethodGroupExpr mg = (MethodGroupExpr) e;
+                                       Invocation i = new Invocation (mg, new ArrayList(), Location.Null);
+                                       Expression te = i.Resolve(ec);
+                                       //((MethodGroupExpr) e).ReportUsageError ();
+                                       //return null;
+                                       return te;
                                }
                                break;
 
@@ -408,8 +414,8 @@ namespace Mono.CSharp {
                                        SimpleName s = (SimpleName) e;
 
                                        Report.Error (
-                                               103, loc,
-                                               "The name `" + s.Name + "' could not be found in `" +
+                                               30451, loc,
+                                               "The name '" + s.Name + "' could not be found in '" +
                                                ec.DeclSpace.Name + "'");
                                        return null;
                                }
@@ -419,8 +425,12 @@ namespace Mono.CSharp {
                                                             " ExprClass is Invalid after resolve");
 
                                if (e.eclass == ExprClass.MethodGroup) {
-                                       ((MethodGroupExpr) e).ReportUsageError ();
-                                       return null;
+                                       MethodGroupExpr mg = (MethodGroupExpr) e;
+                                       Invocation i = new Invocation (mg, new ArrayList(), Location.Null);
+                                       Expression te = i.Resolve(ec);
+                                       return te;
+                                       //((MethodGroupExpr) e).ReportUsageError ();
+                                       //return null;
                                }
 
                                if (e.type == null)
@@ -512,7 +522,7 @@ namespace Mono.CSharp {
                        else if (mi is FieldInfo)
                                return new FieldExpr ((FieldInfo) mi, loc);
                        else if (mi is PropertyInfo)
-                               return new PropertyExpr ((PropertyInfo) mi, loc);
+                               return new PropertyExpr (ec, (PropertyInfo) mi, loc);
                        else if (mi is Type){
                                return new TypeExpr ((System.Type) mi, loc);
                        }
@@ -524,7 +534,7 @@ namespace Mono.CSharp {
                // FIXME: Probably implement a cache for (t,name,current_access_set)?
                //
                // This code could use some optimizations, but we need to do some
-               // measurements.  For example, we could use a delegate to `flag' when
+               // measurements.  For example, we could use a delegate to 'flag' when
                // something can not any longer be a method-group (because it is something
                // else).
                //
@@ -536,7 +546,7 @@ namespace Mono.CSharp {
                //
                //     null on error.
                //
-               // FIXME: When calling MemberLookup inside an `Invocation', we should pass
+               // FIXME: When calling MemberLookup inside an 'Invocation', we should pass
                // the arguments here and have MemberLookup return only the methods that
                // match the argument count/type, unlike we are doing now (we delay this
                // decision).
@@ -555,10 +565,10 @@ namespace Mono.CSharp {
                }
 
                //
-               // Lookup type `t' for code in class `invocation_type'.  Note that it's important
-               // to set `invocation_type' correctly since this method also checks whether the
-               // invoking class is allowed to access the member in class `t'.  When you want to
-               // explicitly do a lookup in the base class, you must set both `t' and `invocation_type'
+               // Lookup type 't' for code in class 'invocation_type'.  Note that it's important
+               // to set 'invocation_type' correctly since this method also checks whether the
+               // invoking class is allowed to access the member in class 't'.  When you want to
+               // explicitly do a lookup in the base class, you must set both 't' and 'invocation_type'
                // to the base class (although a derived class can access protected members of its base
                // class it cannot do so through an instance of the base class (error CS1540)).
                // 
@@ -594,12 +604,12 @@ namespace Mono.CSharp {
                public const BindingFlags AllBindingFlags =
                        BindingFlags.Public |
                        BindingFlags.Static |
-                       BindingFlags.Instance;
+                       BindingFlags.Instance |
+                       BindingFlags.IgnoreCase;
 
                public static Expression MemberLookup (EmitContext ec, Type t, string name, Location loc)
                {
-                       return MemberLookup (ec, ec.ContainerType, t, name,
-                                            AllMemberTypes, AllBindingFlags, loc);
+                       return MemberLookup (ec, ec.ContainerType, t, name, AllMemberTypes, AllBindingFlags, loc);
                }
 
                public static Expression MethodLookup (EmitContext ec, Type t, string name, Location loc)
@@ -640,12 +650,12 @@ namespace Mono.CSharp {
                                          AllBindingFlags | BindingFlags.NonPublic, loc);
                        if (e == null){
                                Report.Error (
-                                       117, loc, "`" + t + "' does not contain a definition " +
-                                       "for `" + name + "'");
+                                       30456, loc, "'" + t + "' does not contain a definition " +
+                                       "for '" + name + "'");
                        } else {
-                               Report.Error (
-                                       122, loc, "`" + t + "." + name +
-                                       "' is inaccessible due to its protection level");
+                                       Report.Error (
+                                               30390, loc, "'" + t + "." + name +
+                                               "' is inaccessible due to its protection level");
                        }
                        
                        return null;
@@ -1031,7 +1041,7 @@ namespace Mono.CSharp {
                {
                        Type expr_type = expr.Type;
 
-                       if (expr_type == TypeManager.void_type)
+                       if (expr_type == null || expr_type == TypeManager.void_type)
                                return false;
                        
                        if (expr_type == target_type)
@@ -1447,7 +1457,7 @@ namespace Mono.CSharp {
 
                /// <summary>
                ///   Computes the MethodGroup for the user-defined conversion
-               ///   operators from source_type to target_type.  `look_for_explicit'
+               ///   operators from source_type to target_type.  'look_for_explicit'
                ///   controls whether we should also include the list of explicit
                ///   operators
                /// </summary>
@@ -1596,9 +1606,9 @@ namespace Mono.CSharp {
                }
                
                /// <summary>
-               ///   Converts implicitly the resolved expression `expr' into the
-               ///   `target_type'.  It returns a new expression that can be used
-               ///   in a context that expects a `target_type'. 
+               ///   Converts implicitly the resolved expression 'expr' into the
+               ///   'target_type'.  It returns a new expression that can be used
+               ///   in a context that expects a 'target_type'. 
                /// </summary>
                static public Expression ConvertImplicit (EmitContext ec, Expression expr,
                                                          Type target_type, Location loc)
@@ -1619,19 +1629,146 @@ namespace Mono.CSharp {
                        e = ImplicitUserConversion (ec, expr, target_type, loc);
                        if (e != null)
                                return e;
+                               
+                       e = RuntimeConversion (ec, expr, target_type, loc);
+                       if (e != null)
+                               return e;                               
 
                        return null;
                }
 
+               /// <summary>
+               ///   Converts the resolved expression 'expr' into the
+               ///   'target_type' using the Microsoft.VisualBasic runtime.
+               ///   It returns a new expression that can be used
+               ///   in a context that expects a 'target_type'. 
+               /// </summary>
+               static private Expression RTConversionExpression (EmitContext ec, string s, Expression expr, Location loc)
+               {
+                       Expression etmp, e;
+                       ArrayList args;
+                       Argument arg;
+                       
+                       etmp = Mono.MonoBASIC.Parser.DecomposeQI("Microsoft.VisualBasic.CompilerServices." + s, loc);
+                       args = new ArrayList();
+                       arg = new Argument (expr, Argument.AType.Expression);
+                       args.Add (arg);
+                       e = (Expression) new Invocation (etmp, args, loc);
+                       e = e.Resolve(ec);      
+                       return (e);             
+               }
                
+               static public bool RuntimeConversionExists (EmitContext ec, Expression expr, Type target_type)
+               {
+                       return (RuntimeConversion (ec, expr, target_type,Location.Null)) != null;       
+               }
+               
+               static public Expression RuntimeConversion (EmitContext ec, Expression expr,
+                                                               Type target_type, Location loc)
+               {
+                       Type expr_type = expr.Type;
+                       TypeCode dest_type = Type.GetTypeCode (target_type);
+                       TypeCode src_type = Type.GetTypeCode (expr_type);
+                       Expression e = null;
+
+                       // VB.NET Objects can be converted to anything by default
+                       // unless, that is, an exception at runtime blows it all
+                       if (src_type == TypeCode.Object) {
+                               Expression cast_type = Mono.MonoBASIC.Parser.DecomposeQI(target_type.ToString(), loc);
+                               Cast ce = new Cast (cast_type, expr, loc);
+                               return ce.Resolve (ec);
+                       }
+                               
+                       switch (dest_type) {
+                               case TypeCode.String:
+                                       switch (src_type) {
+                                               case TypeCode.SByte:                                            
+                                               case TypeCode.Byte:
+                                                       e = RTConversionExpression(ec, "StringType.FromByte", expr, loc);
+                                                       break;  
+                                               case TypeCode.UInt16:
+                                               case TypeCode.Int16:
+                                                       e = RTConversionExpression(ec, "StringType.FromShort", expr, loc);
+                                                       break;          
+                                               case TypeCode.UInt32:                                   
+                                               case TypeCode.Int32:
+                                                       e = RTConversionExpression(ec, "StringType.FromInteger", expr, loc);
+                                                       break;                                                  
+                                               case TypeCode.UInt64:   
+                                               case TypeCode.Int64:
+                                                       e = RTConversionExpression(ec, "StringType.FromLong", expr, loc);
+                                                       break;                                                  
+                                               case TypeCode.Char:
+                                                       e = RTConversionExpression(ec, "StringType.FromChar", expr, loc);
+                                                       break;                                                          
+                                               case TypeCode.Single:
+                                                       e = RTConversionExpression(ec, "StringType.FromSingle", expr, loc);
+                                                       break;          
+                                               case TypeCode.Double:
+                                                       e = RTConversionExpression(ec, "StringType.FromDouble", expr, loc);
+                                                       break;                                                                                                                                                  
+                                               case TypeCode.Boolean:
+                                                       e = RTConversionExpression(ec, "StringType.FromBoolean", expr, loc);
+                                                       break;  
+                                               case TypeCode.DateTime:
+                                                       e = RTConversionExpression(ec, "StringType.FromDate", expr, loc);
+                                                       break;          
+                                               case TypeCode.Decimal:
+                                                       e = RTConversionExpression(ec, "StringType.FromDecimal", expr, loc);
+                                                       break;          
+                                               case TypeCode.Object:
+                                                       e = RTConversionExpression(ec, "StringType.FromObject", expr, loc);
+                                                       break;                                                                                                                                                                                                                          
+                                       }
+                                       break;
+                                       
+                               case TypeCode.Int32:
+                               case TypeCode.UInt32:   
+                                       switch (src_type) {                                             
+                                               case TypeCode.String:                           
+                                                       e = RTConversionExpression(ec, "IntegerType.FromString", expr, loc);
+                                                       break;          
+                                               case TypeCode.Object:                           
+                                                       e = RTConversionExpression(ec, "IntegerType.FromObject", expr, loc);
+                                                       break;                                                                                  
+                                       }
+                                       break;  
+
+                               case TypeCode.Int16:
+                               case TypeCode.UInt16:   
+                                       switch (src_type) {                                             
+                                               case TypeCode.String:                           
+                                                       e = RTConversionExpression(ec, "ShortType.FromString", expr, loc);
+                                                       break;          
+                                               case TypeCode.Object:                           
+                                                       e = RTConversionExpression(ec, "ShortType.FromObject", expr, loc);
+                                                       break;                                                                                  
+                                       }
+                                       break;  
+                               case TypeCode.Byte:
+                                       // Ok, this *is* broken
+                                       e = RTConversionExpression(ec, "ByteType.FromObject", expr, loc);
+                                       break;                                                                                                                                                  
+                       }
+                       
+                       // We must examine separately some types that
+                       // don't have a TypeCode but are supported 
+                       // in the runtime
+                       if (expr_type == typeof(System.String) && target_type == typeof (System.Char[])) {
+                               e = RTConversionExpression(ec, "CharArrayType.FromString", expr, loc);
+                       }
+                       
+                       return e;
+               }
+                                                                                               
                /// <summary>
-               ///   Attempts to apply the `Standard Implicit
-               ///   Conversion' rules to the expression `expr' into
-               ///   the `target_type'.  It returns a new expression
+               ///   Attempts to apply the 'Standard Implicit
+               ///   Conversion' rules to the expression 'expr' into
+               ///   the 'target_type'.  It returns a new expression
                ///   that can be used in a context that expects a
-               ///   `target_type'.
+               ///   'target_type'.
                ///
-               ///   This is different from `ConvertImplicit' in that the
+               ///   This is different from 'ConvertImplicit' in that the
                ///   user defined implicit conversions are excluded. 
                /// </summary>
                static public Expression ConvertImplicitStandard (EmitContext ec, Expression expr,
@@ -1739,15 +1876,15 @@ namespace Mono.CSharp {
 
                static public void Error_CannotConvertImplicit (Location loc, Type source, Type target)
                {
-                       string msg = "Cannot convert implicitly from `"+
-                               TypeManager.CSharpName (source) + "' to `" +
-                               TypeManager.CSharpName (target) + "'";
+                       string msg = "Cannot convert implicitly from '"+
+                               TypeManager.MonoBASIC_Name (source) + "' to '" +
+                               TypeManager.MonoBASIC_Name (target) + "'";
 
                        Report.Error (29, loc, msg);
                }
 
                /// <summary>
-               ///   Attemptes to implicityly convert `target' into `type', using
+               ///   Attemptes to implicityly convert 'target' into 'type', using
                ///   ConvertImplicit.  If there is no implicit conversion, then
                ///   an error is signaled
                /// </summary>
@@ -2180,8 +2317,8 @@ namespace Mono.CSharp {
                }
                
                /// <summary>
-               ///   Performs an explicit conversion of the expression `expr' whose
-               ///   type is expr.Type to `target_type'.
+               ///   Performs an explicit conversion of the expression 'expr' whose
+               ///   type is expr.Type to 'target_type'.
                /// </summary>
                static public Expression ConvertExplicit (EmitContext ec, Expression expr,
                                                          Type target_type, Location loc)
@@ -2227,6 +2364,10 @@ namespace Mono.CSharp {
                                if (t != null)
                                        return t;
                                
+                               t = RuntimeConversion (ec, e, target_type, loc);
+                               if (t != null)
+                                       return t;       
+                                                               
                                Error_CannotConvertType (loc, expr_type, target_type);
                                return null;
                        }
@@ -2283,7 +2424,11 @@ namespace Mono.CSharp {
                        ne = ExplicitUserConversion (ec, expr, target_type, loc);
                        if (ne != null)
                                return ne;
-
+                               
+                       ne = RuntimeConversion (ec, expr, target_type, loc);
+                       if (ne != null)
+                               return ne;
+                                       
                        Error_CannotConvertType (loc, expr_type, target_type);
                        return null;
                }
@@ -2307,6 +2452,10 @@ namespace Mono.CSharp {
                        if (ne != null)
                                return ne;
 
+                       ne = RuntimeConversion (ec, expr, target_type, l);
+                       if (ne != null)
+                               return ne;                              
+
                        Error_CannotConvertType (l, expr.Type, target_type);
                        return null;
                }
@@ -2339,7 +2488,7 @@ namespace Mono.CSharp {
                }
                
                /// <summary>
-               ///   Reports that we were expecting `expr' to be of class `expected'
+               ///   Reports that we were expecting 'expr' to be of class 'expected'
                /// </summary>
                public void Error118 (string expected)
                {
@@ -2347,8 +2496,8 @@ namespace Mono.CSharp {
                        
                        kind = ExprClassName (eclass);
 
-                       Error (118, "Expression denotes a `" + kind +
-                              "' where a `" + expected + "' was expected");
+                       Error (118, "Expression denotes a '" + kind +
+                              "' where a '" + expected + "' was expected");
                }
 
                public void Error118 (ResolveFlags flags)
@@ -2383,14 +2532,14 @@ namespace Mono.CSharp {
 
                        string kind = ExprClassName (eclass);
 
-                       Error (119, "Expression denotes a `" + kind + "' where " +
-                              "a `" + sb.ToString () + "' was expected");
+                       Error (119, "Expression denotes a '" + kind + "' where " +
+                              "a '" + sb.ToString () + "' was expected");
                }
                
                static void Error_ConstantValueCannotBeConverted (Location l, string val, Type t)
                {
-                       Report.Error (31, l, "Constant value `" + val + "' cannot be converted to " +
-                                     TypeManager.CSharpName (t));
+                       Report.Error (31, l, "Constant value '" + val + "' cannot be converted to " +
+                                     TypeManager.MonoBASIC_Name (t));
                }
 
                public static void UnsafeError (Location loc)
@@ -2401,7 +2550,7 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Converts the IntConstant, UIntConstant, LongConstant or
                ///   ULongConstant into the integral target_type.   Notice
-               ///   that we do not return an `Expression' we do return
+               ///   that we do not return an 'Expression' we do return
                ///   a boxed integral type.
                ///
                ///   FIXME: Since I added the new constants, we need to
@@ -2710,7 +2859,7 @@ namespace Mono.CSharp {
                }
 
                //
-               // The stack contains the pointer and the value of type `type'
+               // The stack contains the pointer and the value of type 'type'
                //
                public static void StoreFromPtr (ILGenerator ig, Type type)
                {
@@ -2739,7 +2888,7 @@ namespace Mono.CSharp {
                }
                
                //
-               // Returns the size of type `t' if known, otherwise, 0
+               // Returns the size of type 't' if known, otherwise, 0
                //
                public static int GetTypeSize (Type t)
                {
@@ -2779,7 +2928,7 @@ namespace Mono.CSharp {
                }
                
                //
-               // Converts `source' to an int, uint, long or ulong.
+               // Converts 'source' to an int, uint, long or ulong.
                //
                public Expression ExpressionToArrayArgument (EmitContext ec, Expression source, Location loc)
                {
@@ -2837,7 +2986,7 @@ namespace Mono.CSharp {
        public abstract class ExpressionStatement : Expression {
 
                /// <summary>
-               ///   Requests the expression to be emitted in a `statement'
+               ///   Requests the expression to be emitted in a 'statement'
                ///   context.  This means that no new value is left on the
                ///   stack after invoking this method (constrasted with
                ///   Emit that will always leave a value on the stack).
@@ -3353,10 +3502,10 @@ namespace Mono.CSharp {
        ///   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 this is slower, we should create a 'NamespaceExpr' expression
        ///   that fully participates in the resolution process. 
        ///   
-       ///   For example `System.Console.WriteLine' is decomposed into
+       ///   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
@@ -3365,7 +3514,7 @@ namespace Mono.CSharp {
        ///   
        ///   System.Console will produce a TypeExpr match.
        ///   
-       ///   The downside of this is that we might be hitting `LookupType' too many
+       ///   The downside of this is that we might be hitting 'LookupType' too many
        ///   times with this scheme.
        /// </remarks>
        public class SimpleName : Expression, ITypeExpression {
@@ -3383,12 +3532,12 @@ namespace Mono.CSharp {
                                Report.Error (
                                        236, l,
                                        "A field initializer cannot reference the non-static field, " +
-                                       "method or property `"+name+"'");
+                                       "method or property '"+name+"'");
                        else
                                Report.Error (
                                        120, l,
                                        "An object reference is required " +
-                                       "for the non-static field `"+name+"'");
+                                       "for the non-static field '"+name+"'");
                }
                
                //
@@ -3477,7 +3626,7 @@ namespace Mono.CSharp {
                ///   Local Variables and Parameters are handled at
                ///   parse time, so they never occur as SimpleNames.
                ///
-               ///   The `allow_static' flag is used by MemberAccess only
+               ///   The 'allow_static' flag is used by MemberAccess only
                ///   and it is used to inform us that it is ok for us to 
                ///   avoid the static check, because MemberAccess might end
                ///   up resolving the Name as a Type name and the access as
@@ -3496,7 +3645,7 @@ namespace Mono.CSharp {
                        // Stage 1: Performed by the parser (binding to locals or parameters).
                        //
                        Block current_block = ec.CurrentBlock;
-                       if (current_block != null && current_block.IsVariableDefined (Name)){
+                       if (ec.InvokingOwnOverload == false && current_block != null && current_block.IsVariableDefined (Name)){
                                LocalVariableReference var;
 
                                var = new LocalVariableReference (ec.CurrentBlock, Name, loc);
@@ -3556,6 +3705,34 @@ namespace Mono.CSharp {
                        if (e == null && ec.ContainerType != null)
                                e = MemberLookup (ec, ec.ContainerType, Name, loc);
 
+// #52067 - Start - Trying to solve
+
+                       if (e == null) {
+                               string[] NamespacesInScope = RootContext.SourceBeingCompiled.GetNamespacesInScope(ec.DeclSpace.Namespace.Name);
+                               ArrayList lookups = new ArrayList();
+                               ArrayList typelookups = new ArrayList();
+                               
+                               foreach(Type type in TypeManager.GetPertinentStandardModules(NamespacesInScope)) {
+                                       e = MemberLookup(ec, type, Name, loc);
+                                       if (e != null)  
+                                               lookups.Add(e);
+                                               typelookups.Add(type);
+                               }
+                               if (lookups.Count == 1) { 
+                                       e = (Expression)lookups[0];
+                               } else {
+                                       if (lookups.Count > 1) {
+                                               StringBuilder sb = new StringBuilder();
+                                               foreach(Type type in typelookups)
+                                                       sb.Append("'" + type.FullName + "'");                                           
+                                               Error (-1, "The name '" + Name + "' can be resolved to a member of more than one standard module: " + sb.ToString() + ". Please fully qualify it.");
+                                               return null;
+                                       }
+                               }
+                       }
+
+// #52067 - End
+
                        if (e == null)
                                return DoResolveType (ec);
 
@@ -3576,14 +3753,17 @@ namespace Mono.CSharp {
                                if (!me.IsStatic && (me.InstanceExpression == null))
                                        return e;
 
+/* FIXME    If this is not commented out, it seems that it's not possible to reach class members in mBas.
+            Maybe a grammar-related problem?
+
                                if (!me.IsStatic &&
                                    TypeManager.IsNestedChildOf (me.InstanceExpression.Type, me.DeclaringType)) {
-                                       Error (38, "Cannot access nonstatic member `" + me.Name + "' of " +
-                                              "outer type `" + me.DeclaringType + "' via nested type `" +
+                                       Error (38, "Cannot access nonstatic member '" + me.Name + "' of " +
+                                              "outer type '" + me.DeclaringType + "' via nested type '" +
                                               me.InstanceExpression.Type + "'");
                                        return null;
                                }
-
+*/
                                if (right_side != null)
                                        e = e.DoResolveLValue (ec, right_side);
                                else
@@ -3608,8 +3788,8 @@ namespace Mono.CSharp {
                        // find the name as a namespace
                        //
 
-                       Error (103, "The name `" + Name +
-                              "' does not exist in the class `" +
+                       Error (30451, "The name '" + Name +
+                              "' does not exist in the class '" +
                               ec.DeclSpace.Name + "'");
                }
 
@@ -3733,7 +3913,7 @@ namespace Mono.CSharp {
                }
                
                //
-               // `A method group may have associated an instance expression' 
+               // 'A method group may have associated an instance expression' 
                // 
                public Expression InstanceExpression {
                        get {
@@ -3794,7 +3974,7 @@ namespace Mono.CSharp {
 
                public void ReportUsageError ()
                {
-                       Report.Error (654, loc, "Method `" + Methods [0].DeclaringType + "." +
+                       Report.Error (654, loc, "Method '" + Methods [0].DeclaringType + "." +
                                      Methods [0].Name + "()' is referenced without parentheses");
                }
 
@@ -4096,7 +4276,7 @@ namespace Mono.CSharp {
        
        /// <summary>
        ///   Expression that evaluates to a Property.  The Assign class
-       ///   might set the `Value' expression if we are in an assignment.
+       ///   might set the 'Value' expression if we are in an assignment.
        ///
        ///   This is not an LValue because we need to re-write the expression, we
        ///   can not take data from the stack and store it.  
@@ -4104,29 +4284,23 @@ namespace Mono.CSharp {
        public class PropertyExpr : ExpressionStatement, IAssignMethod, IMemberExpr {
                public readonly PropertyInfo PropertyInfo;
                public bool IsBase;
-               MethodInfo [] Accessors;
+               MethodInfo getter, setter;
                bool is_static;
-               
+               public ArrayList PropertyArgs;
+
                Expression instance_expr;
 
-               public PropertyExpr (PropertyInfo pi, Location l)
+               public PropertyExpr (EmitContext ec, PropertyInfo pi, Location l)
                {
                        PropertyInfo = pi;
                        eclass = ExprClass.PropertyAccess;
+                       PropertyArgs = new ArrayList();
                        is_static = false;
                        loc = l;
-                       Accessors = TypeManager.GetAccessors (pi);
 
-                       if (Accessors != null)
-                               foreach (MethodInfo mi in Accessors){
-                                       if (mi != null)
-                                               if (mi.IsStatic)
-                                                       is_static = true;
-                               }
-                       else
-                               Accessors = new MethodInfo [2];
-                       
                        type = TypeManager.TypeToCoreType (pi.PropertyType);
+
+                       ResolveAccessors (ec);
                }
 
                public string Name {
@@ -4170,7 +4344,7 @@ namespace Mono.CSharp {
                {
                        if (!PropertyInfo.CanWrite){
                                Report.Error (200, loc, 
-                                             "The property `" + PropertyInfo.Name +
+                                             "The property '" + PropertyInfo.Name +
                                              "' can not be assigned to, as it has not set accessor");
                                return false;
                        }
@@ -4178,11 +4352,41 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               void ResolveAccessors (EmitContext ec)
+               {
+                       BindingFlags flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
+                       MemberInfo [] group;
+                       
+                       group = TypeManager.MemberLookup (ec.ContainerType, PropertyInfo.DeclaringType,
+                                                             MemberTypes.Method, flags, "get_" + PropertyInfo.Name);
+
+                       //
+                       // The first method is the closest to us
+                       //
+                       if (group != null && group.Length > 0){
+                               getter = (MethodInfo) group [0];
+
+                               if (getter.IsStatic)
+                                       is_static = true;
+                       }                       
+
+                       //
+                       // The first method is the closest to us
+                       //
+                       group = TypeManager.MemberLookup (ec.ContainerType, PropertyInfo.DeclaringType,
+                                                         MemberTypes.Method, flags, "set_" + PropertyInfo.Name);
+                       if (group != null && group.Length > 0){
+                               setter = (MethodInfo) group [0];
+                               if (setter.IsStatic)
+                                       is_static = true;
+                       }
+               }
+
                override public Expression DoResolve (EmitContext ec)
                {
-                       if (!PropertyInfo.CanRead){
+                       if (getter == null){
                                Report.Error (154, loc, 
-                                             "The property `" + PropertyInfo.Name +
+                                             "The property '" + PropertyInfo.Name +
                                              "' can not be used in " +
                                              "this context because it lacks a get accessor");
                                return null;
@@ -4204,9 +4408,9 @@ namespace Mono.CSharp {
 
                override public Expression DoResolveLValue (EmitContext ec, Expression right_side)
                {
-                       if (!PropertyInfo.CanWrite){
+                       if (setter == null){
                                Report.Error (154, loc, 
-                                             "The property `" + PropertyInfo.Name +
+                                             "The property '" + PropertyInfo.Name +
                                              "' can not be used in " +
                                              "this context because it lacks a set accessor");
                                return null;
@@ -4223,13 +4427,11 @@ namespace Mono.CSharp {
 
                override public void Emit (EmitContext ec)
                {
-                       MethodInfo method = Accessors [0];
-
                        //
-                       // Special case: length of single dimension array is turned into ldlen
+                       // Special case: length of single dimension array property is turned into ldlen
                        //
-                       if ((method == TypeManager.system_int_array_get_length) ||
-                           (method == TypeManager.int_array_get_length)){
+                       if ((getter == TypeManager.system_int_array_get_length) ||
+                           (getter == TypeManager.int_array_get_length)){
                                Type iet = instance_expr.Type;
 
                                //
@@ -4242,9 +4444,7 @@ namespace Mono.CSharp {
                                        return;
                                }
                        }
-
-                       Invocation.EmitCall (ec, IsBase, IsStatic, instance_expr, method, null, loc);
-                       
+                       Invocation.EmitCall (ec, IsBase, IsStatic, instance_expr, getter, null, PropertyArgs, loc);
                }
 
                //
@@ -4254,9 +4454,9 @@ namespace Mono.CSharp {
                {
                        Argument arg = new Argument (source, Argument.AType.Expression);
                        ArrayList args = new ArrayList ();
-
+//HERE
                        args.Add (arg);
-                       Invocation.EmitCall (ec, IsBase, IsStatic, instance_expr, Accessors [1], args, loc);
+                       Invocation.EmitCall (ec, IsBase, IsStatic, instance_expr, setter, args, PropertyArgs,loc);
                }
 
                override public void EmitStatement (EmitContext ec)
@@ -4341,7 +4541,7 @@ namespace Mono.CSharp {
 
                public override void Emit (EmitContext ec)
                {
-                       Report.Error (70, loc, "The event `" + Name + "' can only appear on the left hand side of += or -= (except on the defining type)");
+                       Report.Error (70, loc, "The event '" + Name + "' can only appear on the left hand side of += or -= (except on the defining type)");
                }
 
                public void EmitAddOrRemove (EmitContext ec, Expression source)
@@ -4361,4 +4561,4 @@ namespace Mono.CSharp {
                                        ec, false, IsStatic, instance_expr, remove_accessor, args, loc);
                }
        }
-}      
+}