STALE: Add IOp support for with(...) elements.#81058
Conversation
…-arguments' into creationArguments
| @@ -393,8 +393,17 @@ static void Main() | |||
| var operation = semanticModel.GetOperation(root.DescendantNodes().OfType<CollectionExpressionSyntax>().ToArray()[1]); | |||
| VerifyOperationTree(compilation, operation, """ | |||
| ICollectionExpressionOperation (1 elements, ConstructMethod: MyList<System.Int32>..ctor([System.Int32 capacity = 0], [System.String name = "default"])) (OperationKind.CollectionExpression, Type: MyList<System.Int32>) (Syntax: '[with(capacity: 10), 2]') | |||
There was a problem hiding this comment.
review with whitespace off.
| { | ||
| EvalStackFrame frame = PushStackFrame(); | ||
| var creationArguments = VisitArguments(operation.CreationArguments, instancePushed: false); | ||
| PopStackFrame(frame); |
There was a problem hiding this comment.
it seemed sensible to me to push/pop a frame here independent of the frame for visiting the elements. But i wasn't 100% sure. LMK if this is correct. #Closed
There was a problem hiding this comment.
I'm not sure what the decision to keep the frames for the arguments and elements "independent" versus nested like in VisitObjectCreation could impact.
There was a problem hiding this comment.
Maybe Aleksey can advise. Otherwise this does need some more research
I suspect we can do await with the split
There was a problem hiding this comment.
note: my intent was to match VisitObjectCreation.
There was a problem hiding this comment.
note: my intent was to match VisitObjectCreation.
Thanks for the clarification
In that case, would it be an outer frame with an inner frame (push, push, pop, pop) instead of two separate frames (push, pop, push, pop)?
There was a problem hiding this comment.
Maybe Aleksey can advise.
See my other comments
| </summary> | ||
| </Comments> | ||
| </Property> | ||
| <Property Name="CreationArguments" Type="ImmutableArray<IArgumentOperation>"> |
There was a problem hiding this comment.
i went with CreationArguments as i think it's nicely 'generic'. They are the arguments that control the 'creation' of the collection. I didn't really want to be very explicit that they were the 'WithElement' arguments. But i don't feel strongly on this. If people think it should align more closely with the syntax, that's ok with me.
There was a problem hiding this comment.
It feels like ConstructArguments to emphasize the connection with ConstructMethod would be reasonable here. However, I also don't feel strongly. :)
|
@RikkiGibson @jjonescz @333fred ptal. |
| // (12,74): warning CS8620: Argument of type 'T' cannot be used for parameter 'items' of type 'ReadOnlySpan<T?>' in 'MyCollection<T?> MyCollectionBuilder.Create<T?>(ReadOnlySpan<T?> items)' due to differences in the nullability of reference types. | ||
| // static IMyCollection<T?> F<T>(ReadOnlySpan<T> items, T arg) => [with(arg), ..items]; | ||
| Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "arg").WithArguments("T", "System.ReadOnlySpan<T?>", "items", "MyCollection<T?> MyCollectionBuilder.Create<T?>(ReadOnlySpan<T?> items)").WithLocation(12, 74)); | ||
| Diagnostic(ErrorCode.ERR_BadCollectionArgumentsArgCount, "with(arg)").WithArguments("Create", "1").WithLocation(12, 69)); |
There was a problem hiding this comment.
note: this now matches CollectionBuilder_SpreadElement_BoxingConversion_A, which also has no nullable warning here. the only error we should report is the bad-with, since we only bind to (ReadOnlySpan<T> items) not (ReadOnlySpan<T> items, T arg) (since arguments can't go at builder end, they must be at the start).
|
Closes #80998 ? |
|
Assert added in d4da134 |
|
Done with review pass (commit 75), only glanced over the test changes #Closed |
|
@CyrusNajmabadi It looks like there are legitimate CI failures |
| } | ||
|
|
||
| [Fact] | ||
| public void ControlFlowBuilder() |
| IFlowCaptureReferenceOperation: 0 (OperationKind.FlowCaptureReference, Type: System.Int32, IsImplicit) (Syntax: 'ComputeCapacity()') | ||
| 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) | ||
| IArgumentOperation (ArgumentKind.Explicit, Matching Parameter: items) (OperationKind.Argument, Type: null, IsImplicit) (Syntax: 'with(ComputeCapacity())') |
There was a problem hiding this comment.
ah. good catch. investigating.
|
Done with review pass (commit 83), only glanced over the test changes |
62026b2
into
dotnet:features/collection-expression-arguments
|
@CyrusNajmabadi It looks like there are no sign-offs for this PR. Am I missing something? |
|
I didn't merge this. I have no idea how a merge would even be possible given that there were no sign-offs... |
Let's revert the merge then. Based on GitHub status updates, it merged and deleted the branch on you behalf. If that was not the case, I guess it would be good to understand what happened. |
with(...) elements.with(...) elements.
with(...) elements.with(...) elements.
|
PR continues in #81427 |
Relates to test plan #80613
Closes #80998