[656918] Implement expression tree access to hoisted variable reference
authorMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 16:03:56 +0000 (16:03 +0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 16:05:47 +0000 (16:05 +0000)
mcs/mcs/anonymous.cs
mcs/mcs/delegate.cs
mcs/tests/gtest-etree-07.cs
mcs/tests/gtest-etree-25.cs [new file with mode: 0644]
mcs/tests/ver-il-dmcs.xml
mcs/tests/ver-il-gmcs.xml

index bbd0b70cb32399cc4fb13ae2c5fa6f2cccfd30d2..31f73896fd918fab91033154a9d559c6fe69327d 100644 (file)
@@ -584,7 +584,7 @@ namespace Mono.CSharp {
 
                        public override Expression CreateExpressionTree (ResolveContext ec)
                        {
-                               throw new NotSupportedException ("ET");
+                               return hv.CreateExpressionTree ();
                        }
 
                        protected override Expression DoResolve (ResolveContext ec)
index 1d7be8f894b569cc3e0cbf18c48550c990f62d62..0a7eb732e702d135e5ed376198075f37162bacca 100644 (file)
@@ -455,7 +455,7 @@ namespace Mono.CSharp {
                        if (method_group.InstanceExpression == null)
                                args.Add (new Argument (new NullLiteral (loc)));
                        else
-                               args.Add (new Argument (method_group.InstanceExpression.CreateExpressionTree (ec)));
+                               args.Add (new Argument (method_group.InstanceExpression));
 
                        args.Add (new Argument (method_group.CreateExpressionTree (ec)));
                        Expression e = new Invocation (ma, args).Resolve (ec);
index 14455fac6a1130ad23903c599e4ece4d3dd85617..74a4d1ad1f4f4788e16453eb942c84357efa6f5c 100644 (file)
@@ -27,11 +27,16 @@ class C
        int TestInstance ()
        {
                Expression<Func<EmptyDelegate>> e = () => M;
-               Console.WriteLine (e.Body.ToString ());
                if (e.Body.ToString () != "Convert(CreateDelegate(EmptyDelegate, value(C), Void M()))")
                        return 1;
                
                e.Compile () ();
+               
+               Expression<Func<C, EmptyDelegate>> e2 = (l) => l.M;
+               if (e2.Body.ToString () != "Convert(CreateDelegate(EmptyDelegate, l, Void M()))")
+                       return 2;
+               
+               e2.Compile () (this);
                return 0;
        }
        
diff --git a/mcs/tests/gtest-etree-25.cs b/mcs/tests/gtest-etree-25.cs
new file mode 100644 (file)
index 0000000..40ffe66
--- /dev/null
@@ -0,0 +1,37 @@
+using System;
+using System.Linq.Expressions;
+
+class Foo
+{
+       public void OnBaz (IBaz baz)
+       {
+       }
+}
+
+interface IBar
+{
+       void RunOnBaz (Action<IBaz> action);
+}
+
+interface IBaz
+{
+}
+
+class C : IBar
+{
+       public void RunOnBaz (Action<IBaz> action)
+       {
+               action (null);
+       }
+       
+    static int Main ()
+    {
+               var foo = new Foo ();
+
+               Expression<Action<IBar>> e = bar => bar.RunOnBaz (foo.OnBaz);
+               e.Compile () (new C ());
+               
+               return 0;
+    }
+}
+
index 24bc62e0aa2fded8f8a99eec64e846f7ca66cac3..408c76a5d6129cd12b383777ce910e34ccb2e0ab 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-333.cs">
+    <type name="Program">
+      <method name="Void Main()">
+        <size>13</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-334.cs">
     <type name="Test">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-353.cs">
+    <type name="A`3[D1,D2,D3]">
+      <method name="Void Foo[T]()">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="B`1[DD2]">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Void Foo[T]()">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Program">
+      <method name="Void Main()">
+        <size>11</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-354.cs">
+    <type name="M">
+      <method name="Void IC.Method(System.Int32[])">
+        <size>1</size>
+      </method>
+      <method name="System.String IA&lt;string&gt;.Method(Int32)">
+        <size>6</size>
+      </method>
+      <method name="Void IB.Method(Int32)">
+        <size>6</size>
+      </method>
+      <method name="Void Main()">
+        <size>23</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-355.cs">
     <type name="A">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-374.cs">
+    <type name="Z">
+      <method name="Z IGenericInterface&lt;Z&gt;.Start()">
+        <size>2</size>
+      </method>
+      <method name="Void Stop()">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="A`3[Y,Y2,W]">
+      <method name="Void SomeOperation(W)">
+        <size>28</size>
+      </method>
+      <method name="Void SomeOtherOperation(Y)">
+        <size>28</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="Foo">
+      <method name="Int32 Main()">
+        <size>30</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-375.cs">
     <type name="X">
       <method name="Void .ctor()">
       </method>
     </type>
   </test>
+  <test name="gtest-415.cs">
+    <type name="Foo">
+      <method name="Int32 Main()">
+        <size>32</size>
+      </method>
+      <method name="Boolean Bar[T](T)">
+        <size>15</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-418.cs">
     <type name="N.Nested">
       <method name="Void .ctor()">
         <size>3</size>
       </method>
       <method name="Int32 Main()">
-        <size>519</size>
+        <size>536</size>
       </method>
     </type>
     <type name="EmptyDelegate">
         <size>0</size>
       </method>
     </type>
+    <type name="C">
+      <method name="Void M()">
+        <size>1</size>
+      </method>
+      <method name="Int32 TestInstance()">
+        <size>321</size>
+      </method>
+    </type>
   </test>
   <test name="gtest-etree-08.cs">
     <type name="Foo">
       </method>
     </type>
   </test>
+  <test name="gtest-etree-25.cs">
+    <type name="Foo">
+      <method name="Void OnBaz(IBaz)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Void RunOnBaz(System.Action`1[IBaz])">
+        <size>8</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>214</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C+&lt;Main&gt;c__AnonStorey0">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-exmethod-01.cs">
     <type name="SimpleTest">
       <method name="System.String Prefix(System.String, System.String)">
       <method name="Void .ctor()">
         <size>7</size>
       </method>
-      <method name="Void Main()">
-        <size>1</size>
+      <method name="Int32 Main()">
+        <size>84</size>
       </method>
     </type>
   </test>
       </method>
     </type>
   </test>
-  <test name="test-679.cs">
-    <type name="Program">
-      <method name="Void .ctor()">
-        <size>7</size>
-      </method>
-      <method name="Int32 Main()">
-        <size>12</size>
-      </method>
-    </type>
-  </test>
   <test name="test-68.cs">
     <type name="Y">
       <method name="Void .ctor()">
index 3c7af2f804dcb9f62b323d69833d93bd4a247cb1..d8ea2e4e447848d40ab960a2a0ee50ddc162ca99 100644 (file)
         <size>3</size>
       </method>
       <method name="Int32 Main()">
-        <size>564</size>
+        <size>581</size>
       </method>
     </type>
     <type name="EmptyDelegate">
         <size>0</size>
       </method>
     </type>
+    <type name="C">
+      <method name="Void M()">
+        <size>1</size>
+      </method>
+      <method name="Int32 TestInstance()">
+        <size>351</size>
+      </method>
+    </type>
   </test>
   <test name="gtest-etree-08.cs">
     <type name="Foo">
       </method>
     </type>
   </test>
+  <test name="gtest-etree-25.cs">
+    <type name="Foo">
+      <method name="Void OnBaz(IBaz)">
+        <size>1</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C">
+      <method name="Void RunOnBaz(System.Action`1[IBaz])">
+        <size>8</size>
+      </method>
+      <method name="Int32 Main()">
+        <size>229</size>
+      </method>
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="C+&lt;Main&gt;c__AnonStorey0">
+      <method name="Void .ctor()">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-exmethod-01.cs">
     <type name="SimpleTest">
       <method name="System.String Prefix(System.String, System.String)">