-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Record structs: Bind type declaration #51494
Conversation
internal abstract bool IsRecord { get; } | ||
|
||
internal abstract bool IsRecordStruct { get; } |
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.
📝 Alternatively, we could re-use and extend IsRecord
. Some places that previously checked IsRecord
would need to be updated to also check IsReferenceType
. This probably should be discussed more in context of public API we want to expose (tracked in test plan). #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.
If it is convenient to have IsRecordStruct
, it might make sense to have the following set of properties
// new property
internal abstract bool IsRecord { get; }
// current IsRecord property renamed (with usages audited to determine what property they should be changed to)
internal bool IsRecordClass => IsRecord && TypeKind == TypeKind.Class;
internal bool IsRecordStruct => IsRecord && TypeKind == TypeKind.Struct;
``` #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.
Right, that's what I was considering. I have a follow-up in test plan and also PROTOTYPE above to track.
In reply to: 588778787 [](ancestors = 588778787)
@@ -1593,185 +1784,6 @@ record R() | |||
); | |||
} | |||
|
|||
[Fact(Skip = "record struct")] |
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.
📝 All the skipped tests were moved to new file (still skipped for now) #Resolved
public void EmptyRecord_01_RecordClass() | ||
{ | ||
var src = @" | ||
record class C(); |
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 class
keyword is ignored by the compiler. So I just picked a couple of tests and duplicated them to give record class
some coverage. #Resolved
} | ||
|
||
[Fact] | ||
public void TypeDeclaration_AllowedModifiers() |
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.
TypeDeclaration_AllowedModifiers [](start = 20, length = 32)
Are we testing an unsafe
modifier? #Closed
} | ||
|
||
[Fact] | ||
public void TypeDeclaration_DifferentPartials() |
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.
TypeDeclaration_DifferentPartials [](start = 20, length = 33)
It feels like there are more permutations that we can test. Perhaps we should cover record struct
declaration paired with all other kinds of declarations, the same for record class
. #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.
LGTM (commit 1), with test suggestions.
@@ -182,6 +182,7 @@ Global | |||
src\Analyzers\VisualBasic\Analyzers\VisualBasicAnalyzers.projitems*{2531a8c4-97dd-47bc-a79c-b7846051e137}*SharedItemsImports = 5 | |||
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\VisualBasic\VisualBasicCompilerExtensions.projitems*{2531a8c4-97dd-47bc-a79c-b7846051e137}*SharedItemsImports = 5 | |||
src\Analyzers\Core\Analyzers\Analyzers.projitems*{275812ee-dedb-4232-9439-91c9757d2ae4}*SharedItemsImports = 5 | |||
src\Dependencies\Collections\Microsoft.CodeAnalysis.Collections.projitems*{275812ee-dedb-4232-9439-91c9757d2ae4}*SharedItemsImports = 5 |
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.
src\Dependencies\Collections\Microsoft.CodeAnalysis.Collections.projitems*{275812ee-dedb-4232-9439-91c9757d2ae4}*SharedItemsImports = 5 [](start = 2, length = 135)
Is this an intentional change? #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.
IDE has tended to add this implicitly when using certain refactorings in recent weeks. IIRC we saw this change come in another PR and decided to just merge it. Merging latest main into the feature branch will probably cause this diff to go away. #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.
|
||
var comp = CreateCompilation(src); | ||
comp.VerifyDiagnostics( | ||
// (16,22): error CS0227: Unsafe code may only appear if compiling with /unsafe |
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.
// (16,22): error CS0227: Unsafe code may only appear if compiling with /unsafe [](start = 16, length = 79)
It looks like this error is covered in the test below. I was looking for a success case. #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.
|
||
var comp = CreateCompilation(src1, parseOptions: TestOptions.Regular9, options: TestOptions.ReleaseDll); | ||
comp.VerifyDiagnostics( | ||
// (2,13): error CS1514: { expected |
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 starting to wonder whether such type declarations should instead be treated as records with a missing 'record' keyword. Not asking you to do it in this PR but I'm curious what you think. #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.
It's not obvious. If someone is making the mistake of thinking that primary constructors are generally a thing, then they really don't want to add "record" to fix this. I'll add a note for follow-up discussion.
In reply to: 588779583 [](ancestors = 588779583)
var src3 = @" | ||
struct E | ||
{ | ||
record struct Point(int x, int y); |
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.
For completeness consider also nesting this in a namespace #Resolved
Test plan: #51199
Spec: https://github.com/dotnet/csharplang/blob/master/proposals/record-structs.md
This PR implements the following sections, but the parts related to the primary constructor parameters will be handled in the follow-up PR (which synthesizes positional members and primary constructor).
and