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 40 additions and 32 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
66 changes: 39 additions & 27 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,58 +25,69 @@ public PatternParsingTests2(ITestOutputHelper output) : base(output)
public void ExtendedPropertySubpattern_01()
{
UsingExpression(@"e is { a.b.c: p }");
verify();

N(SyntaxKind.IsPatternExpression);
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.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "e");
}
N(SyntaxKind.IsKeyword);
N(SyntaxKind.RecursivePattern);

N(SyntaxKind.IsPatternExpression);
{
N(SyntaxKind.PropertyPatternClause);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.Subpattern);
N(SyntaxKind.IdentifierToken, "e");
}
N(SyntaxKind.IsKeyword);
N(SyntaxKind.RecursivePattern);
{
N(SyntaxKind.PropertyPatternClause);
{
N(SyntaxKind.ExpressionColon);
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.Subpattern);
{
N(SyntaxKind.SimpleMemberAccessExpression);
N(SyntaxKind.ExpressionColon);
{
N(SyntaxKind.SimpleMemberAccessExpression);
{
N(SyntaxKind.IdentifierName);
N(SyntaxKind.SimpleMemberAccessExpression);
{
N(SyntaxKind.IdentifierToken, "a");
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "a");
}
N(SyntaxKind.DotToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "b");
}
}
N(SyntaxKind.DotToken);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "b");
N(SyntaxKind.IdentifierToken, "c");
}
}
N(SyntaxKind.DotToken);
N(SyntaxKind.ColonToken);
}
N(SyntaxKind.ConstantPattern);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "c");
N(SyntaxKind.IdentifierToken, "p");
}
}
N(SyntaxKind.ColonToken);
}
N(SyntaxKind.ConstantPattern);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "p");
}
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.CloseBraceToken);
}
}
EOF();
}
EOF();
}

[Fact]
Expand Down

0 comments on commit d3f1e7f

Please sign in to comment.