-
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
Brace completion and IOperation for with
expression
#44712
Changes from 4 commits
52b4c8a
26c5612
154b634
c833047
57048ed
96f7341
dceba97
751af04
b9cc321
5580493
9d3ee98
b612da6
60406da
81dc5a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1119,6 +1119,50 @@ .maxstack 3 | |
IL_002d: pop | ||
IL_002e: ret | ||
}"); | ||
|
||
var comp = verifier.Compilation; | ||
var tree = comp.SyntaxTrees.First(); | ||
var root = tree.GetRoot(); | ||
var model = comp.GetSemanticModel(tree); | ||
|
||
var withExpr1 = root.DescendantNodes().OfType<WithExpressionSyntax>().First(); | ||
comp.VerifyOperationTree(withExpr1, @" | ||
IWithExpressionOperation (OperationKind.WithExpression, Type: C) (Syntax: 'c with { Y ... = W(""X"") }') | ||
Value: | ||
ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') | ||
CloneMethod: C C.Clone() | ||
Initializer: | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C) (Syntax: '{ Y = W(""Y"" ... = W(""X"") }') | ||
Initializers(2): | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32) (Syntax: 'Y = W(""Y"")') | ||
Left: | ||
IPropertyReferenceOperation: System.Int32 C.Y { get; init; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'Y') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: C, IsImplicit) (Syntax: 'Y') | ||
Right: | ||
IInvocationOperation (System.Int32 C.W(System.String s)) (OperationKind.Invocation, Type: System.Int32) (Syntax: 'W(""Y"")') | ||
Instance Receiver: | ||
null | ||
Arguments(1): | ||
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: s) (OperationKind.Argument, Type: null) (Syntax: '""Y""') | ||
ILiteralOperation (OperationKind.Literal, Type: System.String, Constant: ""Y"") (Syntax: '""Y""') | ||
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) | ||
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32) (Syntax: 'X = W(""X"")') | ||
Left: | ||
IPropertyReferenceOperation: System.Int32 C.X { get; init; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'X') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: C, IsImplicit) (Syntax: 'X') | ||
Right: | ||
IInvocationOperation (System.Int32 C.W(System.String s)) (OperationKind.Invocation, Type: System.Int32) (Syntax: 'W(""X"")') | ||
Instance Receiver: | ||
null | ||
Arguments(1): | ||
IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: s) (OperationKind.Argument, Type: null) (Syntax: '""X""') | ||
ILiteralOperation (OperationKind.Literal, Type: System.String, Constant: ""X"") (Syntax: '""X""') | ||
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) | ||
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) | ||
"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1514,6 +1558,22 @@ public static void Main() | |
var xId = withExpr.DescendantNodes().Single(id => id.ToString() == "X"); | ||
var symbolInfo = model.GetSymbolInfo(xId); | ||
Assert.True(x.ISymbol.Equals(symbolInfo.Symbol)); | ||
|
||
comp.VerifyOperationTree(withExpr, @" | ||
IWithExpressionOperation (OperationKind.WithExpression, Type: C) (Syntax: 'c with { X = 2 }') | ||
Value: | ||
ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') | ||
CloneMethod: C C.Clone() | ||
Initializer: | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C) (Syntax: '{ X = 2 }') | ||
Initializers(1): | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32) (Syntax: 'X = 2') | ||
Left: | ||
IPropertyReferenceOperation: System.Int32 C.X { get; init; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'X') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: C, IsImplicit) (Syntax: 'X') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider adjusting the comment for the node and the ReferenceKind to include information about this usage #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AlekseyTs I didn't understand this comment. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
IInstanceReferenceOperation and OperationKind.InstanceReference are now used in a new scenario. Consider reflecting this in the doc comment for them In reply to: 436106963 [](ancestors = 436106963) |
||
Right: | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 2) (Syntax: '2')"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1555,6 +1615,33 @@ public static void Main() | |
// } | ||
Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(11, 1) | ||
); | ||
|
||
var tree = comp.SyntaxTrees[0]; | ||
var root = tree.GetRoot(); | ||
var model = comp.GetSemanticModel(tree); | ||
|
||
var withExpr1 = root.DescendantNodes().OfType<WithExpressionSyntax>().First(); | ||
comp.VerifyOperationTree(withExpr1, @" | ||
IWithExpressionOperation (OperationKind.WithExpression, Type: C, IsInvalid) (Syntax: 'c with { 5 }') | ||
Value: | ||
ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') | ||
CloneMethod: C C.Clone() | ||
Initializer: | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C, IsInvalid) (Syntax: '{ 5 }') | ||
Initializers(1): | ||
IInvalidOperation (OperationKind.Invalid, Type: System.Int32, IsInvalid, IsImplicit) (Syntax: '5') | ||
Children(1): | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 5, IsInvalid) (Syntax: '5')"); | ||
|
||
var withExpr2 = root.DescendantNodes().OfType<WithExpressionSyntax>().Skip(1).Single(); | ||
comp.VerifyOperationTree(withExpr2, @" | ||
IWithExpressionOperation (OperationKind.WithExpression, Type: C, IsInvalid) (Syntax: 'c with { ') | ||
Value: | ||
ILocalReferenceOperation: c (OperationKind.LocalReference, Type: C) (Syntax: 'c') | ||
CloneMethod: C C.Clone() | ||
Initializer: | ||
IObjectOrCollectionInitializerOperation (OperationKind.ObjectOrCollectionInitializer, Type: C, IsInvalid) (Syntax: '{ ') | ||
Initializers(0)"); | ||
} | ||
|
||
[Fact] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -662,5 +662,7 @@ public override IOperation VisitUsingDeclaration(IUsingDeclarationOperation oper | |
{ | ||
return new UsingDeclarationOperation(Visit(operation.DeclarationGroup), operation.IsAsynchronous, ((Operation)operation).OwningSemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit); | ||
} | ||
|
||
// TODO2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If work still needs to be done here, could you please create a follow-up issue and reference it instead of including a TODO in source? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops. I'll remove the comment and file an issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a note to test plan #Resolved |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3001,4 +3001,30 @@ | |
</Comments> | ||
</Property> | ||
</Node> | ||
<Node Name="IWithExpressionOperation" Base="IOperation" ChildrenOrder="Value,Initializer"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we would want a special rewrite for this node in CFG, something very similar to a an object initializer operation #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please run all tests with -testIOperation switch locally and confirm that none of the failures are related to the feature. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we need to adjust OperationCloner for this node #Closed |
||
<Comments> | ||
<summary> | ||
Represents cloning of an object instance. | ||
<para> | ||
Current usage: | ||
(1) C# with expression. | ||
</para> | ||
</summary> | ||
</Comments> | ||
<Property Name="Value" Type="IOperation"> | ||
<Comments> | ||
<summary>Value to be cloned.</summary> | ||
</Comments> | ||
</Property> | ||
<Property Name="CloneMethod" Type="IMethodSymbol"> | ||
<Comments> | ||
<summary>Clone method to be invoked on the value.</summary> | ||
</Comments> | ||
</Property> | ||
<Property Name="Initializer" Type="IObjectOrCollectionInitializerOperation"> | ||
<Comments> | ||
<summary>With collection initializer.</summary> | ||
</Comments> | ||
</Property> | ||
</Node> | ||
</Tree> |
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 the clone method? The name is confusing. #Closed