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 generate method type parameter nullability #39079
base: main
Are you sure you want to change the base?
Fix generate method type parameter nullability #39079
Conversation
Fixes dotnet#39074. Further commits will follow up on this one that futher refines various senarios.
|
||
// Add a ? if the type parameter is annotated as nullable, and the constraints allow it. It's possible to end up with | ||
// a T? where T is constrained to class? if we combined a type parameter with some flow state -- we'll ignore the ? here | ||
// at this stage. We should consider moving that check earlier when we actually wrap the symbol. |
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.
I recognize this check isn't right -- I'm just getting things off the ground to see what else might be breaking here.
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 you elaborate when this would be incorrect? Is it the case where flow state shows that we don't need to mark as nullable only because null will never be passed in?
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.
The check for "HasReferenceTypeConstraint" is probably insufficient, because you can be constrainted to reference types if you have something like "T : SomeClass". And there's probably other cases too.
01d4bb5
to
21584df
Compare
Can you include me when this is ready for review? Thanks! |
@CyrusNajmabadi Sure! And to give some context: @333fred, @AlekseyTs and I are working through some of the details of eliminating the symbol wrapping and moving that to the compiler directly; this came out of that so this is somewhat bugfixing and somewhat exploratory. |
Sounds awesome! You guys rock! |
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)] | ||
public async Task TestInvocationWithClassConstrainedTypeArgumentAndNullableTypes() | ||
{ | ||
await TestInRegularAndScriptAsync( |
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 make sure to test nullable constraint with not-null flow analysis?
class C
{
public T M<T>() where T : class?, new
{
var t = new T();
return [|M2|](t);
}
}
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.
Isn't that the TestInvocationWithNullableClassConstrainedTypeArgumentAndNullableTypes test below?
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.
oof, mondays...
Based on current draft it looks good. Not complete, but does solve some immediate issues without regression afaict |
No description provided.