Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Produce errors for 'partial file record' #62686

Merged
merged 5 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,8 @@ private void ParseModifiers(SyntaxListBuilder tokens, bool forAccessors, bool fo
modTok = ConvertToKeyword(this.EatToken());
modTok = CheckFeatureAvailability(modTok,
isPartialType ? MessageID.IDS_FeaturePartialTypes : MessageID.IDS_FeaturePartialMethod);
tokens.Add(modTok);
return;
}
else if (nextToken.Kind == SyntaxKind.NamespaceKeyword)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,27 @@ public void FileModifier_03(SyntaxKind typeKeyword)
EOF();
}

[Theory]
[InlineData(SyntaxKind.RecordKeyword)]
public void FileModifier_04(SyntaxKind typeKeyword)
[Fact]
public void FileModifier_04()
{
UsingNode($$"""
partial file {{SyntaxFacts.GetText(typeKeyword)}} C { }
""");
UsingNode("""
partial file record C { }
""",
// (1,1): error CS1031: Type expected
// partial file record C { }
Diagnostic(ErrorCode.ERR_TypeExpected, "partial").WithLocation(1, 1),
// (1,1): error CS1525: Invalid expression term 'partial'
// partial file record C { }
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "partial").WithArguments("partial").WithLocation(1, 1),
// (1,1): error CS1003: Syntax error, ',' expected
// partial file record C { }
Diagnostic(ErrorCode.ERR_SyntaxError, "partial").WithArguments(",").WithLocation(1, 1),
// (1,25): error CS1002: ; expected
// partial file record C { }
Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(1, 25),
// (1,25): error CS1022: Type or namespace definition, or end-of-file expected
// partial file record C { }
Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(1, 25));
N(SyntaxKind.CompilationUnit);
{
N(SyntaxFacts.GetBaseTypeDeclarationKind(typeKeyword));
Expand Down Expand Up @@ -243,7 +257,19 @@ public void FileModifier_06()
{
UsingNode($$"""
partial file record struct C { }
""");
""",
// (1,1): error CS1031: Type expected
// partial file record struct C { }
Diagnostic(ErrorCode.ERR_TypeExpected, "partial").WithLocation(1, 1),
// (1,1): error CS1525: Invalid expression term 'partial'
// partial file record struct C { }
Diagnostic(ErrorCode.ERR_InvalidExprTerm, "partial").WithArguments("partial").WithLocation(1, 1),
// (1,1): error CS1003: Syntax error, ',' expected
// partial file record struct C { }
Diagnostic(ErrorCode.ERR_SyntaxError, "partial").WithArguments(",").WithLocation(1, 1),
// (1,21): error CS1002: ; expected
// partial file record struct C { }
Diagnostic(ErrorCode.ERR_SemicolonExpected, "struct").WithLocation(1, 21));
Youssef1313 marked this conversation as resolved.
Show resolved Hide resolved
N(SyntaxKind.CompilationUnit);
{
N(SyntaxKind.RecordStructDeclaration);
Expand Down