-
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
Fix error recovery for various nested conversion scenarios #74089
Conversation
@dotnet/roslyn-compiler for review |
@@ -683,6 +683,7 @@ private static void CheckInlineArrayTypeIsSupported(SyntaxNode syntax, TypeSymbo | |||
} | |||
|
|||
var elementConversions = conversion.UnderlyingConversions; | |||
conversion.MarkUnderlyingConversionsChecked(); |
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.
BTW, it is not clear to me what is this operation going to change. It look like we are mutating a local value of a struct, which is not returned or stored anywhere.
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.
it is not clear to me what is this operation going to change
I guess this operation is mutating a class instance referenced by the struct, therefore, the mutation is preserved even when the struct value is not preserved.
Is this change backed by a test?
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.
If we do not make this call, then newly added test Tuple_UserDefinedConversion_CollectionExpression_NotAmbiguous
will fail in AssertUnderlyingConversionsChecked
.
@@ -1645,6 +1646,7 @@ internal bool TryGetCollectionIterationType(SyntaxNode syntax, TypeSymbol collec | |||
bool targetTyped = conversionIfTargetTyped is { }; | |||
Debug.Assert(targetTyped || destination.IsErrorType() || destination.Equals(source.Type, TypeCompareKind.ConsiderEverything)); | |||
ImmutableArray<Conversion> underlyingConversions = conversionIfTargetTyped.GetValueOrDefault().UnderlyingConversions; | |||
conversionIfTargetTyped.GetValueOrDefault().MarkUnderlyingConversionsChecked(); |
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.
@@ -1645,6 +1646,7 @@ internal bool TryGetCollectionIterationType(SyntaxNode syntax, TypeSymbol collec | |||
bool targetTyped = conversionIfTargetTyped is { }; | |||
Debug.Assert(targetTyped || destination.IsErrorType() || destination.Equals(source.Type, TypeCompareKind.ConsiderEverything)); | |||
ImmutableArray<Conversion> underlyingConversions = conversionIfTargetTyped.GetValueOrDefault().UnderlyingConversions; | |||
conversionIfTargetTyped.GetValueOrDefault().MarkUnderlyingConversionsChecked(); |
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.
Is this change backed by a test?
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.
If we do not make this call, then newly added test Tuple_UserDefinedConversion_ConditionalExpression_NotAmbiguous
will fail in AssertUnderlyingConversionsChecked
.
@@ -1682,6 +1684,7 @@ private BoundExpression ConvertSwitchExpression(BoundUnconvertedSwitchExpression | |||
Conversion conversion = conversionIfTargetTyped ?? Conversion.Identity; | |||
Debug.Assert(targetTyped || destination.IsErrorType() || destination.Equals(source.Type, TypeCompareKind.ConsiderEverything)); | |||
ImmutableArray<Conversion> underlyingConversions = conversion.UnderlyingConversions; | |||
conversion.MarkUnderlyingConversionsChecked(); |
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.
Is this change backed by a test
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.
If we do not make this call, then newly added test Tuple_UserDefinedConversion_SwitchExpression_NotAmbiguous
will fail in AssertUnderlyingConversionsChecked
.
Done with review pass (commit 1) |
It looks like some test runs are timing out. I would be surprised if just the changes in c39c918 were causing this. Following up with infraswat. |
src/Compilers/CSharp/Test/Semantic/Semantics/UserDefinedConversionTests.cs
Outdated
Show resolved
Hide resolved
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 3)
@dotnet/roslyn-compiler for a second review |
1 similar comment
@dotnet/roslyn-compiler for a second review |
@@ -1723,7 +1727,7 @@ private BoundExpression ConvertSwitchExpression(BoundUnconvertedSwitchExpression | |||
|
|||
return new BoundConversion( | |||
syntax, | |||
source, | |||
BindToNaturalType(source, 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.
Should we be calling BindToTypeForErrorRecovery
instead? It seems like the main difference is around error reporting; any errors from BindToNaturalType
will be put into diagnostics
, while BindToTypeForErrorRecovery
will discard them. Do we already have a diagnostic at this point?
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.
We will definitely have some diagnostic about this expression, because of the preceding if (!hasErrors) GenerateImplicitConversionError(...)
.
re: the difference in practice. If we used BindToTypeForErrorRecovery here, then test Repro_VsFeedback_2088611
wouldn't report ERR_ImplicitObjectCreationNoTargetType
. It would only report ERR_ConversionNotTupleCompatible
. I feel like in this particular case, it's maybe better to have a squiggle on the new() because it happens to be related to the ambiguity. But, ideally, we would be able to report some kind of user-defined operator overload resolution error here, I think.
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2088611