[mcs] Add expression bodied syntax for accessors. Fixes #54991
authorMarek Safar <marek.safar@gmail.com>
Mon, 22 May 2017 21:29:54 +0000 (23:29 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 22 May 2017 21:31:07 +0000 (23:31 +0200)
mcs/errors/cs1043.cs
mcs/mcs/cs-parser.jay
mcs/tests/test-expression-bodied-03.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index e1fd9567feafa53bfd859ad33aa66627ed94c542..746d04d510dc06bf780bee1e57c2c4f721b4040c 100755 (executable)
@@ -1,4 +1,4 @@
-// CS1043: Invalid accessor body `1', expecting `;' or `{'
+// CS1043: Invalid accessor body `1', expecting `;', `{', or `=>'
 // Line: 6
 
 class C
index a9748379086bbde75a62e2c78329576af82f3755..91e6a23b1406f17bcc0ff188c1161ba949f1a98d 100644 (file)
@@ -2073,7 +2073,8 @@ set_accessor_declaration
        ;
 
 accessor_body
-       : block 
+       : block
+       | expression_block
        | SEMICOLON
          {
                // TODO: lbag
@@ -2086,6 +2087,7 @@ accessor_body
          }
        ;
 
+
 interface_declaration
        : opt_attributes
          opt_modifiers
@@ -2742,7 +2744,8 @@ event_accessor_block
                report.Error (73, lexer.Location, "An add or remove accessor must have a body");
                $$ = null;
          }
-       | block;
+       | block
+       | expression_block
        ;
 
 attributes_without_members
diff --git a/mcs/tests/test-expression-bodied-03.cs b/mcs/tests/test-expression-bodied-03.cs
new file mode 100644 (file)
index 0000000..fdde90c
--- /dev/null
@@ -0,0 +1,20 @@
+using System;
+
+class X
+{
+       int v;
+
+       public int Prop {
+               get => 1;
+               set => v = value;
+       }
+
+       public event Action A {
+               add => v = 1;
+               remove => v = 2;
+       }
+
+       public static void Main ()
+       {               
+       }
+}
\ No newline at end of file
index 25d08a8063e2bc53362fd3eaeca3790b000bae60..4882b788602ee9e5fb99495bac6bd98d1c8d546c 100644 (file)
       </method>
     </type>
   </test>
+  <test name="test-expression-bodied-03.cs">
+    <type name="X">
+      <method name="Int32 get_Prop()" attrs="2182">
+        <size>9</size>
+      </method>
+      <method name="Void set_Prop(Int32)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void add_A(System.Action)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void remove_A(System.Action)" attrs="2182">
+        <size>8</size>
+      </method>
+      <method name="Void Main()" attrs="150">
+        <size>2</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="test-externalias-01.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="150">