Skip to content

Commit

Permalink
Move langversion check to the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
alrz committed May 4, 2021
1 parent 4897191 commit d3f1e7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,6 @@ private ImmutableArray<BoundSubpattern> BindPropertyPatternClause(
var memberBuilder = ArrayBuilder<Symbol>.GetInstance();
LookupMembersForPropertyPattern(inputType, expr, memberBuilder, diagnostics, ref hasErrors, out memberType);
members = memberBuilder.ToImmutableAndFree();
if (!hasErrors && members.Length > 1)
{
MessageID.IDS_FeatureExtendedPropertyPatterns.CheckFeatureAvailability(diagnostics, this.Compilation, expr.GetLocation());
}
}

BoundPattern boundPattern = BindPattern(pattern, memberType, GetValEscape(memberType, inputValEscape), permitDesignations, hasErrors, diagnostics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private SubpatternSyntax ParseSubpatternElement()
var colon = EatToken();
exprColon = expr is IdentifierNameSyntax identifierName
? _syntaxFactory.NameColon(identifierName, colon)
: _syntaxFactory.ExpressionColon(expr, colon);
: _syntaxFactory.ExpressionColon(CheckFeatureAvailability(expr, MessageID.IDS_FeatureExtendedPropertyPatterns), colon);

pattern = ParsePattern(Precedence.Conditional);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -24,6 +25,16 @@ public PatternParsingTests2(ITestOutputHelper output) : base(output)
public void ExtendedPropertySubpattern_01()
{
UsingExpression(@"e is { a.b.c: p }");
verify();

UsingExpression(@"e is { a.b.c: p }", TestOptions.Regular9,
// (1,8): error CS8652: The feature 'extended property patterns' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// e is { a.b.c: p }
Diagnostic(ErrorCode.ERR_FeatureInPreview, "a.b.c").WithArguments("extended property patterns").WithLocation(1, 8));
verify();

void verify()
{

N(SyntaxKind.IsPatternExpression);
{
Expand Down Expand Up @@ -77,6 +88,7 @@ public void ExtendedPropertySubpattern_01()
}
EOF();
}
}

[Fact]
public void ExtendedPropertySubpattern_02()
Expand Down

0 comments on commit d3f1e7f

Please sign in to comment.