提交 150784e9 编写于 作者: A Alireza Habibi 提交者: Julien Couvreur

Fix parsing an expression-bodied property with async as the type (#25704)

上级 8887bc11
......@@ -2316,7 +2316,7 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatement(SyntaxKind par
if (!sawRef &&
identifierOrThisOpt != null &&
(typeParameterListOpt != null && typeParameterListOpt.ContainsDiagnostics
|| this.CurrentToken.Kind != SyntaxKind.OpenParenToken && this.CurrentToken.Kind != SyntaxKind.OpenBraceToken) &&
|| this.CurrentToken.Kind != SyntaxKind.OpenParenToken && this.CurrentToken.Kind != SyntaxKind.OpenBraceToken && this.CurrentToken.Kind != SyntaxKind.EqualsGreaterThanToken) &&
ReconsiderTypeAsAsyncModifier(ref modifiers, ref type, ref explicitInterfaceOpt, identifierOrThisOpt, typeParameterListOpt))
{
goto parse_member_name;
......
......@@ -1698,5 +1698,246 @@ public void AsyncGenericType()
}
EOF();
}
[Fact]
[WorkItem(16044, "https://github.com/dotnet/roslyn/issues/16044")]
public void AsyncAsType_Property_ExpressionBody()
{
UsingTree("class async { async async => null; }").GetDiagnostics().Verify(
// (1,27): error CS8026: Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater.
// class async { async async => null; }
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion5, "=> null").WithArguments("expression-bodied property", "6").WithLocation(1, 27)
);
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.ClassDeclaration);
{
N(SyntaxKind.ClassKeyword);
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.PropertyDeclaration);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.ArrowExpressionClause);
{
N(SyntaxKind.EqualsGreaterThanToken);
N(SyntaxKind.NullLiteralExpression);
{
N(SyntaxKind.NullKeyword);
}
}
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
[Fact]
[WorkItem(16044, "https://github.com/dotnet/roslyn/issues/16044")]
public void AsyncAsType_Property()
{
UsingTree("class async { async async { get; } }").GetDiagnostics().Verify();
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.ClassDeclaration);
{
N(SyntaxKind.ClassKeyword);
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.PropertyDeclaration);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.AccessorList);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.GetAccessorDeclaration);
{
N(SyntaxKind.GetKeyword);
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
[Fact]
[WorkItem(16044, "https://github.com/dotnet/roslyn/issues/16044")]
public void AsyncAsType_Indexer_ExpressionBody_ErrorCase()
{
UsingTree("interface async { async this[async i] => null; }").GetDiagnostics().Verify(
// (1,39): error CS8026: Feature 'expression-bodied indexer' is not available in C# 5. Please use language version 6 or greater.
// interface async { async this[async i] => null; }
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion5, "=> null").WithArguments("expression-bodied indexer", "6").WithLocation(1, 39)
);
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.InterfaceDeclaration);
{
N(SyntaxKind.InterfaceKeyword);
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.IndexerDeclaration);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.ThisKeyword);
N(SyntaxKind.BracketedParameterList);
{
N(SyntaxKind.OpenBracketToken);
N(SyntaxKind.Parameter);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.IdentifierToken, "i");
}
N(SyntaxKind.CloseBracketToken);
}
N(SyntaxKind.ArrowExpressionClause);
{
N(SyntaxKind.EqualsGreaterThanToken);
N(SyntaxKind.NullLiteralExpression);
{
N(SyntaxKind.NullKeyword);
}
}
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
[Fact]
[WorkItem(16044, "https://github.com/dotnet/roslyn/issues/16044")]
public void AsyncAsType_Indexer()
{
UsingTree("interface async { async this[async i] { get; } }").GetDiagnostics().Verify();
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.InterfaceDeclaration);
{
N(SyntaxKind.InterfaceKeyword);
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.IndexerDeclaration);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.ThisKeyword);
N(SyntaxKind.BracketedParameterList);
{
N(SyntaxKind.OpenBracketToken);
N(SyntaxKind.Parameter);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.IdentifierToken, "i");
}
N(SyntaxKind.CloseBracketToken);
}
N(SyntaxKind.AccessorList);
{
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.GetAccessorDeclaration);
{
N(SyntaxKind.GetKeyword);
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
[Fact]
[WorkItem(16044, "https://github.com/dotnet/roslyn/issues/16044")]
public void AsyncAsType_Property_ExplicitInterface()
{
UsingTree("class async : async { async async.async => null; }").GetDiagnostics().Verify(
// (1,41): error CS8026: Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater.
// class async : async { async async.async => null; }
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion5, "=> null").WithArguments("expression-bodied property", "6").WithLocation(1, 41)
);
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.ClassDeclaration);
{
N(SyntaxKind.ClassKeyword);
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.BaseList);
{
N(SyntaxKind.ColonToken);
N(SyntaxKind.SimpleBaseType);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
}
}
N(SyntaxKind.OpenBraceToken);
N(SyntaxKind.PropertyDeclaration);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.ExplicitInterfaceSpecifier);
{
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "async");
}
N(SyntaxKind.DotToken);
}
N(SyntaxKind.IdentifierToken, "async");
N(SyntaxKind.ArrowExpressionClause);
{
N(SyntaxKind.EqualsGreaterThanToken);
N(SyntaxKind.NullLiteralExpression);
{
N(SyntaxKind.NullKeyword);
}
}
N(SyntaxKind.SemicolonToken);
}
N(SyntaxKind.CloseBraceToken);
}
N(SyntaxKind.EndOfFileToken);
}
EOF();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册