From 08fa2946d0c34320623de25e234fd3f38584e8d2 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 26 Apr 2024 12:26:17 +0200 Subject: [PATCH 01/18] Ignore Nullness applied on structs (C# allows T? when when T is a struct) --- src/Compiler/TypedTree/TypedTreeBasics.fs | 7 ++++++- .../Language/NullableCsharpImportTests.fs | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Compiler/TypedTree/TypedTreeBasics.fs b/src/Compiler/TypedTree/TypedTreeBasics.fs index f57c443f4d5..b125675651f 100644 --- a/src/Compiler/TypedTree/TypedTreeBasics.fs +++ b/src/Compiler/TypedTree/TypedTreeBasics.fs @@ -283,7 +283,12 @@ let addNullnessToTy (nullness: Nullness) (ty:TType) = | _ -> match ty with | TType_var (tp, nullnessOrig) -> TType_var (tp, combineNullness nullnessOrig nullness) - | TType_app (tcr, tinst, nullnessOrig) -> TType_app (tcr, tinst, combineNullness nullnessOrig nullness) + | TType_app (tcr, tinst, nullnessOrig) -> + let tycon = tcr.Deref + if tycon.IsStructRecordOrUnionTycon || tycon.IsStructOrEnumTycon then + ty + else + TType_app (tcr, tinst, combineNullness nullnessOrig nullness) | TType_fun (d, r, nullnessOrig) -> TType_fun (d, r, combineNullness nullnessOrig nullness) //| TType_ucase _ -> None // TODO NULLNESS //| TType_tuple _ -> None // TODO NULLNESS diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs index 7c138db4e47..38efbd12808 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs @@ -34,6 +34,18 @@ let doSomethingAboutIt (ilg:ILGenerator) = |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``Consuming C# generic API which allows struct and yet uses question mark on the typar`` () = + FSharp """module MyLibrary +let ec = + { new System.Collections.Generic.IEqualityComparer with + member this.Equals(x, y) = (x+0) = (y+0) + member this.GetHashCode(obj) = obj * 2} +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] let ``Consuming C# extension methods which allow nullable this`` () = FSharp """module MyLibrary From b55889055135542ff6c30fe10c77e6c428ed597f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 29 Apr 2024 14:02:11 +0200 Subject: [PATCH 02/18] Bigfix: Working with CLI events in Fsharp --- src/Compiler/Checking/CheckExpressions.fs | 3 ++- .../Language/NullableCsharpImportTests.fs | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index d1879119973..b5ab3ef6ac4 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -9522,7 +9522,8 @@ and TcEventItemThen (cenv: cenv) overallTy env tpenv mItem mExprAndItem objDetai | None, false -> error (Error (FSComp.SR.tcEventIsNotStatic nm, mItem)) | _ -> () - let delTy = einfo.GetDelegateType(cenv.amap, mItem) + // The F# wrappers around events are null safe (impl is in FSharp.Core). Therefore, from an F# perspective, the type of the delegate can be considered Not Null. + let delTy = einfo.GetDelegateType(cenv.amap, mItem) |> replaceNullnessOfTy KnownWithoutNull let (SigOfFunctionForDelegate(delInvokeMeth, delArgTys, _, _)) = GetSigOfFunctionForDelegate cenv.infoReader delTy mItem ad let objArgs = Option.toList (Option.map fst objDetails) MethInfoChecks g cenv.amap true None objArgs env.eAccessRights mItem delInvokeMeth diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs index 38efbd12808..b7118fbe61e 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableCsharpImportTests.fs @@ -12,6 +12,7 @@ let typeCheckWithStrictNullness cu = |> withOptions ["--warnaserror+"] |> compile + [] let ``Passing null to IlGenerator BeginCatchBlock is fine`` () = FSharp """module MyLibrary @@ -46,6 +47,30 @@ let ec = |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``TypeBuilder CreateTypeInfo with an upcast`` () = + FSharp """module MyLibrary +open System +open System.Reflection.Emit + +let createType (typB:TypeBuilder) : Type= + typB.CreateTypeInfo() :> Type +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + +[] +let ``CurrentDomain ProcessExit add to event`` () = + FSharp """module MyLibrary +open System + +do System.AppDomain.CurrentDomain.ProcessExit |> Event.add (fun args -> failwith $"{args.GetHashCode()}") +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] let ``Consuming C# extension methods which allow nullable this`` () = FSharp """module MyLibrary From 8c2fd6c04f2e76a28a245bc8106c60a8e63119a8 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 29 Apr 2024 17:28:14 +0200 Subject: [PATCH 03/18] Bugfix: Mutable binding initially assigned to null should not need type annotation --- src/Compiler/Checking/CheckExpressions.fs | 1 + src/Compiler/Checking/ConstraintSolver.fs | 19 +++++++++- src/Compiler/TypedTree/TypedTree.fs | 36 ++++++++++++++----- src/Compiler/TypedTree/TypedTree.fsi | 9 ++++- .../Language/NullableReferenceTypesTests.fs | 31 ++++++++++++++++ 5 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index b5ab3ef6ac4..2218793f468 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -5264,6 +5264,7 @@ and TcExprFlex (cenv: cenv) flex compat (desiredTy: TType) (env: TcEnv) tpenv (s if flex then let argTy = NewInferenceType g + (destTyparTy g argTy).SetSupportsNullFlex(true) if compat then (destTyparTy g argTy).SetIsCompatFlex(true) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 37bb43a28cd..b13158d9cee 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -308,6 +308,9 @@ type ConstraintSolverEnv = // Is this speculative, with a trace allowing undo, and trial method overload resolution IsSpeculativeForMethodOverloading: bool + // Can this ignore the 'must support null' constraint, e.g. in a mutable assignment scenario + IsSupportsNullFlex: bool + /// Indicates that when unifying ty1 = ty2, only type variables in ty1 may be solved. Constraints /// can't be added to type variables in ty2 MatchingOnly: bool @@ -344,6 +347,7 @@ let MakeConstraintSolverEnv contextInfo css m denv = EquivEnv = TypeEquivEnv.Empty DisplayEnv = denv IsSpeculativeForMethodOverloading = false + IsSupportsNullFlex = false ExtraRigidTypars = emptyFreeTypars } @@ -953,6 +957,13 @@ let rec SolveTyparEqualsTypePart1 (csenv: ConstraintSolverEnv) m2 (trace: Option // Record the solution before we solve the constraints, since // We may need to make use of the equation when solving the constraints. // Record a entry in the undo trace if one is provided + + //let ty1AllowsNull = r.Constraints |> List.exists (function | TyparConstraint.SupportsNull _ -> true | _ -> false ) + //let tyAllowsNull() = TypeNullIsExtraValueNew csenv.g m2 ty + //if ty1AllowsNull && not (tyAllowsNull()) then + // trace.Exec (fun () -> r.typar_solution <- Some (ty |> replaceNullnessOfTy csenv.g.knownWithNull)) (fun () -> r.typar_solution <- None) + //else + // trace.Exec (fun () -> r.typar_solution <- Some ty) (fun () -> r.typar_solution <- None) trace.Exec (fun () -> r.typar_solution <- Some ty) (fun () -> r.typar_solution <- None) } @@ -1006,7 +1017,8 @@ and SolveTypMeetsTyparConstraints (csenv: ConstraintSolverEnv) ndeep m2 trace ty AddConstraint csenv ndeep m2 trace destTypar (TyparConstraint.DefaultsTo(priority, dty, m)) | TyparConstraint.NotSupportsNull m2 -> SolveTypeUseNotSupportsNull csenv ndeep m2 trace ty - | TyparConstraint.SupportsNull m2 -> SolveTypeUseSupportsNull csenv ndeep m2 trace ty + | TyparConstraint.SupportsNull _ when csenv.IsSupportsNullFlex -> CompleteD + | TyparConstraint.SupportsNull m2 -> SolveTypeUseSupportsNull csenv ndeep m2 trace ty | TyparConstraint.IsEnum(underlyingTy, m2) -> SolveTypeIsEnum csenv ndeep m2 trace ty underlyingTy | TyparConstraint.SupportsComparison(m2) -> SolveTypeSupportsComparison csenv ndeep m2 trace ty | TyparConstraint.SupportsEquality(m2) -> SolveTypeSupportsEquality csenv ndeep m2 trace ty @@ -1222,6 +1234,11 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr let sty1 = stripTyEqnsA csenv.g canShortcut ty1 let sty2 = stripTyEqnsA csenv.g canShortcut ty2 + let csenv = + match ty1 with + | TType.TType_var(r,_) when r.typar_flags.IsSupportsNullFlex -> { csenv with IsSupportsNullFlex = true} + | _ -> csenv + match sty1, sty2 with // type vars inside forall-types may be alpha-equivalent | TType_var (tp1, nullness1), TType_var (tp2, nullness2) when typarEq tp1 tp2 || (match aenv.EquivTypars.TryFind tp1 with | Some tpTy1 when typeEquiv g tpTy1 ty2 -> true | _ -> false) -> diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 7c832224c25..b2fc36e9e7d 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -300,7 +300,7 @@ type TyparRigidity = [] type TyparFlags(flags: int32) = - new (kind: TyparKind, rigidity: TyparRigidity, isFromError: bool, isCompGen: bool, staticReq: TyparStaticReq, dynamicReq: TyparDynamicReq, equalityDependsOn: bool, comparisonDependsOn: bool) = + new (kind: TyparKind, rigidity: TyparRigidity, isFromError: bool, isCompGen: bool, staticReq: TyparStaticReq, dynamicReq: TyparDynamicReq, equalityDependsOn: bool, comparisonDependsOn: bool, supportsNullFlex: bool) = TyparFlags((if isFromError then 0b00000000000000010 else 0) ||| (if isCompGen then 0b00000000000000100 else 0) ||| (match staticReq with @@ -321,7 +321,11 @@ type TyparFlags(flags: int32) = | TyparDynamicReq.No -> 0b00000000000000000 | TyparDynamicReq.Yes -> 0b00000010000000000) ||| (if equalityDependsOn then - 0b00000100000000000 else 0)) + 0b00000100000000000 else 0) ||| + // 0b00001000100000000 is being checked by x.Kind, but never set in this version of the code + // 0b00010000000000000 is taken by compat flex + (if supportsNullFlex then + 0b00100000000000000 else 0)) /// Indicates if the type inference variable was generated after an error when type checking expressions or patterns member x.IsFromError = (flags &&& 0b00000000000000010) <> 0x0 @@ -380,8 +384,20 @@ type TyparFlags(flags: int32) = else TyparFlags(flags &&& ~~~0b00010000000000000) + /// Indicates that whether this type parameter is flexible for 'supports null' constraint, e.g. in the case of assignment to a mutable value + member x.IsSupportsNullFlex = + (flags &&& 0b00100000000000000) <> 0x0 + + member x.WithSupportsNullFlex b = + if b then + TyparFlags(flags ||| 0b00100000000000000) + else + TyparFlags(flags &&& ~~~0b00100000000000000) + + + member x.WithStaticReq staticReq = - TyparFlags(x.Kind, x.Rigidity, x.IsFromError, x.IsCompilerGenerated, staticReq, x.DynamicReq, x.EqualityConditionalOn, x.ComparisonConditionalOn) + TyparFlags(x.Kind, x.Rigidity, x.IsFromError, x.IsCompilerGenerated, staticReq, x.DynamicReq, x.EqualityConditionalOn, x.ComparisonConditionalOn, x.IsSupportsNullFlex) /// Get the flags as included in the F# binary metadata. We pickle this as int64 to allow for future expansion member x.PickledBits = flags @@ -2320,6 +2336,8 @@ type Typar = /// Set whether this type parameter is a compat-flex type parameter (i.e. where "expr :> tp" only emits an optional warning) member x.SetIsCompatFlex b = x.typar_flags <- x.typar_flags.WithCompatFlex b + member x.SetSupportsNullFlex b = x.typar_flags <- x.typar_flags.WithSupportsNullFlex b + /// Indicates whether a type variable can be instantiated by types or units-of-measure. member x.Kind = x.typar_flags.Kind @@ -2424,12 +2442,12 @@ type Typar = /// Sets the rigidity of a type variable member x.SetRigidity b = let flags = x.typar_flags - x.typar_flags <- TyparFlags(flags.Kind, b, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn) + x.typar_flags <- TyparFlags(flags.Kind, b, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex) /// Sets whether a type variable is compiler generated member x.SetCompilerGenerated b = let flags = x.typar_flags - x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, b, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn) + x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, b, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex) /// Sets whether a type variable has a static requirement member x.SetStaticReq b = @@ -2438,17 +2456,17 @@ type Typar = /// Sets whether a type variable is required at runtime member x.SetDynamicReq b = let flags = x.typar_flags - x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, b, flags.EqualityConditionalOn, flags.ComparisonConditionalOn) + x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, b, flags.EqualityConditionalOn, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex) /// Sets whether the equality constraint of a type definition depends on this type variable member x.SetEqualityDependsOn b = let flags = x.typar_flags - x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, b, flags.ComparisonConditionalOn) + x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, b, flags.ComparisonConditionalOn, flags.IsSupportsNullFlex) /// Sets whether the comparison constraint of a type definition depends on this type variable member x.SetComparisonDependsOn b = let flags = x.typar_flags - x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, b) + x.typar_flags <- TyparFlags(flags.Kind, flags.Rigidity, flags.IsFromError, flags.IsCompilerGenerated, flags.StaticReq, flags.DynamicReq, flags.EqualityConditionalOn, b, flags.IsSupportsNullFlex) [] member x.DebugText = x.ToString() @@ -6117,7 +6135,7 @@ type Construct() = Typar.New { typar_id = id typar_stamp = newStamp() - typar_flags= TyparFlags(kind, rigid, isFromError, isCompGen, staticReq, dynamicReq, eqDep, compDep) + typar_flags= TyparFlags(kind, rigid, isFromError, isCompGen, staticReq, dynamicReq, eqDep, compDep, false) typar_solution = None typar_astype = Unchecked.defaultof<_> typar_opt_data = diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index d5a486f4c9d..94c6c6ffb4a 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -205,7 +205,8 @@ type TyparFlags = staticReq: Syntax.TyparStaticReq * dynamicReq: TyparDynamicReq * equalityDependsOn: bool * - comparisonDependsOn: bool -> + comparisonDependsOn: bool * + supportsNullFlex: bool -> TyparFlags new: flags: int32 -> TyparFlags @@ -232,6 +233,9 @@ type TyparFlags = /// Indicates if the type inference variable was generated after an error when type checking expressions or patterns member IsFromError: bool + /// Indicates whether this type parameter is flexible for 'supports null' constraint, e.g. in the case of assignment to a mutable value + member IsSupportsNullFlex: bool + /// Indicates whether a type variable can be instantiated by types or units-of-measure. member Kind: TyparKind @@ -1552,6 +1556,9 @@ type Typar = /// Set whether this type parameter is a compat-flex type parameter (i.e. where "expr :> tp" only emits an optional warning) member SetIsCompatFlex: b: bool -> unit + /// Set whether this type parameter is flexible for 'supports null' constraint, e.g. in the case of assignment to a mutable value + member SetSupportsNullFlex: b:bool -> unit + /// Sets the rigidity of a type variable member SetRigidity: b: TyparRigidity -> unit diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index f546c8e8d59..8b4c9a919cb 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -26,6 +26,37 @@ let nonStrictFunc(x:string | null) = strictFunc(x) |> withDiagnostics [ Error 3261, Line 4, Col 49, Line 4, Col 50, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."] +[] +let ``Mutable binding initially assigned to null should not need type annotation``() = + FSharp """ +module MyLib +open System.Collections.Concurrent +open System + +let mkCacheInt32 () = + let mutable cache = null + + fun f (idx: int32) -> + let cache = + match cache with + | null -> + let v = ConcurrentDictionary(Environment.ProcessorCount, 11) + cache <- v + v + | v -> v + + match cache.TryGetValue idx with + | true, res -> res + | _ -> + let res = f idx + cache[idx] <- res + res + + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] let ``Boolean literal to string is not nullable`` () = FSharp """module MyLibrary From 44ad5119e8bbb611417ef405cda0e9a12aa5a30b Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 29 Apr 2024 17:45:18 +0200 Subject: [PATCH 04/18] fantomas --- src/Compiler/TypedTree/TypedTree.fsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index 94c6c6ffb4a..2583327d36d 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -1557,7 +1557,7 @@ type Typar = member SetIsCompatFlex: b: bool -> unit /// Set whether this type parameter is flexible for 'supports null' constraint, e.g. in the case of assignment to a mutable value - member SetSupportsNullFlex: b:bool -> unit + member SetSupportsNullFlex: b: bool -> unit /// Sets the rigidity of a type variable member SetRigidity: b: TyparRigidity -> unit From 84d35880f4b491c58f11cc0d8f4e5ecc0245f1ea Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 30 Apr 2024 13:38:10 +0200 Subject: [PATCH 05/18] Move stats keeping of caches into #IF STATISTICS blocks. --- src/Compiler/AbstractIL/ilread.fs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 08c82f9b270..4379da764c1 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -931,8 +931,9 @@ let mkCacheInt32 lowMem _inbase _nm _sz = (fun f x -> f x) else let mutable cache: ConcurrentDictionary MaybeNull = null // TODO NULLNESS: this explicit annotation should not be needed - let mutable count = 0 #if STATISTICS + let mutable count = 0 + addReport (fun oc -> if count <> 0 then oc.WriteLine((_inbase + string count + " " + _nm + " cache hits"): string)) @@ -948,7 +949,9 @@ let mkCacheInt32 lowMem _inbase _nm _sz = match cache.TryGetValue idx with | true, res -> +#if STATISTICS count <- count + 1 +#endif res | _ -> let res = f idx @@ -960,8 +963,8 @@ let mkCacheGeneric lowMem _inbase _nm _sz = (fun f x -> f x) else let mutable cache: ConcurrentDictionary<_, _> MaybeNull = null // TODO NULLNESS: this explicit annotation should not be needed - let mutable count = 0 #if STATISTICS + let mutable count = 0 addReport (fun oc -> if !count <> 0 then oc.WriteLine((_inbase + string !count + " " + _nm + " cache hits"): string)) @@ -977,7 +980,9 @@ let mkCacheGeneric lowMem _inbase _nm _sz = match cache.TryGetValue idx with | true, v -> +#if STATISTICS count <- count + 1 +#endif v | _ -> let res = f idx From 29c408e21ba119ba780a4141879b3ec606d79572 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 May 2024 16:39:29 +0200 Subject: [PATCH 06/18] Solving `let mutable cache = null` via type inference --- src/Compiler/Checking/ConstraintSolver.fs | 28 ++- .../Language/NullableReferenceTypesTests.fs | 180 +++++++++++++++++- 2 files changed, 192 insertions(+), 16 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index b13158d9cee..05c8608d744 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -1017,8 +1017,7 @@ and SolveTypMeetsTyparConstraints (csenv: ConstraintSolverEnv) ndeep m2 trace ty AddConstraint csenv ndeep m2 trace destTypar (TyparConstraint.DefaultsTo(priority, dty, m)) | TyparConstraint.NotSupportsNull m2 -> SolveTypeUseNotSupportsNull csenv ndeep m2 trace ty - | TyparConstraint.SupportsNull _ when csenv.IsSupportsNullFlex -> CompleteD - | TyparConstraint.SupportsNull m2 -> SolveTypeUseSupportsNull csenv ndeep m2 trace ty + | TyparConstraint.SupportsNull m2 -> SolveTypeUseSupportsNull csenv ndeep m2 trace ty | TyparConstraint.IsEnum(underlyingTy, m2) -> SolveTypeIsEnum csenv ndeep m2 trace ty underlyingTy | TyparConstraint.SupportsComparison(m2) -> SolveTypeSupportsComparison csenv ndeep m2 trace ty | TyparConstraint.SupportsEquality(m2) -> SolveTypeSupportsEquality csenv ndeep m2 trace ty @@ -1236,7 +1235,8 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr let csenv = match ty1 with - | TType.TType_var(r,_) when r.typar_flags.IsSupportsNullFlex -> { csenv with IsSupportsNullFlex = true} + | TType.TType_var(r,_) when r.typar_flags.IsSupportsNullFlex -> + { csenv with IsSupportsNullFlex = true} | _ -> csenv match sty1, sty2 with @@ -1294,6 +1294,15 @@ and SolveTypeEqualsType (csenv: ConstraintSolverEnv) ndeep m2 (trace: OptionalTr // Unifying 'T1? and 'T2? | ValueSome NullnessInfo.WithNull, ValueSome NullnessInfo.WithNull -> SolveTyparEqualsType csenv ndeep m2 trace sty1 (replaceNullnessOfTy g.knownWithoutNull sty2) + | ValueSome NullnessInfo.WithoutNull, ValueSome NullnessInfo.WithoutNull when + csenv.IsSupportsNullFlex && + isAppTy g sty2 && + tp1.Constraints |> List.exists (function TyparConstraint.SupportsNull _ -> true | _ -> false) -> + let tpNew = NewCompGenTypar(TyparKind.Type, TyparRigidity.Flexible, TyparStaticReq.None, TyparDynamicReq.No, false) + trackErrors { + do! SolveTypeEqualsType csenv ndeep m2 trace cxsln (TType_var(tpNew, g.knownWithoutNull)) sty2 + do! SolveTypeEqualsType csenv ndeep m2 trace cxsln ty1 (TType_var(tpNew, g.knownWithNull)) + } // Unifying 'T1 % and 'T2 % //| ValueSome NullnessInfo.AmbivalentToNull, ValueSome NullnessInfo.AmbivalentToNull -> // SolveTyparEqualsType csenv ndeep m2 trace sty1 (replaceNullnessOfTy g.knownWithoutNull sty2) @@ -2555,16 +2564,18 @@ and SolveTypeUseSupportsNull (csenv: ConstraintSolverEnv) ndeep m2 trace ty = return! ErrorD (ConstraintSolverError(FSComp.SR.csNullableTypeDoesNotHaveNull(NicePrint.minimalStringOfType denv ty), m, m2)) else match tryDestTyparTy g ty with - | ValueSome tp -> + | ValueSome tp -> let nullness = nullnessOfTy g ty match nullness.TryEvaluate() with // NULLNESS TODO: This rule means turning on checkNullness changes type inference results for the cases // mentioned in the comment above. THat's OK but needs to be documented in the RFC. | ValueNone when not g.checkNullness -> - return! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.SupportsNull m) - | ValueSome NullnessInfo.WithoutNull -> + return! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.SupportsNull m) + | ValueSome NullnessInfo.WithoutNull -> return! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.SupportsNull m) | _ -> + if tp.Constraints |> List.exists (function | TyparConstraint.IsReferenceType _ -> true | _ -> false) |> not then + do! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.IsReferenceType m) return! SolveNullnessSupportsNull csenv ndeep m2 trace ty nullness | _ -> let nullness = nullnessOfTy g ty @@ -2601,9 +2612,10 @@ and SolveNullnessSupportsNull (csenv: ConstraintSolverEnv) ndeep m2 (trace: Opti match n1 with | NullnessInfo.AmbivalentToNull -> () | NullnessInfo.WithNull -> () - | NullnessInfo.WithoutNull -> + | NullnessInfo.WithoutNull -> if g.checkNullness then - return! WarnD(ConstraintSolverNullnessWarningWithType(denv, ty, n1, m, m2)) + // TODO nullness: Shouldn't this be an error? We have a 'must support null' situation which is not being met. + return! WarnD(ConstraintSolverNullnessWarningWithType(denv, ty, n1, m, m2)) } and SolveTypeUseNotSupportsNull (csenv: ConstraintSolverEnv) ndeep m2 trace ty = diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index 8b4c9a919cb..7fc62586c57 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -3,15 +3,18 @@ module Language.NullableReferenceTypes open Xunit open FSharp.Test.Compiler -let typeCheckWithStrictNullness cu = +let withNullnessOptions cu = cu |> withLangVersionPreview |> withCheckNulls |> withWarnOn 3261 |> withWarnOn 3262 |> withOptions ["--warnaserror+"] - |> compile +let typeCheckWithStrictNullness cu = + cu + |> withNullnessOptions + |> typecheck [] let ``Cannot pass possibly null value to a strict function``() = @@ -26,22 +29,118 @@ let nonStrictFunc(x:string | null) = strictFunc(x) |> withDiagnostics [ Error 3261, Line 4, Col 49, Line 4, Col 50, "Nullness warning: The types 'string' and 'string | null' do not have equivalent nullability."] + +// P1: inline or not +// P2: type annotation for function argument +// P3: type annotation for cache +let MutableBindingAnnotationCombinations = + [| + for functionInlineFlag in ["" + "inline"] do + for xArg in ["" + ":'T" + ":'T|null" + ": _" + ": _|null" + ": string|null" + ": string"] do + // No annotation or _ must work all the time + for cacheArg in ["" + ": _"] do + yield [|functionInlineFlag :> obj; xArg :> obj; cacheArg :> obj|] + + // If we have a named type, the same one must work for cache binding as well + if xArg.Contains("'T") || xArg.Contains("string|null") then + yield [|functionInlineFlag :> obj; xArg :> obj; xArg :> obj|] + + // If we have a type WithNull, using _|null should infer the exact same type + if xArg.Contains("|null") || xArg.Contains("string") then + yield [|functionInlineFlag :> obj; xArg :> obj; ":_|null" :> obj|] + + if xArg = ":'T" then + for guard in [" when 'T:null" + " when 'T:null and 'T:not struct"] do + yield [|functionInlineFlag :> obj; (xArg + guard) :> obj; "" :> obj|] + + if xArg = ":'T|null" then + for guard in [" when 'T:not struct" + " when 'T:not null" + " when 'T:not struct and 'T:not null"] do + yield [|functionInlineFlag :> obj; (xArg + guard) :> obj; "" :> obj|] + |] + +[] +[] +let ``Mutable binding with a null literal`` inln xArg cache = + FSharp $"""module MyLib + +let %s{inln} f (x %s{xArg}) = + let mutable cache %s{cache} = null + cache <- x + + match cache with + | null -> failwith "It was null" + | c -> c + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + +[] +let ``Mutable string binding initially assigned to null should not need type annotation``() = + FSharp """ +module MyLib + + +let name = "abc" +let mutable cache = null +cache <- name + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + +[] +let ``Mutable string binding assigned to null and matched againts null``() = + FSharp """ +module MyLib + +let whatEver() = + let mutable x = null + x <- "abc" + x + + +(* This is a comment +let name = "abc" +let mutable cache = null +cache <- name + +match cache with +| null -> () +| c -> ()*) + + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] -let ``Mutable binding initially assigned to null should not need type annotation``() = +let ``Mutable cache binding initially assigned to null should not need type annotation``() = FSharp """ module MyLib open System.Collections.Concurrent open System let mkCacheInt32 () = - let mutable cache = null + let mutable topLevelCache = null fun f (idx: int32) -> let cache = - match cache with + match topLevelCache with | null -> let v = ConcurrentDictionary(Environment.ProcessorCount, 11) - cache <- v + topLevelCache <- v v | v -> v @@ -326,8 +425,73 @@ strictFunc("hi") |> ignore """ |> shouldFail |> withDiagnostics [ Error 3261, Line 4, Col 12, Line 4, Col 16, "Nullness warning: The type 'obj | null' supports 'null' but a non-null type is expected."] - - + +[] +let ``Supports null in generic code`` () = + FSharp """module MyLibrary +let myGenericFunction p = + match p with + | null -> () + | p -> printfn "%s" (p.ToString()) + +[] +type X(p:int) = + member _.P = p + +let myValOfX : X = null + +myGenericFunction "HiThere" +myGenericFunction ("HiThere":string | null) +myGenericFunction (System.DateTime.Now) +myGenericFunction 123 +myGenericFunction myValOfX + +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldFail + |> withDiagnostics + [Error 3261, Line 13, Col 19, Line 13, Col 28, "Nullness warning: The type 'string' does not support 'null'." + Error 3261, Line 15, Col 20, Line 15, Col 39, "Nullness warning: The type 'System.DateTime' does not support 'null'." + Error 3261, Line 16, Col 19, Line 16, Col 22, "Nullness warning: The type 'int' does not support 'null'."] + +[] +let ``Null assignment in generic code`` () = + FSharp """module MyLibrary +let myNullReturningFunction p = + let mutable x = p + x <- null + x + +[] +type X(p:int) = + member _.P = p + +type Y (p:int) = + member _.P = p + +let myValOfX : X = null +let myValOfY : Y = Unchecked.defaultof + +myNullReturningFunction "HiThere" |> ignore +myNullReturningFunction ("HiThere":string | null) |> ignore +myNullReturningFunction (System.DateTime.Now) |> ignore +myNullReturningFunction {|Anon=42|} |> ignore +myNullReturningFunction (1,2,3) |> ignore +myNullReturningFunction myValOfX |> ignore +myNullReturningFunction myValOfY |> ignore + +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldFail + |> withDiagnostics + [Error 3261, Line 17, Col 25, Line 17, Col 34, "Nullness warning: The type 'string' does not support 'null'." + Error 3261, Line 19, Col 26, Line 19, Col 45, "Nullness warning: The type 'System.DateTime' does not support 'null'." + Error 3261, Line 20, Col 25, Line 20, Col 36, "Nullness warning: The type '{| Anon: 'a |}' does not support 'null'." + Error 3261, Line 21, Col 26, Line 21, Col 31, "Nullness warning: The type '('a * 'b * 'c)' does not support 'null'." + Error 3261, Line 23, Col 25, Line 23, Col 33, "Nullness warning: The type 'Y' does not support 'null'."] + [] let ``Nullnesss support for F# types`` () = FSharp """module MyLibrary From 744e1a9b814e46968ac22ac10abadbe7fdb27ff0 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 May 2024 16:43:40 +0200 Subject: [PATCH 07/18] fantomas --- src/Compiler/AbstractIL/ilread.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/AbstractIL/ilread.fs b/src/Compiler/AbstractIL/ilread.fs index 4379da764c1..020aa4498a5 100644 --- a/src/Compiler/AbstractIL/ilread.fs +++ b/src/Compiler/AbstractIL/ilread.fs @@ -965,6 +965,7 @@ let mkCacheGeneric lowMem _inbase _nm _sz = let mutable cache: ConcurrentDictionary<_, _> MaybeNull = null // TODO NULLNESS: this explicit annotation should not be needed #if STATISTICS let mutable count = 0 + addReport (fun oc -> if !count <> 0 then oc.WriteLine((_inbase + string !count + " " + _nm + " cache hits"): string)) From 901bf322802b24b02d337ae516ee7e9289a9b78d Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 15 May 2024 16:06:54 +0200 Subject: [PATCH 08/18] Enforcing TyparConstraint.IsReferenceType when WithNull type is used --- .gitignore | 1 + src/Compiler/Checking/CheckExpressions.fs | 1 + src/Compiler/Checking/ConstraintSolver.fs | 5 +- src/Compiler/CodeGen/IlxGen.fs | 12 +- .../EmittedIL/Nullness/CurriedFunctions.fs | 2 +- .../CurriedFunctions.fs.il.net472.bsl | 25 +- .../CurriedFunctions.fs.il.netcore.bsl | 16 +- .../Nullness/GenericStructDu.fs.il.net472.bsl | 62 ++--- .../GenericStructDu.fs.il.netcore.bsl | 41 ++- .../Nullness/NullAsTrueValue.fs.il.net472.bsl | 77 ++---- .../NullAsTrueValue.fs.il.netcore.bsl | 62 ++--- .../EmittedIL/Nullness/NullnessMetadata.fs | 6 + .../Nullness/Records.fs.il.net472.bsl | 44 ++-- .../Nullness/Records.fs.il.netcore.bsl | 29 +- .../EmittedIL/Nullness/SupportsNull.fs | 40 +++ .../Nullness/SupportsNull.fs.il.net472.bsl | 248 ++++++++++++++++++ .../Nullness/SupportsNull.fs.il.netcore.bsl | 184 +++++++++++++ .../Language/NullableReferenceTypesTests.fs | 24 +- 18 files changed, 645 insertions(+), 234 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl diff --git a/.gitignore b/.gitignore index e6d289dd19b..013ade3ce24 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ nCrunchTemp_* tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstandard.actual *.vsp /tests/AheadOfTime/Trimming/output.txt +*.svclog diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 2218793f468..52ebdab9842 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -1040,6 +1040,7 @@ let TcAddNullnessToType (warn: bool) (cenv: cenv) (env: TcEnv) nullness innerTyC if not g.compilingFSharpCore || not (isTyparTy g innerTyC) then AddCxTypeDefnNotSupportsNull env.DisplayEnv cenv.css m NoTrace innerTyC + AddCxTypeIsReferenceType env.DisplayEnv cenv.css m NoTrace innerTyC if not g.compilingFSharpCore && isTyparTy g innerTyC then // A typar might be later infered into a type not supporting `| null|, like tuple or anon. diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 05c8608d744..3c8622b08f2 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2636,6 +2636,7 @@ and SolveTypeUseNotSupportsNull (csenv: ConstraintSolverEnv) ndeep m2 trace ty = match tryDestTyparTy g ty with | ValueSome tp -> do! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.NotSupportsNull m) + do! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.IsReferenceType m) | ValueNone -> let nullness = nullnessOfTy g ty do! SolveNullnessNotSupportsNull csenv ndeep m2 trace ty nullness @@ -2668,7 +2669,9 @@ and SolveTypeCanCarryNullness (csenv: ConstraintSolverEnv) ty nullness = let m = csenv.m let strippedTy = stripTyEqnsA g true ty match tryAddNullnessToTy nullness strippedTy with - | Some _ -> () + | Some _ -> + if isTyparTy g strippedTy && not (isReferenceTyparTy g strippedTy) then + return! AddConstraint csenv 0 m NoTrace (destTyparTy g strippedTy) (TyparConstraint.IsReferenceType m) | None -> let tyString = NicePrint.minimalStringOfType csenv.DisplayEnv strippedTy return! ErrorD(Error(FSComp.SR.tcTypeDoesNotHaveAnyNull(tyString), m)) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 71854a4ac28..45b25c3138a 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -5642,7 +5642,7 @@ and GenGenericParam cenv eenv (tp: Typar) = | TyparConstraint.IsNonNullableStruct _ -> true | _ -> false) - let notNullReferenceTypeConstraint = + let nullnessOfTypar = if g.langFeatureNullness && g.checkNullness then let hasNotSupportsNull = tp.Constraints @@ -5650,9 +5650,15 @@ and GenGenericParam cenv eenv (tp: Typar) = | TyparConstraint.NotSupportsNull _ -> true | _ -> false) + let hasSupportsNull() = + tp.Constraints + |> List.exists (function + | TyparConstraint.SupportsNull _ -> true + | _ -> false) + if hasNotSupportsNull || notNullableValueTypeConstraint then NullnessInfo.WithoutNull - elif hasNotSupportsNull || refTypeConstraint then + elif refTypeConstraint || hasSupportsNull() then NullnessInfo.WithNull else NullnessInfo.AmbivalentToNull @@ -5705,7 +5711,7 @@ and GenGenericParam cenv eenv (tp: Typar) = yield! GenAttrs cenv eenv tp.Attribs if emitUnmanagedInIlOutput then yield (GetIsUnmanagedAttribute g) - match notNullReferenceTypeConstraint with + match nullnessOfTypar with | Some nullInfo -> yield GetNullableAttribute g [ nullInfo ] | _ -> () ] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs index 7245cd2cd8e..f289363294b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs @@ -1,6 +1,6 @@ module MyTestModule -type Maybe<'T> = 'T | null +type Maybe<'T when 'T: not struct> = 'T | null type MaybeString = string | null let curried3Func (a:MaybeString) (b:string) (c:int) = (a,b,c) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl index 083abfd072c..9907f3410bd 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl @@ -32,8 +32,7 @@ { .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .field public string propperString - .method assembly specialname rtspecialname - instance void .ctor(string propperString) cil managed + .method assembly specialname rtspecialname instance void .ctor(string propperString) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -87,8 +86,7 @@ IL_0008: ret } - .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>> - partiallyAplied(string propperString) cil managed + .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>> partiallyAplied(string propperString) cil managed { .param [0] .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 06 00 00 00 01 01 01 01 02 01 00 00 ) @@ -99,11 +97,11 @@ IL_0006: ret } - .method public static !!b secondOutOfTriple(!!a a, - !!b b, - !!c c, - !!d d, - !!e e) cil managed + .method public static !!b secondOutOfTriple(!!a a, + !!b b, + !!c c, + !!d d, + !!e e) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 00 00 ) @@ -137,8 +135,7 @@ .field public uint8[] NullableFlags .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 scalarByteValue) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 scalarByteValue) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -157,8 +154,7 @@ IL_0016: ret } - .method public specialname rtspecialname - instance void .ctor(uint8[] NullableFlags) cil managed + .method public specialname rtspecialname instance void .ctor(uint8[] NullableFlags) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -181,8 +177,7 @@ .field public uint8 Flag .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 Flag) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 Flag) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl index 5d449672a57..3dbcb185add 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl @@ -32,8 +32,7 @@ { .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .field public string propperString - .method assembly specialname rtspecialname - instance void .ctor(string propperString) cil managed + .method assembly specialname rtspecialname instance void .ctor(string propperString) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -87,8 +86,7 @@ IL_0008: ret } - .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>> - partiallyAplied(string propperString) cil managed + .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>> partiallyAplied(string propperString) cil managed { .param [0] .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 06 00 00 00 01 01 01 01 02 01 00 00 ) @@ -99,11 +97,11 @@ IL_0006: ret } - .method public static !!b secondOutOfTriple(!!a a, - !!b b, - !!c c, - !!d d, - !!e e) cil managed + .method public static !!b secondOutOfTriple(!!a a, + !!b b, + !!c c, + !!d d, + !!e e) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl index 97f43391f53..f237e7a5c9c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 + .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 extends [runtime]System.ValueType { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoEqualityAttribute::.ctor() = ( 01 00 00 00 ) @@ -39,7 +39,7 @@ .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -68,8 +68,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public static valuetype TestModule/MyStructOption`1 - get_MyStructNone() cil managed + .method public static valuetype TestModule/MyStructOption`1 get_MyStructNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -80,8 +79,7 @@ IL_0006: ret } - .method public hidebysig instance bool - get_IsMyStructNone() cil managed + .method public hidebysig instance bool get_IsMyStructNone() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -130,8 +128,7 @@ IL_0031: ret } - .method public hidebysig instance bool - get_IsMyStructSome() cil managed + .method public hidebysig instance bool get_IsMyStructSome() cil managed { .custom instance void System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute::.ctor(bool, string[]) = ( 01 00 01 04 00 00 00 0D 6E 6F 74 4E 75 6C 6C 46 @@ -150,8 +147,7 @@ IL_0009: ret } - .method assembly specialname rtspecialname - instance void .ctor(int32 _tag) cil managed + .method assembly specialname rtspecialname instance void .ctor(int32 _tag) cil managed { .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 1B 54 65 73 74 4D 6F 64 75 6C @@ -167,8 +163,7 @@ IL_0007: ret } - .method public hidebysig instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> - get_nestedGenericField() cil managed + .method public hidebysig instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> get_nestedGenericField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -181,8 +176,7 @@ IL_0006: ret } - .method public hidebysig instance string - get_notNullField2() cil managed + .method public hidebysig instance string get_notNullField2() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -195,8 +189,7 @@ IL_0006: ret } - .method public hidebysig instance string - get_canBeNullField() cil managed + .method public hidebysig instance string get_canBeNullField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -209,8 +202,7 @@ IL_0006: ret } - .method public hidebysig instance !T - get_notNullField1() cil managed + .method public hidebysig instance !T get_notNullField1() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -223,8 +215,7 @@ IL_0006: ret } - .method public hidebysig instance int32 - get_Tag() cil managed + .method public hidebysig instance int32 get_Tag() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -235,8 +226,7 @@ IL_0006: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -251,8 +241,7 @@ IL_001a: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -345,8 +334,8 @@ } .method public static valuetype TestModule/MyStructOption`1 - mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - valuetype TestModule/MyStructOption`1 myOpt) cil managed + mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + valuetype TestModule/MyStructOption`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a @@ -462,8 +451,7 @@ IL_0014: ret } - .method public hidebysig specialname instance class [runtime]System.Type - get_Type() cil managed + .method public hidebysig specialname instance class [runtime]System.Type get_Type() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -474,8 +462,7 @@ IL_0006: ret } - .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes - get_MemberType() cil managed + .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes get_MemberType() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -531,8 +518,7 @@ IL_0014: ret } - .method public hidebysig specialname instance string[] - get_Members() cil managed + .method public hidebysig specialname instance string[] get_Members() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -543,8 +529,7 @@ IL_0006: ret } - .method public hidebysig specialname instance bool - get_ReturnValue() cil managed + .method public hidebysig specialname instance bool get_ReturnValue() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -576,8 +561,7 @@ .field public uint8[] NullableFlags .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 scalarByteValue) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 scalarByteValue) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -596,8 +580,7 @@ IL_0016: ret } - .method public specialname rtspecialname - instance void .ctor(uint8[] NullableFlags) cil managed + .method public specialname rtspecialname instance void .ctor(uint8[] NullableFlags) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -620,8 +603,7 @@ .field public uint8 Flag .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 Flag) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 Flag) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl index 74b8ce8a49f..095f4b897dc 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 + .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 extends [runtime]System.ValueType { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoEqualityAttribute::.ctor() = ( 01 00 00 00 ) @@ -39,7 +39,7 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -68,8 +68,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public static valuetype TestModule/MyStructOption`1 - get_MyStructNone() cil managed + .method public static valuetype TestModule/MyStructOption`1 get_MyStructNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -80,8 +79,7 @@ IL_0006: ret } - .method public hidebysig instance bool - get_IsMyStructNone() cil managed + .method public hidebysig instance bool get_IsMyStructNone() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -130,8 +128,7 @@ IL_0031: ret } - .method public hidebysig instance bool - get_IsMyStructSome() cil managed + .method public hidebysig instance bool get_IsMyStructSome() cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute::.ctor(bool, string[]) = ( 01 00 01 04 00 00 00 0D 6E 6F 74 4E 75 6C 6C 46 @@ -150,8 +147,7 @@ IL_0009: ret } - .method assembly specialname rtspecialname - instance void .ctor(int32 _tag) cil managed + .method assembly specialname rtspecialname instance void .ctor(int32 _tag) cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype [runtime]System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 1B 54 65 73 74 4D 6F 64 75 6C @@ -167,8 +163,7 @@ IL_0007: ret } - .method public hidebysig instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> - get_nestedGenericField() cil managed + .method public hidebysig instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> get_nestedGenericField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -181,8 +176,7 @@ IL_0006: ret } - .method public hidebysig instance string - get_notNullField2() cil managed + .method public hidebysig instance string get_notNullField2() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -195,8 +189,7 @@ IL_0006: ret } - .method public hidebysig instance string - get_canBeNullField() cil managed + .method public hidebysig instance string get_canBeNullField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -209,8 +202,7 @@ IL_0006: ret } - .method public hidebysig instance !T - get_notNullField1() cil managed + .method public hidebysig instance !T get_notNullField1() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -223,8 +215,7 @@ IL_0006: ret } - .method public hidebysig instance int32 - get_Tag() cil managed + .method public hidebysig instance int32 get_Tag() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -235,8 +226,7 @@ IL_0006: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -251,8 +241,7 @@ IL_001a: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -345,8 +334,8 @@ } .method public static valuetype TestModule/MyStructOption`1 - mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - valuetype TestModule/MyStructOption`1 myOpt) cil managed + mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + valuetype TestModule/MyStructOption`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl index e092d8fd8ea..2a35c1c1aba 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl @@ -53,8 +53,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method assembly specialname rtspecialname - instance void .ctor() cil managed + .method assembly specialname rtspecialname instance void .ctor() cil managed { .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 E0 07 00 00 1D 54 65 73 74 4D 6F 64 75 6C @@ -69,8 +68,7 @@ IL_0006: ret } - .method public static class TestModule/MyNullableOption`1 - get_MyNone() cil managed + .method public static class TestModule/MyNullableOption`1 get_MyNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -82,8 +80,7 @@ IL_0001: ret } - .method public static class TestModule/MyNullableOption`1 - NewMySome(!T _value) cil managed + .method public static class TestModule/MyNullableOption`1 NewMySome(!T _value) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 01 00 00 00 00 00 ) @@ -94,8 +91,7 @@ IL_0006: ret } - .method assembly specialname rtspecialname - instance void .ctor(!T _value) cil managed + .method assembly specialname rtspecialname instance void .ctor(!T _value) cil managed { .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 1D 54 65 73 74 4D 6F 64 75 6C @@ -113,8 +109,7 @@ IL_000d: ret } - .method public hidebysig instance !T - get_value() cil managed + .method public hidebysig instance !T get_value() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -141,8 +136,7 @@ IL_0007: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -156,8 +150,7 @@ IL_0015: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -170,8 +163,7 @@ IL_0015: ret } - .method public specialname static bool - get_IsMyNone(class TestModule/MyNullableOption`1 A_0) cil managed + .method public specialname static bool get_IsMyNone(class TestModule/MyNullableOption`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -182,8 +174,7 @@ IL_0004: ret } - .method public specialname static bool - get_IsMySome(class TestModule/MyNullableOption`1 A_0) cil managed + .method public specialname static bool get_IsMySome(class TestModule/MyNullableOption`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -228,7 +219,7 @@ } } - .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 + .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 extends [runtime]System.Object { .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) @@ -241,7 +232,7 @@ .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -254,8 +245,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method assembly specialname rtspecialname - instance void .ctor() cil managed + .method assembly specialname rtspecialname instance void .ctor() cil managed { .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 E0 07 00 00 33 54 65 73 74 4D 6F 64 75 6C @@ -271,8 +261,7 @@ IL_0006: ret } - .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - get_MyNotNullNone() cil managed + .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 get_MyNotNullNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -284,8 +273,7 @@ IL_0001: ret } - .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - NewMyNotNullSome(!T _value) cil managed + .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 NewMyNotNullSome(!T _value) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 01 00 00 00 00 00 ) @@ -296,8 +284,7 @@ IL_0006: ret } - .method assembly specialname rtspecialname - instance void .ctor(!T _value) cil managed + .method assembly specialname rtspecialname instance void .ctor(!T _value) cil managed { .custom instance void System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 33 54 65 73 74 4D 6F 64 75 6C @@ -316,8 +303,7 @@ IL_000d: ret } - .method public hidebysig instance !T - get_value() cil managed + .method public hidebysig instance !T get_value() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -344,8 +330,7 @@ IL_0007: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -359,8 +344,7 @@ IL_0015: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -373,8 +357,7 @@ IL_0015: ret } - .method public specialname static bool - get_IsMyNotNullNone(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed + .method public specialname static bool get_IsMyNotNullNone(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -385,8 +368,7 @@ IL_0004: ret } - .method public specialname static bool - get_IsMyNotNullSome(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed + .method public specialname static bool get_IsMyNotNullSome(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -468,8 +450,8 @@ } .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed + mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a @@ -564,8 +546,7 @@ IL_0014: ret } - .method public hidebysig specialname instance class [runtime]System.Type - get_Type() cil managed + .method public hidebysig specialname instance class [runtime]System.Type get_Type() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -576,8 +557,7 @@ IL_0006: ret } - .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes - get_MemberType() cil managed + .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes get_MemberType() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -611,8 +591,7 @@ .field public uint8[] NullableFlags .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 scalarByteValue) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 scalarByteValue) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -631,8 +610,7 @@ IL_0016: ret } - .method public specialname rtspecialname - instance void .ctor(uint8[] NullableFlags) cil managed + .method public specialname rtspecialname instance void .ctor(uint8[] NullableFlags) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -655,8 +633,7 @@ .field public uint8 Flag .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 Flag) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 Flag) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl index d48f01435d7..d95f4572cf1 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl @@ -53,8 +53,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method assembly specialname rtspecialname - instance void .ctor() cil managed + .method assembly specialname rtspecialname instance void .ctor() cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype [runtime]System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 E0 07 00 00 1D 54 65 73 74 4D 6F 64 75 6C @@ -69,8 +68,7 @@ IL_0006: ret } - .method public static class TestModule/MyNullableOption`1 - get_MyNone() cil managed + .method public static class TestModule/MyNullableOption`1 get_MyNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -82,8 +80,7 @@ IL_0001: ret } - .method public static class TestModule/MyNullableOption`1 - NewMySome(!T _value) cil managed + .method public static class TestModule/MyNullableOption`1 NewMySome(!T _value) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 01 00 00 00 00 00 ) @@ -94,8 +91,7 @@ IL_0006: ret } - .method assembly specialname rtspecialname - instance void .ctor(!T _value) cil managed + .method assembly specialname rtspecialname instance void .ctor(!T _value) cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype [runtime]System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 1D 54 65 73 74 4D 6F 64 75 6C @@ -113,8 +109,7 @@ IL_000d: ret } - .method public hidebysig instance !T - get_value() cil managed + .method public hidebysig instance !T get_value() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -141,8 +136,7 @@ IL_0007: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -156,8 +150,7 @@ IL_0015: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -170,8 +163,7 @@ IL_0015: ret } - .method public specialname static bool - get_IsMyNone(class TestModule/MyNullableOption`1 A_0) cil managed + .method public specialname static bool get_IsMyNone(class TestModule/MyNullableOption`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -182,8 +174,7 @@ IL_0004: ret } - .method public specialname static bool - get_IsMySome(class TestModule/MyNullableOption`1 A_0) cil managed + .method public specialname static bool get_IsMySome(class TestModule/MyNullableOption`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -228,7 +219,7 @@ } } - .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 + .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 extends [runtime]System.Object { .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) @@ -241,7 +232,7 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -254,8 +245,7 @@ .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method assembly specialname rtspecialname - instance void .ctor() cil managed + .method assembly specialname rtspecialname instance void .ctor() cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype [runtime]System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 E0 07 00 00 33 54 65 73 74 4D 6F 64 75 6C @@ -271,8 +261,7 @@ IL_0006: ret } - .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - get_MyNotNullNone() cil managed + .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 get_MyNotNullNone() cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 00 00 00 00 00 00 ) @@ -284,8 +273,7 @@ IL_0001: ret } - .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - NewMyNotNullSome(!T _value) cil managed + .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 NewMyNotNullSome(!T _value) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags, int32) = ( 01 00 08 00 00 00 01 00 00 00 00 00 ) @@ -296,8 +284,7 @@ IL_0006: ret } - .method assembly specialname rtspecialname - instance void .ctor(!T _value) cil managed + .method assembly specialname rtspecialname instance void .ctor(!T _value) cil managed { .custom instance void [runtime]System.Diagnostics.CodeAnalysis.DynamicDependencyAttribute::.ctor(valuetype [runtime]System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes, class [runtime]System.Type) = ( 01 00 60 06 00 00 33 54 65 73 74 4D 6F 64 75 6C @@ -316,8 +303,7 @@ IL_000d: ret } - .method public hidebysig instance !T - get_value() cil managed + .method public hidebysig instance !T get_value() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -344,8 +330,7 @@ IL_0007: ret } - .method assembly hidebysig specialname - instance object __DebugDisplay() cil managed + .method assembly hidebysig specialname instance object __DebugDisplay() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -359,8 +344,7 @@ IL_0015: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -373,8 +357,7 @@ IL_0015: ret } - .method public specialname static bool - get_IsMyNotNullNone(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed + .method public specialname static bool get_IsMyNotNullNone(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -385,8 +368,7 @@ IL_0004: ret } - .method public specialname static bool - get_IsMyNotNullSome(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed + .method public specialname static bool get_IsMyNotNullSome(class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 A_0) cil managed { .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -468,8 +450,8 @@ } .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed + mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs index 46672e0208c..061c6dba9d7 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs @@ -84,6 +84,12 @@ let ``Custom pipe`` compilation = compilation |> verifyCompilation DoNotOptimize +[] +let ``SupportsNull`` compilation = + compilation + |> withNoWarn 52 + |> verifyCompilation DoNotOptimize + module Interop = open System.IO diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl index 01a99cf449b..c3378476c29 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 + .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 extends [runtime]System.Object { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoComparisonAttribute::.ctor() = ( 01 00 00 00 ) @@ -62,8 +62,7 @@ .field assembly !Z GenericNotNullField@ .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) - .method public hidebysig specialname - instance int32 get_JustInt() cil managed + .method public hidebysig specialname instance int32 get_JustInt() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -87,8 +86,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance string get_JustString() cil managed + .method public hidebysig specialname instance string get_JustString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -99,8 +97,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance string get_NullableString() cil managed + .method public hidebysig specialname instance string get_NullableString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -111,8 +108,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !X get_GenericNormalField() cil managed + .method public hidebysig specialname instance !X get_GenericNormalField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -123,8 +119,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !Y get_GenericNullableField() cil managed + .method public hidebysig specialname instance !Y get_GenericNullableField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -135,8 +130,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !Z get_GenericNotNullField() cil managed + .method public hidebysig specialname instance !Z get_GenericNotNullField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -187,8 +181,7 @@ IL_003b: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -246,8 +239,7 @@ } } - .method public specialname static string - get_maybeString() cil managed + .method public specialname static string get_maybeString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -257,8 +249,7 @@ IL_0001: ret } - .method public static class MyTestModule/MyRecord`3 - createAnInstance() cil managed + .method public static class MyTestModule/MyRecord`3 createAnInstance() cil managed { .param [0] .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 03 00 00 00 01 02 01 00 00 ) @@ -348,8 +339,7 @@ IL_0014: ret } - .method public hidebysig specialname instance class [runtime]System.Type - get_Type() cil managed + .method public hidebysig specialname instance class [runtime]System.Type get_Type() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -360,8 +350,7 @@ IL_0006: ret } - .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes - get_MemberType() cil managed + .method public hidebysig specialname instance valuetype System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes get_MemberType() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -395,8 +384,7 @@ .field public uint8[] NullableFlags .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 scalarByteValue) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 scalarByteValue) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -415,8 +403,7 @@ IL_0016: ret } - .method public specialname rtspecialname - instance void .ctor(uint8[] NullableFlags) cil managed + .method public specialname rtspecialname instance void .ctor(uint8[] NullableFlags) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -439,8 +426,7 @@ .field public uint8 Flag .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - .method public specialname rtspecialname - instance void .ctor(uint8 Flag) cil managed + .method public specialname rtspecialname instance void .ctor(uint8 Flag) cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl index 8858ce8beac..7875f759770 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 + .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 extends [runtime]System.Object { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoComparisonAttribute::.ctor() = ( 01 00 00 00 ) @@ -62,8 +62,7 @@ .field assembly !Z GenericNotNullField@ .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) - .method public hidebysig specialname - instance int32 get_JustInt() cil managed + .method public hidebysig specialname instance int32 get_JustInt() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -87,8 +86,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance string get_JustString() cil managed + .method public hidebysig specialname instance string get_JustString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -99,8 +97,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance string get_NullableString() cil managed + .method public hidebysig specialname instance string get_NullableString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -111,8 +108,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !X get_GenericNormalField() cil managed + .method public hidebysig specialname instance !X get_GenericNormalField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -123,8 +119,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !Y get_GenericNullableField() cil managed + .method public hidebysig specialname instance !Y get_GenericNullableField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -135,8 +130,7 @@ IL_0006: ret } - .method public hidebysig specialname - instance !Z get_GenericNotNullField() cil managed + .method public hidebysig specialname instance !Z get_GenericNotNullField() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -187,8 +181,7 @@ IL_003b: ret } - .method public strict virtual instance string - ToString() cil managed + .method public strict virtual instance string ToString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) @@ -246,8 +239,7 @@ } } - .method public specialname static string - get_maybeString() cil managed + .method public specialname static string get_maybeString() cil managed { .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) @@ -257,8 +249,7 @@ IL_0001: ret } - .method public static class MyTestModule/MyRecord`3 - createAnInstance() cil managed + .method public static class MyTestModule/MyRecord`3 createAnInstance() cil managed { .param [0] .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 03 00 00 00 01 02 01 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs new file mode 100644 index 00000000000..843f7be1aaf --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs @@ -0,0 +1,40 @@ +module MyTestModule + +let iCanProduceNullSometimes (arg:'a) : 'a = + let mutable cache = null + + if (System.DateTime.Now.Hour = 7) then + cache <- arg + + if (System.DateTime.Now.Hour = 7) then + null + else + arg + +let iPatternMatchOnArg arg = + match arg with + | null -> "null" + | _ -> "not null" + +//let iAcceptNullPartiallyInfered(arg: _ | null) = +let iAcceptNullPartiallyInfered(arg: 'a | null when 'a: not struct) = + if isNull arg then + 1 + else + 0 + +let iAcceptNullExplicitAnnotation(arg: 'T when 'T:null) = + if isNull arg then + 1 + else + 0 + + +let fullyInferedTestCase arg1 arg2 = + System.Console.Write(iAcceptNullPartiallyInfered arg1) + let maybeNull = iCanProduceNullSometimes arg2 + maybeNull + +let structShouldBeAllowedHere arg = + let boxed : obj | null = box arg + iAcceptNullPartiallyInfered boxed \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl new file mode 100644 index 00000000000..464a1d603cd --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl @@ -0,0 +1,248 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed MyTestModule + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .method public static !!a iCanProduceNullSometimes(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 4 + .locals init (!!a V_0, + valuetype [runtime]System.DateTime V_1, + valuetype [runtime]System.DateTime V_2, + !!a V_3) + IL_0000: call valuetype [runtime]System.DateTime [runtime]System.DateTime::get_Now() + IL_0005: stloc.1 + IL_0006: ldloca.s V_1 + IL_0008: call instance int32 [runtime]System.DateTime::get_Hour() + IL_000d: ldc.i4.7 + IL_000e: bne.un.s IL_0014 + + IL_0010: ldarg.0 + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: call valuetype [runtime]System.DateTime [runtime]System.DateTime::get_Now() + IL_0019: stloc.2 + IL_001a: ldloca.s V_2 + IL_001c: call instance int32 [runtime]System.DateTime::get_Hour() + IL_0021: ldc.i4.7 + IL_0022: bne.un.s IL_0026 + + IL_0024: ldloc.3 + IL_0025: ret + + IL_0026: ldarg.0 + IL_0027: ret + } + + .method public static string iPatternMatchOnArg(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: box !!a + IL_0006: brfalse.s IL_000a + + IL_0008: br.s IL_0010 + + IL_000a: ldstr "null" + IL_000f: ret + + IL_0010: ldstr "not null" + IL_0015: ret + } + + .method public static int32 iAcceptNullPartiallyInfered(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 3 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: box !!a + IL_0008: brtrue.s IL_000d + + IL_000a: ldc.i4.1 + IL_000b: br.s IL_000e + + IL_000d: ldc.i4.0 + IL_000e: brfalse.s IL_0012 + + IL_0010: ldc.i4.1 + IL_0011: ret + + IL_0012: ldc.i4.0 + IL_0013: ret + } + + .method public static int32 iAcceptNullExplicitAnnotation(!!T arg) cil managed + { + .param type T + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 3 + .locals init (!!T V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: box !!T + IL_0008: brtrue.s IL_000d + + IL_000a: ldc.i4.1 + IL_000b: br.s IL_000e + + IL_000d: ldc.i4.0 + IL_000e: brfalse.s IL_0012 + + IL_0010: ldc.i4.1 + IL_0011: ret + + IL_0012: ldc.i4.0 + IL_0013: ret + } + + .method public static !!b fullyInferedTestCase(!!a arg1, + !!b arg2) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param type b + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 3 + .locals init (!!b V_0) + IL_0000: ldarg.0 + IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0006: call void [runtime]System.Console::Write(int32) + IL_000b: ldarg.1 + IL_000c: call !!0 MyTestModule::iCanProduceNullSometimes(!!0) + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: ret + } + + .method public static int32 structShouldBeAllowedHere(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + + .maxstack 3 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: box !!a + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_000d: ret + } + +} + +.class private abstract auto ansi sealed ''.$MyTestModule + extends [runtime]System.Object +{ +} + +.class private auto ansi beforefieldinit System.Runtime.CompilerServices.NullableAttribute + extends [runtime]System.Attribute +{ + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public uint8[] NullableFlags + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method public specialname rtspecialname instance void .ctor(uint8 scalarByteValue) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [runtime]System.Attribute::.ctor() + IL_0006: ldarg.0 + IL_0007: ldc.i4.1 + IL_0008: newarr [runtime]System.Byte + IL_000d: dup + IL_000e: ldc.i4.0 + IL_000f: ldarg.1 + IL_0010: stelem.i1 + IL_0011: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags + IL_0016: ret + } + + .method public specialname rtspecialname instance void .ctor(uint8[] NullableFlags) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [runtime]System.Attribute::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld uint8[] System.Runtime.CompilerServices.NullableAttribute::NullableFlags + IL_000d: ret + } + +} + +.class private auto ansi beforefieldinit System.Runtime.CompilerServices.NullableContextAttribute + extends [runtime]System.Attribute +{ + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .field public uint8 Flag + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method public specialname rtspecialname instance void .ctor(uint8 Flag) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void [runtime]System.Attribute::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld uint8 System.Runtime.CompilerServices.NullableContextAttribute::Flag + IL_000d: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl new file mode 100644 index 00000000000..c11cd791f9b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl @@ -0,0 +1,184 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed MyTestModule + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .method public static !!a iCanProduceNullSometimes(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 4 + .locals init (!!a V_0, + valuetype [runtime]System.DateTime V_1, + valuetype [runtime]System.DateTime V_2, + !!a V_3) + IL_0000: call valuetype [runtime]System.DateTime [runtime]System.DateTime::get_Now() + IL_0005: stloc.1 + IL_0006: ldloca.s V_1 + IL_0008: call instance int32 [runtime]System.DateTime::get_Hour() + IL_000d: ldc.i4.7 + IL_000e: bne.un.s IL_0014 + + IL_0010: ldarg.0 + IL_0011: stloc.0 + IL_0012: br.s IL_0014 + + IL_0014: call valuetype [runtime]System.DateTime [runtime]System.DateTime::get_Now() + IL_0019: stloc.2 + IL_001a: ldloca.s V_2 + IL_001c: call instance int32 [runtime]System.DateTime::get_Hour() + IL_0021: ldc.i4.7 + IL_0022: bne.un.s IL_0026 + + IL_0024: ldloc.3 + IL_0025: ret + + IL_0026: ldarg.0 + IL_0027: ret + } + + .method public static string iPatternMatchOnArg(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: box !!a + IL_0006: brfalse.s IL_000a + + IL_0008: br.s IL_0010 + + IL_000a: ldstr "null" + IL_000f: ret + + IL_0010: ldstr "not null" + IL_0015: ret + } + + .method public static int32 iAcceptNullPartiallyInfered(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 3 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: box !!a + IL_0008: brtrue.s IL_000d + + IL_000a: ldc.i4.1 + IL_000b: br.s IL_000e + + IL_000d: ldc.i4.0 + IL_000e: brfalse.s IL_0012 + + IL_0010: ldc.i4.1 + IL_0011: ret + + IL_0012: ldc.i4.0 + IL_0013: ret + } + + .method public static int32 iAcceptNullExplicitAnnotation(!!T arg) cil managed + { + .param type T + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 3 + .locals init (!!T V_0) + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: box !!T + IL_0008: brtrue.s IL_000d + + IL_000a: ldc.i4.1 + IL_000b: br.s IL_000e + + IL_000d: ldc.i4.0 + IL_000e: brfalse.s IL_0012 + + IL_0010: ldc.i4.1 + IL_0011: ret + + IL_0012: ldc.i4.0 + IL_0013: ret + } + + .method public static !!b fullyInferedTestCase(!!a arg1, + !!b arg2) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param type b + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + + .maxstack 3 + .locals init (!!b V_0) + IL_0000: ldarg.0 + IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0006: call void [runtime]System.Console::Write(int32) + IL_000b: ldarg.1 + IL_000c: call !!0 MyTestModule::iCanProduceNullSometimes(!!0) + IL_0011: stloc.0 + IL_0012: ldloc.0 + IL_0013: ret + } + + .method public static int32 structShouldBeAllowedHere(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + + .maxstack 3 + .locals init (object V_0) + IL_0000: ldarg.0 + IL_0001: box !!a + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_000d: ret + } + +} + +.class private abstract auto ansi sealed ''.$MyTestModule + extends [runtime]System.Object +{ +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index 7fc62586c57..b00e883f730 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -156,6 +156,16 @@ let mkCacheInt32 () = |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``Can infer underscore or null``() = + FSharp """ +module MyLib +let iAcceptNullPartiallyInfered(arg: _ | null) = 42 + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed + [] let ``Boolean literal to string is not nullable`` () = FSharp """module MyLibrary @@ -260,6 +270,18 @@ let doStuff() = |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``Match null on two strings`` () = + FSharp """module MyLibrary +let len2r (str1: string | null) (str2: string | null) = + match str1, str2 with + | null, _ -> -1 + | _, null -> -1 + | s1, s2 -> s1.Length + s2.Length +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldSucceed [] [] @@ -320,7 +342,7 @@ let myFunction (input1 : string | null) (input2 : string | null): (string*string let ``Eliminate aliased nullness after matching`` () = FSharp $"""module MyLibrary -type Maybe<'T> = 'T | null +type Maybe<'T when 'T:not struct> = 'T | null let myFunction (input : string Maybe) : string = match input with From c50b5adbb44a965260fa7d66557a8892e294e3be Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 15 May 2024 16:27:04 +0200 Subject: [PATCH 09/18] "when T:not null" does not enforce reference type --- src/Compiler/Checking/ConstraintSolver.fs | 1 - .../EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl | 8 ++++---- .../EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl | 8 ++++---- .../EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl | 8 ++++---- .../EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl | 8 ++++---- .../EmittedIL/Nullness/Records.fs.il.net472.bsl | 2 +- .../EmittedIL/Nullness/Records.fs.il.netcore.bsl | 2 +- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 3c8622b08f2..21da3de8101 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2636,7 +2636,6 @@ and SolveTypeUseNotSupportsNull (csenv: ConstraintSolverEnv) ndeep m2 trace ty = match tryDestTyparTy g ty with | ValueSome tp -> do! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.NotSupportsNull m) - do! AddConstraint csenv ndeep m2 trace tp (TyparConstraint.IsReferenceType m) | ValueNone -> let nullness = nullnessOfTy g ty do! SolveNullnessNotSupportsNull csenv ndeep m2 trace ty nullness diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl index f237e7a5c9c..581fe00c63f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 + .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 extends [runtime]System.ValueType { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoEqualityAttribute::.ctor() = ( 01 00 00 00 ) @@ -39,7 +39,7 @@ .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -334,8 +334,8 @@ } .method public static valuetype TestModule/MyStructOption`1 - mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - valuetype TestModule/MyStructOption`1 myOpt) cil managed + mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + valuetype TestModule/MyStructOption`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl index 095f4b897dc..e4c49f2f6de 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 + .class sequential autochar serializable sealed nested public beforefieldinit MyStructOption`1 extends [runtime]System.ValueType { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoEqualityAttribute::.ctor() = ( 01 00 00 00 ) @@ -39,7 +39,7 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -334,8 +334,8 @@ } .method public static valuetype TestModule/MyStructOption`1 - mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - valuetype TestModule/MyStructOption`1 myOpt) cil managed + mapStructContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + valuetype TestModule/MyStructOption`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl index 2a35c1c1aba..f4977bfcd8d 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.net472.bsl @@ -219,7 +219,7 @@ } } - .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 + .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 extends [runtime]System.Object { .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) @@ -232,7 +232,7 @@ .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -450,8 +450,8 @@ } .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed + mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl index d95f4572cf1..057fa515964 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullAsTrueValue.fs.il.netcore.bsl @@ -219,7 +219,7 @@ } } - .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 + .class auto autochar serializable sealed nested public beforefieldinit MyOptionWhichCannotHaveNullInTheInside`1 extends [runtime]System.Object { .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) @@ -232,7 +232,7 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type T .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class abstract auto ansi sealed nested public Tags + .class abstract auto ansi sealed nested public Tags extends [runtime]System.Object { .param type T @@ -450,8 +450,8 @@ } .method public static class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 - mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed + mapNotNullableContents(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class TestModule/MyOptionWhichCannotHaveNullInTheInside`1 myOpt) cil managed { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) .param type a diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl index c3378476c29..14108f77f92 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.net472.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 + .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 extends [runtime]System.Object { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoComparisonAttribute::.ctor() = ( 01 00 00 00 ) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl index 7875f759770..46f7f58bdc6 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/Records.fs.il.netcore.bsl @@ -27,7 +27,7 @@ { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) .custom instance void [runtime]System.Runtime.CompilerServices.NullableContextAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) - .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 + .class auto ansi serializable sealed nested public beforefieldinit MyRecord`3 extends [runtime]System.Object { .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoComparisonAttribute::.ctor() = ( 01 00 00 00 ) From 05b6b479460702f41dd4a408bf6687d0d43d497f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 15 May 2024 17:13:46 +0200 Subject: [PATCH 10/18] Nullness-related constraint consistency --- src/Compiler/Checking/ConstraintSolver.fs | 4 +++ .../EmittedIL/Nullness/SupportsNull.fs | 11 +++++--- .../Nullness/SupportsNull.fs.il.net472.bsl | 26 ++++++++++++++++--- .../Nullness/SupportsNull.fs.il.netcore.bsl | 26 ++++++++++++++++--- .../Language/NullableReferenceTypesTests.fs | 17 ++++++++++++ 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 21da3de8101..72c0f4ef71f 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -2384,6 +2384,10 @@ and EnforceConstraintConsistency (csenv: ConstraintSolverEnv) ndeep m2 trace ret | TyparConstraint.IsNonNullableStruct _, TyparConstraint.IsReferenceType _ | TyparConstraint.IsReferenceType _, TyparConstraint.IsNonNullableStruct _ -> return! ErrorD (Error(FSComp.SR.csStructConstraintInconsistent(), m)) + + | TyparConstraint.SupportsNull _, TyparConstraint.NotSupportsNull _ + | TyparConstraint.NotSupportsNull _, TyparConstraint.SupportsNull _ -> + return! ErrorD (Error(FSComp.SR.csNullNotNullConstraintInconsistent(), m)) | TyparConstraint.IsUnmanaged _, TyparConstraint.IsReferenceType _ | TyparConstraint.IsReferenceType _, TyparConstraint.IsUnmanaged _ -> diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs index 843f7be1aaf..ca7cc4d98bc 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs @@ -16,8 +16,11 @@ let iPatternMatchOnArg arg = | null -> "null" | _ -> "not null" -//let iAcceptNullPartiallyInfered(arg: _ | null) = -let iAcceptNullPartiallyInfered(arg: 'a | null when 'a: not struct) = +let iAcceptNullPartiallyInferedFromUnderscore(arg: _ | null) = 0 + +let iAcceptNullPartiallyInferedFromNamedTypar(arg: 'a | null) = 0 + +let iAcceptNullWithNullAnnotation(arg: 'a | null when 'a: not struct) = if isNull arg then 1 else @@ -31,10 +34,10 @@ let iAcceptNullExplicitAnnotation(arg: 'T when 'T:null) = let fullyInferedTestCase arg1 arg2 = - System.Console.Write(iAcceptNullPartiallyInfered arg1) + System.Console.Write(iAcceptNullPartiallyInferedFromUnderscore arg1) let maybeNull = iCanProduceNullSometimes arg2 maybeNull let structShouldBeAllowedHere arg = let boxed : obj | null = box arg - iAcceptNullPartiallyInfered boxed \ No newline at end of file + iAcceptNullPartiallyInferedFromUnderscore boxed \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl index 464a1d603cd..7ce487229bb 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl @@ -81,7 +81,27 @@ IL_0015: ret } - .method public static int32 iAcceptNullPartiallyInfered(!!a arg) cil managed + .method public static int32 iAcceptNullPartiallyInferedFromUnderscore(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public static int32 iAcceptNullPartiallyInferedFromNamedTypar(!!a arg) cil managed + { + .param type a + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public static int32 iAcceptNullWithNullAnnotation(!!a arg) cil managed { .param type a .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) @@ -145,7 +165,7 @@ .maxstack 3 .locals init (!!b V_0) IL_0000: ldarg.0 - IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInferedFromUnderscore(!!0) IL_0006: call void [runtime]System.Console::Write(int32) IL_000b: ldarg.1 IL_000c: call !!0 MyTestModule::iCanProduceNullSometimes(!!0) @@ -165,7 +185,7 @@ IL_0001: box !!a IL_0006: stloc.0 IL_0007: ldloc.0 - IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInferedFromUnderscore(!!0) IL_000d: ret } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl index c11cd791f9b..e93411f347c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl @@ -82,7 +82,27 @@ IL_0015: ret } - .method public static int32 iAcceptNullPartiallyInfered(!!a arg) cil managed + .method public static int32 iAcceptNullPartiallyInferedFromUnderscore(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public static int32 iAcceptNullPartiallyInferedFromNamedTypar(!!a arg) cil managed + { + .param type a + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public static int32 iAcceptNullWithNullAnnotation(!!a arg) cil managed { .param type a .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) @@ -146,7 +166,7 @@ .maxstack 3 .locals init (!!b V_0) IL_0000: ldarg.0 - IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0001: call int32 MyTestModule::iAcceptNullPartiallyInferedFromUnderscore(!!0) IL_0006: call void [runtime]System.Console::Write(int32) IL_000b: ldarg.1 IL_000c: call !!0 MyTestModule::iCanProduceNullSometimes(!!0) @@ -166,7 +186,7 @@ IL_0001: box !!a IL_0006: stloc.0 IL_0007: ldloc.0 - IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInfered(!!0) + IL_0008: call int32 MyTestModule::iAcceptNullPartiallyInferedFromUnderscore(!!0) IL_000d: ret } diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index b00e883f730..a6f6f6ffd50 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -161,11 +161,28 @@ let ``Can infer underscore or null``() = FSharp """ module MyLib let iAcceptNullPartiallyInfered(arg: _ | null) = 42 +let iHaveMissingContraint(arg: 'a | null) = 42 """ |> asLibrary |> typeCheckWithStrictNullness |> shouldSucceed +[] +let ``Invalid usages of WithNull syntax``() = + FSharp """ +module MyLib +let f1(x: option | null) = () +let f2(x: int | null) = () +let f3(x: ('a*'b) | null) = () +let f4(x: option<'a> | null) = () +let f5(x: ('a | null) when 'a:struct) = () +let f6(x: 'a | null when 'a:null) = () + """ + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldFail + |> withDiagnostics [] + [] let ``Boolean literal to string is not nullable`` () = FSharp """module MyLibrary From 62780bc989ba7f7aabf987f48c25156e6922859e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 15 May 2024 17:26:58 +0200 Subject: [PATCH 11/18] Bugfix for emitting Nullable attrs for C# --- src/Compiler/CodeGen/IlxGenSupport.fs | 3 ++- .../EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl | 4 ++++ .../EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl | 4 ++++ .../EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl | 4 ++-- .../EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl | 4 ++-- .../EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl | 8 ++++++++ .../EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl | 8 ++++++++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGenSupport.fs b/src/Compiler/CodeGen/IlxGenSupport.fs index 0c641898f24..b6efff83045 100644 --- a/src/Compiler/CodeGen/IlxGenSupport.fs +++ b/src/Compiler/CodeGen/IlxGenSupport.fs @@ -446,8 +446,9 @@ let rec GetNullnessFromTType (g: TcGlobals) ty = ] | TType_forall _ | TType_ucase _ - | TType_var _ | TType_measure _ -> [] + | TType_var (nullness=nullness) -> [nullness.Evaluate()] + let GenNullnessIfNecessary (g: TcGlobals) ty = if g.langFeatureNullness && g.checkNullness then diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl index 9907f3410bd..a01419f0ed0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.net472.bsl @@ -115,6 +115,10 @@ .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) .param type e .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .param [0] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + .param [2] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldarg.1 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl index 3dbcb185add..02d5e2cbe40 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/CurriedFunctions.fs.il.netcore.bsl @@ -115,6 +115,10 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) .param type e .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .param [0] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + .param [2] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldarg.1 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl index 581fe00c63f..8d49ce9610c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.net472.bsl @@ -343,9 +343,9 @@ .param type b .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param [0] - .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 00 01 00 00 ) .param [2] - .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 00 01 00 00 ) .maxstack 7 .locals init (valuetype TestModule/MyStructOption`1 V_0, diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl index e4c49f2f6de..43a350944d8 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/GenericStructDu.fs.il.netcore.bsl @@ -343,9 +343,9 @@ .param type b .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param [0] - .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 00 01 00 00 ) .param [2] - .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8[]) = ( 01 00 02 00 00 00 00 01 00 00 ) .maxstack 7 .locals init (valuetype TestModule/MyStructOption`1 V_0, diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl index 7ce487229bb..74d4cc4fc1e 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.net472.bsl @@ -85,6 +85,8 @@ { .param type a .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldc.i4.0 @@ -95,6 +97,8 @@ { .param type a .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldc.i4.0 @@ -105,6 +109,8 @@ { .param type a .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 3 .locals init (!!a V_0) @@ -161,6 +167,8 @@ .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type b .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + .param [1] + .custom instance void System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 3 .locals init (!!b V_0) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl index e93411f347c..8c5236b881b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/SupportsNull.fs.il.netcore.bsl @@ -86,6 +86,8 @@ { .param type a .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldc.i4.0 @@ -96,6 +98,8 @@ { .param type a .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 8 IL_0000: ldc.i4.0 @@ -106,6 +110,8 @@ { .param type a .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) + .param [1] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 3 .locals init (!!a V_0) @@ -162,6 +168,8 @@ .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 01 00 00 ) .param type b .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) + .param [1] + .custom instance void [runtime]System.Runtime.CompilerServices.NullableAttribute::.ctor(uint8) = ( 01 00 02 00 00 ) .maxstack 3 .locals init (!!b V_0) From c1861315dad4b92bcd5a9bd433eeecaa12869a18 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 May 2024 10:34:33 +0200 Subject: [PATCH 12/18] fantomas --- src/Compiler/CodeGen/IlxGen.fs | 4 ++-- src/Compiler/CodeGen/IlxGenSupport.fs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 45b25c3138a..102ec23cc54 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -5650,7 +5650,7 @@ and GenGenericParam cenv eenv (tp: Typar) = | TyparConstraint.NotSupportsNull _ -> true | _ -> false) - let hasSupportsNull() = + let hasSupportsNull () = tp.Constraints |> List.exists (function | TyparConstraint.SupportsNull _ -> true @@ -5658,7 +5658,7 @@ and GenGenericParam cenv eenv (tp: Typar) = if hasNotSupportsNull || notNullableValueTypeConstraint then NullnessInfo.WithoutNull - elif refTypeConstraint || hasSupportsNull() then + elif refTypeConstraint || hasSupportsNull () then NullnessInfo.WithNull else NullnessInfo.AmbivalentToNull diff --git a/src/Compiler/CodeGen/IlxGenSupport.fs b/src/Compiler/CodeGen/IlxGenSupport.fs index b6efff83045..4be01ced411 100644 --- a/src/Compiler/CodeGen/IlxGenSupport.fs +++ b/src/Compiler/CodeGen/IlxGenSupport.fs @@ -447,8 +447,7 @@ let rec GetNullnessFromTType (g: TcGlobals) ty = | TType_forall _ | TType_ucase _ | TType_measure _ -> [] - | TType_var (nullness=nullness) -> [nullness.Evaluate()] - + | TType_var(nullness = nullness) -> [ nullness.Evaluate() ] let GenNullnessIfNecessary (g: TcGlobals) ty = if g.langFeatureNullness && g.checkNullness then From e0e5406a1a962232ae5619668332344e9ff1ce35 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 May 2024 11:32:53 +0200 Subject: [PATCH 13/18] tests adjusted --- .../Language/NullableReferenceTypesTests.fs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index a6f6f6ffd50..ee0b238aeec 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -181,7 +181,14 @@ let f6(x: 'a | null when 'a:null) = () |> asLibrary |> typeCheckWithStrictNullness |> shouldFail - |> withDiagnostics [] + |> withDiagnostics + [ 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 qualitification." + 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 qualitification." + 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"] [] let ``Boolean literal to string is not nullable`` () = @@ -449,7 +456,7 @@ strictFunc(null) |> ignore """ |> typeCheckWithStrictNullness |> shouldFail |> withDiagnostics - [ Error 3261, Line 4, Col 12, Line 4, Col 16, "Nullness warning: The type 'obj | null' supports 'null' but a non-null type is expected."] + [ Error 43, Line 4, Col 12, Line 4, Col 16, "The constraints 'null' and 'not null' are inconsistent"] [] let ``Strict func null literal2`` () = @@ -463,7 +470,7 @@ strictFunc("hi") |> ignore """ |> typeCheckWithStrictNullness |> shouldFail |> withDiagnostics - [ Error 3261, Line 4, Col 12, Line 4, Col 16, "Nullness warning: The type 'obj | null' supports 'null' but a non-null type is expected."] + [ Error 43, Line 4, Col 12, Line 4, Col 16, "The constraints 'null' and 'not null' are inconsistent"] [] let ``Supports null in generic code`` () = @@ -580,7 +587,8 @@ looseFunc(maybeTuple2) |> ignore |> typeCheckWithStrictNullness |> shouldFail |> withDiagnostics - [ Error 3260, Line 27, Col 18, Line 27, Col 34, "The type '(int * int)' does not support a nullness qualitification." + [ 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 qualitification." Error 3261, Line 27, Col 37, Line 27, Col 41, "Nullness warning: The type '(int * int)' does not support 'null'." 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." From eb5b5ecfaae59d201b3b97ef08b32d59badbb17f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 May 2024 12:01:47 +0200 Subject: [PATCH 14/18] update micro tests --- .gitignore | 2 ++ tests/adhoc/nullness/enabled/positive.fs | 6 +++--- tests/adhoc/nullness/validate.cmd | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 013ade3ce24..566974acd91 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,5 @@ tests/FSharp.Compiler.Service.Tests/FSharp.CompilerService.SurfaceArea.netstanda *.vsp /tests/AheadOfTime/Trimming/output.txt *.svclog +micro.exe +positive.exe diff --git a/tests/adhoc/nullness/enabled/positive.fs b/tests/adhoc/nullness/enabled/positive.fs index 3a7afebf6ef..66c3847d3b3 100644 --- a/tests/adhoc/nullness/enabled/positive.fs +++ b/tests/adhoc/nullness/enabled/positive.fs @@ -48,19 +48,19 @@ type C(s: String) = // This give a warning since 'T is not known to be reference type non-null -let f<'T when 'T: not null > (x: 'T | null, y: 'T | null) = () +let f<'T when 'T: not null and 'T: not struct > (x: 'T | null, y: 'T | null) = () module Extractions0c = let x = null - let f<'T when 'T : not null> (x: 'T | null, y: 'T | null) = () + let f<'T when 'T : not null and 'T: not struct> (x: 'T | null, y: 'T | null) = () let s : String = "" let result = f (x, s) // expect no warning in any configuration module Extractions0e = let x = null - let f<'T when 'T : not null> (x: 'T | null, y: 'T | null) = () + let f<'T when 'T : not null and 'T: not struct> (x: 'T | null, y: 'T | null) = () let result = f (x, "") // expect no warning in any configuration module Extractions1 = diff --git a/tests/adhoc/nullness/validate.cmd b/tests/adhoc/nullness/validate.cmd index 9b9bd182f92..80059300f67 100644 --- a/tests/adhoc/nullness/validate.cmd +++ b/tests/adhoc/nullness/validate.cmd @@ -1,9 +1,9 @@ REM devenv FSharp.sln /ProjectConfig Proto - +set "fsiLocation="C:\Program Files\dotnet\sdk\8.0.300\FSharp\fsc.dll"" REM dotnet build src\fsc\fscProject -f net472 -c Proto -p ProtoDebug=true -fsc.exe tests\adhoc\nullness\micro.fs -i -fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i +dotnet %fsiLocation% tests\adhoc\nullness\micro.fs -i +dotnet %fsiLocation% tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fs -i artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i @@ -17,12 +17,12 @@ artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fsi tests\adho REM ------------- -fsc.exe tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.previous.bsl & type tests\adhoc\nullness\existing\positive.previous.bsl +dotnet %fsiLocation% tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.previous.bsl & type tests\adhoc\nullness\existing\positive.previous.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.next.bsl & type tests\adhoc\nullness\existing\positive.next.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview 2> tests\adhoc\nullness\existing\positive.next.enabled.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl -fsc.exe tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.previous.bsl & type tests\adhoc\nullness\existing\negative.previous.bsl +dotnet %fsiLocation% tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.previous.bsl & type tests\adhoc\nullness\existing\negative.previous.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.next.bsl & type tests\adhoc\nullness\existing\negative.next.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview 2> tests\adhoc\nullness\existing\negative.next.enabled.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.bsl artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl From 1b59eb26f24a155cad5d494617e393cc8b72b718 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 May 2024 14:17:20 +0200 Subject: [PATCH 15/18] adjusting micro tests --- .../Language/NullableReferenceTypesTests.fs | 29 +++++++++++++++++- .../positive.next.enabled.checknulls.bsl | 10 +++++-- .../negative.next.enabled.checknulls.bsl | 2 ++ tests/adhoc/nullness/existing/positive.fs | 8 ++--- .../positive.next.enabled.checknulls.bsl | 8 +++++ tests/adhoc/nullness/validate.cmd | 30 +++++++++---------- 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index ee0b238aeec..3e2ec6e545a 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -778,4 +778,31 @@ let mappableFunc = """ |> asLibrary |> typeCheckWithStrictNullness - |> shouldSucceed \ No newline at end of file + |> shouldSucceed + +[] +let ``Notnull constraint and inline annotated value`` () = + FSharp """module MyLibrary +open System + +let f3 (x: 'T when 'T : not null) = 1 + +let v3 = f3 (null: obj) +let v4 = f3 (null: String | null) +let v5 = f3 (Some 1) + +let w3 = (null: obj) |> f3 +let w4 = (null: String | null) |> f3 + +let v3WithNull = f3 (null: obj | null) +""" + |> asLibrary + |> typeCheckWithStrictNullness + |> shouldFail + |> withDiagnostics + [ Error 3261, Line 6, Col 14, Line 6, Col 18, "Nullness warning: The type 'obj' does not support 'null'." + Error 3261, Line 7, Col 14, Line 7, Col 33, "Nullness warning: The type 'String | null' supports 'null' but a non-null type is expected." + Error 3261, Line 8, Col 14, Line 8, Col 20, "Nullness warning: The type ''a option' uses 'null' as a representation value but a non-null type is expected." + Error 3261, Line 10, Col 11, Line 10, Col 15, "Nullness warning: The type 'obj' does not support 'null'." + Error 3261, Line 11, Col 35, Line 11, Col 37, "Nullness warning: The type 'String | null' supports 'null' but a non-null type is expected." + Error 3261, Line 13, Col 22, Line 13, Col 38, "Nullness warning: The type 'obj | null' supports 'null' but a non-null type is expected."] \ No newline at end of file diff --git a/tests/adhoc/nullness/enabled/positive.next.enabled.checknulls.bsl b/tests/adhoc/nullness/enabled/positive.next.enabled.checknulls.bsl index 43b59356de0..d8125c7aee9 100644 --- a/tests/adhoc/nullness/enabled/positive.next.enabled.checknulls.bsl +++ b/tests/adhoc/nullness/enabled/positive.next.enabled.checknulls.bsl @@ -1,8 +1,12 @@ +tests\adhoc\nullness\enabled\positive.fs(11,18): warning FS3261: Nullness warning: The type 'obj' does not support 'null'. + tests\adhoc\nullness\enabled\positive.fs(12,18): warning FS3261: Nullness warning: The type 'String | null' supports 'null' but a non-null type is expected. tests\adhoc\nullness\enabled\positive.fs(13,18): warning FS3261: Nullness warning: The type ''a option' uses 'null' as a representation value but a non-null type is expected. +tests\adhoc\nullness\enabled\positive.fs(17,15): warning FS3261: Nullness warning: The type 'obj' does not support 'null'. + tests\adhoc\nullness\enabled\positive.fs(18,39): warning FS3261: Nullness warning: The type 'String | null' supports 'null' but a non-null type is expected. tests\adhoc\nullness\enabled\positive.fs(19,26): warning FS3261: Nullness warning: The type 'int option' uses 'null' as a representation value but a non-null type is expected. @@ -47,9 +51,9 @@ tests\adhoc\nullness\enabled\positive.fs(92,83): warning FS3261: Nullness warnin tests\adhoc\nullness\enabled\positive.fs(120,32): warning FS3261: Nullness warning: The type 'obj array' does not support 'null'. -tests\adhoc\nullness\enabled\positive.fs(129,4): warning FS3261: Nullness warning: The types 'System.String (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)' and 'System.String (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)' do not have compatible nullability. +tests\adhoc\nullness\enabled\positive.fs(129,4): warning FS3261: Nullness warning: The type 'String' does not support 'null'. -tests\adhoc\nullness\enabled\positive.fs(134,5): warning FS3261: Nullness warning: The types 'System.String (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)' and 'System.String (mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)' do not have compatible nullability. +tests\adhoc\nullness\enabled\positive.fs(134,5): warning FS3261: Nullness warning: The type 'String' does not support 'null'. tests\adhoc\nullness\enabled\positive.fs(159,36): warning FS3261: Nullness warning: The type 'String' does not support 'null'. @@ -57,4 +61,6 @@ tests\adhoc\nullness\enabled\positive.fs(162,41): warning FS3261: Nullness warni tests\adhoc\nullness\enabled\positive.fs(164,37): warning FS3261: Nullness warning: The type 'String' does not support 'null'. +tests\adhoc\nullness\enabled\positive.fs(183,14): warning FS3261: Nullness warning: The type 'string' does not support 'null'. + tests\adhoc\nullness\enabled\positive.fs(189,17): warning FS3261: Nullness warning: The type 'String' does not support 'null'. diff --git a/tests/adhoc/nullness/existing/negative.next.enabled.checknulls.bsl b/tests/adhoc/nullness/existing/negative.next.enabled.checknulls.bsl index 5244ca862a8..ab814c80f8a 100644 --- a/tests/adhoc/nullness/existing/negative.next.enabled.checknulls.bsl +++ b/tests/adhoc/nullness/existing/negative.next.enabled.checknulls.bsl @@ -1,6 +1,8 @@ tests\adhoc\nullness\existing\negative.fs(8,17): warning FS3261: Nullness warning: The type '(int * int)' does not support 'null'. +tests\adhoc\nullness\existing\negative.fs(10,17): warning FS3261: Nullness warning: The type 'int list' does not support 'null'. + tests\adhoc\nullness\existing\negative.fs(12,17): warning FS3261: Nullness warning: The type '(int -> int)' does not support 'null'. tests\adhoc\nullness\existing\negative.fs(20,25): warning FS0444: The type of a field using the 'DefaultValue' attribute must admit default initialization, i.e. have 'null' as a proper value or be a struct type whose fields all admit default initialization. You can use 'DefaultValue(false)' to disable this check diff --git a/tests/adhoc/nullness/existing/positive.fs b/tests/adhoc/nullness/existing/positive.fs index a87d5dff156..727a1a8b69d 100644 --- a/tests/adhoc/nullness/existing/positive.fs +++ b/tests/adhoc/nullness/existing/positive.fs @@ -6,19 +6,19 @@ open System.Runtime.CompilerServices module Extractions0a = let x = null - let result = (x = "") // expect no warning under any configuration + let result = (x = "") //The type 'string' does not support 'null'. module Extractions0b = let x = null let f (x: 'T, y: 'T) = () - let result = f (x, "") // expect no warning under any configuration + let result = f (x, "") //The type 'string' does not support 'null'. module Extractions0d = let x = null let f<'T when 'T : null> (x: 'T, y: 'T) = () - let result = f (x, "") // expect no warning under any configuration + let result = f (x, "") //The type 'string' does not support 'null'. module Basics = let x1 : String = null // expect a warning when checknulls is on @@ -46,7 +46,7 @@ System.Console.WriteLine("a", (null: obj[])) // expect a warning when checknulls let f0 line = let add (s:String) = () match line with - | null | "" -> () + | null | "" -> () //The type 'string' does not support 'null'. | _ -> add line module NullConstraintTests = diff --git a/tests/adhoc/nullness/existing/positive.next.enabled.checknulls.bsl b/tests/adhoc/nullness/existing/positive.next.enabled.checknulls.bsl index 2788d57d704..05053aaf03c 100644 --- a/tests/adhoc/nullness/existing/positive.next.enabled.checknulls.bsl +++ b/tests/adhoc/nullness/existing/positive.next.enabled.checknulls.bsl @@ -1,8 +1,16 @@ +tests\adhoc\nullness\existing\positive.fs(9,23): warning FS3261: Nullness warning: The type 'string' does not support 'null'. + +tests\adhoc\nullness\existing\positive.fs(15,24): warning FS3261: Nullness warning: The type 'string' does not support 'null'. + +tests\adhoc\nullness\existing\positive.fs(21,24): warning FS3261: Nullness warning: The type 'string' does not support 'null'. + tests\adhoc\nullness\existing\positive.fs(24,23): warning FS3261: Nullness warning: The type 'String' does not support 'null'. tests\adhoc\nullness\existing\positive.fs(29,26): warning FS3261: Nullness warning: The type 'String' does not support 'null'. tests\adhoc\nullness\existing\positive.fs(44,32): warning FS3261: Nullness warning: The type 'obj array' does not support 'null'. +tests\adhoc\nullness\existing\positive.fs(49,14): warning FS3261: Nullness warning: The type 'string' does not support 'null'. + tests\adhoc\nullness\existing\positive.fs(55,17): warning FS3261: Nullness warning: The type 'String' does not support 'null'. diff --git a/tests/adhoc/nullness/validate.cmd b/tests/adhoc/nullness/validate.cmd index 80059300f67..7aa5f84e88b 100644 --- a/tests/adhoc/nullness/validate.cmd +++ b/tests/adhoc/nullness/validate.cmd @@ -5,31 +5,31 @@ REM dotnet build src\fsc\fscProject -f net472 -c Proto -p ProtoDebug=true dotnet %fsiLocation% tests\adhoc\nullness\micro.fs -i dotnet %fsiLocation% tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fs -i -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fs -i +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fs -i --langversion:preview -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i --langversion:preview +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fs -i --langversion:preview +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i --langversion:preview -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fs -i --langversion:preview --checknulls -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i --langversion:preview --checknulls +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fs -i --langversion:preview --checknulls +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\micro.fsi tests\adhoc\nullness\micro.fs -i --langversion:preview --checknulls REM ------------- dotnet %fsiLocation% tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.previous.bsl & type tests\adhoc\nullness\existing\positive.previous.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.next.bsl & type tests\adhoc\nullness\existing\positive.next.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview 2> tests\adhoc\nullness\existing\positive.next.enabled.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\positive.fs 2> tests\adhoc\nullness\existing\positive.next.bsl & type tests\adhoc\nullness\existing\positive.next.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview 2> tests\adhoc\nullness\existing\positive.next.enabled.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\positive.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\positive.next.enabled.checknulls.bsl dotnet %fsiLocation% tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.previous.bsl & type tests\adhoc\nullness\existing\negative.previous.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.next.bsl & type tests\adhoc\nullness\existing\negative.next.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview 2> tests\adhoc\nullness\existing\negative.next.enabled.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\negative.fs 2> tests\adhoc\nullness\existing\negative.next.bsl & type tests\adhoc\nullness\existing\negative.next.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview 2> tests\adhoc\nullness\existing\negative.next.enabled.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\existing\negative.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl & type tests\adhoc\nullness\existing\negative.next.enabled.checknulls.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\enabled\positive.fs 2> tests\adhoc\nullness\enabled\positive.next.bsl & type tests\adhoc\nullness\enabled\positive.next.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\enabled\positive.fs --langversion:preview 2> tests\adhoc\nullness\enabled\positive.next.enabled.bsl & type tests\adhoc\nullness\enabled\positive.next.enabled.bsl -artifacts\bin\fsc\Proto\net472\fsc.exe tests\adhoc\nullness\enabled\positive.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\enabled\positive.next.enabled.checknulls.bsl & type tests\adhoc\nullness\enabled\positive.next.enabled.checknulls.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\enabled\positive.fs 2> tests\adhoc\nullness\enabled\positive.next.bsl & type tests\adhoc\nullness\enabled\positive.next.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\enabled\positive.fs --langversion:preview 2> tests\adhoc\nullness\enabled\positive.next.enabled.bsl & type tests\adhoc\nullness\enabled\positive.next.enabled.bsl +artifacts\bin\fsc\Release\net8.0\fsc.exe tests\adhoc\nullness\enabled\positive.fs --langversion:preview --checknulls 2> tests\adhoc\nullness\enabled\positive.next.enabled.checknulls.bsl & type tests\adhoc\nullness\enabled\positive.next.enabled.checknulls.bsl REM ------------- From 3191be2fb6fa2a1872c0771a74d183e201b2ca17 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 May 2024 14:46:05 +0200 Subject: [PATCH 16/18] trimmed --- tests/AheadOfTime/Trimming/check.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/AheadOfTime/Trimming/check.ps1 b/tests/AheadOfTime/Trimming/check.ps1 index 6fa3bb6d331..f6921af107f 100644 --- a/tests/AheadOfTime/Trimming/check.ps1 +++ b/tests/AheadOfTime/Trimming/check.ps1 @@ -43,4 +43,4 @@ function CheckTrim($root, $tfm, $outputfile, $expected_len) { CheckTrim -root "SelfContained_Trimming_Test" -tfm "net8.0" -outputfile "FSharp.Core.dll" -expected_len 288256 # Check net7.0 trimmed assemblies -CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8821760 +CheckTrim -root "StaticLinkedFSharpCore_Trimming_Test" -tfm "net8.0" -outputfile "StaticLinkedFSharpCore_Trimming_Test.dll" -expected_len 8819200 From 28be27deb3bb6a484c5def15be4761491a1a7396 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 21 May 2024 10:42:09 +0200 Subject: [PATCH 17/18] nullness fsi update --- tests/adhoc/nullness/out.fsi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/adhoc/nullness/out.fsi b/tests/adhoc/nullness/out.fsi index 9e577b20247..2ef8d77eb31 100644 --- a/tests/adhoc/nullness/out.fsi +++ b/tests/adhoc/nullness/out.fsi @@ -5,9 +5,9 @@ val internal fsProductVersion: string val internal fsLanguageVersion: string +namespace FSharp -namespace FSharp module ExistingPositive @@ -152,7 +152,7 @@ module Basics2 = val f2: unit -> System.String | null - val f3: unit -> 'T | null when 'T: not null + val f3: unit -> 'T | null when 'T: not null and 'T: not struct val f4: unit -> 'T | null when 'T: not null and 'T: not struct @@ -166,13 +166,14 @@ type C = member Value: System.String -val f: x: 'T | null * y: 'T | null -> unit when 'T: not null +val f: x: 'T | null * y: 'T | null -> unit when 'T: not null and 'T: not struct module Extractions0c = val x: 'a when 'a: null - val f: x: 'T | null * y: 'T | null -> unit when 'T: not null + val f: + x: 'T | null * y: 'T | null -> unit when 'T: not null and 'T: not struct val s: System.String @@ -182,7 +183,8 @@ module Extractions0e = val x: 'a when 'a: null - val f: x: 'T | null * y: 'T | null -> unit when 'T: not null + val f: + x: 'T | null * y: 'T | null -> unit when 'T: not null and 'T: not struct val result: unit From 0821508a67092859e1a767cc6c8f7c904a430d6c Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 21 May 2024 10:57:59 +0200 Subject: [PATCH 18/18] try compile instead of typecheck to get tests trough --- .../Language/NullableReferenceTypesTests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs index 3e2ec6e545a..2a7e5a74d87 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/NullableReferenceTypesTests.fs @@ -14,7 +14,7 @@ let withNullnessOptions cu = let typeCheckWithStrictNullness cu = cu |> withNullnessOptions - |> typecheck + |> compile [] let ``Cannot pass possibly null value to a strict function``() =