-
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
Finalize the design for the shape of the BaseTypeSyntax for records and implement SemanticModel APIs around it. #45351
Conversation
…nd implement SemanticModel APIs around it. Closes dotnet#44795.
@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review. |
1 similar comment
@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review. |
@@ -8,16 +8,11 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax | |||
{ | |||
public partial class RecordDeclarationSyntax | |||
{ | |||
internal SimpleBaseTypeSyntax? BaseWithArguments | |||
internal PrimaryConstructorBaseTypeSyntax? PrimaryConstructorBaseTypeSyntax |
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.
PrimaryConstructorBaseTypeSyntax [](start = 51, length = 32)
To be consistent with the way properties on syntax nodes are named, you should drop the Syntax
suffix. #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.
To be consistent with the way properties on syntax nodes are named, you should drop the Syntax suffix.
Renamed
In reply to: 443925572 [](ancestors = 443925572)
@@ -1197,6 +1197,8 @@ private static BoundExpression MakeLiteral(SyntaxNode syntax, ConstantValue cons | |||
case SyntaxKind.BaseConstructorInitializer: | |||
case SyntaxKind.ThisConstructorInitializer: | |||
return new SourceLocation(((ConstructorInitializerSyntax)syntax).ArgumentList.OpenParenToken); | |||
case SyntaxKind.PrimaryConstructorBaseType: |
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.
SyntaxKind [](start = 21, length = 10)
Is this tested? #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.
Is this tested?
The need to test this code path is recorder in the test plan issue.
In reply to: 443927180 [](ancestors = 443927180)
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.
Can you please link to the test plan issue?
In reply to: 443928479 [](ancestors = 443928479,443927180)
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.
nodeToBind.Kind() == SyntaxKind.SimpleBaseType || // initializer for a record constructor | ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && nodeToBind.Parent is ConstructorInitializerSyntax || | ||
nodeToBind.Kind() == SyntaxKind.PrimaryConstructorBaseType || // initializer for a record constructor | ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && (nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax) || |
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.
PrimaryConstructorBaseTypeSyntax [](start = 143, length = 32)
Is this tested? #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.
Is this tested?
Yes, this scenario is exercised by speculative operations.
In reply to: 443927699 [](ancestors = 443927699)
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.
Can you please identify a test which exercises this?
In reply to: 443929018 [](ancestors = 443929018,443927699)
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.
Can you please identify a test which exercises this?
BaseArguments_19, GetSpeculativeSymbolInfo for an initializer with a an out var in an argument.
In reply to: 443929431 [](ancestors = 443929431,443929018,443927699)
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 line as well Assert.Equal("Base..ctor(System.Int32 X)", speculativeModel!.GetSymbolInfo((SyntaxNode)speculativePrimaryInitializer).Symbol.ToTestDisplayString());
In reply to: 443930921 [](ancestors = 443930921,443929431,443929018,443927699)
public Base() {} | ||
} | ||
|
||
record C(int X, int Y) : Base(GetInt(X, out var xx) + xx, Y), 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.
Base [](start = 25, length = 4)
This should also be tested with a class (not record) as the base, as permitted by https://github.com/dotnet/csharplang/blob/master/proposals/records.md #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.
This should also be tested with a class (not record) as the base, as permitted by https://github.com/dotnet/csharplang/blob/master/proposals/records.md
Any particular aspect you have in mind? There were some existing tests with classes with the old representation.
In reply to: 443928983 [](ancestors = 443928983)
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.
Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs:7029 in b65a77f. [](commit_id = b65a77f, deletion_comment = False) |
_nodeBinder.BindConstructorInitializer(ctorInitializer, diagnostics); | ||
break; | ||
case PrimaryConstructorBaseTypeSyntax ctorInitializer: | ||
_nodeBinder.BindConstructorInitializer(ctorInitializer, diagnostics); |
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.
BindConstructorInitializer [](start = 44, length = 26)
Can you please identify a test for this code 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.
Can you please identify a test for this code path?
For example, sBaseArguments_19, OutVarTests.VerifyModelForOutVar(speculativeModel, xxDecl, xxRef);
In reply to: 443929533 [](ancestors = 443929533)
@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review. |
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.
@jcouv, @agocke, @RikkiGibson, @dotnet/roslyn-compiler Please review, need a second sign-off.. |
var diagnostics = DiagnosticBag.GetInstance(); | ||
binder = new ExecutableCodeBinder(constructorInitializer, binder.ContainingMemberOrLambda, binder); | ||
|
||
BoundExpressionStatement bnode = binder.BindConstructorInitializer(constructorInitializer, diagnostics); |
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 believe we need to do a nullable rewrite of these nodes. #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.
I believe we need to do a nullable rewrite of these nodes.
It doesn't look like we do this for any GetSpeculativeXXX APIs. Please open an issue if you think they should do the rewrite.
In reply to: 444528944 [](ancestors = 444528944)
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.
nodeToBind.Kind() == SyntaxKind.SwitchExpressionArm || | ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && nodeToBind.Parent is ConstructorInitializerSyntax || | ||
nodeToBind.Kind() == SyntaxKind.ArgumentList && (nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax) || |
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.
nodeToBind.Parent is ConstructorInitializerSyntax || nodeToBind.Parent is PrimaryConstructorBaseTypeSyntax [](start = 65, length = 106)
This is used a couple of times. Consider making a helper. #WontFix
symbolInfo = model.GetSymbolInfo((SyntaxNode)baseWithargs); | ||
Assert.Equal(SymbolInfo.None, symbolInfo); | ||
symbolInfo = model.GetSymbolInfo(baseWithargs); | ||
Assert.Equal(SymbolInfo.None, symbolInfo); |
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.
Why don't we get a list of failed candidates here? #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.
Why don't we get a list of failed candidates here?
Because there are no candidates, the PrimaryConstructorBaseTypeSyntax is never bound for anything other than a record.
In reply to: 444534737 [](ancestors = 444534737)
Done review pass (commit 2). A couple of questions. I don't see any tests involving nullability for these, is there an item in the test plan tracking nullable public API testing for record constructors? #Closed |
Answered.
This isn't really related to the shape of the syntax. Added a note to the Test Plan #40726. In reply to: 648452941 [](ancestors = 648452941) |
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 2)
Closes #44795.