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

Cannot assign maybe-null value to TNotNull variable #41445

Merged
merged 3 commits into from
Jul 30, 2020

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented Feb 5, 2020

Fixes #41437

Note: some references to #41437 were added to the code since this PR was opened. Don't forget to resolve them before merging.

@jcouv jcouv added this to the 16.6.P1 milestone Feb 5, 2020
@jcouv jcouv self-assigned this Feb 5, 2020
@jcouv jcouv force-pushed the warn-notnull branch 2 times, most recently from 329dd94 to bc9506b Compare February 8, 2020 19:26
@jcouv jcouv marked this pull request as ready for review February 9, 2020 00:15
@jcouv jcouv requested a review from a team as a code owner February 9, 2020 00:15
@@ -121906,6 +121908,80 @@ void M()
);
}

[Fact, WorkItem(41437, "https://github.com/dotnet/roslyn/issues/41437")]
Copy link
Member Author

@jcouv jcouv Feb 9, 2020

Choose a reason for hiding this comment

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

@dotnet/roslyn-compiler This PR fixing a bug we noticed in LDM last week with a TNotNull.

Note that fixing this makes it harder to use TryGet APIs (with [MaybeNullWhen(...)] with a TNotNull) and this problem hit the roslyn codebase.
@cston I wonder if the introduction of T?? later in C# 9 might improve that situation (ie. by inferring TNotNull?? for the out var instead of TNotNull). Something to consider...

Copy link
Member Author

Choose a reason for hiding this comment

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

@jaredpar From discussion with Chuck, it's probably better to hold this PR back and ship it along with T?? work. I'll stop by to talk.

Copy link
Member Author

Choose a reason for hiding this comment

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

From offline discussion with Jared, we'll hold this PR until we do the T?? work.

@jcouv jcouv added PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. Blocked labels Feb 10, 2020
@jcouv jcouv modified the milestones: 16.6.P1, Compiler.Net5 Feb 11, 2020
@jaredpar jaredpar modified the milestones: Compiler.Net5, 16.8 Jun 23, 2020
@jcouv jcouv force-pushed the warn-notnull branch 2 times, most recently from 6aadf94 to 1c6aeda Compare July 24, 2020 04:57
@@ -34740,16 +34740,14 @@ class C<T>

[Theory]
[InlineData("T")]
Copy link
Member

@cston cston Jul 24, 2020

Choose a reason for hiding this comment

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

The test no longer needs parameters. #Closed

@jcouv jcouv removed Blocked PR For Personal Review Only The PR doesn’t require anyone other than the developer to review it. labels Jul 24, 2020
@jcouv jcouv requested review from a team and cston July 24, 2020 17:41
// return t; // 1
Diagnostic(ErrorCode.WRN_NullReferenceReturn, "t").WithLocation(8, 16)
);
}
Copy link
Member

@cston cston Jul 28, 2020

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Please test:

[return: MaybeNull] TNotNull M<TNotNull>(TNotNull t) where TNotNull : notnull
{
    ...
}
``` #Closed

}

[Fact]
public void TNotNullFieldMustBeAssigned()
Copy link
Member

@cston cston Jul 28, 2020

Choose a reason for hiding this comment

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

TNotNullFieldMustBeAssigned [](start = 20, length = 27)

Was the behavior of this method affected? This case and others are covered in UninitializedNonNullableFieldTests.GenericType_NotNullConstraint. #Closed

@RikkiGibson
Copy link
Contributor

Taking a look

@jcouv jcouv merged commit f1a8213 into dotnet:master Jul 30, 2020
@ghost ghost modified the milestones: 16.8, Next Jul 30, 2020
@jcouv jcouv deleted the warn-notnull branch July 30, 2020 18:39
var source = @"
class C
{
TNotNull M<TNotNull>(TNotNull t) where TNotNull : notnull
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I should have asked earlier, but do corresponding tests already exist for 'class' constraint? (I would be surprised if they didn'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.

Yes, it's covered by NullCastToUnannotatableReferenceTypedTypeParameter I think

333fred added a commit to 333fred/roslyn that referenced this pull request Jul 31, 2020
* upstream/master: (304 commits)
  Tweak diagnostics to account for records (dotnet#46341)
  Diagnose precedence inversion in a warning wave (dotnet#46239)
  Remove PROTOTYPE tag (dotnet#45965)
  Only run a single pass of NullableWalker per-member (dotnet#46402)
  Fix crash, and offer "declare as nullable" for tuple fields (dotnet#46437)
  Simplify contract for RunWithShutdownBlockAsync
  Fix optprof plugin input
  check if EditorAdaptersFactoryService gives us a null buffer
  Cannot assign maybe-null value to TNotNull variable (dotnet#41445)
  Fix overload resolution to handle binary compat in the face of covariant returns (dotnet#46367)
  Same failure on Linux
  Skip some tests on Mac
  Added search option for inline parameter name hints
  Spelling
  tweak docs
  Improve comment
  Improve the "not exhaustive" diagnostic in the presence of a when clause. (dotnet#46143)
  PR feedback
  Use record keyword to display records (dotnet#46338)
  remove test that aserts .NET Standard should be prefered over .NET Framework
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 16.8.P2 Aug 11, 2020
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.

Missing warning on returning a maybe-null value to a TNotNull
4 participants