Skip to content

Commit 4800e39

Browse files
Improve error recovery for incomplete attribute in a type-parameter. (#81231)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: CyrusNajmabadi <4564579+CyrusNajmabadi@users.noreply.github.com>
1 parent e9cf142 commit 4800e39

File tree

3 files changed

+898
-17
lines changed

3 files changed

+898
-17
lines changed

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6028,36 +6028,34 @@ private bool IsStartOfTypeParameter()
60286028
if (this.IsCurrentTokenWhereOfConstraintClause())
60296029
return false;
60306030

6031-
// possible attributes
6032-
if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind != SyntaxKind.CloseBracketToken)
6033-
return true;
6034-
6031+
// possible attributes.
60356032
// Variance.
6036-
if (this.CurrentToken.Kind is SyntaxKind.InKeyword or SyntaxKind.OutKeyword)
6033+
if (this.CurrentToken.Kind is SyntaxKind.OpenBracketToken or SyntaxKind.InKeyword or SyntaxKind.OutKeyword)
60376034
return true;
60386035

60396036
return IsTrueIdentifier();
60406037
}
60416038

60426039
private TypeParameterSyntax ParseTypeParameter()
60436040
{
6044-
if (this.IsCurrentTokenWhereOfConstraintClause())
6045-
{
6046-
return _syntaxFactory.TypeParameter(
6047-
default(SyntaxList<AttributeListSyntax>),
6048-
varianceKeyword: null,
6049-
this.AddError(CreateMissingIdentifierToken(), ErrorCode.ERR_IdentifierExpected));
6050-
}
6051-
60526041
var attrs = default(SyntaxList<AttributeListSyntax>);
6053-
if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind != SyntaxKind.CloseBracketToken)
6042+
if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken)
60546043
{
60556044
var saveTerm = _termState;
60566045
_termState = TerminatorState.IsEndOfTypeArgumentList;
60576046
attrs = this.ParseAttributeDeclarations(inExpressionContext: false);
60586047
_termState = saveTerm;
60596048
}
60606049

6050+
if (this.IsCurrentTokenWhereOfConstraintClause() ||
6051+
this.IsCurrentTokenPartialKeywordOfPartialMemberOrType())
6052+
{
6053+
return _syntaxFactory.TypeParameter(
6054+
attrs,
6055+
varianceKeyword: null,
6056+
this.AddError(CreateMissingIdentifierToken(), ErrorCode.ERR_IdentifierExpected));
6057+
}
6058+
60616059
return _syntaxFactory.TypeParameter(
60626060
attrs,
60636061
this.CurrentToken.Kind is SyntaxKind.InKeyword or SyntaxKind.OutKeyword ? EatToken() : null,

0 commit comments

Comments
 (0)