[mcs] Use same rules in dynamic context as in normal instance member hidding.
authorMarek Safar <marek.safar@gmail.com>
Fri, 27 Jun 2014 14:46:59 +0000 (16:46 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 30 Jun 2014 15:25:27 +0000 (17:25 +0200)
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/tests/dtest-056.cs
mcs/tests/ver-il-net_4_5.xml

index 456786e94966869af2d55d58c6f7abd19dfc2a3a..32e6c3fcbdf903abbedfe71ac360b34a224bfa7d 100644 (file)
@@ -3901,8 +3901,15 @@ namespace Mono.CSharp {
 
                        // TODO: When in probing mode do IsApplicable only and when called again do VerifyArguments for full error reporting
                        best_candidate = r.ResolveMember<MethodSpec> (ec, ref args);
-                       if (best_candidate == null)
-                               return r.BestCandidateIsDynamic ? this : null;
+                       if (best_candidate == null) {
+                               if (!r.BestCandidateIsDynamic)
+                                       return null;
+
+                               if (simple_name != null && ec.IsStatic)
+                                       InstanceExpression = ProbeIdenticalTypeName (ec, InstanceExpression, simple_name);
+
+                               return this;
+                       }
 
                        // Overload resolver had to create a new method group, all checks bellow have already been executed
                        if (r.BestCandidateNewMethodGroup != null)
@@ -3913,7 +3920,7 @@ namespace Mono.CSharp {
                                        if (best_candidate.IsExtensionMethod && args[0].Expr == InstanceExpression) {
                                                InstanceExpression = null;
                                        } else {
-                                               if (best_candidate.IsStatic && simple_name != null) {
+                                               if (simple_name != null && best_candidate.IsStatic) {
                                                        InstanceExpression = ProbeIdenticalTypeName (ec, InstanceExpression, simple_name);
                                                }
 
index c195d5438a8b063ac48a13aeedfa1d10b82994ec..02b75423df5544c6488c86ae3d024a8bc1149ebc 100644 (file)
@@ -6315,17 +6315,18 @@ namespace Mono.CSharp
 
                                MemberAccess ma = expr as MemberAccess;
                                if (ma != null) {
-                                       var left_type = ma.LeftExpression as TypeExpr;
+                                       var inst = mg.InstanceExpression;
+                                       var left_type = inst as TypeExpr;
                                        if (left_type != null) {
                                                args.Insert (0, new Argument (new TypeOf (left_type.Type, loc).Resolve (ec), Argument.AType.DynamicTypeName));
-                                       } else {
+                                       } else if (inst != null) {
                                                //
                                                // Any value type has to be pass as by-ref to get back the same
                                                // instance on which the member was called
                                                //
-                                               var mod = ma.LeftExpression is IMemoryLocation && TypeSpec.IsValueType (ma.LeftExpression.Type) ?
+                                               var mod = inst is IMemoryLocation && TypeSpec.IsValueType (inst.Type) ?
                                                        Argument.AType.Ref : Argument.AType.None;
-                                               args.Insert (0, new Argument (ma.LeftExpression.Resolve (ec), mod));
+                                               args.Insert (0, new Argument (inst.Resolve (ec), mod));
                                        }
                                } else {        // is SimpleName
                                        if (ec.IsStatic) {
index 6cc71cada25991714f561017aab4368976b2ecb7..2fb1266a0870d9e80dff190fed83ddd4a2d15b47 100644 (file)
@@ -4,6 +4,7 @@ public class C
 {
        public D D { get; private set; }
        public string Value { get; private set; }
+       public Foo Foo { get; set; }
 
        public int Test ()
        {
@@ -11,11 +12,19 @@ public class C
                return D.Foo (d.Value);
        }
 
+       public static int Test2 (dynamic d)
+       {
+               return Foo.Method(d);
+       }
+
        public static int Main ()
        {
                var c = new C ();
                if (c.Test () != 1)
                        return 1;
+
+               if (C.Test2 ("s") != 1)
+                       return 2;
                
                return 0;
        }
@@ -28,3 +37,11 @@ public struct D
                return 1;
        }
 }
+
+public class Foo
+{
+       public static int Method (string s)
+       {
+               return 1;
+       }
+}
index 10a3669b11f0bbcb2b7f9494229919a64436b4a3..5d85247e3a2216780a95965417583fec831246f8 100644 (file)
         <size>253</size>\r
       </method>\r
       <method name="Int32 Main()" attrs="150">\r
-        <size>35</size>\r
+        <size>58</size>\r
       </method>\r
       <method name="Void .ctor()" attrs="6278">\r
         <size>7</size>\r
         <size>10</size>\r
       </method>\r
     </type>\r
+    <type name="C">\r
+      <method name="Foo get_Foo()" attrs="2182">\r
+        <size>14</size>\r
+      </method>\r
+      <method name="Void set_Foo(Foo)" attrs="2182">\r
+        <size>8</size>\r
+      </method>\r
+      <method name="Int32 Test2(System.Object)" attrs="150">\r
+        <size>175</size>\r
+      </method>\r
+    </type>\r
+    <type name="Foo">\r
+      <method name="Int32 Method(System.String)" attrs="150">\r
+        <size>10</size>\r
+      </method>\r
+      <method name="Void .ctor()" attrs="6278">\r
+        <size>7</size>\r
+      </method>\r
+    </type>\r
   </test>\r
   <test name="dtest-057.cs">\r
     <type name="Program">\r