diff --git a/src/Compiler/Checking/CheckFormatStrings.fs b/src/Compiler/Checking/CheckFormatStrings.fs index b37f21506a6..1264cbbcb86 100644 --- a/src/Compiler/Checking/CheckFormatStrings.fs +++ b/src/Compiler/Checking/CheckFormatStrings.fs @@ -449,7 +449,7 @@ let parseFormatStringInternal checkOtherFlags ch collectSpecifierLocation fragLine fragCol 1 let i = skipPossibleInterpolationHole (i+1) - let stringTy = if g.checkNullness && g.langFeatureNullness then g.string_ty_withNull else g.string_ty + let stringTy = if g.checkNullness && g.langFeatureNullness then g.string_ty_ambivalent else g.string_ty parseLoop ((posi, stringTy) :: acc) (i, fragLine, fragCol+1) fragments | 'O' -> diff --git a/src/Compiler/TypedTree/TcGlobals.fs b/src/Compiler/TypedTree/TcGlobals.fs index 120d61840b5..a5a9af0f9b0 100644 --- a/src/Compiler/TypedTree/TcGlobals.fs +++ b/src/Compiler/TypedTree/TcGlobals.fs @@ -449,7 +449,7 @@ type TcGlobals( let v_FormattableStringFactory_tcref = findSysTyconRef sysCompilerServices "FormattableStringFactory" let v_FormattableStringFactory_ty = mkNonGenericTy v_FormattableStringFactory_tcref let v_string_ty = mkNonGenericTy v_string_tcr - let v_string_ty_withNull = mkNonGenericTyWithNullness v_string_tcr KnownWithNull + let v_string_ty_ambivalent = mkNonGenericTyWithNullness v_string_tcr KnownAmbivalentToNull let v_decimal_ty = mkSysNonGenericTy sys "Decimal" let v_unit_ty = mkNonGenericTy v_unit_tcr_nice let v_system_Type_ty = mkSysNonGenericTy sys "Type" @@ -1341,7 +1341,7 @@ type TcGlobals( member _.bool_ty = v_bool_ty member _.int_ty = v_int_ty member _.string_ty = v_string_ty - member _.string_ty_withNull = v_string_ty_withNull + member _.string_ty_ambivalent = v_string_ty_ambivalent member _.system_IFormattable_tcref = v_IFormattable_tcref member _.system_FormattableString_tcref = v_FormattableString_tcref member _.system_FormattableStringFactory_tcref = v_FormattableStringFactory_tcref diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index 09dc6ca954f..9dca34495c5 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -61,7 +61,7 @@ let maybeNull : string | null = null let nonNullString = "abc" let printedValueNotNull = sprintf "This is not null: %s" nonNullString let printedValueNull = sprintf "This is null: %s" maybeNull -let interpolated = $"This is fine {maybeNull}" +let interpolated = $"This is fine %s{maybeNull}" let interpolatedAnnotatedNotNull = $"This is fine %s{nonNullString}" let interpolatedAnnotatedNullable = $"This is not null %s{maybeNull}" let interpolateNullLiteral = $"This is not null %s{null}" @@ -96,6 +96,19 @@ let printViaA = sprintf "This is null: %A and this has null inside %A" maybeArra |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``Type inference with sprintfn`` () = + FSharp """module MyLibrary +let needsString(x:string) = () + +let myTopFunction inferedVal = + printfn "This is it %s" inferedVal // There was a regression infering this to be (string | null) + needsString inferedVal +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] let ``WhatIf the format itself is null`` () = FSharp """module MyLibrary