Fix a crash when a nullable reference type is used in a pattern.#45206
Fix a crash when a nullable reference type is used in a pattern.#45206gafter merged 2 commits intodotnet:masterfrom
Conversation
| } | ||
| else if (typeSyntax is NullableTypeSyntax) | ||
| { | ||
| Error(diagnostics, ErrorCode.ERR_PatternNullableType, typeSyntax, patternType.ToDisplayString(CodeAnalysis.NullableFlowState.MaybeNull), patternType); |
There was a problem hiding this comment.
Ideally we should delay converting the patternType argument to a string until the diagnostic message is needed. Could we use typeSyntax as the diagnostic argument instead of patternType.ToDisplayString(...)? #Resolved
There was a problem hiding this comment.
No, because we are using ToDisplayString to tack on a ?. I suppose I could put the ? into the diagnostic template? The type syntax might contain multiple lines including comments.
In reply to: 440484936 [](ancestors = 440484936)
There was a problem hiding this comment.
typeSyntax is a NullableTypeSyntax. Doesn't it include ?? #Resolved
There was a problem hiding this comment.
|
@cston I've responded to your comments. I don't know if you still think I should do something about realizing the type as a string in the diagnostic early. I suppose I could put the |
|
@cston I added a commit that keeps the diagnostic arguments lazy. Would you please have a look? #Resolved |
Fixes #45103