From 136e3a21c521624f177b2a2f423636aaf9560e6b Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 24 Oct 2024 14:22:53 +0200 Subject: [PATCH 1/3] speculativeForoverloads exclusion was a mistake --- src/Compiler/Checking/ConstraintSolver.fs | 3 +-- .../Nullness/NullableReferenceTypesTests.fs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 6c79c33be97..6d59c68c7e8 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -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 @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs index 0da1169b9a8..ad12f484e63 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs @@ -19,6 +19,23 @@ let typeCheckWithStrictNullness cu = +[] +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'."] + [] let ``Can convert generic value to objnull arg`` () = FSharp """module TestLib From 6c42f55233b1018e107cc6986de2c4dff4163fac Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 24 Oct 2024 15:15:43 +0200 Subject: [PATCH 2/3] DateTime not annotated on desktop --- .../Language/Nullness/NullableReferenceTypesTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs index ad12f484e63..2933d00e438 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableReferenceTypesTests.fs @@ -19,7 +19,7 @@ let typeCheckWithStrictNullness cu = -[] +[] let ``Does report when null goes to DateTime Parse`` () = FSharp """module TestLib From 7499f395a7fd8ff160bda2720aa965f218b022fb Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 6 Nov 2024 19:08:49 +0100 Subject: [PATCH 3/3] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.200.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md index 012beaecb6b..88b486d2b12 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.200.md @@ -9,6 +9,7 @@ * Fix concurrency issue in `ILPreTypeDefImpl` ([PR #17812](https://github.com/dotnet/fsharp/pull/17812)) * Fix nullness inference for member val and other OO scenarios ([PR #17845](https://github.com/dotnet/fsharp/pull/17845)) * Fix internal error when analyzing incomplete inherit member ([PR #17905](https://github.com/dotnet/fsharp/pull/17905)) +* Fix missing nullness warning in case of method resolution multiple candidates ([PR #17917](https://github.com/dotnet/fsharp/pull/17918)) ### Added