Produce specific error for misplaced 'record' keyword#59622
Produce specific error for misplaced 'record' keyword#59622RikkiGibson merged 7 commits intodotnet:mainfrom
Conversation
| Diagnostic(ErrorCode.ERR_MisplacedRecord, "record").WithLocation(1, 8), | ||
| // (1,16): error CS1514: { expected | ||
| // struct record C(int X, int Y); | ||
| Diagnostic(ErrorCode.ERR_LbraceExpected, "(").WithLocation(1, 16), |
There was a problem hiding this comment.
this is a pity. consider (if cheap) supporting this as a record, with misplaced struct. Once you see 'record' (even if it's errant) i think we should exercise the record-parsing path. #Closed
There was a problem hiding this comment.
the primary reason for this is so that the tree doesn't go off the rails. that helps the entire experience.
There was a problem hiding this comment.
I understand, but prefer to leave as-is.
It's not trivial because the keyword is struct (not record) and so we'd have to loosen assertions in constructTypeDeclaration(...) below which I'd rather not.
This will likely resolve when we allow parameter list on type declaration for primary constructors.
There was a problem hiding this comment.
That works for me! Thanks :)
| { | ||
| var text = "class record C(int X, int Y);"; | ||
| UsingTree(text, options: TestOptions.Regular10, | ||
| // (1,7): error CS9012: Unexpected keyword 'record'. Did you mean 'struct record' or 'class record'? |
There was a problem hiding this comment.
i'm a bit confused by the error message. It says Did you mean 'struct record' or 'class record'? but the user did write class record. #Resolved
| [Fact] | ||
| public void StructNamedRecord() | ||
| { | ||
| var source = "struct record { } "; |
There was a problem hiding this comment.
struct record : IMyInterface? #Closed
|
@333fred @dotnet/roslyn-compiler for review. Thanks |
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax | ||
| { | ||
| using System.Diagnostics.CodeAnalysis; |
| { | ||
| var source = @" | ||
| interface I { } | ||
| struct record<T> : I { } |
There was a problem hiding this comment.
Add a non-generic version? #Resolved
| } | ||
|
|
||
| [Fact] | ||
| public void StructNamedRecord() |
There was a problem hiding this comment.
Probably want class record versions of these tests as well. #Resolved
| [Fact, CompilerTrait(CompilerFeature.RecordStructs)] | ||
| public void RecordStructParsing_WrongOrder() | ||
| [Fact, CompilerTrait(CompilerFeature.RecordStructs), WorkItem(59534, "https://github.com/dotnet/roslyn/issues/59534")] | ||
| public void RecordStructParsing_WrongOrder_CSharp10() |
There was a problem hiding this comment.
Consider making these theories over struct vs class. #Resolved
There was a problem hiding this comment.
I think we have sufficient coverage for class case now (added a few tests)
| } | ||
|
|
||
| [Fact, CompilerTrait(CompilerFeature.RecordStructs), WorkItem(59534, "https://github.com/dotnet/roslyn/issues/59534")] | ||
| public void StructNamedRecord_CSharp8() |
There was a problem hiding this comment.
We have an IDE PR waiting for this to be merged, so I'd rather avoid one more iteration to combine two tests. Thanks
Fixes #59534