Brace completion and IOperation for with expression#44712
Brace completion and IOperation for with expression#44712jcouv merged 14 commits intodotnet:features/recordsfrom
with expression#44712Conversation
|
@dotnet/roslyn-compiler for review. |
| { | ||
| public class SmartTokenFormatterFormatTokenTests : CSharpFormatterTestsBase | ||
| { | ||
| public SmartTokenFormatterFormatTokenTests(ITestOutputHelper output) : base(output) { } |
There was a problem hiding this comment.
nit, we don't place {} on the same line ever. #Resolved
| public CoreFormatterTestsBase(ITestOutputHelper output) | ||
| { | ||
| this._output = output; | ||
| } |
There was a problem hiding this comment.
| public CoreFormatterTestsBase(ITestOutputHelper output) | |
| { | |
| this._output = output; | |
| } | |
| public CoreFormatterTestsBase(ITestOutputHelper output) | |
| => _output = output; |
| Assert.Equal(expected, actual); | ||
| if (actual != expected) | ||
| { | ||
| _output.WriteLine(actual); |
There was a problem hiding this comment.
what't he value of this? #Resolved
There was a problem hiding this comment.
This gives easy access to the actual result in Test Explorer, in addition to the usual diff output with pluses and minuses. #Resolved
| while (parent != null) | ||
| { | ||
| if (parent.Kind() == SyntaxKind.ObjectInitializerExpression) | ||
| if (parent.IsKind(SyntaxKind.ObjectInitializerExpression, SyntaxKind.WithInitializerExpression)) |
There was a problem hiding this comment.
i'm fine with this. however, actual question about with. does it allow for nested initializers like object initializers do? #Resolved
There was a problem hiding this comment.
with is limited to one level, simple assignments only.
{ Property = 1 }is okay{ [0] = 1 }is illegal{ 1, 2, 3 }is illegal{ Property = { ... } }is illegal #Resolved
| 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.
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.
Oops. I'll remove the comment and file an issue.
I think OperationCloner is used by CFG, we'll probably need to do some work there for records. #Resolved
There was a problem hiding this comment.
Added a note to test plan #Resolved
| </Comments> | ||
| </Property> | ||
| </Node> | ||
| <Node Name="IWithExpressionOperation" Base="IOperation" ChildrenOrder="Value,Initializer"> |
There was a problem hiding this comment.
IWithExpressionOperation [](start = 14, length = 24)
I think we would want a special rewrite for this node in CFG, something very similar to a an object initializer operation #Closed
| VisitArray(operation.DimensionSizes, "DimensionSizes", logElementCount: true); | ||
| } | ||
|
|
||
| public override void VisitWithExpression(IWithExpressionOperation operation) |
There was a problem hiding this comment.
VisitWithExpression [](start = 29, length = 19)
We have another test visitor that should be adjusted as well #Closed
| return (switchExpression.OpenBraceToken, switchExpression.CloseBraceToken); | ||
| case PropertyPatternClauseSyntax property: | ||
| return (property.OpenBraceToken, property.CloseBraceToken); | ||
| #if !CODE_STYLE |
There was a problem hiding this comment.
do we have any way of tracking when this #if should be removed? #Resolved
There was a problem hiding this comment.
There is a general issue for removing all CODE_STYLE conditions:
#41462 #Resolved
| </Comments> | ||
| </Property> | ||
| </Node> | ||
| <Node Name="IWithExpressionOperation" Base="IOperation" ChildrenOrder="Value,Initializer"> |
There was a problem hiding this comment.
IWithExpressionOperation [](start = 14, length = 24)
Please run all tests with -testIOperation switch locally and confirm that none of the failures are related to the feature. #Closed
| </Comments> | ||
| </Property> | ||
| </Node> | ||
| <Node Name="IWithExpressionOperation" Base="IOperation" ChildrenOrder="Value,Initializer"> |
There was a problem hiding this comment.
IWithExpressionOperation [](start = 14, length = 24)
I think we need to adjust OperationCloner for this node #Closed
| IOperation visitedInstance = Visit(operation.Value); | ||
|
|
||
| IOperation cloned = operation.CloneMethod is null | ||
| ? visitedInstance |
There was a problem hiding this comment.
visitedInstance [](start = 18, length = 15)
Is this for an error case? If that is the case, I think we should use MakeInvalidOperation helper to create an invalid operation on top of the instance. #Closed
| ? visitedInstance | ||
| : new InvocationOperation(operation.CloneMethod, visitedInstance, | ||
| isVirtual: false, arguments: ImmutableArray<IArgumentOperation>.Empty, | ||
| semanticModel: null, operation.Syntax, operation.Type, operation.ConstantValue, IsImplicit(operation)); |
There was a problem hiding this comment.
IsImplicit(operation) [](start = 100, length = 21)
I think the call should always be implicit. #Closed
| private readonly CSharpOperationFactory _operationFactory; | ||
| private readonly BoundWithExpression _withExpression; | ||
|
|
||
| internal CSharpLazyWithExpressionOperation(CSharpOperationFactory operationFactory, BoundWithExpression withExpression, IMethodSymbol constructor, SemanticModel semanticModel, SyntaxNode syntax, ITypeSymbol type, Optional<object> constantValue, bool isImplicit) : |
There was a problem hiding this comment.
constructor [](start = 142, length = 11)
Is this the clone method? The name is confusing. #Closed
|
|
||
| IOperation cloned = operation.CloneMethod is null | ||
| ? visitedInstance | ||
| : new InvocationOperation(operation.CloneMethod, visitedInstance, |
There was a problem hiding this comment.
visitedInstance [](start = 65, length = 15)
Is Clone method an instance method? #Closed
There was a problem hiding this comment.
Yes, it is an instance method #Resolved
|
It doesn't look like any tests were added on the compiler side for IOperation or CFG #Closed |
|
Done with review pass (iteration 9) #Closed |
I don't know what you mean. Look for calls to VerifyFlowGraph and VerifyOperationTree in RecordsTest #Closed |
I accidentally collapsed that folder. Sorry. In reply to: 639073864 [](ancestors = 639073864) |
|
Consider adding a note to Test Plan to add tests for scenarios involving control flow inside 'with' expression #Closed |
| 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.
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: C, IsImplicit) (Syntax: 'X') [](start = 18, length = 130)
Consider adjusting the comment for the node and the ReferenceKind to include information about this usage #Closed
There was a problem hiding this comment.
@AlekseyTs I didn't understand this comment. #Resolved
There was a problem hiding this comment.
I didn't understand this comment.
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)
|
Added " test control flow within with expression initializer" In reply to: 639150193 [](ancestors = 639150193) |
| /// (1) C# this or base expression. | ||
| /// (2) VB Me, MyClass, or MyBase expression. | ||
| /// (3) C# object or collection initializers. | ||
| /// (3) C# object or collection or 'with' expression initializers. |
There was a problem hiding this comment.
or 'with' expression [](start = 37, length = 20)
This is a generated file, should probably modify XML instead #Resolved
AlekseyTs
left a comment
There was a problem hiding this comment.
LGTM (iteration 12), modulo direct modification of a comment in a generated file
|
@jcouv FYI it looks like the InlineIntoWithExpression test is broken. |
| IOperation cloned = operation.CloneMethod is null | ||
| ? MakeInvalidOperation(visitedInstance.Type, visitedInstance) | ||
| : new InvocationOperation(operation.CloneMethod, visitedInstance, | ||
| isVirtual: false, arguments: ImmutableArray<IArgumentOperation>.Empty, |
There was a problem hiding this comment.
false [](start = 31, length = 5)
Based on #44852, the call probably should be virtual
There was a problem hiding this comment.
Thanks. Will fix in a follow-up PR
There was a problem hiding this comment.
@AlekseyTs It looks like Andy fixed this already (we now have isVirtual: true in master.
|
@jcouv did we discuss using something like |
|
@333fred I discussed re-using I'll start a thread with broader IOperation v-team to confirm shape and names. Thanks |
Relates to #40726 (test plan)