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

Make nullability inference associative and commutative #30990

Merged
merged 1 commit into from Nov 9, 2018

Conversation

gafter
Copy link
Member

@gafter gafter commented Nov 6, 2018

Fixes #30966
Implements the spec change described in #30670
See also #30989

@gafter gafter added this to the 16.0.P2 milestone Nov 6, 2018
@gafter gafter self-assigned this Nov 6, 2018
@gafter gafter requested review from cston and a team November 6, 2018 17:57
@gafter gafter added this to Working/In Review in Compiler: Gafter Nov 6, 2018
@jcouv jcouv changed the title Make nullabiulity inference associative and commutative Make nullability inference associative and commutative Nov 6, 2018
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)

@gafter
Copy link
Member Author

gafter commented Nov 7, 2018

@cston Could you please review this?

Diagnostic(ErrorCode.WRN_NoBestNullabilityConditionalExpression, "b ? ref y2 : ref x2").WithArguments("I<string>", "I<string?>").WithLocation(16, 10),
// (16,27): warning CS8619: Nullability of reference types in value of type 'I<string?>' doesn't match target type 'I<string>'.
// (b ? ref y2 : ref x2)/*T:I<string!>!*/.P.ToString();
Diagnostic(ErrorCode.WRN_NullabilityMismatchInAssignment, "x2").WithArguments("I<string?>", "I<string>").WithLocation(16, 27),
Copy link
Member

Choose a reason for hiding this comment

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

WRN_NullabilityMismatchInAssignment [](start = 37, length = 35)

Should we avoid calling ApplyConversion in NullableWalker.VisitConditionalOperator if we reported WRN_NoBestNullability? (See similar handling in VisitArrayInitializer.)

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be a good way of reducing cascaded diagnostics in a future PR; see #30989

Diagnostic(ErrorCode.WRN_CantInferNullabilityOfMethodTypeArgs, "F(x1, y1)").WithArguments("C.F<T>(T, T)").WithLocation(12, 9),
// (12,15): warning CS8620: Nullability of reference types in argument of type 'I<string?>' doesn't match target type 'I<string>' for parameter 'y' in 'I<string> C.F<I<string>>(I<string> x, I<string> y)'.
// F(x1, y1)/*T:I<string!>!*/; // 1
Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "y1").WithArguments("I<string?>", "I<string>", "y", "I<string> C.F<I<string>>(I<string> x, I<string> y)").WithLocation(12, 15),
Copy link
Member

@cston cston Nov 7, 2018

Choose a reason for hiding this comment

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

WRN_NullabilityMismatchInArgument [](start = 37, length = 33)

Should we avoid using the inferred type arguments in NullableWalker.InferMethodTypeArguments if there was a nullability mismatch from MethodTypeInferrer.Infer?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be a good way of reducing cascaded diagnostics in a future PR; see #30989

Copy link
Member

@cston cston left a comment

Choose a reason for hiding this comment

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

LGTM. We should consider removing the cascading diagnostics from conditional operator conversions and inferred method arguments, perhaps in a subsequent PR.

@jcouv jcouv self-assigned this Nov 8, 2018
@jcouv
Copy link
Member

jcouv commented Nov 8, 2018

Approved for preview2

@jcouv jcouv closed this Nov 8, 2018
@jcouv jcouv reopened this Nov 8, 2018
@gafter gafter merged commit e923acd into dotnet:dev16.0-preview2 Nov 9, 2018
@gafter gafter removed this from Working/In Review in Compiler: Gafter Nov 9, 2018
wachulski added a commit to wachulski/roslyn that referenced this pull request Nov 12, 2018
…out-if-error-message

* origin/master: (174 commits)
  Add Compilers filter for Roslyn (dotnet#30880)
  Remove NonNullTypes context and other unnecessary information stored in TypeSymbolWithAnnotations. (dotnet#30913)
  Update BoundCall method based on receiver nullability (dotnet#31000)
  Make nullabiulity inference associative and commutative (dotnet#30990)
  Async-streams: minimal test for IOperation and CFG. Improve diagnostics (dotnet#30363)
  Add src.
  Add test.
  Remove dead code
  Update the build status table
  Script for generating our build status tables
  Add parsing tests to compiler benchmarks (dotnet#31033)
  Fix Edit and Continue in CPS projects
  Add comment
  Sorting.
  Save work
  Address PR feedback
  only produce optprof data on an official build
  Add bunch of exclusions to dead code analysis for special methods
  Disable WinRT tests on Linux (dotnet#31026)
  Change prerelease version to beta2 (dotnet#31017)
  ...

# Conflicts:
#	src/Compilers/CSharp/Portable/CSharpResources.resx
#	src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
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.

None yet

3 participants