Skip to content

Commit 24116f0

Browse files
authored
Merge pull request #17491 from dotnet/merges/main-to-release/dev17.12
Merge main to release/dev17.12
2 parents 2f69126 + 9ee9282 commit 24116f0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ and SolveNullnessSubsumesNullness (csenv: ConstraintSolverEnv) m2 (trace: Option
11011101
| NullnessInfo.WithNull, NullnessInfo.WithoutNull ->
11021102
CompleteD
11031103
| NullnessInfo.WithoutNull, NullnessInfo.WithNull ->
1104-
if csenv.g.checkNullness then
1104+
if csenv.g.checkNullness && not csenv.IsSpeculativeForMethodOverloading then
11051105
WarnD(ConstraintSolverNullnessWarningWithTypes(csenv.DisplayEnv, ty1, ty2, n1, n2, csenv.m, m2))
11061106
else
11071107
CompleteD

tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ let typeCheckWithStrictNullness cu =
1515
cu
1616
|> withNullnessOptions
1717
|> typecheck
18+
19+
[<Fact>]
20+
let ``Does not duplicate warnings`` () =
21+
FSharp """
22+
module MyLib
23+
let getLength (x: string | null) = x.Length
24+
"""
25+
|> asLibrary
26+
|> typeCheckWithStrictNullness
27+
|> shouldFail
28+
|> withDiagnostics [Error 3261, Line 3, Col 36, Line 3, Col 44, "Nullness warning: The types 'string' and 'string | null' do not have compatible nullability."]
29+
1830

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

0 commit comments

Comments
 (0)