[mcs] Resolve target before resolving collection/dictionary initializers. Fixes ...
authorMarek Safar <marek.safar@gmail.com>
Thu, 8 Oct 2015 13:03:04 +0000 (15:03 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 8 Oct 2015 13:04:45 +0000 (15:04 +0200)
mcs/errors/cs1918.cs
mcs/mcs/expression.cs
mcs/tests/test-dictinit-05.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 245d6bef89a99f165e462f28ddccd2653071497e..b1f325420156192360dd2b3e8513015a706284fe 100644 (file)
@@ -10,7 +10,7 @@ struct S
 class C
 {
        public S Value {
-               set { }
+               set; get;
        }
 
        static void Main ()
index 7241d4c9571f8d1d01422c6ccdecdbd0ac65fbe6..5df7bb0c41e8372e26b2504a18bf583d7c32f769 100644 (file)
@@ -11653,6 +11653,10 @@ namespace Mono.CSharp
                                return null;
 
                        if (source is CollectionOrObjectInitializers) {
+                               target = target.Resolve (ec);
+                               if (target == null)
+                                       return null;
+                               
                                Expression previous = ec.CurrentInitializerVariable;
                                ec.CurrentInitializerVariable = target;
                                source = source.Resolve (ec);
@@ -11662,6 +11666,7 @@ namespace Mono.CSharp
                                        
                                eclass = source.eclass;
                                type = source.Type;
+
                                return this;
                        }
 
@@ -11848,7 +11853,7 @@ namespace Mono.CSharp
                                return false;
                        }
 
-                       target = new IndexerExpr (indexers, type, init, args, loc).Resolve (rc);
+                       target = new IndexerExpr (indexers, type, init, args, loc);
                        return true;
                }
        }
diff --git a/mcs/tests/test-dictinit-05.cs b/mcs/tests/test-dictinit-05.cs
new file mode 100644 (file)
index 0000000..2d05213
--- /dev/null
@@ -0,0 +1,23 @@
+using System.Collections.Generic;
+
+class A {
+       public A ()
+       {
+               Info = new Dictionary<string, int>();
+       }
+
+       public Dictionary<string, int> Info { get; set; }
+}
+
+class X
+{
+       public static void Main ()
+       {
+               var x = new A () {
+                       Info = { 
+                               ["x"] = 1,
+                               ["y"] = 2
+                       }
+               };
+       }
+}
\ No newline at end of file
index 7681bd5e933e23e970833bcc3ef8f0e619fcb9e9..5f67520de7d6cdc755b4364fada13315a71de998 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-dictinit-05.cs">
+    <type name="A">
+      <method name="System.Collections.Generic.Dictionary`2[System.String,System.Int32] get_Info()" attrs="2182">
+        <size>14</size>
+      </method>
+      <method name="Void set_Info(System.Collections.Generic.Dictionary`2[System.String,System.Int32])" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>19</size>
+      </method>
+    </type>
+    <type name="X">
+      <method name="Void Main()" attrs="150">
+        <size>44</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-ex-filter-01.cs">
     <type name="X">
       <method name="Int32 Main()" attrs="150">