Improve diagnostic when decoding tuples but VT is missing#23949
Improve diagnostic when decoding tuples but VT is missing#23949jcouv merged 8 commits intodotnet:masterfrom
Conversation
78d7730 to
3f12569
Compare
3f12569 to
967eb68
Compare
|
@dotnet/roslyn-compiler for review. Thanks |
1 similar comment
|
@dotnet/roslyn-compiler for review. Thanks |
|
@MeiChin-Tsai for ask-mode approval for 15.6. Thanks |
|
Does VB have the same issue? #Closed |
| if (!hasTupleElementNamesAttribute || | ||
| decoder._namesIndex == 0) | ||
| decoder._namesIndex == 0 || | ||
| (object)decoded.VisitType(s_containsErrorPredicate, null) != null) |
There was a problem hiding this comment.
(object)decoded.VisitType(s_containsErrorPredicate, null) != null [](start = 20, length = 65)
I do not think this is the right way to fix the problem. We should be able to construct TupeTypeSymbol with the right names even when the definition of the underlying type is missing. It looks like the bug is in the private TypeSymbol DecodeType(TypeSymbol type) function below, it should call DecodeNamedType for SymbolKind.ErrorType and everything would just work as it should.
In addition, we probably should improve error recovery in this function for other situations, i.e., if decoding failed and metadataType already has a use-site error associated with it, we should return metadataType instead of losing the original error information by returning UnsupportedMetadataTypeSymbol. I believe, this change alone, would make the new unit-test to pass, but the decoding should succeed in this scenario and the unit-test should be adjusted to verify that. #Closed
There was a problem hiding this comment.
@AlekseyTs I thought about making a TupleTypeSymbol with an underlying error type, but that felt riskier. I'll take another look and will push out to 15.7 depending on what I find.
As far as checking the use-site errors on metadataType, I think that is what I tried initially, but that created an unbounded recursion when compiling Roslyn with the bootstrap compiler. I didn't keep the precise stack trace.
There was a problem hiding this comment.
That worked out. Error types have everything to pass for ValueTuples. The main thing is to not mangle the name.
AlekseyTs
left a comment
There was a problem hiding this comment.
Please consider an alternative way to address the problem - #23949 (comment)
|
Done with review pass (iteration 1). #Closed |
|
@jcouv please ping me again after you address Aleksey's change request. Thanks. |
| Return DirectCast(substituted.GetMemberForDefinition(origMember), T) | ||
| End If | ||
|
|
||
| 'Dim errorType = DirectCast(type, SubstitutedErrorType) |
There was a problem hiding this comment.
What's going on here? #Resolved
There was a problem hiding this comment.
That's a WIP commit (to transfer from work to home). #Resolved
| Case SymbolKind.ErrorType, | ||
| SymbolKind.DynamicType, | ||
| Case SymbolKind.ErrorType | ||
| Return DecodeNamedType(DirectCast(type, NamedTypeSymbol)) |
There was a problem hiding this comment.
Is the same change needed in C#? #Resolved
There was a problem hiding this comment.
The PR is marked for personal review. Still working on it. #Resolved
There was a problem hiding this comment.
I'll be removing this change. #Resolved
|
Done with removing unnecessary code. |
|
Thanks. |
Customer scenario
Use a type that implements an interface that involves named tuples, but don't reference the assembly which defines
ValueTupletypes.The interface that involves named tuples will be substituted with an error type with no details. This results in confusing error, such as
error CS0648: '' is a type not supported by the languageBut in some cases, the compilation should not even fail (if the interface doesn't end-up being used). And in some cases it should fail, but with an error reporting the missing
ValueTupletype.Bugs this fixes
Fixes #21727
Workarounds, if any
Add the missing reference. But the diagnostics don't offer much guidance...
Risk
Performance impact
Low. When decoding tuple names fails, use the partially decoded type (which has errors) rather than making a blank error type.
Is this a regression from a previous update?
No
Root cause analysis
Fairly edge case.
How was the bug found?
Reported by customer.