Skip to content
2 changes: 1 addition & 1 deletion docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* Fix active pattern typechecking regression. ([Issue #18638](https://github.com/dotnet/fsharp/issues/18638), [PR #18642](https://github.com/dotnet/fsharp/pull/18642))
* Fix nullness warnings when casting non-nullable values to `IEquatable<T>` to match C# behavior. ([Issue #18759](https://github.com/dotnet/fsharp/issues/18759))
* Fix IsByRefLikeAttribute types being incorrectly suppressed in completion lists. Types like `Span<T>` and `ReadOnlySpan<T>` now appear correctly in IntelliSense.

* Fix SRTP nullness constraint resolution for types imported from older assemblies. AmbivalentToNull types now use legacy F# nullness rules instead of always satisfying `'T : null` constraints. ([Issue #18390](https://github.com/dotnet/fsharp/issues/18390), [Issue #18344](https://github.com/dotnet/fsharp/issues/18344))
* Fix Show XML doc for enum fields in external metadata ([Issue #17939](https://github.com/dotnet/fsharp/issues/17939#issuecomment-3137410105), [PR #18800](https://github.com/dotnet/fsharp/pull/18800))
* Fix nullable types formatting in `FSharpType.Format` and tooltips to include parentheses. ([PR #18842](https://github.com/dotnet/fsharp/pull/18842))
* TypeMismatchDiagnosticExtendedData: fix expected and actual types calculation. ([Issue ](https://github.com/dotnet/fsharp/pull/18851))

### Changed
Expand Down
34 changes: 20 additions & 14 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ module internal PrintUtilities =
| [x] -> [resultFunction x (layoutFunction x)]
| x :: rest -> [ resultFunction x (layoutFunction x -- leftL (tagText (match rest.Length with 1 -> FSComp.SR.nicePrintOtherOverloads1() | n -> FSComp.SR.nicePrintOtherOverloadsN(n)))) ]
| _ -> []

let showNullness (denv: DisplayEnv) (nullness: Nullness) =
denv.showNullnessAnnotations <> Some false && nullness.Evaluate() = NullnessInfo.WithNull

let tagEntityRefName(denv: DisplayEnv) (xref: EntityRef) name =
if xref.IsNamespace then tagNamespace name
Expand Down Expand Up @@ -942,15 +945,12 @@ module PrintTypes =
| [arg] -> layoutTypeWithInfoAndPrec denv env 2 arg ^^ tcL
| args -> bracketIfL (prec <= 1) (bracketL (layoutTypesWithInfoAndPrec denv env 2 SepL.comma args) --- tcL)

and layoutNullness (denv: DisplayEnv) part2 (nullness: Nullness) =
and layoutNullness (denv: DisplayEnv) part2 (nullness: Nullness) prec =
// Show nullness annotations unless explicitly turned off
if denv.showNullnessAnnotations <> Some false then
match nullness.Evaluate() with
| NullnessInfo.WithNull -> part2 ^^ wordL (tagPunctuation "|") ^^ wordL (tagKeyword "null")
| NullnessInfo.WithoutNull -> part2
| NullnessInfo.AmbivalentToNull -> part2 //^^ wordL (tagText "__maybenull")
if showNullness denv nullness then
part2 ^^ wordL (tagPunctuation "|") ^^ wordL (tagKeyword "null") |> bracketIfL (prec <= 3)
else
part2
part2 // if NullnessInfo.AmbivalentToNull -> part2 ^^ wordL (tagText "__maybenull")

/// Layout a type, taking precedence into account to insert brackets where needed
and layoutTypeWithInfoAndPrec denv env prec ty =
Expand Down Expand Up @@ -1014,7 +1014,7 @@ module PrintTypes =
prefix
args

let part2 = layoutNullness denv part1 nullness
let part2 = layoutNullness denv part1 nullness prec

part2
// Layout a tuple type
Expand Down Expand Up @@ -1046,14 +1046,15 @@ module PrintTypes =
let retTyL = layoutTypeWithInfoAndPrec denv env 5 retTy
let argTysL = argTys |> List.map (layoutTypeWithInfoAndPrec denv env 4)
let funcTyL = curriedLayoutsL arrow argTysL retTyL
let part1 = bracketIfL (prec <= 4) funcTyL
let part2 = layoutNullness denv part1 nullness
let showNull = showNullness denv nullness
let part1 = bracketIfL (prec <= 4 || showNull) funcTyL
let part2 = layoutNullness denv part1 nullness prec
part2

// Layout a type variable .
| TType_var (r, nullness) ->
let part1 = layoutTyparRefWithInfo denv env r
let part2 = layoutNullness denv part1 nullness
let part2 = layoutNullness denv part1 nullness prec
part2

| TType_measure unt -> layoutMeasure denv unt
Expand Down Expand Up @@ -1104,8 +1105,13 @@ module PrintTypes =

// Layout an unnamed argument
// Cannot have any attributes
| None, _, _ ->
layoutTypeWithInfoAndPrec denv env 2 ty
| None, _, _ ->
let prec =
match ty with
| TType_tuple _ -> 2
| _ -> 4

layoutTypeWithInfoAndPrec denv env prec ty

// Layout a named argument
| Some id, _, _ ->
Expand Down Expand Up @@ -2945,7 +2951,7 @@ let minimalStringOfType denv ty =
let ty, _cxs = PrettyTypes.PrettifyType denv.g ty
let denv = suppressNullnessAnnotations denv
let denvMin = { denv with showInferenceTyparAnnotations=false; showStaticallyResolvedTyparAnnotations=false }
showL (PrintTypes.layoutTypeWithInfoAndPrec denvMin SimplifyTypes.typeSimplificationInfo0 2 ty)
showL (PrintTypes.layoutTypeWithInfoAndPrec denvMin SimplifyTypes.typeSimplificationInfo0 5 ty)

let minimalStringOfTypeWithNullness denv ty =
minimalStringOfType {denv with showNullnessAnnotations = Some true} ty
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@ module ByrefSafetyAnalysis =
(Error 438, Line 113, Col 23, Line 113, Col 33, "Duplicate method. The method 'TestMethod' has the same name and signature as another method in type 'NegativeTests.TestNegativeOverloading'.")
(Error 412, Line 121, Col 18, Line 121, Col 22, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 123, Col 18, Line 123, Col 23, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3301, Line 125, Col 9, Line 125, Col 14, "The function or method has an invalid return type '(byref<int> * int)'. This is not permitted by the rules of Common IL.")
(Error 3301, Line 125, Col 9, Line 125, Col 14, "The function or method has an invalid return type 'byref<int> * int'. This is not permitted by the rules of Common IL.")
(Error 412, Line 125, Col 34, Line 125, Col 39, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 418, Line 125, Col 35, Line 125, Col 36, "The byref typed value 'x' cannot be used at this point")
(Error 3301, Line 127, Col 9, Line 127, Col 14, "The function or method has an invalid return type '(byref<int> -> unit)'. This is not permitted by the rules of Common IL.")
(Error 3301, Line 127, Col 9, Line 127, Col 14, "The function or method has an invalid return type 'byref<int> -> unit'. This is not permitted by the rules of Common IL.")
(Error 412, Line 129, Col 14, Line 129, Col 15, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3300, Line 131, Col 17, Line 131, Col 18, "The parameter 'x' has an invalid type '((byref<int> -> unit) * int)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 133, Col 17, Line 133, Col 18, "The parameter 'x' has an invalid type '(byref<int> -> unit)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 133, Col 41, Line 133, Col 42, "The parameter 'y' has an invalid type '(byref<int> * int)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 139, Col 36, Line 139, Col 39, "The parameter 'tup' has an invalid type '(inref<int> * int)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 131, Col 17, Line 131, Col 18, "The parameter 'x' has an invalid type '(byref<int> -> unit) * int'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 133, Col 17, Line 133, Col 18, "The parameter 'x' has an invalid type 'byref<int> -> unit'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 133, Col 41, Line 133, Col 42, "The parameter 'y' has an invalid type 'byref<int> * int'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 139, Col 36, Line 139, Col 39, "The parameter 'tup' has an invalid type 'inref<int> * int'. This is not permitted by the rules of Common IL.")
(Error 412, Line 140, Col 13, Line 140, Col 33, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3300, Line 142, Col 37, Line 142, Col 38, "The parameter 'x' has an invalid type '(byref<int> -> unit)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 142, Col 37, Line 142, Col 38, "The parameter 'x' has an invalid type 'byref<int> -> unit'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 144, Col 37, Line 144, Col 38, "The parameter 'x' has an invalid type 'byref<int> option'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 146, Col 17, Line 146, Col 18, "The parameter 'x' has an invalid type 'byref<int> option'. This is not permitted by the rules of Common IL.")
(Error 412, Line 151, Col 13, Line 151, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 151, Col 17, Line 151, Col 30, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3301, Line 154, Col 9, Line 154, Col 15, "The function or method has an invalid return type '(byref<int> -> unit)'. This is not permitted by the rules of Common IL.")
(Error 3301, Line 154, Col 9, Line 154, Col 15, "The function or method has an invalid return type 'byref<int> -> unit'. This is not permitted by the rules of Common IL.")
(Error 412, Line 155, Col 9, Line 155, Col 22, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 158, Col 13, Line 158, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 160, Col 13, Line 160, Col 26, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 165, Col 9, Line 165, Col 22, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 169, Col 13, Line 169, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 169, Col 17, Line 169, Col 28, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3301, Line 172, Col 9, Line 172, Col 15, "The function or method has an invalid return type '(int -> byref<int> -> unit)'. This is not permitted by the rules of Common IL.")
(Error 3301, Line 172, Col 9, Line 172, Col 15, "The function or method has an invalid return type 'int -> byref<int> -> unit'. This is not permitted by the rules of Common IL.")
(Error 412, Line 173, Col 9, Line 173, Col 20, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 176, Col 13, Line 176, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 178, Col 13, Line 178, Col 24, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
Expand All @@ -102,7 +102,7 @@ module ByrefSafetyAnalysis =
(Error 412, Line 191, Col 13, Line 191, Col 14, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 193, Col 13, Line 193, Col 28, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 198, Col 9, Line 198, Col 24, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 3301, Line 201, Col 9, Line 201, Col 15, "The function or method has an invalid return type '(byref<int> * int)'. This is not permitted by the rules of Common IL.")
(Error 3301, Line 201, Col 9, Line 201, Col 15, "The function or method has an invalid return type 'byref<int> * int'. This is not permitted by the rules of Common IL.")
(Error 412, Line 203, Col 10, Line 203, Col 15, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 421, Line 203, Col 11, Line 203, Col 12, "The address of the variable 'x' cannot be used at this point")
(Error 412, Line 206, Col 9, Line 206, Col 18, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
Expand Down Expand Up @@ -807,7 +807,7 @@ type outref<'T> with
|> compile
|> shouldFail
|> withDiagnostics [
(Error 3300, Line 5, Col 18, Line 5, Col 19, "The parameter 'f' has an invalid type '(byref<int> -> 'a)'. This is not permitted by the rules of Common IL.")
(Error 3300, Line 5, Col 18, Line 5, Col 19, "The parameter 'f' has an invalid type 'byref<int> -> 'a'. This is not permitted by the rules of Common IL.")
(Error 424, Line 7, Col 6, Line 7, Col 13, "The address of an array element cannot be used at this point")
(Error 412, Line 9, Col 19, Line 9, Col 20, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
(Error 412, Line 11, Col 19, Line 11, Col 20, "A type instantiation involves a byref type. This is not permitted by the rules of Common IL.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let myVal =
\tf1: int list
\t{| X: string |}
\tf3: U
\tf4: (int * System.String)")
\tf4: int * System.String")

[<Fact>]
let ``Union matching error - Named args - Name used twice`` () =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ let main _args =
|> withDiagnostics
[ Error 3265, Line 13, Col 13, Line 13, Col 60, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for '{| x: int |}'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 14, Col 13, Line 14, Col 51, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for 'System.Int32'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 15, Col 13, Line 15, Col 59, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for '(int * float)'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 15, Col 13, Line 15, Col 59, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for 'int * float'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 16, Col 13, Line 16, Col 67, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for 'struct (int * float)'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 17, Col 13, Line 17, Col 57, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for 'int<mykg>'. Nullness warnings won't be reported correctly for such types."
Error 3265, Line 18, Col 13, Line 18, Col 57, "Application of method 'Deserialize' attempted to create a nullable type ('T | null) for 'int<mykg>'. Nullness warnings won't be reported correctly for such types."]
Expand Down Expand Up @@ -152,7 +152,7 @@ let doNotWarnOnDowncastRepeatedNestedNullable(o:objnull) = o :? list<((AB | null
[ Error 3264, Line 4, Col 39, Line 4, Col 47, "Nullness warning: Downcasting from 'objnull' into 'AB' can introduce unexpected null values. Cast to 'AB|null' instead or handle the null before downcasting."
Error 3060, Line 5, Col 42, Line 5, Col 59, "This type test or downcast will erase the provided type 'AB | null' to the type 'AB'"
Error 3060, Line 6, Col 41, Line 6, Col 55, "This type test or downcast will erase the provided type 'AB | null' to the type 'AB'"
Error 3060, Line 7, Col 51, Line 7, Col 97, "This type test or downcast will erase the provided type 'List<AB | null array | null> | null' to the type 'List<AB array>'"]
Error 3060, Line 7, Col 51, Line 7, Col 97, "This type test or downcast will erase the provided type 'List<(AB | null) array | null> | null' to the type 'List<AB array>'"]


[<Fact>]
Expand Down Expand Up @@ -611,7 +611,7 @@ let f6(x: 'a | null when 'a:null) = ()
[ Error 3261, Line 3, Col 11, Line 3, Col 32, "Nullness warning: The type 'string option' uses 'null' as a representation value but a non-null type is expected."
Error 3260, Line 4, Col 11, Line 4, Col 21, "The type 'int' does not support a nullness qualification."
Error 43, Line 4, Col 11, Line 4, Col 21, "A generic construct requires that the type 'int' have reference semantics, but it does not, i.e. it is a struct"
Error 3260, Line 5, Col 11, Line 5, Col 25, "The type '('a * 'b)' does not support a nullness qualification."
Error 3260, Line 5, Col 11, Line 5, Col 25, "The type ''a * 'b' does not support a nullness qualification."
Error 3261, Line 6, Col 11, Line 6, Col 28, "Nullness warning: The type ''a option' uses 'null' as a representation value but a non-null type is expected."
Error 43, Line 7, Col 28, Line 7, Col 37, "The constraints 'struct' and 'not struct' are inconsistent"
Error 43, Line 8, Col 26, Line 8, Col 33, "The constraints 'null' and 'not null' are inconsistent"]
Expand Down Expand Up @@ -1013,7 +1013,7 @@ myNullReturningFunction myValOfY |> ignore
[Error 3261, Line 17, Col 25, Line 17, Col 34, "Nullness warning: The type 'string' does not support 'null'."
Error 193, Line 19, Col 26, Line 19, Col 45, "The type 'System.DateTime' does not have 'null' as a proper value"
Error 1, Line 20, Col 25, Line 20, Col 36, "The type '{| Anon: 'a |}' does not have 'null' as a proper value"
Error 1, Line 21, Col 26, Line 21, Col 31, "The type '('a * 'b * 'c)' does not have 'null' as a proper value"
Error 1, Line 21, Col 26, Line 21, Col 31, "The type ''a * 'b * 'c' does not have 'null' as a proper value"
Error 1, Line 23, Col 25, Line 23, Col 33, "The type 'Y' does not have 'null' as a proper value"]


Expand Down Expand Up @@ -1084,8 +1084,8 @@ looseFunc(maybeTuple2) |> ignore
|> shouldFail
|> withDiagnostics
[ Error 43, Line 21, Col 12, Line 21, Col 16, "The constraints 'null' and 'not null' are inconsistent"
Error 3260, Line 27, Col 18, Line 27, Col 34, "The type '(int * int)' does not support a nullness qualification."
Error 43, Line 27, Col 37, Line 27, Col 41, "The type '(int * int)' does not have 'null' as a proper value"
Error 3260, Line 27, Col 18, Line 27, Col 34, "The type 'int * int' does not support a nullness qualification."
Error 43, Line 27, Col 37, Line 27, Col 41, "The type 'int * int' does not have 'null' as a proper value"
Error 3261, Line 29, Col 12, Line 29, Col 19, "Nullness warning: The type 'MyDu | null' supports 'null' but a non-null type is expected."
Error 3261, Line 30, Col 12, Line 30, Col 21, "Nullness warning: The type 'MyRecord | null' supports 'null' but a non-null type is expected."
Error 43, Line 40, Col 36, Line 40, Col 40, "The type 'Maybe<int * int>' does not have 'null' as a proper value"]
Expand Down
Loading
Loading