-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Don't generate nullable type when applying value type with unconstrained nullable generic #49154
Changes from all commits
dce77d1
3fe21a8
328759d
b64f3f2
083c3e3
78074bf
fbb7d61
3638c73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,9 +300,10 @@ public override TypeSyntax VisitNamedType(INamedTypeSymbol symbol) | |
} | ||
} | ||
|
||
if (symbol.NullableAnnotation == NullableAnnotation.Annotated && | ||
!symbol.IsValueType) | ||
if (symbol is { IsValueType: false, NullableAnnotation: NullableAnnotation.Annotated }) | ||
{ | ||
// value type with nullable annotation may be composed from unconstrained nullable generic | ||
// doesn't mean nullable value type in this case | ||
typeSyntax = AddInformationTo(SyntaxFactory.NullableType(typeSyntax), symbol); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about other named types that can be value types. like tuples. can you update as well (or add tests showing they're k). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are they special for this case? Here is adding top-level nullability, I couldn't imagine any type to have special semantics. The inner type has been handled above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they're a named type that is a value type :) i just want to make sure it works properly and nothing unexpected happens. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding tests should be OK I think |
||
|
||
|
@@ -355,8 +356,12 @@ public override TypeSyntax VisitPointerType(IPointerTypeSymbol symbol) | |
public override TypeSyntax VisitTypeParameter(ITypeParameterSymbol symbol) | ||
{ | ||
TypeSyntax typeSyntax = AddInformationTo(symbol.Name.ToIdentifierName(), symbol); | ||
if (symbol.NullableAnnotation == NullableAnnotation.Annotated) | ||
if (symbol is { IsValueType: false, NullableAnnotation: NullableAnnotation.Annotated }) | ||
{ | ||
// value type with nullable annotation may be composed from unconstrained nullable generic | ||
// doesn't mean nullable value type in this case | ||
typeSyntax = AddInformationTo(SyntaxFactory.NullableType(typeSyntax), symbol); | ||
} | ||
|
||
return typeSyntax; | ||
} | ||
|
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.
can we a few more tests.
class
.class
, and passed as T? to the base typestruct
, and passed as T? to the base typeThere 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.
Sure, make sure that other cases doesn't regress.