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 missing nullness warning in case of multiple applicable candidates for method resolution (e.g. string and ROS<char>) #17918

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,6 @@ and SolveTypMeetsTyparConstraints (csenv: ConstraintSolverEnv) ndeep m2 trace ty

and shouldWarnUselessNullCheck (csenv:ConstraintSolverEnv) =
csenv.g.checkNullness &&
csenv.IsSpeculativeForMethodOverloading = false &&
csenv.SolverState.WarnWhenUsingWithoutNullOnAWithNullTarget.IsSome

// nullness1: actual
Expand Down Expand Up @@ -1102,7 +1101,7 @@ and SolveNullnessSubsumesNullness (csenv: ConstraintSolverEnv) m2 (trace: Option
| NullnessInfo.WithNull, NullnessInfo.WithoutNull ->
CompleteD
| NullnessInfo.WithoutNull, NullnessInfo.WithNull ->
if csenv.g.checkNullness && not csenv.IsSpeculativeForMethodOverloading then
if csenv.g.checkNullness then
WarnD(ConstraintSolverNullnessWarningWithTypes(csenv.DisplayEnv, ty1, ty2, n1, n2, csenv.m, m2))
else
CompleteD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ let typeCheckWithStrictNullness cu =



[<FSharp.Test.FactForNETCOREAPPAttribute>]
let ``Does report when null goes to DateTime Parse`` () =

FSharp """module TestLib
open System
let parsedDate = DateTime.Parse(null:(string|null))
let parseDate2(s:string|null) = DateTime.Parse(s)
let parsedDate3 = DateTime.Parse(null)
"""
|> asLibrary
|> typeCheckWithStrictNullness
|> shouldFail
|> withDiagnostics
[Error 3261, Line 3, Col 18, Line 3, Col 52, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."
Error 3261, Line 4, Col 33, Line 4, Col 50, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."
Error 3261, Line 5, Col 19, Line 5, Col 39, "Nullness warning: The type 'string' does not support 'null'."]

[<Fact>]
let ``Can convert generic value to objnull arg`` () =
FSharp """module TestLib
Expand Down
Loading