Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jasonmalinowski
Copy link
Member

No description provided.

Fixes dotnet#39074. Further commits
will follow up on this one that futher refines various senarios.
@jasonmalinowski jasonmalinowski self-assigned this Oct 4, 2019
@jasonmalinowski jasonmalinowski added this to In Progress in IDE Nullability Work via automation Oct 4, 2019

// 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.
Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

@jasonmalinowski jasonmalinowski force-pushed the fix-generate-method-type-parameter-nullability branch from 01d4bb5 to 21584df Compare October 4, 2019 23:28
@CyrusNajmabadi
Copy link
Member

Can you include me when this is ready for review? Thanks!

@jasonmalinowski
Copy link
Member Author

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

@CyrusNajmabadi
Copy link
Member

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

Sounds awesome! You guys rock!

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
public async Task TestInvocationWithClassConstrainedTypeArgumentAndNullableTypes()
{
await TestInRegularAndScriptAsync(
Copy link
Contributor

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);
    }
}

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

oof, mondays...

@ryzngard
Copy link
Contributor

ryzngard commented Oct 8, 2019

Based on current draft it looks good. Not complete, but does solve some immediate issues without regression afaict

Base automatically changed from master to main March 3, 2021 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
IDE Nullability Work
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants