-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 specific error for misplaced 'record' keyword #59622
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh! Fixed
[Fact] | ||
public void StructNamedRecord() | ||
{ | ||
var source = "struct record { } "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct record : IMyInterface
? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Thanks
@333fred @dotnet/roslyn-compiler for review. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done review pass (commit 5)
@@ -15,6 +15,7 @@ | |||
|
|||
namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax | |||
{ | |||
using System.Diagnostics.CodeAnalysis; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Top of the file? #Resolved
{ | ||
var source = @" | ||
interface I { } | ||
struct record<T> : I { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a non-generic version? #Resolved
@@ -11159,5 +11159,86 @@ public void ExplicitConstructors_11() | |||
// static S() : this() { } | |||
Diagnostic(ErrorCode.ERR_StaticConstructorWithExplicitConstructorCall, "this").WithArguments("S").WithLocation(4, 18)); | |||
} | |||
|
|||
[Fact] | |||
public void StructNamedRecord() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making these theories over struct
vs class
. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have sufficient coverage for class case now (added a few tests)
@@ -3237,11 +3282,116 @@ public void RecordStructParsing_WrongOrder() | |||
EOF(); | |||
} | |||
|
|||
[Fact, CompilerTrait(CompilerFeature.RecordStructs), WorkItem(59534, "https://github.com/dotnet/roslyn/issues/59534")] | |||
public void StructNamedRecord_CSharp8() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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