Skip to content

Commit

Permalink
[mcs] Constrain expression bodied accessors to C# 7 (#9547)
Browse files Browse the repository at this point in the history
* [mcs] Expression body for accessors are a C# 7 feature

* [mcs] Add tests for constraining expression accessors to C# 7
  • Loading branch information
jbevain authored and akoeplinger committed Jul 14, 2018
1 parent ff26178 commit 0f87948
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mcs/errors/cs1644-64.cs
@@ -0,0 +1,13 @@
// CS1644: Feature `expression body property accessor' cannot be used because it is not part of the C# 6.0 language specification
// Line: 11
// Compiler options: -langversion:6

using System;

class C
{
public int Integer
{
get => 0;
}
}
13 changes: 13 additions & 0 deletions mcs/errors/cs1644-65.cs
@@ -0,0 +1,13 @@
// CS1644: Feature `expression body property accessor' cannot be used because it is not part of the C# 6.0 language specification
// Line: 11
// Compiler options: -langversion:6

using System;

class C
{
public int this[int i]
{
get => i;
}
}
17 changes: 17 additions & 0 deletions mcs/errors/cs1644-66.cs
@@ -0,0 +1,17 @@
// CS1644: Feature `expression body event accessor' cannot be used because it is not part of the C# 6.0 language specification
// Line: 11
// Compiler options: -langversion:6

using System;

class C
{
public event EventHandler Event
{
add => Ignore ();
}

static void Ignore ()
{
}
}
10 changes: 10 additions & 0 deletions mcs/mcs/cs-parser.jay
Expand Up @@ -2207,6 +2207,11 @@ set_accessor_declaration
accessor_body
: block
| expression_block
{
if (lang_version < LanguageVersion.V_7) {
FeatureIsNotAvailable (GetLocation ($1), "expression body property accessor");
}
}
| SEMICOLON
{
// TODO: lbag
Expand Down Expand Up @@ -2876,6 +2881,11 @@ event_accessor_block
}
| block
| expression_block
{
if (lang_version < LanguageVersion.V_7) {
FeatureIsNotAvailable (GetLocation ($1), "expression body event accessor");
}
}
;

attributes_without_members
Expand Down

0 comments on commit 0f87948

Please sign in to comment.