Skip to content
12 changes: 10 additions & 2 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13904,9 +13904,17 @@ private JoinClauseSyntax ParseJoinClause()
private LetClauseSyntax ParseLetClause()
{
Debug.Assert(this.CurrentToken.ContextualKind == SyntaxKind.LetKeyword);
var letKeyword = this.EatContextualToken(SyntaxKind.LetKeyword);

Check failure on line 13908 in src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

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

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs(13908,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 13908 in src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

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

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs(13908,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Roslyn disallows blank lines with spaces on them. Please update the copilot contributing document to mention that this should be avoided as it will cause linting errors that will have to be fixed up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 2ce564d. Fixed the blank lines with spaces in ParseLetClause and updated .github/copilot-instructions.md to include a note about this requirement under the Formatting section.

// If we see a keyword followed by '=', use EatTokenAsKind to produce
// a better error message (ERR_IdentifierExpectedKW) and recover well.
var identifier = SyntaxFacts.IsReservedKeyword(this.CurrentToken.Kind) && this.PeekToken(1).Kind == SyntaxKind.EqualsToken
? this.EatTokenAsKind(SyntaxKind.IdentifierToken)
: this.ParseIdentifierToken();

Check failure on line 13914 in src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

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

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs(13914,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)

Check failure on line 13914 in src/Compilers/CSharp/Portable/Parser/LanguageParser.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

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

src/Compilers/CSharp/Portable/Parser/LanguageParser.cs(13914,1): error IDE0055: (NETCORE_ENGINEERING_TELEMETRY=Build) Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055)
return _syntaxFactory.LetClause(
this.EatContextualToken(SyntaxKind.LetKeyword),
this.ParseIdentifierToken(),
letKeyword,
identifier,
this.EatToken(SyntaxKind.EqualsToken),
this.ParseExpressionCore());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7330,5 +7330,50 @@ public void ObjectInitializerWithColonAndDashInsteadOfEqualsSigns()
}
EOF();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/10446")]
public void LetClauseWithKeywordAsIdentifier()
{
UsingExpression("from m in methods let params = 1 select m",
// (1,23): error CS1041: Identifier expected; 'params' is a keyword
// from m in methods let params = m.GetParameters() select m
Diagnostic(ErrorCode.ERR_IdentifierExpectedKW, "params").WithArguments("", "params").WithLocation(1, 23));

N(SyntaxKind.QueryExpression);
{
N(SyntaxKind.FromClause);
{
N(SyntaxKind.FromKeyword);
N(SyntaxKind.IdentifierToken, "m");
N(SyntaxKind.InKeyword);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "methods");
}
}
N(SyntaxKind.QueryBody);
{
N(SyntaxKind.LetClause);
{
N(SyntaxKind.LetKeyword);
M(SyntaxKind.IdentifierToken);
N(SyntaxKind.EqualsToken);
N(SyntaxKind.NumericLiteralExpression);
{
N(SyntaxKind.NumericLiteralToken, "1");
}
}
N(SyntaxKind.SelectClause);
{
N(SyntaxKind.SelectKeyword);
N(SyntaxKind.IdentifierName);
{
N(SyntaxKind.IdentifierToken, "m");
}
}
}
}
EOF();
}
}
}
Loading