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 specific error for misplaced 'record' keyword #59622

Merged
merged 7 commits into from
Mar 1, 2022

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Feb 17, 2022

Fixes #59534

@jcouv jcouv marked this pull request as ready for review February 17, 2022 19:00
@jcouv jcouv requested a review from a team as a code owner February 17, 2022 19:00
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),
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Feb 17, 2022

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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'?
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Feb 17, 2022

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

Copy link
Member Author

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 { } ";
Copy link
Member

@Youssef1313 Youssef1313 Feb 17, 2022

Choose a reason for hiding this comment

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

struct record : IMyInterface? #Closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Thanks

@jcouv jcouv closed this Feb 18, 2022
@jcouv jcouv reopened this Feb 18, 2022
@jcouv
Copy link
Member Author

jcouv commented Feb 23, 2022

@333fred Could you take another look? We've updated the PR with Cyrus's commit to treat struct record and class record as record declarations (placing struct as leading trivia on record rather than record as trailing trivia on struct).

@jcouv
Copy link
Member Author

jcouv commented Feb 24, 2022

@333fred @dotnet/roslyn-compiler for review. Thanks

Copy link
Member

@333fred 333fred left a 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;
Copy link
Member

@333fred 333fred Feb 24, 2022

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 { }
Copy link
Member

@333fred 333fred Feb 24, 2022

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()
Copy link
Member

@333fred 333fred Feb 24, 2022

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()
Copy link
Member

@333fred 333fred Feb 24, 2022

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

Copy link
Member Author

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)

@jcouv jcouv requested a review from cston February 27, 2022 19:22
@@ -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()
Copy link
Member

@cston cston Feb 28, 2022

Choose a reason for hiding this comment

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

StructNamedRecord_CSharp8

Consider merging these three into a single test, either with [Theory] or with a verify(ParseOptions) helper method, and add a similar test for class record { }.

Copy link
Member Author

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

@jcouv jcouv enabled auto-merge (squash) March 1, 2022 01:57
@RikkiGibson RikkiGibson disabled auto-merge March 1, 2022 18:07
@RikkiGibson RikkiGibson merged commit 44956a2 into dotnet:main Mar 1, 2022
@ghost ghost added this to the Next milestone Mar 1, 2022
@jcouv jcouv deleted the struct-record branch March 1, 2022 18:16
@allisonchou allisonchou modified the milestones: Next, 17.2.P3 Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IDE help after typing struct record Foo
7 participants