Skip to content

Improve diagnostic when decoding tuples but VT is missing#23949

Merged
jcouv merged 8 commits intodotnet:masterfrom
jcouv:tuple-decoding
Feb 2, 2018
Merged

Improve diagnostic when decoding tuples but VT is missing#23949
jcouv merged 8 commits intodotnet:masterfrom
jcouv:tuple-decoding

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Dec 27, 2017

Customer scenario

Use a type that implements an interface that involves named tuples, but don't reference the assembly which defines ValueTuple types.
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 language

But 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 ValueTuple type.

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.

@jcouv jcouv added this to the 15.6 milestone Dec 27, 2017
@jcouv jcouv self-assigned this Dec 27, 2017
@jcouv
Copy link
Member Author

jcouv commented Dec 28, 2017

@dotnet/roslyn-compiler for review. Thanks

1 similar comment
@jcouv
Copy link
Member Author

jcouv commented Jan 2, 2018

@dotnet/roslyn-compiler for review. Thanks

Copy link
Member

@VSadov VSadov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jcouv
Copy link
Member Author

jcouv commented Jan 2, 2018

@MeiChin-Tsai for ask-mode approval for 15.6. Thanks

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jan 3, 2018

Does VB have the same issue? #Closed

if (!hasTupleElementNamesAttribute ||
decoder._namesIndex == 0)
decoder._namesIndex == 0 ||
(object)decoded.VisitType(s_containsErrorPredicate, null) != null)
Copy link
Contributor

@AlekseyTs AlekseyTs Jan 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That worked out. Error types have everything to pass for ValueTuples. The main thing is to not mangle the name.

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider an alternative way to address the problem - #23949 (comment)

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jan 3, 2018

Done with review pass (iteration 1). #Closed

@MeiChin-Tsai
Copy link

@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)
Copy link
Member

@agocke agocke Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here? #Resolved

Copy link
Member Author

@jcouv jcouv Jan 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a WIP commit (to transfer from work to home). #Resolved

@jcouv jcouv added the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Jan 5, 2018
@jcouv jcouv modified the milestones: 15.6, 15.7 Jan 17, 2018
@jcouv jcouv requested a review from a team as a code owner February 1, 2018 00:07
@jcouv jcouv added PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. and removed 3 - Working PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Feb 1, 2018
Case SymbolKind.ErrorType,
SymbolKind.DynamicType,
Case SymbolKind.ErrorType
Return DecodeNamedType(DirectCast(type, NamedTypeSymbol))
Copy link
Contributor

@cston cston Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same change needed in C#? #Resolved

Copy link
Member Author

@jcouv jcouv Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is marked for personal review. Still working on it. #Resolved

Copy link
Member Author

@jcouv jcouv Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be removing this change. #Resolved

@jcouv jcouv removed the PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. label Feb 1, 2018
@jcouv
Copy link
Member Author

jcouv commented Feb 1, 2018

Done with removing unnecessary code.
@dotnet/roslyn-compiler for review. Thanks

@AlekseyTs AlekseyTs dismissed their stale review February 1, 2018 22:26

obsolete

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (iteration 8)

@jcouv
Copy link
Member Author

jcouv commented Feb 2, 2018

Thanks.
@MeiChin-Tsai I'll go ahead and merge since this is no longer a 15.6 issue and my understanding is that compiler fixes for 15.7 and 15.8 do not require ask-mode approval at this stage.

@jcouv jcouv modified the milestones: 15.7, 15.8 Feb 2, 2018
@jcouv jcouv merged commit 7064277 into dotnet:master Feb 2, 2018
@jcouv jcouv deleted the tuple-decoding branch February 2, 2018 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect diagnostic: error CS0648: '' is a type not supported by the language (tuple decoding issue)

6 participants