Skip to content

Commit

Permalink
prevent duplicate warnings coming from speculative method resolution (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Gro authored Aug 5, 2024
1 parent 4a7a0f9 commit 599bb69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ and SolveNullnessSubsumesNullness (csenv: ConstraintSolverEnv) m2 (trace: Option
| NullnessInfo.WithNull, NullnessInfo.WithoutNull ->
CompleteD
| NullnessInfo.WithoutNull, NullnessInfo.WithNull ->
if csenv.g.checkNullness then
if csenv.g.checkNullness && not csenv.IsSpeculativeForMethodOverloading 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 @@ -15,6 +15,18 @@ let typeCheckWithStrictNullness cu =
cu
|> withNullnessOptions
|> typecheck

[<Fact>]
let ``Does not duplicate warnings`` () =
FSharp """
module MyLib
let getLength (x: string | null) = x.Length
"""
|> asLibrary
|> typeCheckWithStrictNullness
|> shouldFail
|> withDiagnostics [Error 3261, Line 3, Col 36, Line 3, Col 44, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."]


[<Fact>]
let ``Cannot pass possibly null value to a strict function``() =
Expand Down

0 comments on commit 599bb69

Please sign in to comment.