From d3f1e7f1bd1c14c2ca3a398eae71a9c18b912a1f Mon Sep 17 00:00:00 2001 From: Alireza Habibi Date: Tue, 4 May 2021 21:13:56 +0430 Subject: [PATCH] Move langversion check to the parser --- .../CSharp/Portable/Binder/Binder_Patterns.cs | 4 -- .../Parser/LanguageParser_Patterns.cs | 2 +- .../Syntax/Parsing/PatternParsingTests2.cs | 66 +++++++++++-------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs index 9f0126d62aa8e..61402bf756da5 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Patterns.cs @@ -1184,10 +1184,6 @@ private ImmutableArray BindPropertyPatternClause( var memberBuilder = ArrayBuilder.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); diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser_Patterns.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_Patterns.cs index 97c5f6af1279f..7eb53d7cdb002 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser_Patterns.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser_Patterns.cs @@ -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); } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests2.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests2.cs index 7e51a4365091f..ee47e59f6cbde 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests2.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/PatternParsingTests2.cs @@ -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; @@ -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]