Repository navigation
Improve IOperation shape for a cast utilizing user-defined conversions - #85262
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical conversion-path assertions and operation mapping failures remain, and the explicit operation shape needs correction.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Improves IOperation trees for explicit casts involving user-defined conversions, particularly nullable targets.
Changes:
- Adjusts conversion grouping and implicitness.
- Adds regression tests and updates operation-tree baselines.
- Updates conversion-tree validation and return-type adjustment handling.
File summaries
| File | Review summary |
|---|---|
src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs |
Updates expected operation-tree baselines. |
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs |
Moderate issue (1 vote): the outer explicit conversion does not expose the user-defined operator method as expected. |
src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs |
Critical issue (3 votes): valid return-type-adjustment nodes are treated as unexpected and can throw. |
src/Compilers/CSharp/Portable/BoundTree/BoundConversion.cs |
Critical issue (3 votes): unconditional assertions abort a supported conversion path. |
src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs |
Critical issue (3 votes): an unconditional assertion aborts a legal return-type-adjustment branch. |
Review details
Suppressed comments (2)
src/Compilers/CSharp/Portable/BoundTree/BoundConversion.cs:136
- This new invariant rejects a tree shape that the binder deliberately constructs: when
UserDefinedReturnTypeAdjustmentis inserted inCreateUserDefinedConversion, it becomes the operand ofUserDefinedFinal, sooperandAsConversion.Conversion.IsUserDefinedis false. The previous assertion explicitly allowed that flag combination, and the addedCast_UserDefined_03exercises it; in a DEBUG build this assertion fires while binding a valid program. Keep the adjustment form valid, or update the binder and operation-factory handling together.
Debug.Assert(Operand is BoundConversion operandAsConversion &&
operandAsConversion.ConversionGroupOpt == ConversionGroupOpt &&
operandAsConversion.WasCompilerGenerated &&
operandAsConversion.Conversion.IsUserDefined &&
operandAsConversion.Syntax == Syntax);
src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IConversionExpression.cs:3519
- The cast syntax is mapped to this outer non-implicit operation, but the expected tree leaves
OperatorMethodnull on it and exposesS1.op_Implicitonly on an implicit child.OperationMapBuilderrecords and returns the outer operation forGetOperation(castSyntax), so this does not meet the linked issue's stated result that the returnedIConversionOperationcarries the user-defined operator method. The explicit node should be built from the full conversion-group conversion and original operand (and the corresponding expectations should be updated).
IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: S1?) (Syntax: '(S1?)10')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand:
IConversionOperation (TryCast: False, Unchecked) (OperatorMethod: S1 S1.op_Implicit(System.Int32 x)) (OperationKind.Conversion, Type: S1, IsImplicit) (Syntax: '(S1?)10')
- Files reviewed: 5/5 changed files
- Comments generated: 3
- Review effort level: Lite
|
@dotnet/roslyn-compiler Please review |
1 similar comment
|
@dotnet/roslyn-compiler Please review |
| } | ||
| else | ||
| { | ||
| ExceptionUtilities.UnexpectedValue(boundConversion); // Unexpected tree shape |
There was a problem hiding this comment.
| ExceptionUtilities.UnexpectedValue(boundConversion); // Unexpected tree shape | |
| throw ExceptionUtilities.UnexpectedValue(boundConversion); // Unexpected tree shape |
There was a problem hiding this comment.
There is no intent to throw here.
There was a problem hiding this comment.
Then it feels confusing to use this helper which by its name suggests an exception should be thrown. Consider replacing this with a simple assert instead.
There was a problem hiding this comment.
Then it feels confusing to use this helper which by its name suggests an exception should be thrown. Consider replacing this with a simple assert instead.
I prefer to leave the code as is. This helper is used in this manner in many other places.
Fixed |
|
@jjonescz, @dotnet/roslyn-compiler Please review |
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
Fixes #81781
Related to #85267.
Microsoft Reviewers: Open in CodeFlow