Skip to content

Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal#46344

Merged
cston merged 1 commit intodotnet:masterfrom
cston:lambda-return-null
Jul 27, 2020
Merged

Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal#46344
cston merged 1 commit intodotnet:masterfrom
cston:lambda-return-null

Conversation

@cston
Copy link
Contributor

@cston cston commented Jul 27, 2020

Fixes #46342

@cston cston requested a review from a team as a code owner July 27, 2020 06:47
@cston cston added this to the 16.8.P1 milestone Jul 27, 2020
// (10,9): warning CS8602: Dereference of a possibly null reference.
// F(() => { if (x.Length == 0) return null; return x; }).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReturn, "null").WithLocation(10, 45));
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(() => { if (x.Length == 0) return null; return x; })").WithLocation(10, 9));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restores behavior from before #45993.

var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview);
comp.VerifyEmitDiagnostics();
}

Copy link
Member

Choose a reason for hiding this comment

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

Could we add similar tests with default? File an issue if misbehaving.

Copy link
Contributor Author

@cston cston Jul 27, 2020

Choose a reason for hiding this comment

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

return default; results in "warning CS8603: Possible null reference return" with 16.7 and this PR.
return default(T); compiles without warnings with both.

Added tests in #46405.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 1)

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (iteration 1)

@RikkiGibson
Copy link
Member

This needs to merge to master. We are reverting the feature in preview1 (see #46358).

@RikkiGibson RikkiGibson changed the base branch from release/dev16.8-preview1 to master July 27, 2020 21:24
@cston cston merged commit e128267 into dotnet:master Jul 27, 2020
@ghost ghost modified the milestones: 16.8.P1, Next Jul 27, 2020
@cston cston deleted the lambda-return-null branch July 27, 2020 23:51
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 28, 2020
…-pointers

* upstream/master: (207 commits)
  Update argument state when parameter has not-null type (dotnet#46072)
  Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal (dotnet#46344)
  Update README (dotnet#46136)
  Revert "Revert "Support nullable annotations on unconstrained type parameters""
  Revert "Support nullable annotations on unconstrained type parameters (dotnet#45993)"
  Fix type in publish data
  Update VSIXExpInstaller version to one available on ADO
  Update publish data for 16.8
  Update version of RichCodeNav.EnvVarDump
  A fixed initializer must be bound to its natural type (dotnet#46293)
  Update features merged into 16.7p4 (dotnet#46229)
  Async-streams: disposal should continue without jump within a finally (dotnet#46188)
  Recommend default in type constraint, but not record (dotnet#46311)
  Add use site diagnostics to IsUnmanaged (dotnet#46114)
  Add another flaky test.
  Ensure NuGet connections use TLS 1.2
  Update to Microsoft.CodeAnalysis.Testing 1.0.1-beta1.20374.2
  Skip flaky test.
  Fix build break. (dotnet#46303)
  Skip a flaky test Relates to dotnet#46304
  ...
333fred added a commit to 333fred/roslyn that referenced this pull request Jul 28, 2020
…to function-pointer-type-lookup

* upstream/features/function-pointers: (212 commits)
  Correct public API number.
  Update argument state when parameter has not-null type (dotnet#46072)
  Fix TypeWithAnnotations.ToTypeWithState() for (untyped) null literal (dotnet#46344)
  Update README (dotnet#46136)
  Revert "Revert "Support nullable annotations on unconstrained type parameters""
  Revert "Support nullable annotations on unconstrained type parameters (dotnet#45993)"
  Fix type in publish data
  Update VSIXExpInstaller version to one available on ADO
  Update publish data for 16.8
  Update version of RichCodeNav.EnvVarDump
  A fixed initializer must be bound to its natural type (dotnet#46293)
  Update features merged into 16.7p4 (dotnet#46229)
  Async-streams: disposal should continue without jump within a finally (dotnet#46188)
  Recommend default in type constraint, but not record (dotnet#46311)
  Add use site diagnostics to IsUnmanaged (dotnet#46114)
  Add another flaky test.
  Ensure NuGet connections use TLS 1.2
  Update to Microsoft.CodeAnalysis.Testing 1.0.1-beta1.20374.2
  Skip flaky test.
  Fix build break. (dotnet#46303)
  ...
@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.

"CS8603: Possible null reference return" reported for null from lambda that returns T? where T : class

4 participants