From c7295c2bd87b5e5f1cc44a53f7aa4dbfe1dc487a Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 30 Dec 2024 12:43:42 +0100 Subject: [PATCH 01/52] type equivalence - add nullness support for signature conformance --- src/Compiler/Checking/CheckDeclarations.fs | 6 +- src/Compiler/Checking/ConstraintSolver.fs | 2 +- .../Checking/Expressions/CheckExpressions.fs | 2 +- src/Compiler/Checking/MethodOverrides.fs | 4 +- src/Compiler/Checking/NicePrint.fs | 2 +- src/Compiler/Checking/infos.fs | 4 +- src/Compiler/TypedTree/TypedTreeOps.fs | 71 ++++++++++--------- src/Compiler/TypedTree/TypedTreeOps.fsi | 12 ++-- .../Language/Nullness/micro.fs | 13 +++- .../Language/Nullness/micro.fsi | 12 +++- 10 files changed, 75 insertions(+), 53 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 80c1a656c2d..da7e7af1086 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -4238,7 +4238,7 @@ module TcDeclarations = // For historical reasons we only give a warning for incorrect type parameters on intrinsic extensions if nReqTypars <> synTypars.Length then errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) - if not (typarsAEquiv g TypeEquivEnv.Empty reqTypars declaredTypars) then + if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then warning(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) // Note we return 'reqTypars' for intrinsic extensions since we may only have given warnings IntrinsicExtensionBinding, reqTypars @@ -4247,7 +4247,7 @@ module TcDeclarations = errorR(Error(FSComp.SR.tcMembersThatExtendInterfaceMustBePlacedInSeparateModule(), tcref.Range)) if nReqTypars <> synTypars.Length then error(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) - if not (typarsAEquiv g TypeEquivEnv.Empty reqTypars declaredTypars) then + if not (typarsAEquiv g (TypeEquivEnv.EmptyWithNullChecks g) reqTypars declaredTypars) then errorR(Error(FSComp.SR.tcDeclaredTypeParametersForExtensionDoNotMatchOriginal(tcref.DisplayNameWithStaticParametersAndUnderscoreTypars), m)) ExtrinsicExtensionBinding, declaredTypars @@ -5701,7 +5701,7 @@ let CheckModuleSignature g (cenv: cenv) m denvAtEnd rootSigOpt implFileTypePrior // Compute the remapping from implementation to signature let remapInfo, _ = ComputeRemappingFromInferredSignatureToExplicitSignature g implFileTypePriorToSig sigFileType - let aenv = { TypeEquivEnv.Empty with EquivTycons = TyconRefMap.OfList remapInfo.RepackagedEntities } + let aenv = { TypeEquivEnv.EmptyWithNullChecks g with EquivTycons = TyconRefMap.OfList remapInfo.RepackagedEntities } if not (SignatureConformance.Checker(g, cenv.amap, denv, remapInfo, true).CheckSignature aenv cenv.infoReader (mkLocalModuleRef implFileSpecPriorToSig) sigFileType) then // We can just raise 'ReportedError' since CheckModuleOrNamespace raises its own error diff --git a/src/Compiler/Checking/ConstraintSolver.fs b/src/Compiler/Checking/ConstraintSolver.fs index 8be7ec551ea..8fbbaa0dcf8 100644 --- a/src/Compiler/Checking/ConstraintSolver.fs +++ b/src/Compiler/Checking/ConstraintSolver.fs @@ -344,7 +344,7 @@ let MakeConstraintSolverEnv contextInfo css m denv = eContextInfo = contextInfo MatchingOnly = false ErrorOnFailedMemberConstraintResolution = false - EquivEnv = TypeEquivEnv.Empty + EquivEnv = TypeEquivEnv.EmptyIgnoreNulls DisplayEnv = denv IsSpeculativeForMethodOverloading = false IsSupportsNullFlex = false diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 16dc49c1a61..fa5704c7c45 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -12670,7 +12670,7 @@ and FixupLetrecBind (cenv: cenv) denv generalizedTyparsForRecursiveBlock (bind: | Some _ -> match PartitionValTyparsForApparentEnclosingType g vspec with | Some(parentTypars, memberParentTypars, _, _, _) -> - ignore(SignatureConformance.Checker(g, cenv.amap, denv, SignatureRepackageInfo.Empty, false).CheckTypars vspec.Range TypeEquivEnv.Empty memberParentTypars parentTypars) + ignore(SignatureConformance.Checker(g, cenv.amap, denv, SignatureRepackageInfo.Empty, false).CheckTypars vspec.Range TypeEquivEnv.EmptyIgnoreNulls memberParentTypars parentTypars) | None -> errorR(Error(FSComp.SR.tcMemberIsNotSufficientlyGeneric(), vspec.Range)) | _ -> () diff --git a/src/Compiler/Checking/MethodOverrides.fs b/src/Compiler/Checking/MethodOverrides.fs index 18b3f23190f..25dae041e0b 100644 --- a/src/Compiler/Checking/MethodOverrides.fs +++ b/src/Compiler/Checking/MethodOverrides.fs @@ -269,7 +269,7 @@ module DispatchSlotChecking = // Compare the types. CompiledSigOfMeth, GetObjectExprOverrideInfo and GetTypeMemberOverrideInfo have already // applied all relevant substitutions except the renamings from fvtmps <-> methTypars - let aenv = TypeEquivEnv.FromEquivTypars fvmethTypars methTypars + let aenv = (TypeEquivEnv.EmptyWithNullChecks g).FromEquivTypars fvmethTypars methTypars List.forall2 (List.lengthsEqAndForall2 (typeAEquiv g aenv)) vargTys argTys && returnTypesAEquiv g aenv vrty retTy && @@ -305,7 +305,7 @@ module DispatchSlotChecking = ComposeTyparInsts ttpinst (ReverseTyparRenaming g memberToParentInst) // Compare under the composed substitutions - let aenv = TypeEquivEnv.FromTyparInst ttpinst + let aenv = (TypeEquivEnv.EmptyWithNullChecks g).FromTyparInst ttpinst typarsAEquiv g aenv fvmethTypars methTypars diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index a01802b1d7c..686015a83e3 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -764,7 +764,7 @@ module PrintTypes = |> ListSet.setify (fun (_, cx1) (_, cx2) -> match cx1, cx2 with | TyparConstraint.MayResolveMember(traitInfo1, _), - TyparConstraint.MayResolveMember(traitInfo2, _) -> traitsAEquiv denv.g TypeEquivEnv.Empty traitInfo1 traitInfo2 + TyparConstraint.MayResolveMember(traitInfo2, _) -> traitsAEquiv denv.g (TypeEquivEnv.EmptyWithNullChecks denv.g) traitInfo1 traitInfo2 | _ -> false) let cxsL = List.collect (layoutConstraintWithInfo denv env) cxs diff --git a/src/Compiler/Checking/infos.fs b/src/Compiler/Checking/infos.fs index 18add6588d0..e0d20bbb3f2 100644 --- a/src/Compiler/Checking/infos.fs +++ b/src/Compiler/Checking/infos.fs @@ -2503,7 +2503,7 @@ let MethInfosEquivByPartialSig erasureFlag ignoreFinal g amap m (minfo: MethInfo let argTys = minfo.GetParamTypes(amap, m, fminst) let argTys2 = minfo2.GetParamTypes(amap, m, fminst2) (argTys, argTys2) ||> List.lengthsEqAndForall2 (List.lengthsEqAndForall2 (fun ty1 ty2 -> - typeAEquivAux erasureFlag g (TypeEquivEnv.FromEquivTypars formalMethTypars formalMethTypars2) (stripByrefTy g ty1) (stripByrefTy g ty2))) + typeAEquivAux erasureFlag g (TypeEquivEnv.EmptyIgnoreNulls.FromEquivTypars formalMethTypars formalMethTypars2) (stripByrefTy g ty1) (stripByrefTy g ty2))) /// Used to hide/filter members from super classes based on signature /// Inref and outref parameter types will be treated as a byref type for equivalency. @@ -2525,7 +2525,7 @@ let MethInfosEquivByNameAndSig erasureFlag ignoreFinal g amap m minfo minfo2 = let (CompiledSig(_, retTy2, formalMethTypars2, _)) = CompiledSigOfMeth g amap m minfo2 match retTy, retTy2 with | None, None -> true - | Some retTy, Some retTy2 -> typeAEquivAux erasureFlag g (TypeEquivEnv.FromEquivTypars formalMethTypars formalMethTypars2) retTy retTy2 + | Some retTy, Some retTy2 -> typeAEquivAux erasureFlag g (TypeEquivEnv.EmptyIgnoreNulls.FromEquivTypars formalMethTypars formalMethTypars2) retTy retTy2 | _ -> false /// Used to hide/filter members from super classes based on signature diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index d383130d0ee..59e8bee1ee9 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -962,15 +962,26 @@ let stripMeasuresFromTy g ty = [] type TypeEquivEnv = { EquivTypars: TyparMap - EquivTycons: TyconRefRemap} + EquivTycons: TyconRefRemap + NullnessMustEqual : bool} + +let private nullnessEqual anev (n1:Nullness) (n2:Nullness) = + if anev.NullnessMustEqual then + (n1.Evaluate()) = (n2.Evaluate()) + else + true // allocate a singleton -let typeEquivEnvEmpty = +let private typeEquivEnvEmpty = { EquivTypars = TyparMap.Empty - EquivTycons = emptyTyconRefRemap } + EquivTycons = emptyTyconRefRemap + NullnessMustEqual = false} + +let private typeEquivCheckNullness = {typeEquivEnvEmpty with NullnessMustEqual = true} type TypeEquivEnv with - static member Empty = typeEquivEnvEmpty + static member EmptyIgnoreNulls = typeEquivEnvEmpty + static member EmptyWithNullChecks (g:TcGlobals) = if g.checkNullness then typeEquivCheckNullness else typeEquivEnvEmpty member aenv.BindTyparsToTypes tps1 tys2 = { aenv with EquivTypars = (tps1, tys2, aenv.EquivTypars) |||> List.foldBack2 (fun tp ty tpmap -> tpmap.Add(tp, ty)) } @@ -978,12 +989,12 @@ type TypeEquivEnv with member aenv.BindEquivTypars tps1 tps2 = aenv.BindTyparsToTypes tps1 (List.map mkTyparTy tps2) - static member FromTyparInst tpinst = + member aenv.FromTyparInst tpinst = let tps, tys = List.unzip tpinst - TypeEquivEnv.Empty.BindTyparsToTypes tps tys + aenv.BindTyparsToTypes tps tys - static member FromEquivTypars tps1 tps2 = - TypeEquivEnv.Empty.BindEquivTypars tps1 tps2 + member aenv.FromEquivTypars tps1 tps2 = + aenv.BindEquivTypars tps1 tps2 let rec traitsAEquivAux erasureFlag g aenv traitInfo1 traitInfo2 = let (TTrait(tys1, nm, mf1, argTys, retTy, _, _)) = traitInfo1 @@ -1064,16 +1075,18 @@ and typeAEquivAux erasureFlag g aenv ty1 ty2 = | TType_forall(tps1, rty1), TType_forall(tps2, retTy2) -> typarsAEquivAux erasureFlag g aenv tps1 tps2 && typeAEquivAux erasureFlag g (aenv.BindEquivTypars tps1 tps2) rty1 retTy2 - | TType_var (tp1, _), TType_var (tp2, _) when typarEq tp1 tp2 -> // NOTE: nullness annotations are ignored for type equivalence - true + | TType_var (tp1, n1), TType_var (tp2, n2) when typarEq tp1 tp2 -> + nullnessEqual aenv n1 n2 - | TType_var (tp1, _), _ -> + | TType_var (tp1, n1), _ -> match aenv.EquivTypars.TryFind tp1 with - | Some tpTy1 -> typeEquivAux erasureFlag g tpTy1 ty2 + | Some tpTy1 -> + let tpTy1 = addNullnessToTy n1 tpTy1 + typeAEquivAux erasureFlag g aenv tpTy1 ty2 | None -> false - // NOTE: nullness annotations are ignored for type equivalence - | TType_app (tcref1, tinst1, _), TType_app (tcref2, tinst2, _) -> + | TType_app (tcref1, tinst1, n1), TType_app (tcref2, tinst2, n2) -> + nullnessEqual aenv n1 n2 && tcrefAEquiv g aenv tcref1 tcref2 && typesAEquivAux erasureFlag g aenv tinst1 tinst2 @@ -1085,8 +1098,8 @@ and typeAEquivAux erasureFlag g aenv ty1 ty2 = | TType_tuple (tupInfo1, l1), TType_tuple (tupInfo2, l2) -> structnessAEquiv tupInfo1 tupInfo2 && typesAEquivAux erasureFlag g aenv l1 l2 - // NOTE: nullness annotations are ignored for type equivalence - | TType_fun (domainTy1, rangeTy1, _), TType_fun (domainTy2, rangeTy2, _) -> + | TType_fun (domainTy1, rangeTy1, n1), TType_fun (domainTy2, rangeTy2, n2) -> + nullnessEqual aenv n1 n2 && typeAEquivAux erasureFlag g aenv domainTy1 domainTy2 && typeAEquivAux erasureFlag g aenv rangeTy1 rangeTy2 | TType_anon (anonInfo1, l1), TType_anon (anonInfo2, l2) -> @@ -1100,18 +1113,6 @@ and typeAEquivAux erasureFlag g aenv ty1 ty2 = | _ -> false -and nullnessSensitivetypeAEquivAux erasureFlag g aenv ty1 ty2 = - let ty1 = stripTyEqnsWrtErasure erasureFlag g ty1 - let ty2 = stripTyEqnsWrtErasure erasureFlag g ty2 - match ty1, ty2 with - | TType_var (_,n1), TType_var (_,n2) - | TType_app (_,_,n1), TType_app (_,_,n2) - | TType_fun (_,_,n1), TType_fun (_,_,n2) -> - n1 === n2 - | _ -> true - - && typeAEquivAux erasureFlag g aenv ty1 ty2 - and anonInfoEquiv (anonInfo1: AnonRecdTypeInfo) (anonInfo2: AnonRecdTypeInfo) = ccuEq anonInfo1.Assembly anonInfo2.Assembly && structnessAEquiv anonInfo1.TupInfo anonInfo2.TupInfo && @@ -1136,7 +1137,7 @@ and measureAEquiv g aenv un1 un2 = and typesAEquivAux erasureFlag g aenv l1 l2 = List.lengthsEqAndForall2 (typeAEquivAux erasureFlag g aenv) l1 l2 -and typeEquivAux erasureFlag g ty1 ty2 = typeAEquivAux erasureFlag g TypeEquivEnv.Empty ty1 ty2 +and typeEquivAux erasureFlag g ty1 ty2 = typeAEquivAux erasureFlag g TypeEquivEnv.EmptyIgnoreNulls ty1 ty2 let typeAEquiv g aenv ty1 ty2 = typeAEquivAux EraseNone g aenv ty1 ty2 @@ -1152,7 +1153,7 @@ let typarsAEquiv g aenv d1 d2 = typarsAEquivAux EraseNone g aenv d1 d2 let returnTypesAEquiv g aenv t1 t2 = returnTypesAEquivAux EraseNone g aenv t1 t2 -let measureEquiv g m1 m2 = measureAEquiv g TypeEquivEnv.Empty m1 m2 +let measureEquiv g m1 m2 = measureAEquiv g TypeEquivEnv.EmptyIgnoreNulls m1 m2 // Get measure of type, float<_> or float32<_> or decimal<_> but not float=float<1> or float32=float32<1> or decimal=decimal<1> let getMeasureOfType g ty = @@ -2718,7 +2719,7 @@ let GetTraitConstraintInfosOfTypars g (tps: Typars) = match cx with | TyparConstraint.MayResolveMember(traitInfo, _) -> traitInfo | _ -> () ] - |> ListSet.setify (traitsAEquiv g TypeEquivEnv.Empty) + |> ListSet.setify (traitsAEquiv g TypeEquivEnv.EmptyIgnoreNulls) |> List.sortBy (fun traitInfo -> traitInfo.MemberLogicalName, traitInfo.GetCompiledArgumentTypes().Length) /// Get information about the runtime witnesses needed for a set of generalized typars @@ -4833,7 +4834,7 @@ type SignatureRepackageInfo = { RepackagedVals: (ValRef * ValRef) list RepackagedEntities: (TyconRef * TyconRef) list } - member remapInfo.ImplToSigMapping = { TypeEquivEnv.Empty with EquivTycons = TyconRefMap.OfList remapInfo.RepackagedEntities } + member remapInfo.ImplToSigMapping g = { TypeEquivEnv.EmptyWithNullChecks g with EquivTycons = TyconRefMap.OfList remapInfo.RepackagedEntities } static member Empty = { RepackagedVals = []; RepackagedEntities= [] } type SignatureHidingInfo = @@ -4959,7 +4960,7 @@ let rec accValRemapFromModuleOrNamespaceType g aenv (mty: ModuleOrNamespaceType) let ComputeRemappingFromInferredSignatureToExplicitSignature g mty msigty = let mrpi, _ as entityRemap = accEntityRemapFromModuleOrNamespaceType mty msigty (SignatureRepackageInfo.Empty, SignatureHidingInfo.Empty) - let aenv = mrpi.ImplToSigMapping + let aenv = mrpi.ImplToSigMapping g let valAndEntityRemap = accValRemapFromModuleOrNamespaceType g aenv mty msigty entityRemap valAndEntityRemap @@ -5022,7 +5023,7 @@ and accValRemapFromModuleOrNamespaceDefs g aenv msigty mdefs acc = List.foldBack let ComputeRemappingFromImplementationToSignature g mdef msigty = let mrpi, _ as entityRemap = accEntityRemapFromModuleOrNamespace msigty mdef (SignatureRepackageInfo.Empty, SignatureHidingInfo.Empty) - let aenv = mrpi.ImplToSigMapping + let aenv = mrpi.ImplToSigMapping g let valAndEntityRemap = accValRemapFromModuleOrNamespace g aenv msigty mdef entityRemap valAndEntityRemap @@ -11410,7 +11411,7 @@ type TraitWitnessInfoHashMap<'T> = ImmutableDictionary let EmptyTraitWitnessInfoHashMap g : TraitWitnessInfoHashMap<'T> = ImmutableDictionary.Create( { new IEqualityComparer<_> with - member _.Equals(a, b) = nullSafeEquality a b (fun a b -> traitKeysAEquiv g TypeEquivEnv.Empty a b) + member _.Equals(a, b) = nullSafeEquality a b (fun a b -> traitKeysAEquiv g TypeEquivEnv.EmptyIgnoreNulls a b) member _.GetHashCode(a) = hash a.MemberName }) diff --git a/src/Compiler/TypedTree/TypedTreeOps.fsi b/src/Compiler/TypedTree/TypedTreeOps.fsi index 8b2cf510ac9..fb6cb3462bf 100755 --- a/src/Compiler/TypedTree/TypedTreeOps.fsi +++ b/src/Compiler/TypedTree/TypedTreeOps.fsi @@ -879,15 +879,17 @@ val stripMeasuresFromTy: TcGlobals -> TType -> TType [] type TypeEquivEnv = { EquivTypars: TyparMap - EquivTycons: TyconRefRemap } + EquivTycons: TyconRefRemap + NullnessMustEqual: bool} - static member Empty: TypeEquivEnv + static member EmptyIgnoreNulls: TypeEquivEnv + static member EmptyWithNullChecks: TcGlobals -> TypeEquivEnv member BindEquivTypars: Typars -> Typars -> TypeEquivEnv - static member FromTyparInst: TyparInstantiation -> TypeEquivEnv + member FromTyparInst: TyparInstantiation -> TypeEquivEnv - static member FromEquivTypars: Typars -> Typars -> TypeEquivEnv + member FromEquivTypars: Typars -> Typars -> TypeEquivEnv val traitsAEquivAux: Erasure -> TcGlobals -> TypeEquivEnv -> TraitConstraintInfo -> TraitConstraintInfo -> bool @@ -905,8 +907,6 @@ val typarsAEquiv: TcGlobals -> TypeEquivEnv -> Typars -> Typars -> bool val typeAEquivAux: Erasure -> TcGlobals -> TypeEquivEnv -> TType -> TType -> bool -val nullnessSensitivetypeAEquivAux: Erasure -> TcGlobals -> TypeEquivEnv -> TType -> TType -> bool - val typeAEquiv: TcGlobals -> TypeEquivEnv -> TType -> TType -> bool val returnTypesAEquivAux: Erasure -> TcGlobals -> TypeEquivEnv -> TType option -> TType option -> bool diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs index a0027c2d0a9..34472061b92 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs @@ -10,4 +10,15 @@ let isNotNull (value: 'T) = let s: System.String | null = null #else let s: System.String = null -#endif \ No newline at end of file +#endif + +let test1 (x: string) = () +let test2 (x: string | null) = () + +let iRejectNulls (x:_|null) = + if (String.length x) > 5 then "big" else "small" + +type GenericContainer<'T>(x:'T) = + let innerVal = x + + member _.GetNull() : ('T|null) = null \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi index 25271ae6d7e..bc2b2ea895c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi @@ -1,3 +1,13 @@ module M -val isNotNull: value: 'T -> bool when 'T : null \ No newline at end of file +val isNotNull: value: 'T -> bool when 'T : null + +val test1: string | null -> unit +val test2: string -> unit + + +val iRejectNulls: string -> string + +type GenericContainer<'T> = + + member GetNull : unit -> ('T|null) \ No newline at end of file From 52bf00b4d88c74badfaeae78dedde505a071c6e7 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 30 Dec 2024 15:17:02 +0100 Subject: [PATCH 02/52] tests for nullness signature conformance --- src/Compiler/Checking/CheckDeclarations.fs | 2 +- src/Compiler/Checking/MethodOverrides.fs | 4 +- .../Nullness/NullableRegressionTests.fs | 40 +++++++++++++++++++ .../Language/Nullness/micro.fs | 11 ----- .../Language/Nullness/micro.fsi | 10 ----- .../Language/Nullness/signatures.fs | 15 +++++++ .../Language/Nullness/signatures.fsi | 13 ++++++ 7 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index da7e7af1086..e3d6b0d2a86 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -5689,7 +5689,7 @@ let CheckModuleSignature g (cenv: cenv) m denvAtEnd rootSigOpt implFileTypePrior |] // We want to show imperative type variables in any types in error messages at this late point - let denv = { denvAtEnd with showInferenceTyparAnnotations=true } + let denv = { denvAtEnd with showInferenceTyparAnnotations=true;showNullnessAnnotations=Some g.checkNullness } try // As typechecked the signature and implementation use different tycons etc. diff --git a/src/Compiler/Checking/MethodOverrides.fs b/src/Compiler/Checking/MethodOverrides.fs index 25dae041e0b..4621aed620e 100644 --- a/src/Compiler/Checking/MethodOverrides.fs +++ b/src/Compiler/Checking/MethodOverrides.fs @@ -269,7 +269,7 @@ module DispatchSlotChecking = // Compare the types. CompiledSigOfMeth, GetObjectExprOverrideInfo and GetTypeMemberOverrideInfo have already // applied all relevant substitutions except the renamings from fvtmps <-> methTypars - let aenv = (TypeEquivEnv.EmptyWithNullChecks g).FromEquivTypars fvmethTypars methTypars + let aenv = (TypeEquivEnv.EmptyIgnoreNulls).FromEquivTypars fvmethTypars methTypars List.forall2 (List.lengthsEqAndForall2 (typeAEquiv g aenv)) vargTys argTys && returnTypesAEquiv g aenv vrty retTy && @@ -305,7 +305,7 @@ module DispatchSlotChecking = ComposeTyparInsts ttpinst (ReverseTyparRenaming g memberToParentInst) // Compare under the composed substitutions - let aenv = (TypeEquivEnv.EmptyWithNullChecks g).FromTyparInst ttpinst + let aenv = (TypeEquivEnv.EmptyIgnoreNulls).FromTyparInst ttpinst typarsAEquiv g aenv fvmethTypars methTypars diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs index e6398675a01..18058469dd4 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs @@ -28,6 +28,46 @@ let ``Micro compilation`` langVersion checknulls = |> compile |> shouldSucceed +[] +[] +let ``Signature conformance`` langVersion checknulls = + + FsFromPath (__SOURCE_DIRECTORY__ ++ "signatures.fsi") + |> withAdditionalSourceFile (SourceFromPath (__SOURCE_DIRECTORY__ ++ "signatures.fs")) + |> withLangVersion langVersion + |> fun x -> + if checknulls then + x |> withCheckNulls |> withDefines ["CHECKNULLS"] + else x + |> compile + |> shouldFail + |> withDiagnostics + [(Error 34, Line 4, Col 5, Line 4, Col 10, "Module 'M' contains + val test2: x: string | null -> unit + but its signature specifies + val test2: string -> unit + The types differ"); + (Error 34, Line 3, Col 5, Line 3, Col 10, "Module 'M' contains + val test1: x: string -> unit + but its signature specifies + val test1: string | null -> unit + The types differ"); + (Error 34, Line 6, Col 5, Line 6, Col 17, "Module 'M' contains + val iRejectNulls: x: string | null -> string + but its signature specifies + val iRejectNulls: string -> string + The types differ"); + (Error 34, Line 14, Col 14, Line 14, Col 21, "Module 'M' contains + member GenericContainer.GetNull: unit -> 'T + but its signature specifies + member GenericContainer.GetNull: unit -> 'T | null + The types differ"); + (Error 34, Line 15, Col 14, Line 15, Col 24, "Module 'M' contains + member GenericContainer.GetNotNull: unit -> 'T | null + but its signature specifies + member GenericContainer.GetNotNull: unit -> 'T + The types differ")] + [] let ``Existing positive v8 disabled`` compilation = compilation diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs index 34472061b92..191d1d0f274 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fs @@ -11,14 +11,3 @@ let s: System.String | null = null #else let s: System.String = null #endif - -let test1 (x: string) = () -let test2 (x: string | null) = () - -let iRejectNulls (x:_|null) = - if (String.length x) > 5 then "big" else "small" - -type GenericContainer<'T>(x:'T) = - let innerVal = x - - member _.GetNull() : ('T|null) = null \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi index bc2b2ea895c..a397a9fb162 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/micro.fsi @@ -1,13 +1,3 @@ module M val isNotNull: value: 'T -> bool when 'T : null - -val test1: string | null -> unit -val test2: string -> unit - - -val iRejectNulls: string -> string - -type GenericContainer<'T> = - - member GetNull : unit -> ('T|null) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs new file mode 100644 index 00000000000..7ce39460ff1 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs @@ -0,0 +1,15 @@ +module M + +let test1 (x: string) = () +let test2 (x: string | null) = () + +let iRejectNulls (x:_|null) = + match x with + | null -> "null" + | s -> String.length s |> string + +type GenericContainer<'T when 'T:not null and 'T:not struct>(x:'T) = + let innerVal = x + + member _.GetNull() : ('T) = x + member _.GetNotNull() : ('T|null) = null \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi new file mode 100644 index 00000000000..1737ad4795b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi @@ -0,0 +1,13 @@ +module M + +val test1: string | null -> unit +val test2: string -> unit + + +val iRejectNulls: string -> string + +[] +type GenericContainer<'T when 'T:not null and 'T:not struct> = + + member GetNull : unit -> ('T|null) + member GetNotNull: unit -> 'T From 0deae3d5c31eda8084add618930bbe1203602518 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 30 Dec 2024 15:26:09 +0100 Subject: [PATCH 03/52] softer whitespace handling for "withDiagnostics" check --- tests/FSharp.Test.Utilities/Compiler.fs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index cd409116c3c..23f11a35738 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1474,11 +1474,15 @@ Actual: if not (List.exists (fun (el: ErrorInfo) -> (getErrorNumber el.Error) = exp) source) then failwith (sprintf "Mismatch in ErrorNumber, expected '%A' was not found during compilation.\nAll errors:\n%A" exp (List.map getErrorInfo source)) + let consequtiveWhiteSpaceTrimmer = new Regex(@"\s\s+") + let trimExtraSpaces s = consequtiveWhiteSpaceTrimmer.Replace(s," ") + let private assertErrors (what: string) libAdjust (source: ErrorInfo list) (expected: ErrorInfo list) : unit = // (Error 67, Line 14, Col 3, Line 14, Col 24, "This type test or downcast will always hold") let errorMessage error = let { Error = err; Range = range; Message = message } = error + let message = trimExtraSpaces message let errorType = match err with | ErrorType.Error n -> $"Error {n}" From 307eaef92af07ce17f52894dfa5eee978c48548a Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 30 Dec 2024 15:30:46 +0100 Subject: [PATCH 04/52] fantomasd --- src/Compiler/TypedTree/TypedTreeOps.fsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/TypedTree/TypedTreeOps.fsi b/src/Compiler/TypedTree/TypedTreeOps.fsi index fb6cb3462bf..fb92a7683ee 100755 --- a/src/Compiler/TypedTree/TypedTreeOps.fsi +++ b/src/Compiler/TypedTree/TypedTreeOps.fsi @@ -880,7 +880,7 @@ val stripMeasuresFromTy: TcGlobals -> TType -> TType type TypeEquivEnv = { EquivTypars: TyparMap EquivTycons: TyconRefRemap - NullnessMustEqual: bool} + NullnessMustEqual: bool } static member EmptyIgnoreNulls: TypeEquivEnv static member EmptyWithNullChecks: TcGlobals -> TypeEquivEnv From 5bd7b8ba01dc8c2892745bff8473f1a5f157d659 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 31 Dec 2024 11:55:15 +0100 Subject: [PATCH 05/52] Apply changes to codebase --- src/Compiler/Utilities/illib.fs | 8 ++++---- src/Compiler/Utilities/illib.fsi | 2 +- src/FSharp.Build/FSharpEmbedResourceText.fs | 6 +++--- .../Language/Nullness/signatures.fs | 5 ++++- .../Language/Nullness/signatures.fsi | 2 ++ 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Compiler/Utilities/illib.fs b/src/Compiler/Utilities/illib.fs index e09c650e39b..0b5f07cc412 100644 --- a/src/Compiler/Utilities/illib.fs +++ b/src/Compiler/Utilities/illib.fs @@ -211,7 +211,7 @@ module Order = member _.Compare(x, xx) = pxOrder.Compare(p x, p xx) } - let toFunction (pxOrder: IComparer<'U>) x y = pxOrder.Compare(x, y) + let toFunction (pxOrder: IComparer<'U>) (x:'U) (y:'U) = pxOrder.Compare(x, y) //------------------------------------------------------------------------- // Library: arrays, lists, options, resizearrays @@ -808,10 +808,10 @@ module String = elif (!!value).StartsWithOrdinal pattern then Some() else None - let (|Contains|_|) (pattern:string) value = + let (|Contains|_|) (pattern:string) (value:string|null) = match value with - | value when String.IsNullOrWhiteSpace value -> None | null -> None + | value when String.IsNullOrWhiteSpace value -> None | value -> if value.Contains pattern then Some() else None @@ -823,7 +823,7 @@ module String = let mutable line = reader.ReadLine() while not (isNull line) do - yield line + yield (line |> Unchecked.nonNull) line <- reader.ReadLine() if str.EndsWithOrdinal("\n") then diff --git a/src/Compiler/Utilities/illib.fsi b/src/Compiler/Utilities/illib.fsi index be4edea38f9..ef9f0c95507 100644 --- a/src/Compiler/Utilities/illib.fsi +++ b/src/Compiler/Utilities/illib.fsi @@ -286,7 +286,7 @@ module internal String = val (|StartsWith|_|): pattern: string -> value: string -> unit option - val (|Contains|_|): pattern: string -> value: string -> unit option + val (|Contains|_|): pattern: string -> value: string|null -> unit option val getLines: str: string -> string[] diff --git a/src/FSharp.Build/FSharpEmbedResourceText.fs b/src/FSharp.Build/FSharpEmbedResourceText.fs index 061715184de..68c9c046044 100644 --- a/src/FSharp.Build/FSharpEmbedResourceText.fs +++ b/src/FSharp.Build/FSharpEmbedResourceText.fs @@ -288,10 +288,10 @@ open Printf if isNull s then System.Diagnostics.Debug.Assert(false, sprintf ""**RESOURCE ERROR**: Resource token %s does not exist!"" name) #endif - #if BUILDING_WITH_LKG || NO_NULLCHECKING_LIB_SUPPORT - s - #else + #if NULLABLE Unchecked.nonNull s + #else + s #endif diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs index 7ce39460ff1..ebff7bf03f8 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fs @@ -12,4 +12,7 @@ type GenericContainer<'T when 'T:not null and 'T:not struct>(x:'T) = let innerVal = x member _.GetNull() : ('T) = x - member _.GetNotNull() : ('T|null) = null \ No newline at end of file + member _.GetNotNull() : ('T|null) = null + +let private GetString(key:string) : string = key + "" +let GetTextOpt(key:string) = GetString(key) |> Option.ofObj \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi index 1737ad4795b..42247ec7115 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/signatures.fsi @@ -11,3 +11,5 @@ type GenericContainer<'T when 'T:not null and 'T:not struct> = member GetNull : unit -> ('T|null) member GetNotNull: unit -> 'T + +val GetTextOpt: key:string -> string option From 09d0232431952147e43ec840e4dc76558c0a9744 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 31 Dec 2024 13:21:33 +0100 Subject: [PATCH 06/52] adjust code to meet signature conformance --- src/Compiler/Utilities/illib.fs | 4 ++-- src/Compiler/Utilities/illib.fsi | 4 ++++ src/FSharp.Build/FSharpEmbedResourceText.fs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Utilities/illib.fs b/src/Compiler/Utilities/illib.fs index 0b5f07cc412..7941eac77ec 100644 --- a/src/Compiler/Utilities/illib.fs +++ b/src/Compiler/Utilities/illib.fs @@ -206,9 +206,9 @@ module Order = member _.Compare(x, xx) = compare (p !!x) (p !!xx) } - let orderOn p (pxOrder: IComparer<'U>) = + let orderOn (p:'T->'U) (pxOrder: IComparer<'U>) = { new IComparer<'T> with - member _.Compare(x, xx) = pxOrder.Compare(p x, p xx) + member _.Compare(x, xx) = pxOrder.Compare(p !!x, p !!xx) } let toFunction (pxOrder: IComparer<'U>) (x:'U) (y:'U) = pxOrder.Compare(x, y) diff --git a/src/Compiler/Utilities/illib.fsi b/src/Compiler/Utilities/illib.fsi index ef9f0c95507..94f214db1dc 100644 --- a/src/Compiler/Utilities/illib.fsi +++ b/src/Compiler/Utilities/illib.fsi @@ -94,6 +94,10 @@ module internal Order = #endif val orderOn: p: ('T -> 'U) -> pxOrder: IComparer<'U> -> IComparer<'T> +#if !NO_CHECKNULLS + when 'T:not null + and 'T:not struct +#endif val toFunction: pxOrder: IComparer<'U> -> x: 'U -> y: 'U -> int diff --git a/src/FSharp.Build/FSharpEmbedResourceText.fs b/src/FSharp.Build/FSharpEmbedResourceText.fs index 68c9c046044..9af5eaf4d72 100644 --- a/src/FSharp.Build/FSharpEmbedResourceText.fs +++ b/src/FSharp.Build/FSharpEmbedResourceText.fs @@ -374,7 +374,7 @@ open Printf messageString <- postProcessString messageString createMessageString messageString fmt - static member GetTextOpt(key:string) = GetString(key) |> Option.ofObj + static member GetTextOpt(key:string) : string option = GetString(key) |> Option.ofObj /// If set to true, then all error messages will just return the filled 'holes' delimited by ',,,'s - this is for language-neutral testing (e.g. localization-invariant baselines). static member SwallowResourceText with get () = swallowResourceText From 05db8365e0f300688ca46272d8b8e66896f61d51 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 31 Dec 2024 15:38:04 +0100 Subject: [PATCH 07/52] see errors with ambivalence turned on --- src/Compiler/Checking/NicePrint.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 686015a83e3..ec867adab76 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -946,7 +946,7 @@ module PrintTypes = match nullness.Evaluate() with | NullnessInfo.WithNull -> part2 ^^ wordL (tagText "| null") | NullnessInfo.WithoutNull -> part2 - | NullnessInfo.AmbivalentToNull -> part2 //^^ wordL (tagText "__maybenull") + | NullnessInfo.AmbivalentToNull -> part2 ^^ wordL (tagText "__maybenull") else part2 From c758e17da390dd43739271cd817ba75e234ca739 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 3 Jan 2025 16:33:24 +0100 Subject: [PATCH 08/52] allow (WithoutNull === Ambivalent) in signature conformance --- src/Compiler/TypedTree/TypedTreeOps.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 443f933f621..2667ccdf317 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -966,8 +966,8 @@ type TypeEquivEnv = NullnessMustEqual : bool} let private nullnessEqual anev (n1:Nullness) (n2:Nullness) = - if anev.NullnessMustEqual then - (n1.Evaluate()) = (n2.Evaluate()) + if anev.NullnessMustEqual then + (n1.Evaluate() = NullnessInfo.WithNull) = (n2.Evaluate() = NullnessInfo.WithNull) else true From dd5506486b4d65a377c0fe2faaf9a9de449e9e09 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 3 Jan 2025 17:36:49 +0100 Subject: [PATCH 09/52] conform impl to signature --- src/Compiler/Checking/NicePrint.fs | 2 +- src/Compiler/Utilities/TaggedCollections.fs | 6 +++--- src/Compiler/Utilities/TaggedCollections.fsi | 4 ++-- src/Compiler/Utilities/lib.fsi | 2 +- src/Compiler/Utilities/range.fs | 12 ++++++++++-- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index ec867adab76..686015a83e3 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -946,7 +946,7 @@ module PrintTypes = match nullness.Evaluate() with | NullnessInfo.WithNull -> part2 ^^ wordL (tagText "| null") | NullnessInfo.WithoutNull -> part2 - | NullnessInfo.AmbivalentToNull -> part2 ^^ wordL (tagText "__maybenull") + | NullnessInfo.AmbivalentToNull -> part2 //^^ wordL (tagText "__maybenull") else part2 diff --git a/src/Compiler/Utilities/TaggedCollections.fs b/src/Compiler/Utilities/TaggedCollections.fs index 253b38a196d..897873cb6de 100644 --- a/src/Compiler/Utilities/TaggedCollections.fs +++ b/src/Compiler/Utilities/TaggedCollections.fs @@ -883,7 +883,7 @@ module MapTree = let k3, v3, l' = spliceOutSuccessor mn.Left in k3, v3, mk l' mn.Key mn.Value mn.Right | _ -> m.Key, m.Value, empty - let rec remove (comparer: IComparer<'Key>) k (m: MapTree<'Key, 'Value>) = + let rec remove (comparer: IComparer<'Key>) (k:'Key) (m: MapTree<'Key, 'Value>) = if isEmpty m then empty else @@ -905,7 +905,7 @@ module MapTree = rebalance mn.Left mn.Key mn.Value (remove comparer k mn.Right) | _ -> if c = 0 then empty else m - let rec mem (comparer: IComparer<'Key>) k (m: MapTree<'Key, 'Value>) = + let rec mem (comparer: IComparer<'Key>) (k:'Key) (m: MapTree<'Key, 'Value>) = if isEmpty m then false else @@ -1017,7 +1017,7 @@ module MapTree = let foldBack f m x = foldBackOpt (OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt f) m x - let foldSectionOpt (comparer: IComparer<'Key>) lo hi (f: OptimizedClosures.FSharpFunc<_, _, _, _>) (m: MapTree<'Key, 'Value>) x = + let foldSectionOpt (comparer: IComparer<'Key>) (lo:'Key) (hi:'Key) (f: OptimizedClosures.FSharpFunc<_, _, _, _>) (m: MapTree<'Key, 'Value>) x = let rec foldFromTo (f: OptimizedClosures.FSharpFunc<_, _, _, _>) (m: MapTree<'Key, 'Value>) x = if isEmpty m then x diff --git a/src/Compiler/Utilities/TaggedCollections.fsi b/src/Compiler/Utilities/TaggedCollections.fsi index 25552d0d92c..7b9e75f92a7 100644 --- a/src/Compiler/Utilities/TaggedCollections.fsi +++ b/src/Compiler/Utilities/TaggedCollections.fsi @@ -114,7 +114,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : obj -> bool + override Equals : obj|null -> bool type internal Set<'T> = Set<'T, IComparer<'T>> @@ -218,7 +218,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : obj -> bool + override Equals : obj|null -> bool type internal Map<'Key,'Value> = Map<'Key, 'Value, IComparer<'Key>> diff --git a/src/Compiler/Utilities/lib.fsi b/src/Compiler/Utilities/lib.fsi index cbdb893c5b8..08b834d17c6 100644 --- a/src/Compiler/Utilities/lib.fsi +++ b/src/Compiler/Utilities/lib.fsi @@ -19,7 +19,7 @@ val isEnvVarSet: s: string -> bool val GetEnvInteger: e: string -> dflt: int -> int -val dispose: x: System.IDisposable -> unit +val dispose: x: (System.IDisposable MaybeNull) -> unit module Bits = /// Get the least significant byte of a 32-bit integer diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index f9940461a32..fb4d0d47f32 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -448,10 +448,18 @@ module Range = let mkFileIndexRange fileIndex startPos endPos = range (fileIndex, startPos, endPos) let posOrder = - Order.orderOn (fun (p: pos) -> p.Line, p.Column) (Pair.order (Int32.order, Int32.order)) + let pairOrder = Pair.order (Int32.order, Int32.order) + let lineAndColumn = fun (p: pos) -> p.Line, p.Column + { new IComparer with + member _.Compare(x, xx) = pairOrder.Compare(lineAndColumn x , lineAndColumn xx) + } let rangeOrder = - Order.orderOn (fun (r: range) -> r.FileName, (r.Start, r.End)) (Pair.order (String.order, Pair.order (posOrder, posOrder))) + let tripleOrder = Pair.order (String.order, Pair.order (posOrder, posOrder)) + let fileLineColumn = fun (r: range) -> r.FileName, (r.Start, r.End) + { new IComparer with + member _.Compare(x, xx) = tripleOrder.Compare(fileLineColumn x , fileLineColumn xx) + } let outputRange (os: TextWriter) (m: range) = fprintf os "%s%a-%a" m.FileName outputPos m.Start outputPos m.End From 61236650495db99552ad258a826f70b6c8519747 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 11:50:17 +0100 Subject: [PATCH 10/52] fix --- src/Compiler/Utilities/range.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index fb4d0d47f32..90b1c047547 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -457,7 +457,7 @@ module Range = let rangeOrder = let tripleOrder = Pair.order (String.order, Pair.order (posOrder, posOrder)) let fileLineColumn = fun (r: range) -> r.FileName, (r.Start, r.End) - { new IComparer with + { new IComparer with member _.Compare(x, xx) = tripleOrder.Compare(fileLineColumn x , fileLineColumn xx) } From f87f1fb59bba2b972de14b450a4eff1604526488 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 12:14:48 +0100 Subject: [PATCH 11/52] a few more --- src/Compiler/Utilities/FileSystem.fs | 6 +++--- src/Compiler/Utilities/TaggedCollections.fs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Utilities/FileSystem.fs b/src/Compiler/Utilities/FileSystem.fs index a541234199e..81d6113cc18 100644 --- a/src/Compiler/Utilities/FileSystem.fs +++ b/src/Compiler/Utilities/FileSystem.fs @@ -431,16 +431,16 @@ module internal FileSystemUtils = let fileNameOfPath path = checkPathForIllegalChars path - Path.GetFileName(path) + !! Path.GetFileName(path) let fileNameWithoutExtensionWithValidate (validate: bool) path = if validate then checkPathForIllegalChars path - Path.GetFileNameWithoutExtension(path) + !! Path.GetFileNameWithoutExtension(path) let fileNameWithoutExtension path = - fileNameWithoutExtensionWithValidate true path + !! fileNameWithoutExtensionWithValidate true path let trimQuotes (path: string) = path.Trim([| ' '; '\"' |]) diff --git a/src/Compiler/Utilities/TaggedCollections.fs b/src/Compiler/Utilities/TaggedCollections.fs index 897873cb6de..7fd15dba738 100644 --- a/src/Compiler/Utilities/TaggedCollections.fs +++ b/src/Compiler/Utilities/TaggedCollections.fs @@ -658,7 +658,7 @@ type internal Set<'T, 'ComparerTag> when 'ComparerTag :> IComparer<'T>(comparer: member s.ToArray() = SetTree.toArray tree - override this.Equals(that) = + override this.Equals(that:objnull) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Set<'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) @@ -1232,7 +1232,7 @@ type internal Map<'Key, 'T, 'ComparerTag> when 'ComparerTag :> IComparer<'Key>(c override s.GetEnumerator() = (MapTree.toSeq tree :> System.Collections.IEnumerator) - override this.Equals(that) = + override this.Equals(that:objnull) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Map<'Key, 'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) From 79e0e52074f9a36aa5851dffb15913a36f53989f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 12:15:47 +0100 Subject: [PATCH 12/52] format --- src/Compiler/Utilities/TaggedCollections.fs | 17 ++++++++++++----- src/Compiler/Utilities/range.fs | 8 ++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Utilities/TaggedCollections.fs b/src/Compiler/Utilities/TaggedCollections.fs index 7fd15dba738..fd302039d17 100644 --- a/src/Compiler/Utilities/TaggedCollections.fs +++ b/src/Compiler/Utilities/TaggedCollections.fs @@ -658,7 +658,7 @@ type internal Set<'T, 'ComparerTag> when 'ComparerTag :> IComparer<'T>(comparer: member s.ToArray() = SetTree.toArray tree - override this.Equals(that:objnull) = + override this.Equals(that: objnull) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Set<'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) @@ -883,7 +883,7 @@ module MapTree = let k3, v3, l' = spliceOutSuccessor mn.Left in k3, v3, mk l' mn.Key mn.Value mn.Right | _ -> m.Key, m.Value, empty - let rec remove (comparer: IComparer<'Key>) (k:'Key) (m: MapTree<'Key, 'Value>) = + let rec remove (comparer: IComparer<'Key>) (k: 'Key) (m: MapTree<'Key, 'Value>) = if isEmpty m then empty else @@ -905,7 +905,7 @@ module MapTree = rebalance mn.Left mn.Key mn.Value (remove comparer k mn.Right) | _ -> if c = 0 then empty else m - let rec mem (comparer: IComparer<'Key>) (k:'Key) (m: MapTree<'Key, 'Value>) = + let rec mem (comparer: IComparer<'Key>) (k: 'Key) (m: MapTree<'Key, 'Value>) = if isEmpty m then false else @@ -1017,7 +1017,14 @@ module MapTree = let foldBack f m x = foldBackOpt (OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt f) m x - let foldSectionOpt (comparer: IComparer<'Key>) (lo:'Key) (hi:'Key) (f: OptimizedClosures.FSharpFunc<_, _, _, _>) (m: MapTree<'Key, 'Value>) x = + let foldSectionOpt + (comparer: IComparer<'Key>) + (lo: 'Key) + (hi: 'Key) + (f: OptimizedClosures.FSharpFunc<_, _, _, _>) + (m: MapTree<'Key, 'Value>) + x + = let rec foldFromTo (f: OptimizedClosures.FSharpFunc<_, _, _, _>) (m: MapTree<'Key, 'Value>) x = if isEmpty m then x @@ -1232,7 +1239,7 @@ type internal Map<'Key, 'T, 'ComparerTag> when 'ComparerTag :> IComparer<'Key>(c override s.GetEnumerator() = (MapTree.toSeq tree :> System.Collections.IEnumerator) - override this.Equals(that:objnull) = + override this.Equals(that: objnull) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Map<'Key, 'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) diff --git a/src/Compiler/Utilities/range.fs b/src/Compiler/Utilities/range.fs index 90b1c047547..5e13752df0b 100755 --- a/src/Compiler/Utilities/range.fs +++ b/src/Compiler/Utilities/range.fs @@ -450,15 +450,19 @@ module Range = let posOrder = let pairOrder = Pair.order (Int32.order, Int32.order) let lineAndColumn = fun (p: pos) -> p.Line, p.Column + { new IComparer with - member _.Compare(x, xx) = pairOrder.Compare(lineAndColumn x , lineAndColumn xx) + member _.Compare(x, xx) = + pairOrder.Compare(lineAndColumn x, lineAndColumn xx) } let rangeOrder = let tripleOrder = Pair.order (String.order, Pair.order (posOrder, posOrder)) let fileLineColumn = fun (r: range) -> r.FileName, (r.Start, r.End) + { new IComparer with - member _.Compare(x, xx) = tripleOrder.Compare(fileLineColumn x , fileLineColumn xx) + member _.Compare(x, xx) = + tripleOrder.Compare(fileLineColumn x, fileLineColumn xx) } let outputRange (os: TextWriter) (m: range) = From 582f9af196a9c87811e58bfdb77672e9be889d46 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 12:30:22 +0100 Subject: [PATCH 13/52] few more --- src/Compiler/Facilities/DiagnosticsLogger.fs | 3 +-- src/Compiler/Utilities/TaggedCollections.fsi | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fs b/src/Compiler/Facilities/DiagnosticsLogger.fs index 69d1f4fc306..cf5c20fe84c 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fs +++ b/src/Compiler/Facilities/DiagnosticsLogger.fs @@ -795,8 +795,7 @@ let NewlineifyErrorString (message: string) = /// fixes given string by replacing all control chars with spaces. /// NOTE: newlines are recognized and replaced with stringThatIsAProxyForANewlineInFlatErrors (ASCII 29, the 'group separator'), /// which is decoded by the IDE with 'NewlineifyErrorString' back into newlines, so that multi-line errors can be displayed in QuickInfo -let NormalizeErrorString (text: string MaybeNull) = - let text = nullArgCheck "text" text +let NormalizeErrorString (text: string) = let text = text.Trim() let buf = System.Text.StringBuilder() diff --git a/src/Compiler/Utilities/TaggedCollections.fsi b/src/Compiler/Utilities/TaggedCollections.fsi index 7b9e75f92a7..2c79621965e 100644 --- a/src/Compiler/Utilities/TaggedCollections.fsi +++ b/src/Compiler/Utilities/TaggedCollections.fsi @@ -114,7 +114,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : obj|null -> bool + override Equals : objnull -> bool type internal Set<'T> = Set<'T, IComparer<'T>> @@ -218,7 +218,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : obj|null -> bool + override Equals : objnull -> bool type internal Map<'Key,'Value> = Map<'Key, 'Value, IComparer<'Key>> From 21f9e2075e2cb89171e509b80582fb203f6654e0 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 14:42:16 +0100 Subject: [PATCH 14/52] Can I get all errors at once if I replace them with warnings? --- src/Compiler/Checking/SignatureConformance.fs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Compiler/Checking/SignatureConformance.fs b/src/Compiler/Checking/SignatureConformance.fs index 8e8dc84eb2b..6b13d7a8caa 100644 --- a/src/Compiler/Checking/SignatureConformance.fs +++ b/src/Compiler/Checking/SignatureConformance.fs @@ -352,14 +352,22 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = else let implTypars, implValTy = implVal.GeneralizedType let sigTypars, sigValTy = sigVal.GeneralizedType - if implTypars.Length <> sigTypars.Length then (err {denv with showTyparBinding=true} FSComp.SR.ValueNotContainedMutabilityParameterCountsDiffer) else - let aenv = aenv.BindEquivTypars implTypars sigTypars - checkTypars m aenv implTypars sigTypars && - if not (typeAEquiv g aenv implValTy sigValTy) then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer - elif not (checkValInfo aenv (err denv) implVal sigVal) then false - elif implVal.IsExtensionMember <> sigVal.IsExtensionMember then err denv FSComp.SR.ValueNotContainedMutabilityExtensionsDiffer - elif not (checkMemberDatasConform (err denv) (implVal.Attribs, implVal, implVal.MemberInfo) (sigVal.Attribs, sigVal, sigVal.MemberInfo)) then false - else checkAttribs aenv implVal.Attribs sigVal.Attribs (fun attribs -> implVal.SetAttribs attribs) + if implTypars.Length <> sigTypars.Length then (err {denv with showTyparBinding=true} FSComp.SR.ValueNotContainedMutabilityParameterCountsDiffer) + else + let aenv = aenv.BindEquivTypars implTypars sigTypars + checkTypars m aenv implTypars sigTypars && + let strictTyEquals = typeAEquiv g aenv implValTy sigValTy + let nullTolerantEquals = g.checkNullness && typeAEquiv g {aenv with NullnessMustEqual = false} implValTy sigValTy + + // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error + if not strictTyEquals && nullTolerantEquals then + warning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) + + if not strictTyEquals && not nullTolerantEquals then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer + elif not (checkValInfo aenv (err denv) implVal sigVal) then false + elif implVal.IsExtensionMember <> sigVal.IsExtensionMember then err denv FSComp.SR.ValueNotContainedMutabilityExtensionsDiffer + elif not (checkMemberDatasConform (err denv) (implVal.Attribs, implVal, implVal.MemberInfo) (sigVal.Attribs, sigVal, sigVal.MemberInfo)) then false + else checkAttribs aenv implVal.Attribs sigVal.Attribs (fun attribs -> implVal.SetAttribs attribs) and checkExnInfo err aenv (infoReader: InfoReader) (enclosingImplTycon: Tycon) (enclosingSigTycon: Tycon) implTypeRepr sigTypeRepr = From c1ba534eb50bb931dfbfa8be33225326df86eba8 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 16:00:48 +0100 Subject: [PATCH 15/52] some more --- src/Compiler/Facilities/prim-parsing.fs | 3 ++- src/Compiler/Utilities/NullnessShims.fs | 8 ++++++++ src/Compiler/Utilities/TaggedCollections.fs | 4 ++-- src/Compiler/Utilities/TaggedCollections.fsi | 5 +++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Facilities/prim-parsing.fs b/src/Compiler/Facilities/prim-parsing.fs index 7fb0d7fca41..5ce02cf59d6 100644 --- a/src/Compiler/Facilities/prim-parsing.fs +++ b/src/Compiler/Facilities/prim-parsing.fs @@ -5,6 +5,7 @@ namespace Internal.Utilities.Text.Parsing open Internal.Utilities.Text.Lexing +open Internal.Utilities.Library open System open System.Buffers @@ -28,7 +29,7 @@ type internal IParseState member _.ResultEndPosition = lhsPos[1] - member _.GetInput index = ruleValues[index - 1] + member _.GetInput index = !! ruleValues[index - 1] member _.ResultRange = (lhsPos[0], lhsPos[1]) diff --git a/src/Compiler/Utilities/NullnessShims.fs b/src/Compiler/Utilities/NullnessShims.fs index 785a6c6a3b8..ee801610255 100644 --- a/src/Compiler/Utilities/NullnessShims.fs +++ b/src/Compiler/Utilities/NullnessShims.fs @@ -63,6 +63,14 @@ module internal NullnessShims = #endif +#if NET5_0_OR_GREATER + // Argument type for overriding System.Object.Equals(arg) + // Desktop frameworks as well as netstandard need plain 'obj' and are not annotated, NET5 and higher can use (obj|null) + type objEqualsArg = objnull +#else + type objEqualsArg = obj +#endif + [] let inline (|NonEmptyString|_|) (x: string MaybeNull) = diff --git a/src/Compiler/Utilities/TaggedCollections.fs b/src/Compiler/Utilities/TaggedCollections.fs index fd302039d17..cb6add28b10 100644 --- a/src/Compiler/Utilities/TaggedCollections.fs +++ b/src/Compiler/Utilities/TaggedCollections.fs @@ -658,7 +658,7 @@ type internal Set<'T, 'ComparerTag> when 'ComparerTag :> IComparer<'T>(comparer: member s.ToArray() = SetTree.toArray tree - override this.Equals(that: objnull) = + override this.Equals(that) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Set<'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) @@ -1239,7 +1239,7 @@ type internal Map<'Key, 'T, 'ComparerTag> when 'ComparerTag :> IComparer<'Key>(c override s.GetEnumerator() = (MapTree.toSeq tree :> System.Collections.IEnumerator) - override this.Equals(that: objnull) = + override this.Equals(that) = match that with // Cast to the exact same type as this, otherwise not equal. | :? Map<'Key, 'T, 'ComparerTag> as that -> ((this :> System.IComparable).CompareTo(that) = 0) diff --git a/src/Compiler/Utilities/TaggedCollections.fsi b/src/Compiler/Utilities/TaggedCollections.fsi index 2c79621965e..e826f2719b3 100644 --- a/src/Compiler/Utilities/TaggedCollections.fsi +++ b/src/Compiler/Utilities/TaggedCollections.fsi @@ -5,6 +5,7 @@ namespace Internal.Utilities.Collections.Tagged open System open System.Collections.Generic + open Internal.Utilities.Library /// Immutable sets based on binary trees, default tag @@ -114,7 +115,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : objnull -> bool + override Equals : objEqualsArg -> bool type internal Set<'T> = Set<'T, IComparer<'T>> @@ -218,7 +219,7 @@ namespace Internal.Utilities.Collections.Tagged interface IComparable - override Equals : objnull -> bool + override Equals : objEqualsArg -> bool type internal Map<'Key,'Value> = Map<'Key, 'Value, IComparer<'Key>> From 3f2ae241baa31e5ebbef73f745bdca816e13ee94 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 6 Jan 2025 17:06:56 +0100 Subject: [PATCH 16/52] parsing --- src/Compiler/Facilities/prim-parsing.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Facilities/prim-parsing.fs b/src/Compiler/Facilities/prim-parsing.fs index 5ce02cf59d6..c3253bf3db0 100644 --- a/src/Compiler/Facilities/prim-parsing.fs +++ b/src/Compiler/Facilities/prim-parsing.fs @@ -573,7 +573,7 @@ module internal Implementation = else if Flags.debug then Console.WriteLine("ALARM!!! drop through case in parser") // OK, we're done - read off the overall generated value - valueStack.Peep().value + !! valueStack.Peep().value type internal Tables<'Token> with From 9c300b2b51d1f0f1df3ba0090a942d3a05bc275e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 11:52:27 +0100 Subject: [PATCH 17/52] one more --- src/Compiler/Facilities/CompilerLocation.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/Facilities/CompilerLocation.fs b/src/Compiler/Facilities/CompilerLocation.fs index 9cd20c1863e..2e9137fc75d 100644 --- a/src/Compiler/Facilities/CompilerLocation.fs +++ b/src/Compiler/Facilities/CompilerLocation.fs @@ -32,6 +32,7 @@ module internal FSharpEnvironment = let FSharpCoreLibRunningVersion = try match versionOf with + | null -> None | s when String.IsNullOrEmpty(s) -> None | s -> Some(s) with _ -> From 703e821b40e86eeae28b3ca5cb7b6be3ffecc253 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 12:50:09 +0100 Subject: [PATCH 18/52] try get more errors at once --- src/Compiler/Checking/SignatureConformance.fs | 2 +- src/Compiler/Driver/ParseAndCheckInputs.fs | 2 +- src/Compiler/Driver/fsc.fs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Checking/SignatureConformance.fs b/src/Compiler/Checking/SignatureConformance.fs index 6b13d7a8caa..a4f4583f10a 100644 --- a/src/Compiler/Checking/SignatureConformance.fs +++ b/src/Compiler/Checking/SignatureConformance.fs @@ -361,7 +361,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error if not strictTyEquals && nullTolerantEquals then - warning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) + informationalWarning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) if not strictTyEquals && not nullTolerantEquals then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer elif not (checkValInfo aenv (err denv) implVal sigVal) then false diff --git a/src/Compiler/Driver/ParseAndCheckInputs.fs b/src/Compiler/Driver/ParseAndCheckInputs.fs index 22ea3c7f033..e1da78545ff 100644 --- a/src/Compiler/Driver/ParseAndCheckInputs.fs +++ b/src/Compiler/Driver/ParseAndCheckInputs.fs @@ -1907,7 +1907,7 @@ let CheckMultipleInputsUsingGraphMode let (Finisher(finisher = finisher)) = cancellable { use _ = UseDiagnosticsLogger logger - let checkForErrors2 () = priorErrors || (logger.ErrorCount > 0) + let checkForErrors2 () = priorErrors || (logger.CheckForRealErrorsIgnoringWarnings) let tcSink = TcResultsSink.NoSink return! diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 696761f43da..aa1d3a25860 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -135,7 +135,7 @@ type ConsoleLoggerProvider() = /// Notify the exiter if any error has occurred let AbortOnError (diagnosticsLogger: DiagnosticsLogger, exiter: Exiter) = - if diagnosticsLogger.ErrorCount > 0 then + if diagnosticsLogger.CheckForRealErrorsIgnoringWarnings then exiter.Exit 1 let TypeCheck From a0ef43ef982f93e4603bef829ccef4ba40b0026d Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 12:55:28 +0100 Subject: [PATCH 19/52] That one should stay strict - this is checked per-phase (OK), not per file --- src/Compiler/Driver/fsc.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index aa1d3a25860..696761f43da 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -135,7 +135,7 @@ type ConsoleLoggerProvider() = /// Notify the exiter if any error has occurred let AbortOnError (diagnosticsLogger: DiagnosticsLogger, exiter: Exiter) = - if diagnosticsLogger.CheckForRealErrorsIgnoringWarnings then + if diagnosticsLogger.ErrorCount > 0 then exiter.Exit 1 let TypeCheck From d30504c70320a22250cbafeed582475984ca5b16 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 14:45:48 +0100 Subject: [PATCH 20/52] Can I process more diags now? --- src/Compiler/Checking/SignatureConformance.fs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Checking/SignatureConformance.fs b/src/Compiler/Checking/SignatureConformance.fs index a4f4583f10a..e1ec859df26 100644 --- a/src/Compiler/Checking/SignatureConformance.fs +++ b/src/Compiler/Checking/SignatureConformance.fs @@ -357,13 +357,13 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = let aenv = aenv.BindEquivTypars implTypars sigTypars checkTypars m aenv implTypars sigTypars && let strictTyEquals = typeAEquiv g aenv implValTy sigValTy - let nullTolerantEquals = g.checkNullness && typeAEquiv g {aenv with NullnessMustEqual = false} implValTy sigValTy + let onlyDiffersInNullness = not(strictTyEquals) && g.checkNullness && typeAEquiv g {aenv with NullnessMustEqual = false} implValTy sigValTy // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error - if not strictTyEquals && nullTolerantEquals then + if onlyDiffersInNullness then informationalWarning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) - if not strictTyEquals && not nullTolerantEquals then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer + if not strictTyEquals && not onlyDiffersInNullness then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer elif not (checkValInfo aenv (err denv) implVal sigVal) then false elif implVal.IsExtensionMember <> sigVal.IsExtensionMember then err denv FSComp.SR.ValueNotContainedMutabilityExtensionsDiffer elif not (checkMemberDatasConform (err denv) (implVal.Attribs, implVal, implVal.MemberInfo) (sigVal.Attribs, sigVal, sigVal.MemberInfo)) then false @@ -402,7 +402,21 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = and checkField aenv infoReader (enclosingImplTycon: Tycon) (enclosingSigTycon: Tycon) implField sigField = implField.SetOtherXmlDoc(sigField.XmlDoc) - let err f = errorR(FieldNotContained(denv, infoReader, enclosingImplTycon, enclosingSigTycon, implField, sigField, f)); false + let diag f = FieldNotContained(denv, infoReader, enclosingImplTycon, enclosingSigTycon, implField, sigField, f) + let err f = errorR(diag f); false + + let areTypesDifferent() = + let strictTyEquals = typeAEquiv g aenv implField.FormalType sigField.FormalType + let onlyDiffersInNullness = not(strictTyEquals) && g.checkNullness && typeAEquiv g {aenv with NullnessMustEqual = false} implField.FormalType sigField.FormalType + + // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error + if onlyDiffersInNullness then + informationalWarning(diag FSComp.SR.FieldNotContainedTypesDiffer) + false + else + not strictTyEquals + + sigField.rfield_other_range <- Some (implField.Range, true) implField.rfield_other_range <- Some (sigField.Range, false) if implField.rfield_id.idText <> sigField.rfield_id.idText then err FSComp.SR.FieldNotContainedNamesDiffer @@ -410,7 +424,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = elif implField.IsStatic <> sigField.IsStatic then err FSComp.SR.FieldNotContainedStaticsDiffer elif implField.IsMutable <> sigField.IsMutable then err FSComp.SR.FieldNotContainedMutablesDiffer elif implField.LiteralValue <> sigField.LiteralValue then err FSComp.SR.FieldNotContainedLiteralsDiffer - elif not (typeAEquiv g aenv implField.FormalType sigField.FormalType) then err FSComp.SR.FieldNotContainedTypesDiffer + elif areTypesDifferent() then err FSComp.SR.FieldNotContainedTypesDiffer else checkAttribs aenv implField.FieldAttribs sigField.FieldAttribs (fun attribs -> implField.rfield_fattribs <- attribs) && checkAttribs aenv implField.PropertyAttribs sigField.PropertyAttribs (fun attribs -> implField.rfield_pattribs <- attribs) From c67b453f3a9644b8b3286c5f05863e22826f519f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 15:20:17 +0100 Subject: [PATCH 21/52] Revisit this - this produced a "mismatch on accessibility" first --- src/Compiler/DependencyManager/AssemblyResolveHandler.fs | 2 +- src/Compiler/DependencyManager/AssemblyResolveHandler.fsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/DependencyManager/AssemblyResolveHandler.fs b/src/Compiler/DependencyManager/AssemblyResolveHandler.fs index 0c87130608e..2dd48bc5026 100644 --- a/src/Compiler/DependencyManager/AssemblyResolveHandler.fs +++ b/src/Compiler/DependencyManager/AssemblyResolveHandler.fs @@ -113,7 +113,7 @@ type AssemblyResolveHandler internal (assemblyProbingPaths: AssemblyResolutionPr else new AssemblyResolveHandlerDeskTop(assemblyProbingPaths) :> IDisposable) - new(assemblyProbingPaths: AssemblyResolutionProbe MaybeNull) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths) + new(assemblyProbingPaths: AssemblyResolutionProbe|null) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths) interface IDisposable with member _.Dispose() = diff --git a/src/Compiler/DependencyManager/AssemblyResolveHandler.fsi b/src/Compiler/DependencyManager/AssemblyResolveHandler.fsi index 0fbb6c33535..e1c0b2574e3 100644 --- a/src/Compiler/DependencyManager/AssemblyResolveHandler.fsi +++ b/src/Compiler/DependencyManager/AssemblyResolveHandler.fsi @@ -12,7 +12,7 @@ type AssemblyResolutionProbe = delegate of Unit -> seq type AssemblyResolveHandler = /// Construct a new DependencyProvider - new: assemblyProbingPaths: AssemblyResolutionProbe -> AssemblyResolveHandler + new: assemblyProbingPaths: AssemblyResolutionProbe|null -> AssemblyResolveHandler /// Construct a new DependencyProvider internal new: assemblyProbingPaths: AssemblyResolutionProbe option -> AssemblyResolveHandler From 8449fc4aa25241bdc1c71f5a49dd13c3789f76b9 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 7 Jan 2025 16:13:49 +0100 Subject: [PATCH 22/52] another --- src/Compiler/DependencyManager/NativeDllResolveHandler.fs | 2 +- src/Compiler/DependencyManager/NativeDllResolveHandler.fsi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/DependencyManager/NativeDllResolveHandler.fs b/src/Compiler/DependencyManager/NativeDllResolveHandler.fs index 6319f3df48b..bcfafb5763f 100644 --- a/src/Compiler/DependencyManager/NativeDllResolveHandler.fs +++ b/src/Compiler/DependencyManager/NativeDllResolveHandler.fs @@ -184,7 +184,7 @@ type NativeDllResolveHandler(nativeProbingRoots: NativeResolutionProbe option) = |> Option.filter (fun _ -> isRunningOnCoreClr) |> Option.map (fun _ -> new NativeDllResolveHandlerCoreClr(nativeProbingRoots)) - new(nativeProbingRoots: NativeResolutionProbe MaybeNull) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots) + new(nativeProbingRoots: NativeResolutionProbe|null) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots) member internal _.RefreshPathsInEnvironment(roots: string seq) = handler |> Option.iter (fun handler -> handler.RefreshPathsInEnvironment(roots)) diff --git a/src/Compiler/DependencyManager/NativeDllResolveHandler.fsi b/src/Compiler/DependencyManager/NativeDllResolveHandler.fsi index 8bb2babae2a..9d2961aa94e 100644 --- a/src/Compiler/DependencyManager/NativeDllResolveHandler.fsi +++ b/src/Compiler/DependencyManager/NativeDllResolveHandler.fsi @@ -12,7 +12,7 @@ type NativeResolutionProbe = delegate of Unit -> seq type NativeDllResolveHandler = /// Construct a new NativeDllResolveHandler - new: nativeProbingRoots: NativeResolutionProbe -> NativeDllResolveHandler + new: nativeProbingRoots: NativeResolutionProbe|null -> NativeDllResolveHandler /// Construct a new NativeDllResolveHandler internal new: nativeProbingRoots: NativeResolutionProbe option -> NativeDllResolveHandler From b1635c07d11b23db596f4a2a13ffd45a126b668d Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 8 Jan 2025 12:14:24 +0100 Subject: [PATCH 23/52] cannot see info warning in output --- src/Compiler/Checking/SignatureConformance.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/SignatureConformance.fs b/src/Compiler/Checking/SignatureConformance.fs index e1ec859df26..fa9e00bd4d7 100644 --- a/src/Compiler/Checking/SignatureConformance.fs +++ b/src/Compiler/Checking/SignatureConformance.fs @@ -361,7 +361,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error if onlyDiffersInNullness then - informationalWarning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) + warning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) if not strictTyEquals && not onlyDiffersInNullness then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer elif not (checkValInfo aenv (err denv) implVal sigVal) then false @@ -411,7 +411,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error if onlyDiffersInNullness then - informationalWarning(diag FSComp.SR.FieldNotContainedTypesDiffer) + warning(diag FSComp.SR.FieldNotContainedTypesDiffer) false else not strictTyEquals From d8fa0e6eaf50c4c57cd1fc1b160e7e2a3acfe903 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 8 Jan 2025 14:23:38 +0100 Subject: [PATCH 24/52] i really want to see all warnings --- src/Compiler/Driver/ParseAndCheckInputs.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Driver/ParseAndCheckInputs.fs b/src/Compiler/Driver/ParseAndCheckInputs.fs index e1da78545ff..645dfd569f1 100644 --- a/src/Compiler/Driver/ParseAndCheckInputs.fs +++ b/src/Compiler/Driver/ParseAndCheckInputs.fs @@ -1922,7 +1922,7 @@ let CheckMultipleInputsUsingGraphMode (fun (state: State) -> let tcState, priorErrors = state let (partialResult: PartialResult, tcState) = finisher tcState - let hasErrors = logger.ErrorCount > 0 + let hasErrors = logger.CheckForRealErrorsIgnoringWarnings let priorOrCurrentErrors = priorErrors || hasErrors let state: State = tcState, priorOrCurrentErrors partialResult, state) From dc3e815a7594b5be54138036b9d5f237ecd1fda7 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 8 Jan 2025 14:25:20 +0100 Subject: [PATCH 25/52] prettynaming conformant now --- src/Compiler/SyntaxTree/PrettyNaming.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/SyntaxTree/PrettyNaming.fs b/src/Compiler/SyntaxTree/PrettyNaming.fs index 8ea10266de8..b0ef32edaf0 100755 --- a/src/Compiler/SyntaxTree/PrettyNaming.fs +++ b/src/Compiler/SyntaxTree/PrettyNaming.fs @@ -670,8 +670,8 @@ let IsLogicalPrefixOperator logicalName = if String.IsNullOrEmpty logicalName then false else - let displayName = ConvertValLogicalNameToDisplayNameCore !!logicalName - displayName <> !!logicalName && IsValidPrefixOperatorDefinitionName displayName + let displayName = ConvertValLogicalNameToDisplayNameCore logicalName + displayName <> logicalName && IsValidPrefixOperatorDefinitionName displayName let IsLogicalTernaryOperator logicalName = let displayName = ConvertValLogicalNameToDisplayNameCore logicalName From 9cc522710c4c06b0eb51e6e430d116e65a7e0a4e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 8 Jan 2025 14:28:05 +0100 Subject: [PATCH 26/52] ilreflect conformant --- src/Compiler/AbstractIL/ilreflect.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/AbstractIL/ilreflect.fs b/src/Compiler/AbstractIL/ilreflect.fs index d88cc24d689..45c0652c59d 100644 --- a/src/Compiler/AbstractIL/ilreflect.fs +++ b/src/Compiler/AbstractIL/ilreflect.fs @@ -2548,7 +2548,7 @@ let EmitDynamicAssemblyFragment ignore (typB.InvokeMemberAndLog(methodName, BindingFlags.InvokeMethod ||| BindingFlags.Public ||| BindingFlags.Static, [||])) None with :? TargetInvocationException as exn -> - Some exn.InnerException + Option.ofObj exn.InnerException let emEnv, entryPts = envPopEntryPts emEnv let execs = List.map execEntryPtFun entryPts From f1454ea81c75d4f94f653a9c5f353f8dc959e165 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 8 Jan 2025 14:29:05 +0100 Subject: [PATCH 27/52] format --- src/Compiler/DependencyManager/AssemblyResolveHandler.fs | 2 +- src/Compiler/DependencyManager/NativeDllResolveHandler.fs | 2 +- src/Compiler/Driver/ParseAndCheckInputs.fs | 5 ++++- src/Compiler/Facilities/prim-parsing.fs | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Compiler/DependencyManager/AssemblyResolveHandler.fs b/src/Compiler/DependencyManager/AssemblyResolveHandler.fs index 2dd48bc5026..1f20caa392e 100644 --- a/src/Compiler/DependencyManager/AssemblyResolveHandler.fs +++ b/src/Compiler/DependencyManager/AssemblyResolveHandler.fs @@ -113,7 +113,7 @@ type AssemblyResolveHandler internal (assemblyProbingPaths: AssemblyResolutionPr else new AssemblyResolveHandlerDeskTop(assemblyProbingPaths) :> IDisposable) - new(assemblyProbingPaths: AssemblyResolutionProbe|null) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths) + new(assemblyProbingPaths: AssemblyResolutionProbe | null) = new AssemblyResolveHandler(Option.ofObj assemblyProbingPaths) interface IDisposable with member _.Dispose() = diff --git a/src/Compiler/DependencyManager/NativeDllResolveHandler.fs b/src/Compiler/DependencyManager/NativeDllResolveHandler.fs index bcfafb5763f..3c6bbe0a900 100644 --- a/src/Compiler/DependencyManager/NativeDllResolveHandler.fs +++ b/src/Compiler/DependencyManager/NativeDllResolveHandler.fs @@ -184,7 +184,7 @@ type NativeDllResolveHandler(nativeProbingRoots: NativeResolutionProbe option) = |> Option.filter (fun _ -> isRunningOnCoreClr) |> Option.map (fun _ -> new NativeDllResolveHandlerCoreClr(nativeProbingRoots)) - new(nativeProbingRoots: NativeResolutionProbe|null) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots) + new(nativeProbingRoots: NativeResolutionProbe | null) = new NativeDllResolveHandler(Option.ofObj nativeProbingRoots) member internal _.RefreshPathsInEnvironment(roots: string seq) = handler |> Option.iter (fun handler -> handler.RefreshPathsInEnvironment(roots)) diff --git a/src/Compiler/Driver/ParseAndCheckInputs.fs b/src/Compiler/Driver/ParseAndCheckInputs.fs index 645dfd569f1..2602c574973 100644 --- a/src/Compiler/Driver/ParseAndCheckInputs.fs +++ b/src/Compiler/Driver/ParseAndCheckInputs.fs @@ -1907,7 +1907,10 @@ let CheckMultipleInputsUsingGraphMode let (Finisher(finisher = finisher)) = cancellable { use _ = UseDiagnosticsLogger logger - let checkForErrors2 () = priorErrors || (logger.CheckForRealErrorsIgnoringWarnings) + + let checkForErrors2 () = + priorErrors || (logger.CheckForRealErrorsIgnoringWarnings) + let tcSink = TcResultsSink.NoSink return! diff --git a/src/Compiler/Facilities/prim-parsing.fs b/src/Compiler/Facilities/prim-parsing.fs index c3253bf3db0..632832b8d85 100644 --- a/src/Compiler/Facilities/prim-parsing.fs +++ b/src/Compiler/Facilities/prim-parsing.fs @@ -29,7 +29,7 @@ type internal IParseState member _.ResultEndPosition = lhsPos[1] - member _.GetInput index = !! ruleValues[index - 1] + member _.GetInput index = !!ruleValues[index - 1] member _.ResultRange = (lhsPos[0], lhsPos[1]) @@ -573,7 +573,7 @@ module internal Implementation = else if Flags.debug then Console.WriteLine("ALARM!!! drop through case in parser") // OK, we're done - read off the overall generated value - !! valueStack.Peep().value + !!valueStack.Peep().value type internal Tables<'Token> with From c1991ce15ba90a53cc711b807d41b1d94f20d056 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Fri, 10 Jan 2025 13:19:44 +0100 Subject: [PATCH 28/52] apply --- src/Compiler/FSharp.Compiler.Service.fsproj | 4 ++ src/Compiler/TypedTree/TypeProviders.fsi | 56 ++++++++++----------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/Compiler/FSharp.Compiler.Service.fsproj b/src/Compiler/FSharp.Compiler.Service.fsproj index b345d6ed1ca..b6f79465afc 100644 --- a/src/Compiler/FSharp.Compiler.Service.fsproj +++ b/src/Compiler/FSharp.Compiler.Service.fsproj @@ -12,6 +12,10 @@ $(NoWarn);NU5125 $(NoWarn);64;1182;1204 $(OtherFlags) --warnaserror-:1182 + $(OtherFlags) --warnaserror-:34 + $(OtherFlags) --warnaserror-:193 + + FSharp.Compiler.Service true $(DefineConstants);COMPILER diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index c99f2ab3775..3d4502bf2a1 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -104,33 +104,33 @@ type ProvidedType = member IsGenericType: bool - member Namespace: string + member Namespace: string MaybeNull - member FullName: string + member FullName: string MaybeNull member IsArray: bool - member GetInterfaces: unit -> ProvidedType[] + member GetInterfaces: unit -> ProvidedType[] MaybeNull - member Assembly: ProvidedAssembly + member Assembly: ProvidedAssembly MaybeNull member BaseType: ProvidedType MaybeNull - member GetNestedType: string -> ProvidedType + member GetNestedType: string -> ProvidedType MaybeNull - member GetNestedTypes: unit -> ProvidedType[] + member GetNestedTypes: unit -> ProvidedType[] MaybeNull member GetAllNestedTypes: unit -> ProvidedType[] - member GetMethods: unit -> ProvidedMethodInfo[] + member GetMethods: unit -> ProvidedMethodInfo[] MaybeNull member GetFields: unit -> ProvidedFieldInfo[] member GetField: string -> ProvidedFieldInfo - member GetProperties: unit -> ProvidedPropertyInfo[] + member GetProperties: unit -> ProvidedPropertyInfo[] MaybeNull - member GetProperty: string -> ProvidedPropertyInfo + member GetProperty: string -> ProvidedPropertyInfo MaybeNull member GetEvents: unit -> ProvidedEventInfo[] @@ -138,7 +138,7 @@ type ProvidedType = member GetConstructors: unit -> ProvidedConstructorInfo[] - member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo[] + member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo[] MaybeNull member GetGenericTypeDefinition: unit -> ProvidedType @@ -180,19 +180,19 @@ type ProvidedType = member GetEnumUnderlyingType: unit -> ProvidedType - member MakePointerType: unit -> ProvidedType + member MakePointerType: unit -> ProvidedType MaybeNull - member MakeByRefType: unit -> ProvidedType + member MakeByRefType: unit -> ProvidedType MaybeNull - member MakeArrayType: unit -> ProvidedType + member MakeArrayType: unit -> ProvidedType MaybeNull - member MakeArrayType: rank: int -> ProvidedType + member MakeArrayType: rank: int -> ProvidedType MaybeNull - member MakeGenericType: args: ProvidedType[] -> ProvidedType + member MakeGenericType: args: ProvidedType[] MaybeNull -> ProvidedType MaybeNull member AsProvidedVar: name: string -> ProvidedVar - static member Void: ProvidedType + static member Void: ProvidedType MaybeNull static member CreateNoContext: Type -> ProvidedType @@ -275,7 +275,7 @@ type ProvidedMethodBase = member IsConstructor: bool - member GetParameters: unit -> ProvidedParameterInfo[] + member GetParameters: unit -> ProvidedParameterInfo[] MaybeNull member GetGenericArguments: unit -> ProvidedType[] @@ -335,7 +335,7 @@ type ProvidedFieldInfo = member IsLiteral: bool - member GetRawConstantValue: unit -> obj + member GetRawConstantValue: unit -> obj MaybeNull member FieldType: ProvidedType @@ -359,11 +359,11 @@ type ProvidedPropertyInfo = inherit ProvidedMemberInfo - member GetGetMethod: unit -> ProvidedMethodInfo + member GetGetMethod: unit -> ProvidedMethodInfo MaybeNull - member GetSetMethod: unit -> ProvidedMethodInfo + member GetSetMethod: unit -> ProvidedMethodInfo MaybeNull - member GetIndexParameters: unit -> ProvidedParameterInfo[] + member GetIndexParameters: unit -> ProvidedParameterInfo[] MaybeNull member CanRead: bool @@ -385,7 +385,7 @@ type ProvidedEventInfo = member GetAddMethod: unit -> ProvidedMethodInfo - member GetRemoveMethod: unit -> ProvidedMethodInfo + member GetRemoveMethod: unit -> ProvidedMethodInfo MaybeNull member EventHandlerType: ProvidedType @@ -422,7 +422,7 @@ type ProvidedExprType = | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr[] - | ProvidedConstantExpr of obj * ProvidedType + | ProvidedConstantExpr of obj MaybeNull * ProvidedType | ProvidedDefaultExpr of ProvidedType @@ -448,10 +448,10 @@ type ProvidedExprType = #endif type ProvidedExpr = - member Type: ProvidedType + member Type: ProvidedType MaybeNull /// Convert the expression to a string for diagnostics - member UnderlyingExpressionString: string + member UnderlyingExpressionString: string MaybeNull member GetExprType: unit -> ProvidedExprType option @@ -461,7 +461,7 @@ type ProvidedExpr = #endif type ProvidedVar = - member Type: ProvidedType + member Type: ProvidedType MaybeNull member Name: string @@ -472,7 +472,7 @@ type ProvidedVar = override GetHashCode: unit -> int /// Get the provided expression for a particular use of a method. -val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr +val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr MaybeNull /// Validate that the given provided type meets some of the rules for F# provided types val ValidateProvidedTypeAfterStaticInstantiation: @@ -497,7 +497,7 @@ val TryLinkProvidedType: Tainted * string[] * typeLogicalName: string * range: range -> Tainted option /// Get the parts of a .NET namespace. Special rules: null means global, empty is not allowed. -val GetProvidedNamespaceAsPath: range * Tainted * string -> string list +val GetProvidedNamespaceAsPath: range * Tainted * string MaybeNull -> string list /// Decompose the enclosing name of a type (including any class nestings) into a list of parts. /// e.g. System.Object -> ["System"; "Object"] From 800c7e5a24767a522c2bb03b28448b144630418e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 11:10:55 +0100 Subject: [PATCH 29/52] type provider nullness --- src/Compiler/Checking/CheckDeclarations.fs | 4 +-- src/Compiler/Checking/MethodCalls.fs | 2 +- src/Compiler/Checking/NameResolution.fs | 2 +- src/Compiler/Checking/import.fs | 4 +-- src/Compiler/TypedTree/TypeProviders.fs | 39 ++++++++-------------- src/Compiler/TypedTree/TypeProviders.fsi | 30 ++++++++--------- src/FSharp.Core/prim-types.fsi | 12 +++---- 7 files changed, 41 insertions(+), 52 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index e2d087e5b5b..a868f06bf66 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3060,7 +3060,7 @@ module EstablishTypeDefinitionCores = if not isRootGenerated then let desig = theRootTypeWithRemapping.TypeProviderDesignation - let nm = theRootTypeWithRemapping.PUntaint((fun st -> st.FullName), m) + let nm = theRootTypeWithRemapping.PUntaint((fun st -> string st.FullName), m) error(Error(FSComp.SR.etErasedTypeUsedInGeneration(desig, nm), m)) cenv.createsGeneratedProvidedTypes <- true @@ -3101,7 +3101,7 @@ module EstablishTypeDefinitionCores = if not isGenerated then let desig = st.TypeProviderDesignation - let nm = st.PUntaint((fun st -> st.FullName), m) + let nm = st.PUntaint((fun st -> string st.FullName), m) error(Error(FSComp.SR.etErasedTypeUsedInGeneration(desig, nm), m)) // Embed the type into the module we're compiling diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index 4c561dd7fee..e19fbdd021a 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -2115,7 +2115,7 @@ module ProvidedMethodCalls = methInfoOpt, expr, exprTy with | :? TypeProviderError as tpe -> - let typeName = mi.PUntaint((fun mb -> (nonNull mb.DeclaringType).FullName), m) + let typeName = mi.PUntaint((fun mb -> (nonNull mb.DeclaringType).FullName |> string), m) let methName = mi.PUntaint((fun mb -> mb.Name), m) raise( tpe.WithContext(typeName, methName) ) // loses original stack trace #endif diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 5b0c9842f77..e3ad26d3ed7 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -991,7 +991,7 @@ let ResolveProvidedTypeNameInEntity (amap, m, typeName, modref: ModuleOrNamespac //if staticResInfo.NumStaticArgs > 0 then // error(Error(FSComp.SR.etNestedProvidedTypesDoNotTakeStaticArgumentsOrGenericParameters(), m)) [] - | nestedSty -> + | Tainted.NonNull nestedSty -> [AddEntityForProvidedType (amap, modref, resolutionEnvironment, nestedSty, m) ] | _ -> [] #endif diff --git a/src/Compiler/Checking/import.fs b/src/Compiler/Checking/import.fs index a1deee1c8a1..53bcb93916c 100644 --- a/src/Compiler/Checking/import.fs +++ b/src/Compiler/Checking/import.fs @@ -598,7 +598,7 @@ let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Ta | Some found -> found.Coerce(m) | None -> let methodName = minfo.PUntaint((fun minfo -> minfo.Name), m) - let typeName = declaringGenericTypeDefn.PUntaint((fun declaringGenericTypeDefn -> declaringGenericTypeDefn.FullName), m) + let typeName = declaringGenericTypeDefn.PUntaint((fun declaringGenericTypeDefn -> string declaringGenericTypeDefn.FullName), m) error(Error(FSComp.SR.etIncorrectProvidedMethod(DisplayNameOfTypeProvider(minfo.TypeProvider, m), methodName, metadataToken, typeName), m)) | _ -> match mbase.OfType() with @@ -630,7 +630,7 @@ let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Ta match found with | Some found -> found.Coerce(m) | None -> - let typeName = declaringGenericTypeDefn.PUntaint((fun x -> x.FullName), m) + let typeName = declaringGenericTypeDefn.PUntaint((fun x -> string x.FullName), m) error(Error(FSComp.SR.etIncorrectProvidedConstructor(DisplayNameOfTypeProvider(cinfo.TypeProvider, m), typeName), m)) | _ -> mbase diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index be22209a27a..d71026599f8 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -413,7 +413,7 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = /// Type.BaseType can be null when Type is interface or object member _.BaseType = x.BaseType |> ProvidedType.Create ctxt - member _.GetStaticParameters(provider: ITypeProvider) : ProvidedParameterInfo[] MaybeNull = provider.GetStaticParameters x |> ProvidedParameterInfo.CreateArray ctxt + member _.GetStaticParameters(provider: ITypeProvider) : ProvidedParameterInfo[] = provider.GetStaticParameters x |> ProvidedParameterInfo.CreateArray ctxt /// Type.GetElementType can be null if i.e. Type is not array\pointer\byref type member _.GetElementType() = x.GetElementType() |> ProvidedType.Create ctxt @@ -486,12 +486,10 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = | null -> nullArg name | t -> ProvidedType (t, ctxt) - static member CreateArray ctxt (xs: Type[] MaybeNull) : ProvidedType[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedType.CreateNonNull ctxt) + static member CreateArray ctxt (xs: Type[] ) : ProvidedType[] = + xs |> Array.map (ProvidedType.CreateNonNull ctxt) - static member CreateNoContext (x:Type) = ProvidedType.Create ProvidedTypeContext.Empty x + static member CreateNoContext (x:Type) = ProvidedType.CreateNonNull ProvidedTypeContext.Empty x static member Void = ProvidedType.CreateNoContext typeof @@ -628,15 +626,8 @@ type ProvidedParameterInfo (x: ParameterInfo, ctxt) = static member CreateNonNull ctxt x = ProvidedParameterInfo (x, ctxt) - static member CreateArray ctxt (xs: ParameterInfo[] MaybeNull) : ProvidedParameterInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedParameterInfo.CreateNonNull ctxt) - - static member CreateArrayNonNull ctxt xs : ProvidedParameterInfo[] = - match box xs with - | Null -> [| |] - | _ -> xs |> Array.map (ProvidedParameterInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: ParameterInfo[]) : ProvidedParameterInfo[] = + xs |> Array.map (ProvidedParameterInfo.CreateNonNull ctxt) interface IProvidedCustomAttributeProvider with member _.GetHasTypeProviderEditorHideMethodsAttribute provider = @@ -741,7 +732,7 @@ type ProvidedMethodBase (x: MethodBase, ctxt) = with err -> raise (StripException (StripException err)) !!paramsAsObj :?> ParameterInfo[] - staticParams |> ProvidedParameterInfo.CreateArrayNonNull ctxt + staticParams |> ProvidedParameterInfo.CreateArray ctxt member _.ApplyStaticArgumentsForMethod(provider: ITypeProvider, fullNameAfterArguments: string, staticArgs: objnull[]) = let bindingFlags = BindingFlags.Instance ||| BindingFlags.Public ||| BindingFlags.InvokeMethod @@ -844,10 +835,8 @@ type ProvidedMethodInfo (x: MethodInfo, ctxt) = | NonNull x -> ProvidedMethodInfo (x, ctxt) - static member CreateArray ctxt (xs: MethodInfo[] MaybeNull) : ProvidedMethodInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedMethodInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: MethodInfo[]) : ProvidedMethodInfo[] = + xs |> Array.map (ProvidedMethodInfo.CreateNonNull ctxt) member _.Handle = x @@ -997,13 +986,13 @@ type ProvidedExprType = #endif type ProvidedExpr (x: Expr, ctxt) = - member _.Type = x.Type |> ProvidedType.Create ctxt + member _.Type = x.Type |> ProvidedType.CreateNonNull ctxt member _.Handle = x member _.Context = ctxt - member _.UnderlyingExpressionString = x.ToString() + member _.UnderlyingExpressionString = string (x.ToString()) member _.GetExprType() = match x with @@ -1072,7 +1061,7 @@ type ProvidedExpr (x: Expr, ctxt) = [] #endif type ProvidedVar (x: Var, ctxt) = - member _.Type = x.Type |> ProvidedType.Create ctxt + member _.Type = x.Type |> ProvidedType.CreateNonNull ctxt member _.Name = x.Name member _.IsMutable = x.IsMutable member _.Handle = x @@ -1092,7 +1081,7 @@ type ProvidedVar (x: Var, ctxt) = /// Get the provided invoker expression for a particular use of a method. let GetInvokerExpression (provider: ITypeProvider, methodBase: ProvidedMethodBase, paramExprs: ProvidedVar[]) = - provider.GetInvokerExpression(methodBase.Handle, [| for p in paramExprs -> Quotations.Expr.Var p.Handle |]) |> ProvidedExpr.Create methodBase.Context + provider.GetInvokerExpression(methodBase.Handle, [| for p in paramExprs -> Quotations.Expr.Var p.Handle |]) |> ProvidedExpr.CreateNonNull methodBase.Context /// Compute the Name or FullName property of a provided type, reporting appropriate errors let CheckAndComputeProvidedNameProperty(m, st: Tainted, proj, propertyString) = @@ -1181,7 +1170,7 @@ let ValidateProvidedTypeAfterStaticInstantiation(m, st: Tainted, e if String.IsNullOrEmpty memberName then errorR(Error(FSComp.SR.etNullOrEmptyMemberName fullName, m)) else - let miDeclaringType = TryMemberMember(mi, fullName, memberName, "DeclaringType", m, ProvidedType.CreateNoContext(typeof), fun mi -> mi.DeclaringType) + let miDeclaringType = TryMemberMember(mi, fullName, memberName, "DeclaringType", m, (ProvidedType.CreateNoContext(typeof) |> withNull), fun mi -> mi.DeclaringType) match miDeclaringType with // Generated nested types may have null DeclaringType | Tainted.Null when mi.OfType().IsSome -> () diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index 3d4502bf2a1..752234de8c2 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -118,11 +118,11 @@ type ProvidedType = member GetNestedType: string -> ProvidedType MaybeNull - member GetNestedTypes: unit -> ProvidedType[] MaybeNull + member GetNestedTypes: unit -> ProvidedType[] member GetAllNestedTypes: unit -> ProvidedType[] - member GetMethods: unit -> ProvidedMethodInfo[] MaybeNull + member GetMethods: unit -> ProvidedMethodInfo[] member GetFields: unit -> ProvidedFieldInfo[] @@ -138,7 +138,7 @@ type ProvidedType = member GetConstructors: unit -> ProvidedConstructorInfo[] - member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo[] MaybeNull + member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo[] member GetGenericTypeDefinition: unit -> ProvidedType @@ -180,19 +180,19 @@ type ProvidedType = member GetEnumUnderlyingType: unit -> ProvidedType - member MakePointerType: unit -> ProvidedType MaybeNull + member MakePointerType: unit -> ProvidedType - member MakeByRefType: unit -> ProvidedType MaybeNull + member MakeByRefType: unit -> ProvidedType - member MakeArrayType: unit -> ProvidedType MaybeNull + member MakeArrayType: unit -> ProvidedType - member MakeArrayType: rank: int -> ProvidedType MaybeNull + member MakeArrayType: rank: int -> ProvidedType - member MakeGenericType: args: ProvidedType[] MaybeNull -> ProvidedType MaybeNull + member MakeGenericType: args: ProvidedType[] -> ProvidedType member AsProvidedVar: name: string -> ProvidedVar - static member Void: ProvidedType MaybeNull + static member Void: ProvidedType static member CreateNoContext: Type -> ProvidedType @@ -275,7 +275,7 @@ type ProvidedMethodBase = member IsConstructor: bool - member GetParameters: unit -> ProvidedParameterInfo[] MaybeNull + member GetParameters: unit -> ProvidedParameterInfo[] member GetGenericArguments: unit -> ProvidedType[] @@ -363,7 +363,7 @@ type ProvidedPropertyInfo = member GetSetMethod: unit -> ProvidedMethodInfo MaybeNull - member GetIndexParameters: unit -> ProvidedParameterInfo[] MaybeNull + member GetIndexParameters: unit -> ProvidedParameterInfo[] member CanRead: bool @@ -448,10 +448,10 @@ type ProvidedExprType = #endif type ProvidedExpr = - member Type: ProvidedType MaybeNull + member Type: ProvidedType /// Convert the expression to a string for diagnostics - member UnderlyingExpressionString: string MaybeNull + member UnderlyingExpressionString: string member GetExprType: unit -> ProvidedExprType option @@ -461,7 +461,7 @@ type ProvidedExpr = #endif type ProvidedVar = - member Type: ProvidedType MaybeNull + member Type: ProvidedType member Name: string @@ -472,7 +472,7 @@ type ProvidedVar = override GetHashCode: unit -> int /// Get the provided expression for a particular use of a method. -val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr MaybeNull +val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr /// Validate that the given provided type meets some of the rules for F# provided types val ValidateProvidedTypeAfterStaticInstantiation: diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index a992a0204e0..0e24a041b55 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -3587,16 +3587,16 @@ namespace Microsoft.FSharp.Core [] val inline nonNullV : value:Nullable<'T> -> 'T - /// Asserts that the value is non-null. - /// The value to check. - /// True when value is null, false otherwise. + /// Re-types a value into a nullable reference type (|null) + /// The non-nullable value. + /// The same value re-typed as a nullable reference type. [] val inline withNull : value:'T -> 'T | null when 'T : not null and 'T : not struct - /// Asserts that the value is non-null. + /// Wraps a value type into System.Nullable /// In a future revision of nullness support this may be unified with 'withNull'. - /// The value to check. - /// True when value is null, false otherwise. + /// The value to wrap. + /// System.Nullable wrapper of the input argument. [] val inline withNullV : value:'T -> Nullable<'T> #endif From d4621bdffadc69cfd993e2a4ac0212f5fc4ca539 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 12:17:54 +0100 Subject: [PATCH 30/52] more errors resolved --- src/Compiler/TypedTree/TypeProviders.fs | 18 ++++++------------ src/Compiler/TypedTree/TypeProviders.fsi | 10 +++++----- src/Compiler/TypedTree/TypedTree.fsi | 4 ++-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index d71026599f8..90e3e589cb8 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -779,10 +779,8 @@ type ProvidedFieldInfo (x: FieldInfo, ctxt) = | Null -> null | NonNull x -> ProvidedFieldInfo (x, ctxt) - static member CreateArray ctxt (xs: FieldInfo[] MaybeNull) : ProvidedFieldInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedFieldInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: FieldInfo[]) : ProvidedFieldInfo[] = + xs |> Array.map (ProvidedFieldInfo.CreateNonNull ctxt) member _.IsInitOnly = x.IsInitOnly @@ -913,10 +911,8 @@ type ProvidedEventInfo (x: EventInfo, ctxt) = | Null -> null | NonNull x -> ProvidedEventInfo (x, ctxt) - static member CreateArray ctxt (xs: EventInfo[] MaybeNull) : ProvidedEventInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedEventInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: EventInfo[]) : ProvidedEventInfo[] = + xs |> Array.map (ProvidedEventInfo.CreateNonNull ctxt) member _.Handle = x @@ -946,10 +942,8 @@ type ProvidedConstructorInfo (x: ConstructorInfo, ctxt) = | Null -> null | NonNull x -> ProvidedConstructorInfo (x, ctxt) - static member CreateArray ctxt (xs: ConstructorInfo[] MaybeNull) : ProvidedConstructorInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedConstructorInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: ConstructorInfo[]) : ProvidedConstructorInfo[] = + xs |> Array.map (ProvidedConstructorInfo.CreateNonNull ctxt) member _.Handle = x diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index 752234de8c2..2cfda3d1bff 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -126,7 +126,7 @@ type ProvidedType = member GetFields: unit -> ProvidedFieldInfo[] - member GetField: string -> ProvidedFieldInfo + member GetField: string -> ProvidedFieldInfo MaybeNull member GetProperties: unit -> ProvidedPropertyInfo[] MaybeNull @@ -134,7 +134,7 @@ type ProvidedType = member GetEvents: unit -> ProvidedEventInfo[] - member GetEvent: string -> ProvidedEventInfo + member GetEvent: string -> ProvidedEventInfo MaybeNull member GetConstructors: unit -> ProvidedConstructorInfo[] @@ -170,7 +170,7 @@ type ProvidedType = member GenericParameterPosition: int - member GetElementType: unit -> ProvidedType + member GetElementType: unit -> ProvidedType MaybeNull member GetGenericArguments: unit -> ProvidedType[] @@ -383,7 +383,7 @@ type ProvidedEventInfo = inherit ProvidedMemberInfo - member GetAddMethod: unit -> ProvidedMethodInfo + member GetAddMethod: unit -> ProvidedMethodInfo MaybeNull member GetRemoveMethod: unit -> ProvidedMethodInfo MaybeNull @@ -467,7 +467,7 @@ type ProvidedVar = member IsMutable: bool - override Equals: obj -> bool + override Equals: objnull -> bool override GetHashCode: unit -> int diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index 73eeb760b4c..c50225a2591 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -3149,7 +3149,7 @@ type TType = /// For now, used only as a discriminant in error message. /// See https://github.com/dotnet/fsharp/issues/2561 - member GetAssemblyName: unit -> string MaybeNull + member GetAssemblyName: unit -> string override ToString: unit -> string @@ -4048,7 +4048,7 @@ type NamedDebugPointKey = interface IComparable - override Equals: yobj: obj -> bool + override Equals: yobj: objnull -> bool override GetHashCode: unit -> int From a22ee9239692e8bfb14b2916bc998467b13f45a9 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 13:00:38 +0100 Subject: [PATCH 31/52] another wave --- src/Compiler/Checking/AttributeChecking.fsi | 4 +-- src/Compiler/Checking/MethodCalls.fs | 6 ++-- src/Compiler/Checking/NicePrint.fs | 2 +- src/Compiler/Checking/import.fs | 12 +++---- src/Compiler/Checking/import.fsi | 2 +- src/Compiler/CodeGen/IlxGen.fs | 2 +- src/Compiler/CodeGen/IlxGen.fsi | 4 +-- .../DependencyManager/DependencyProvider.fsi | 6 ++-- src/Compiler/Driver/CompilerConfig.fs | 8 ++--- src/Compiler/Driver/ParseAndCheckInputs.fs | 4 +-- src/Compiler/Interactive/fsi.fs | 36 +++++++++++-------- src/Compiler/Interactive/fsi.fsi | 2 +- src/Compiler/Service/FSharpCheckerResults.fs | 2 +- src/Compiler/Service/QuickParse.fs | 2 +- src/Compiler/Symbols/Exprs.fsi | 2 +- src/Compiler/Symbols/Symbols.fs | 2 +- src/Compiler/Symbols/Symbols.fsi | 10 +++--- 17 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/Compiler/Checking/AttributeChecking.fsi b/src/Compiler/Checking/AttributeChecking.fsi index b4a608ef1d1..d8d44095349 100644 --- a/src/Compiler/Checking/AttributeChecking.fsi +++ b/src/Compiler/Checking/AttributeChecking.fsi @@ -21,8 +21,8 @@ type AttribInfo = | FSAttribInfo of TcGlobals * Attrib | ILAttribInfo of TcGlobals * Import.ImportMap * ILScopeRef * ILAttribute * range - member ConstructorArguments: (TType * obj) list - member NamedArguments: (TType * string * bool * obj) list + member ConstructorArguments: (TType * objnull) list + member NamedArguments: (TType * string * bool * objnull) list member Range: range member TyconRef: TyconRef diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index e19fbdd021a..76e13156dec 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -1815,14 +1815,14 @@ module ProvidedMethodCalls = let rec loop (st: Tainted) = if st.PUntaint((fun st -> st.IsGenericParameter), m) then st elif st.PUntaint((fun st -> st.IsArray), m) then - let et = st.PApply((fun st -> st.GetElementType()), m) + let et = st.PApply((fun st -> !! st.GetElementType()), m) let rank = st.PUntaint((fun st -> st.GetArrayRank()), m) (loop et).PApply((fun st -> if rank = 1 then st.MakeArrayType() else st.MakeArrayType(rank)), m) elif st.PUntaint((fun st -> st.IsByRef), m) then - let et = st.PApply((fun st -> st.GetElementType()), m) + let et = st.PApply((fun st -> !! st.GetElementType()), m) (loop et).PApply((fun st -> st.MakeByRefType()), m) elif st.PUntaint((fun st -> st.IsPointer), m) then - let et = st.PApply((fun st -> st.GetElementType()), m) + let et = st.PApply((fun st -> !! st.GetElementType()), m) (loop et).PApply((fun st -> st.MakePointerType()), m) else let isGeneric = st.PUntaint((fun st -> st.IsGenericType), m) diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 686015a83e3..45c8c5bfb12 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -2930,7 +2930,7 @@ let minimalStringsOfTwoTypes denv ty1 ty2 = let denv = denv.SetOpenPaths [] let denv = { denv with includeStaticParametersInTypeNames=true } let makeName t = - let assemblyName = PrintTypes.layoutAssemblyName denv t |> function Null | NonNull "" -> "" | NonNull name -> sprintf " (%s)" name + let assemblyName = PrintTypes.layoutAssemblyName denv t |> function | "" -> "" | name -> sprintf " (%s)" name sprintf "%s%s" (stringOfTy denv t) assemblyName (makeName ty1, makeName ty2, stringOfTyparConstraints denv tpcs) diff --git a/src/Compiler/Checking/import.fs b/src/Compiler/Checking/import.fs index 53bcb93916c..6261f07aedc 100644 --- a/src/Compiler/Checking/import.fs +++ b/src/Compiler/Checking/import.fs @@ -449,13 +449,13 @@ let rec ImportProvidedTypeAsILType (env: ImportMap) (m: range) (st: Tainted st.IsGenericParameter), m) then mkILTyvarTy (uint16 (st.PUntaint((fun st -> st.GenericParameterPosition), m))) elif st.PUntaint((fun st -> st.IsArray), m) then - let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> st.GetElementType()), m)) + let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> !! st.GetElementType()), m)) ILType.Array(ILArrayShape.FromRank (st.PUntaint((fun st -> st.GetArrayRank()), m)), et) elif st.PUntaint((fun st -> st.IsByRef), m) then - let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> st.GetElementType()), m)) + let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> !! st.GetElementType()), m)) ILType.Byref et elif st.PUntaint((fun st -> st.IsPointer), m) then - let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> st.GetElementType()), m)) + let et = ImportProvidedTypeAsILType env m (st.PApply((fun st -> !! st.GetElementType()), m)) ILType.Ptr et else let gst, genericArgs = @@ -493,15 +493,15 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) ( let g = env.g if st.PUntaint((fun st -> st.IsArray), m) then - let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> st.GetElementType()), m)) + let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> !! st.GetElementType()), m)) // TODO Nullness - integration into type providers as a separate feature for later. let nullness = Nullness.knownAmbivalent mkArrayTy g (st.PUntaint((fun st -> st.GetArrayRank()), m)) nullness elemTy m elif st.PUntaint((fun st -> st.IsByRef), m) then - let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> st.GetElementType()), m)) + let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> !! st.GetElementType()), m)) mkByrefTy g elemTy elif st.PUntaint((fun st -> st.IsPointer), m) then - let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> st.GetElementType()), m)) + let elemTy = ImportProvidedType env m (* tinst *) (st.PApply((fun st -> !! st.GetElementType()), m)) if isUnitTy g elemTy || isVoidTy g elemTy && g.voidptr_tcr.CanDeref then mkVoidPtrTy g else diff --git a/src/Compiler/Checking/import.fsi b/src/Compiler/Checking/import.fsi index 001f9367989..b341dd06dff 100644 --- a/src/Compiler/Checking/import.fsi +++ b/src/Compiler/Checking/import.fsi @@ -54,7 +54,7 @@ type TTypeCacheKey = val ty2: TType val canCoerce: CanCoerce val tcGlobals: TcGlobals - override Equals: other: obj -> bool + override Equals: other: objnull -> bool override GetHashCode: unit -> int /// Represents a context used for converting AbstractIL .NET and provided types to F# internal compiler data structures. diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 60a6f012976..e0aa4504cca 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12318,7 +12318,7 @@ type IlxAssemblyGenerator(amap: ImportMap, g: TcGlobals, tcVal: ConstraintSolver member _.ClearGeneratedValue(ctxt, v) = ClearGeneratedValue ctxt ilxGenEnv v /// Invert the compilation of the given value and set the storage of the value, even if it is immutable - member _.ForceSetGeneratedValue(ctxt, v, value: obj) = + member _.ForceSetGeneratedValue(ctxt, v, value: objnull) = SetGeneratedValue ctxt ilxGenEnv true v value /// Invert the compilation of the given value and return its current dynamic value and its compiled System.Type diff --git a/src/Compiler/CodeGen/IlxGen.fsi b/src/Compiler/CodeGen/IlxGen.fsi index 4658dd0693b..bb78a30fe41 100644 --- a/src/Compiler/CodeGen/IlxGen.fsi +++ b/src/Compiler/CodeGen/IlxGen.fsi @@ -111,10 +111,10 @@ type public IlxAssemblyGenerator = member ClearGeneratedValue: ExecutionContext * Val -> unit /// Invert the compilation of the given value and set the storage of the value, even if it is immutable - member ForceSetGeneratedValue: ExecutionContext * Val * obj -> unit + member ForceSetGeneratedValue: ExecutionContext * Val * objnull -> unit /// Invert the compilation of the given value and return its current dynamic value and its compiled System.Type - member LookupGeneratedValue: ExecutionContext * Val -> (obj * Type) option + member LookupGeneratedValue: ExecutionContext * Val -> (objnull * Type) option val ReportStatistics: TextWriter -> unit diff --git a/src/Compiler/DependencyManager/DependencyProvider.fsi b/src/Compiler/DependencyManager/DependencyProvider.fsi index 4c97224fc90..da8dc4b670d 100644 --- a/src/Compiler/DependencyManager/DependencyProvider.fsi +++ b/src/Compiler/DependencyManager/DependencyProvider.fsi @@ -108,10 +108,10 @@ type DependencyProvider = DependencyProvider /// Returns a formatted help messages for registered dependencymanagers for the host to present - member GetRegisteredDependencyManagerHelpText: string seq * string * ResolvingErrorReport -> string[] + member GetRegisteredDependencyManagerHelpText: string seq * string MaybeNull * ResolvingErrorReport -> string[] /// Clear the DependencyManager results caches - member ClearResultsCache: string seq * string * ResolvingErrorReport -> unit + member ClearResultsCache: string seq * string MaybeNull * ResolvingErrorReport -> unit /// Returns a formatted error message for the host to present member CreatePackageManagerUnknownError: string seq * string * string * ResolvingErrorReport -> int * string @@ -123,7 +123,7 @@ type DependencyProvider = packageManagerTextLines: (string * string) seq * reportError: ResolvingErrorReport * executionTfm: string * - [] executionRid: string * + [] executionRid: string MaybeNull* [] implicitIncludeDir: string * [] mainScriptName: string * [] fileName: string * diff --git a/src/Compiler/Driver/CompilerConfig.fs b/src/Compiler/Driver/CompilerConfig.fs index 997f7a50aae..782bac68ce8 100644 --- a/src/Compiler/Driver/CompilerConfig.fs +++ b/src/Compiler/Driver/CompilerConfig.fs @@ -317,14 +317,15 @@ type AssemblyReference = member x.ProjectReference = (let (AssemblyReference(_, _, contents)) = x in contents) - member x.SimpleAssemblyNameIs name = + member x.SimpleAssemblyNameIs (name:string) = (String.Compare(FileSystemUtils.fileNameWithoutExtensionWithValidate false x.Text, name, StringComparison.OrdinalIgnoreCase) = 0) || not (x.Text.Contains "/") && not (x.Text.Contains "\\") && not (x.Text.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) && not (x.Text.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) && (try - let aname = System.Reflection.AssemblyName x.Text in aname.Name = name + let aname = System.Reflection.AssemblyName x.Text + aname.Name = name with _ -> false) @@ -699,9 +700,6 @@ type TcConfigBuilder = rangeForErrors ) = - let defaultFSharpBinariesDir = - nullArgCheck "defaultFSharpBinariesDir" defaultFSharpBinariesDir - // These are all default values, many can be overridden using the command line switch { primaryAssembly = PrimaryAssembly.Mscorlib diff --git a/src/Compiler/Driver/ParseAndCheckInputs.fs b/src/Compiler/Driver/ParseAndCheckInputs.fs index 2602c574973..975bfeef66f 100644 --- a/src/Compiler/Driver/ParseAndCheckInputs.fs +++ b/src/Compiler/Driver/ParseAndCheckInputs.fs @@ -828,7 +828,7 @@ let ParseInputFilesInParallel (tcConfig: TcConfig, lexResourceManager, sourceFil UseMultipleDiagnosticLoggers (sourceFiles, delayLogger, None) (fun sourceFilesWithDelayLoggers -> sourceFilesWithDelayLoggers |> ListParallel.map (fun ((fileName, isLastCompiland), delayLogger) -> - let directoryName = Path.GetDirectoryName fileName + let directoryName = !!(Path.GetDirectoryName fileName) let input = parseInputFileAux (tcConfig, lexResourceManager, fileName, (isLastCompiland, isExe), delayLogger, retryLocked) @@ -841,7 +841,7 @@ let ParseInputFilesSequential (tcConfig: TcConfig, lexResourceManager, sourceFil sourceFiles |> Array.map (fun (fileName, isLastCompiland) -> - let directoryName = Path.GetDirectoryName fileName + let directoryName = !!(Path.GetDirectoryName fileName) let input = ParseOneInputFile(tcConfig, lexResourceManager, fileName, (isLastCompiland, isExe), diagnosticsLogger, retryLocked) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index c31f210022f..be2eaa6e06c 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -77,7 +77,7 @@ open FSharp.Compiler.CheckExpressionsOps // For the FSI as a service methods... //---------------------------------------------------------------------------- -type FsiValue(reflectionValue: obj, reflectionType: Type, fsharpType: FSharpType) = +type FsiValue(reflectionValue: objnull, reflectionType: Type, fsharpType: FSharpType) = member _.ReflectionValue = reflectionValue member _.ReflectionType = reflectionType @@ -93,15 +93,15 @@ type FsiBoundValue(name: string, value: FsiValue) = [] module internal Utilities = type IAnyToLayoutCall = - abstract AnyToLayout: FormatOptions * obj * Type -> Layout - abstract FsiAnyToLayout: FormatOptions * obj * Type -> Layout + abstract AnyToLayout: FormatOptions * objnull * Type -> Layout + abstract FsiAnyToLayout: FormatOptions * objnull * Type -> Layout type private AnyToLayoutSpecialization<'T>() = interface IAnyToLayoutCall with - member _.AnyToLayout(options, o: obj, ty: Type) = + member _.AnyToLayout(options, o: objnull, ty: Type) = Display.any_to_layout options ((Unchecked.unbox o: 'T), ty) - member _.FsiAnyToLayout(options, o: obj, ty: Type) = + member _.FsiAnyToLayout(options, o: objnull, ty: Type) = Display.fsi_any_to_layout options ((Unchecked.unbox o: 'T), ty) let getAnyToLayoutCall (ty: Type) = @@ -112,13 +112,19 @@ module internal Utilities = |> NativeInterop.NativePtr.toNativeInt { new IAnyToLayoutCall with - member _.AnyToLayout(options, o: obj, ty: Type) = - let n = pointerToNativeInt o - Display.any_to_layout options (n, n.GetType()) - - member _.FsiAnyToLayout(options, o: obj, ty: Type) = - let n = pointerToNativeInt o - Display.any_to_layout options (n, n.GetType()) + member _.AnyToLayout(options, o: objnull, ty: Type) = + match o with + | null -> Display.any_to_layout options (o,ty) + | o -> + let n = pointerToNativeInt o + Display.any_to_layout options (n, n.GetType()) + + member _.FsiAnyToLayout(options, o: objnull, ty: Type) = + match o with + | null -> Display.any_to_layout options (o,ty) + | o -> + let n = pointerToNativeInt o + Display.any_to_layout options (n, n.GetType()) } else let specialized = typedefof>.MakeGenericType [| ty |] @@ -677,7 +683,7 @@ type internal FsiValuePrinter(fsi: FsiEvaluationSessionHostConfig, outWriter: Te } /// Generate a layout for an actual F# value, where we know the value has the given static type. - member _.PrintValue(printMode, opts: FormatOptions, x: obj, ty: Type) = + member _.PrintValue(printMode, opts: FormatOptions, x: objnull, ty: Type) = // We do a dynamic invoke of any_to_layout with the right System.Type parameter for the static type of the saved value. // In principle this helps any_to_layout do the right thing as it descends through terms. In practice it means // it at least does the right thing for top level 'null' list and option values (but not for nested ones). @@ -5191,7 +5197,7 @@ module Settings = and set v = args <- v member _.AddPrinter(printer: 'T -> string) = - addedPrinters <- Choice1Of2(typeof<'T>, (fun (x: obj) -> printer (unbox x))) :: addedPrinters + addedPrinters <- Choice1Of2(typeof<'T>, (fun (x: objnull) -> printer (unbox x))) :: addedPrinters member _.EventLoop with get () = evLoop @@ -5200,7 +5206,7 @@ module Settings = evLoop <- x member _.AddPrintTransformer(printer: 'T -> obj) = - addedPrinters <- Choice2Of2(typeof<'T>, (fun (x: obj) -> printer (unbox x))) :: addedPrinters + addedPrinters <- Choice2Of2(typeof<'T>, (fun (x: objnull) -> printer (unbox x))) :: addedPrinters let fsi = InteractiveSettings() diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index c34a583cdb7..60f75559a22 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -15,7 +15,7 @@ open Internal.Utilities.Library type FsiValue = /// The value, as an object - member ReflectionValue: obj + member ReflectionValue: objnull /// The type of the value, from the point of view of the .NET type system member ReflectionType: Type diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index 1c7878c6df8..a92b39264b2 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -188,7 +188,7 @@ and FSharpProjectOptions = && options1.ReferencedProjects = options2.ReferencedProjects && options1.LoadTime = options2.LoadTime - member po.ProjectDirectory = Path.GetDirectoryName(po.ProjectFileName) + member po.ProjectDirectory = !! Path.GetDirectoryName(po.ProjectFileName) override this.ToString() = "FSharpProjectOptions(" + this.ProjectFileName + ")" diff --git a/src/Compiler/Service/QuickParse.fs b/src/Compiler/Service/QuickParse.fs index ddb7d13f126..e7361ce1634 100644 --- a/src/Compiler/Service/QuickParse.fs +++ b/src/Compiler/Service/QuickParse.fs @@ -200,7 +200,7 @@ module QuickParse = /// a call to `DeclItemsForNamesAtPosition` for intellisense. This will /// allow us to use find the correct qualified items rather than resorting /// to the more expensive and less accurate environment lookup. - let GetCompleteIdentifierIsland (tolerateJustAfter: bool) (lineStr: string) (index: int) : (string * int * bool) option = + let GetCompleteIdentifierIsland (tolerateJustAfter: bool) (lineStr: string MaybeNull) (index: int) : (string * int * bool) option = if String.IsNullOrEmpty lineStr then None else diff --git a/src/Compiler/Symbols/Exprs.fsi b/src/Compiler/Symbols/Exprs.fsi index fddc3d0ea4e..7962855a0e9 100644 --- a/src/Compiler/Symbols/Exprs.fsi +++ b/src/Compiler/Symbols/Exprs.fsi @@ -206,7 +206,7 @@ module public FSharpExprPatterns = /// Matches constant expressions, including signed and unsigned integers, strings, characters, booleans, arrays /// of bytes and arrays of unit16. - val (|Const|_|): FSharpExpr -> (obj * FSharpType) option + val (|Const|_|): FSharpExpr -> (objnull * FSharpType) option /// Matches expressions which take the address of a location val (|AddressOf|_|): FSharpExpr -> FSharpExpr option diff --git a/src/Compiler/Symbols/Symbols.fs b/src/Compiler/Symbols/Symbols.fs index c2772cf8736..c0c2c9f56a7 100644 --- a/src/Compiler/Symbols/Symbols.fs +++ b/src/Compiler/Symbols/Symbols.fs @@ -2774,7 +2774,7 @@ type FSharpType(cenv, ty:TType) = type FSharpAttribute(cenv: SymbolEnv, attrib: AttribInfo) = - let rec resolveArgObj (arg: obj) = + let rec resolveArgObj (arg: objnull) = match arg with | :? TType as t -> box (FSharpType(cenv, t)) | :? (obj[]) as a -> a |> Array.map resolveArgObj |> box diff --git a/src/Compiler/Symbols/Symbols.fsi b/src/Compiler/Symbols/Symbols.fsi index 5c26d2d42ea..af6c8d7ac4b 100644 --- a/src/Compiler/Symbols/Symbols.fsi +++ b/src/Compiler/Symbols/Symbols.fsi @@ -572,7 +572,7 @@ type FSharpField = member Name: string /// Get the default initialization info, for static literals - member LiteralValue: obj option + member LiteralValue: objnull option /// Indicates if the declared visibility of the field, not taking signatures into account override Accessibility: FSharpAccessibility @@ -636,7 +636,7 @@ type FSharpStaticParameter = member Kind: FSharpType /// Get the default value for the static parameter - member DefaultValue: obj + member DefaultValue: objnull /// Indicates if the static parameter is optional member IsOptional: bool @@ -945,7 +945,7 @@ type FSharpMemberOrFunctionOrValue = member IsMemberThisValue: bool /// Indicates if this is a [] value, and if so what value? (may be null) - member LiteralValue: obj option + member LiteralValue: objnull option /// Get the accessibility information for the member, function or value override Accessibility: FSharpAccessibility @@ -1189,10 +1189,10 @@ type FSharpAttribute = member AttributeType: FSharpEntity /// The arguments to the constructor for the attribute - member ConstructorArguments: IList + member ConstructorArguments: IList /// The named arguments for the attribute - member NamedArguments: IList + member NamedArguments: IList /// Indicates if the attribute type is in an unresolved assembly member IsUnresolved: bool From 054502510938418ae77704ab24d7ff9fa466a75c Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 13:49:01 +0100 Subject: [PATCH 32/52] messages redone --- src/Compiler/Checking/SignatureConformance.fs | 18 ++++++++++-------- src/Compiler/Checking/SignatureConformance.fsi | 4 ++++ src/Compiler/Driver/CompilerDiagnostics.fs | 10 ++++++---- src/Compiler/FSComp.txt | 2 ++ src/Compiler/FSharp.Compiler.Service.fsproj | 4 ---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Compiler/Checking/SignatureConformance.fs b/src/Compiler/Checking/SignatureConformance.fs index fa9e00bd4d7..d922423017f 100644 --- a/src/Compiler/Checking/SignatureConformance.fs +++ b/src/Compiler/Checking/SignatureConformance.fs @@ -25,15 +25,17 @@ open FSharp.Compiler.TypeHierarchy open FSharp.Compiler.TypeProviders #endif +type TypeMismatchSource = NullnessOnlyMismatch | RegularMismatch + exception RequiredButNotSpecified of DisplayEnv * ModuleOrNamespaceRef * string * (StringBuilder -> unit) * range -exception ValueNotContained of DisplayEnv * InfoReader * ModuleOrNamespaceRef * Val * Val * (string * string * string -> string) +exception ValueNotContained of kind:TypeMismatchSource * DisplayEnv * InfoReader * ModuleOrNamespaceRef * Val * Val * (string * string * string -> string) exception UnionCaseNotContained of DisplayEnv * InfoReader * Tycon * UnionCase * UnionCase * (string * string -> string) exception FSharpExceptionNotContained of DisplayEnv * InfoReader * Tycon * Tycon * (string * string -> string) -exception FieldNotContained of DisplayEnv * InfoReader * Tycon * Tycon * RecdField * RecdField * (string * string -> string) +exception FieldNotContained of kind:TypeMismatchSource * DisplayEnv * InfoReader * Tycon * Tycon * RecdField * RecdField * (string * string -> string) exception InterfaceNotRevealed of DisplayEnv * TType * range @@ -338,8 +340,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = implVal.SetOtherRange (sigVal.Range, false) implVal.SetOtherXmlDoc(sigVal.XmlDoc) - let mk_err denv f = ValueNotContained(denv, infoReader, implModRef, implVal, sigVal, f) - let err denv f = errorR(mk_err denv f); false + let mk_err kind denv f = ValueNotContained(kind,denv, infoReader, implModRef, implVal, sigVal, f) + let err denv f = errorR(mk_err RegularMismatch denv f); false let m = implVal.Range if implVal.IsMutable <> sigVal.IsMutable then (err denv FSComp.SR.ValueNotContainedMutabilityAttributesDiffer) elif implVal.LogicalName <> sigVal.LogicalName then (err denv FSComp.SR.ValueNotContainedMutabilityNamesDiffer) @@ -361,7 +363,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error if onlyDiffersInNullness then - warning(mk_err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer) + warning(mk_err NullnessOnlyMismatch denv FSComp.SR.ValueNotContainedMutabilityTypesDifferNullness) if not strictTyEquals && not onlyDiffersInNullness then err denv FSComp.SR.ValueNotContainedMutabilityTypesDiffer elif not (checkValInfo aenv (err denv) implVal sigVal) then false @@ -402,8 +404,8 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = and checkField aenv infoReader (enclosingImplTycon: Tycon) (enclosingSigTycon: Tycon) implField sigField = implField.SetOtherXmlDoc(sigField.XmlDoc) - let diag f = FieldNotContained(denv, infoReader, enclosingImplTycon, enclosingSigTycon, implField, sigField, f) - let err f = errorR(diag f); false + let diag kind f = FieldNotContained(kind,denv, infoReader, enclosingImplTycon, enclosingSigTycon, implField, sigField, f) + let err f = errorR(diag RegularMismatch f); false let areTypesDifferent() = let strictTyEquals = typeAEquiv g aenv implField.FormalType sigField.FormalType @@ -411,7 +413,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) = // The types would be equal if we did not have nullness checks => lets just generate a warning, not an error if onlyDiffersInNullness then - warning(diag FSComp.SR.FieldNotContainedTypesDiffer) + warning(diag NullnessOnlyMismatch FSComp.SR.FieldNotContainedTypesDifferNullness) false else not strictTyEquals diff --git a/src/Compiler/Checking/SignatureConformance.fsi b/src/Compiler/Checking/SignatureConformance.fsi index 1b137968945..c35a4ec119b 100644 --- a/src/Compiler/Checking/SignatureConformance.fsi +++ b/src/Compiler/Checking/SignatureConformance.fsi @@ -13,9 +13,12 @@ open FSharp.Compiler.TypedTree open FSharp.Compiler.TypedTreeOps open FSharp.Compiler.InfoReader +type TypeMismatchSource = NullnessOnlyMismatch | RegularMismatch + exception RequiredButNotSpecified of DisplayEnv * ModuleOrNamespaceRef * string * (StringBuilder -> unit) * range exception ValueNotContained of + kind:TypeMismatchSource * DisplayEnv * InfoReader * ModuleOrNamespaceRef * @@ -28,6 +31,7 @@ exception UnionCaseNotContained of DisplayEnv * InfoReader * Tycon * UnionCase * exception FSharpExceptionNotContained of DisplayEnv * InfoReader * Tycon * Tycon * (string * string -> string) exception FieldNotContained of + kind:TypeMismatchSource * DisplayEnv * InfoReader * Tycon * diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index 83554e74834..39986ea4590 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -159,8 +159,8 @@ type Exception with | IndeterminateType m | TyconBadArgs(_, _, _, m) -> Some m - | FieldNotContained(_, _, _, _, arf, _, _) -> Some arf.Range - | ValueNotContained(_, _, _, aval, _, _) -> Some aval.Range + | FieldNotContained(_,_, _, _, _, arf, _, _) -> Some arf.Range + | ValueNotContained(_,_, _, _, aval, _, _) -> Some aval.Range | UnionCaseNotContained(_, _, _, aval, _, _) -> Some aval.Id.idRange | FSharpExceptionNotContained(_, _, aexnc, _, _) -> Some aexnc.Range @@ -256,6 +256,8 @@ type Exception with | LetRecUnsound _ -> 31 | FieldsFromDifferentTypes _ -> 32 | TyconBadArgs _ -> 33 + | FieldNotContained(kind=TypeMismatchSource.NullnessOnlyMismatch) -> 3261 + | ValueNotContained (kind=TypeMismatchSource.NullnessOnlyMismatch) -> 3261 | ValueNotContained _ -> 34 | Deprecated _ -> 35 | UnionCaseNotContained _ -> 36 @@ -1618,7 +1620,7 @@ type Exception with | UnionPatternsBindDifferentNames _ -> os.AppendString(UnionPatternsBindDifferentNamesE().Format) - | ValueNotContained(denv, infoReader, mref, implVal, sigVal, f) -> + | ValueNotContained(_,denv, infoReader, mref, implVal, sigVal, f) -> let text1, text2 = NicePrint.minimalStringsOfTwoValues denv infoReader (mkLocalValRef implVal) (mkLocalValRef sigVal) @@ -1642,7 +1644,7 @@ type Exception with ) ) - | FieldNotContained(denv, infoReader, enclosingTycon, _, v1, v2, f) -> + | FieldNotContained(_,denv, infoReader, enclosingTycon, _, v1, v2, f) -> let enclosingTcref = mkLocalEntityRef enclosingTycon os.AppendString( diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index f16be8658dd..5195b1ad191 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -112,6 +112,7 @@ ValueNotContainedMutabilityLiteralConstantValuesDiffer,"Module '%s' contains\n ValueNotContainedMutabilityOneIsTypeFunction,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nOne is a type function and the other is not. The signature requires explicit type parameters if they are present in the implementation." ValueNotContainedMutabilityParameterCountsDiffer,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nThe respective type parameter counts differ" ValueNotContainedMutabilityTypesDiffer,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nThe types differ" +ValueNotContainedMutabilityTypesDifferNullness,"Nullness warning: Module '%s' contains\n %s \nbut its signature specifies\n %s \nThe types differ in their nullness annotations" ValueNotContainedMutabilityExtensionsDiffer,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nOne is an extension member and the other is not" ValueNotContainedMutabilityArityNotInferred,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nAn arity was not inferred for this value" ValueNotContainedMutabilityGenericParametersDiffer,"Module '%s' contains\n %s \nbut its signature specifies\n %s \nThe number of generic parameters in the signature and implementation differ (the signature declares %s but the implementation declares %s" @@ -167,6 +168,7 @@ FieldNotContainedStaticsDiffer,"The module contains the field\n %s \nbut i FieldNotContainedMutablesDiffer,"The module contains the field\n %s \nbut its signature specifies\n %s \nThe 'mutable' modifiers differ" FieldNotContainedLiteralsDiffer,"The module contains the field\n %s \nbut its signature specifies\n %s \nThe 'literal' modifiers differ" FieldNotContainedTypesDiffer,"The module contains the field\n %s \nbut its signature specifies\n %s \nThe types differ" +FieldNotContainedTypesDifferNullness,"Nullness warning: The module contains the field\n %s \nbut its signature specifies\n %s \nThe types differ in their nullness annotations" 331,typrelCannotResolveImplicitGenericInstantiation,"The implicit instantiation of a generic construct at or near this point could not be resolved because it could resolve to multiple unrelated types, e.g. '%s' and '%s'. Consider using type annotations to resolve the ambiguity" 333,typrelCannotResolveAmbiguityInPrintf,"Could not resolve the ambiguity inherent in the use of a 'printf'-style format string" 334,typrelCannotResolveAmbiguityInEnum,"Could not resolve the ambiguity in the use of a generic construct with an 'enum' constraint at or near this position" diff --git a/src/Compiler/FSharp.Compiler.Service.fsproj b/src/Compiler/FSharp.Compiler.Service.fsproj index b6f79465afc..b345d6ed1ca 100644 --- a/src/Compiler/FSharp.Compiler.Service.fsproj +++ b/src/Compiler/FSharp.Compiler.Service.fsproj @@ -12,10 +12,6 @@ $(NoWarn);NU5125 $(NoWarn);64;1182;1204 $(OtherFlags) --warnaserror-:1182 - $(OtherFlags) --warnaserror-:34 - $(OtherFlags) --warnaserror-:193 - - FSharp.Compiler.Service true $(DefineConstants);COMPILER From 8394e5c790157591e5f7ce4fdc31347ea7c10de8 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 13:49:09 +0100 Subject: [PATCH 33/52] another batch --- src/Compiler/Checking/import.fs | 2 +- src/Compiler/CodeGen/IlxGen.fs | 4 ++-- src/Compiler/Interactive/fsi.fs | 2 +- src/Compiler/Interactive/fsi.fsi | 2 +- src/Compiler/TypedTree/TypeProviders.fs | 8 ++++---- src/Compiler/TypedTree/TypeProviders.fsi | 4 ++-- src/Compiler/TypedTree/TypedTree.fs | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Compiler/Checking/import.fs b/src/Compiler/Checking/import.fs index 51b8b5ac105..1ae2f8b4af9 100644 --- a/src/Compiler/Checking/import.fs +++ b/src/Compiler/Checking/import.fs @@ -75,7 +75,7 @@ type [] TTypeCacheKey = stampEquals this.tcGlobals this.ty1 other.ty1 && stampEquals this.tcGlobals this.ty2 other.ty2 - override this.Equals other = + override this.Equals(other:objnull) = match other with | :? TTypeCacheKey as p -> (this :> System.IEquatable).Equals p | _ -> false diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index e0aa4504cca..db6623c56f7 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12172,7 +12172,7 @@ let LookupGeneratedValue (cenv: cenv) (ctxt: ExecutionContext) eenv (v: Val) = // Lookup the compiled v value (as an object). match StorageForVal v.Range v eenv with | StaticPropertyWithField(fspec, _, hasLiteralAttr, ilContainerTy, _, _, ilGetterMethRef, _, _) -> - let obj = + let obj : objnull = if hasLiteralAttr then let staticTy = ctxt.LookupTypeRef fspec.DeclaringTypeRef // Checked: This FieldInfo (FieldBuilder) supports GetValue(). @@ -12190,7 +12190,7 @@ let LookupGeneratedValue (cenv: cenv) (ctxt: ExecutionContext) eenv (v: Val) = Some(obj, objTyp ()) | StaticProperty(ilGetterMethSpec, _) -> - let obj = + let obj : objnull = let staticTy = ctxt.LookupTypeRef ilGetterMethSpec.MethodRef.DeclaringTypeRef // We can't call .Invoke on the ILMethodRef's MethodInfo, // because it is the MethodBuilder and that does not support Invoke. diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index be2eaa6e06c..263e43dae13 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -5205,7 +5205,7 @@ module Settings = evLoop.ScheduleRestart() evLoop <- x - member _.AddPrintTransformer(printer: 'T -> obj) = + member _.AddPrintTransformer(printer: 'T -> objnull) = addedPrinters <- Choice2Of2(typeof<'T>, (fun (x: objnull) -> printer (unbox x))) :: addedPrinters let fsi = InteractiveSettings() diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index 60f75559a22..09e428cc31f 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -308,7 +308,7 @@ type FsiEvaluationSession = member ReportUnhandledException: exn: exn -> unit /// Event fires when a root-level value is bound to an identifier, e.g., via `let x = ...`. - member ValueBound: IEvent + member ValueBound: IEvent /// Gets the root-level values that are bound to an identifier member GetBoundValues: unit -> FsiBoundValue list diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 90e3e589cb8..3a5f112719f 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -376,7 +376,7 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = member _.Namespace : string MaybeNull = x.Namespace - member _.FullName = x.FullName + member _.FullName : string MaybeNull = x.FullName member _.IsArray = x.IsArray @@ -612,7 +612,7 @@ type ProvidedParameterInfo (x: ParameterInfo, ctxt) = member _.IsOptional = x.IsOptional - member _.RawDefaultValue = x.RawDefaultValue + member _.RawDefaultValue : objnull = x.RawDefaultValue member _.HasDefaultValue = x.Attributes.HasFlag(ParameterAttributes.HasDefault) @@ -790,7 +790,7 @@ type ProvidedFieldInfo (x: FieldInfo, ctxt) = member _.IsLiteral = x.IsLiteral - member _.GetRawConstantValue() = x.GetRawConstantValue() + member _.GetRawConstantValue() : objnull = x.GetRawConstantValue() /// FieldInfo.FieldType cannot be null @@ -1069,7 +1069,7 @@ type ProvidedVar (x: Var, ctxt) = | Null -> [| |] | _ -> xs |> Array.map (ProvidedVar.CreateNonNull ctxt) - override _.Equals y = match y with :? ProvidedVar as y -> x.Equals y.Handle | _ -> false + override _.Equals (y:objnull) = match y with :? ProvidedVar as y -> x.Equals y.Handle | _ -> false override _.GetHashCode() = x.GetHashCode() diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index 2cfda3d1bff..f7149070768 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -110,7 +110,7 @@ type ProvidedType = member IsArray: bool - member GetInterfaces: unit -> ProvidedType[] MaybeNull + member GetInterfaces: unit -> ProvidedType[] member Assembly: ProvidedAssembly MaybeNull @@ -335,7 +335,7 @@ type ProvidedFieldInfo = member IsLiteral: bool - member GetRawConstantValue: unit -> obj MaybeNull + member GetRawConstantValue: unit -> objnull member FieldType: ProvidedType diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 11ff117cc25..3d6c89957d9 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -5578,7 +5578,7 @@ type NamedDebugPointKey = override x.GetHashCode() = hash x.Name + hash x.Range - override x.Equals(yobj: obj) = + override x.Equals(yobj: objnull) = match yobj with | :? NamedDebugPointKey as y -> Range.equals x.Range y.Range && x.Name = y.Name | _ -> false From bbc326308ceae05abd9eee140523bb2686ca6e7e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 13:59:12 +0100 Subject: [PATCH 34/52] fix --- src/Compiler/Symbols/FSharpDiagnostic.fs | 4 ++-- src/Compiler/xlf/FSComp.txt.cs.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.de.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.es.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.it.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 10 ++++++++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 10 ++++++++++ 14 files changed, 132 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Symbols/FSharpDiagnostic.fs b/src/Compiler/Symbols/FSharpDiagnostic.fs index 31ec0536c3e..0ef03b0b82a 100644 --- a/src/Compiler/Symbols/FSharpDiagnostic.fs +++ b/src/Compiler/Symbols/FSharpDiagnostic.fs @@ -189,10 +189,10 @@ type FSharpDiagnostic(m: range, severity: FSharpDiagnosticSeverity, message: str | FunctionValueUnexpected(_, actualType, _) -> Some(ExpressionIsAFunctionExtendedData(symbolEnv, actualType)) - | FieldNotContained(_, _, implEntity, sigEntity, impl, sign, _) -> + | FieldNotContained(_,_, _, implEntity, sigEntity, impl, sign, _) -> Some(FieldNotContainedDiagnosticExtendedData(symbolEnv, implEntity, sigEntity, sign, impl)) - | ValueNotContained(_, _, _, implValue, sigValue, _) -> + | ValueNotContained(_,_, _, _, implValue, sigValue, _) -> Some(ValueNotContainedDiagnosticExtendedData(symbolEnv, sigValue, implValue)) | ArgumentsInSigAndImplMismatch(sigArg, implArg) -> diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 46543dceeda..86ba50284fe 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. Interpolovaný řetězec obsahuje netypové identifikátory. Doporučuje se přidat specifikátory zadaného formátu. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 15daa1c6f0c..5b6891e8121 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. Die interpolierte Zeichenfolge enthält nicht typisierte Bezeichner. Das Hinzufügen typisierter Formatbezeichner wird empfohlen. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index e7da4d1c8c0..5324c52c038 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. La cadena interpolada contiene identificadores sin tipo. Se recomienda agregar especificadores de formato con tipo. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index b45be9ead6f..e85dd53caf2 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. La chaîne interpolée contient des identifiants non typés. L'ajout de spécificateurs de format typés est recommandé. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index a2836525b32..2cfe691ac3f 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. La stringa interpolata contiene identificatori non tipizzati. È consigliabile aggiungere identificatori di formato tipizzato. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 1c4d2a34843..2c8b69d20fc 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. 挿入文字列には、型指定されていない識別子が含まれています。型指定された書式指定子を追加することをお勧めします。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 191f33e9eca..87bc740ed05 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. 보간된 문자열은 형식화되지 않은 식별자를 포함합니다. 형식화된 형식 지정자를 추가하는 것이 좋습니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 46ddfa1e868..11c4f22b90b 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. Ciąg interpolowany zawiera identyfikatory bez typu. Rekomendowane jest dodanie specyfikatorów formatu pisanego. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 2a86f172c2b..6d72f99c1f7 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. A cadeia de caracteres interpolada contém identificadores sem tipo. É recomendável adicionar especificadores de formato com tipo. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 3e52e4501b4..c998c6b19ff 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. Интерполированная строка содержит нетипизированные идентификаторы. Рекомендуется добавить типизированные описатели формата. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 81ed83f5717..20a5d1232ff 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. İlişkilendirilmiş dize, türü belirsiz tanımlayıcılar içeriyor. Türü belirtilen biçim belirticiler eklenmesi önerilir. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 35e9ec9073e..5d25caebb5e 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. 内插字符串包含非类型化标识符。建议添加类型化格式说明符。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index bed34cb225b..4be5e7e6d38 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -2,6 +2,16 @@ + + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + Nullness warning: The module contains the field\n {0} \nbut its signature specifies\n {1} \nThe types differ in their nullness annotations + + + + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + Nullness warning: Module '{0}' contains\n {1} \nbut its signature specifies\n {2} \nThe types differ in their nullness annotations + + Interpolated string contains untyped identifiers. Adding typed format specifiers is recommended. 差補字串包含不具類型的識別項。建議新增具類型的格式規範。 From 6b1c981aa7d99c28ec978c5384d23ca1f1591ec8 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 14:30:17 +0100 Subject: [PATCH 35/52] one more time --- src/Compiler/Interactive/fsi.fsi | 2 +- src/Compiler/TypedTree/TypeProviders.fs | 2 +- src/Compiler/TypedTree/TypeProviders.fsi | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Interactive/fsi.fsi b/src/Compiler/Interactive/fsi.fsi index 09e428cc31f..0e7415ca728 100644 --- a/src/Compiler/Interactive/fsi.fsi +++ b/src/Compiler/Interactive/fsi.fsi @@ -395,7 +395,7 @@ module Settings = member AddPrinter: ('T -> string) -> unit /// Register a print transformer that controls the output of the interactive session. - member AddPrintTransformer: ('T -> obj) -> unit + member AddPrintTransformer: ('T -> objnull) -> unit member internal AddedPrinters: Choice string), Type * (objnull -> objnull)> list diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 3a5f112719f..1a048b8d72e 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -1069,7 +1069,7 @@ type ProvidedVar (x: Var, ctxt) = | Null -> [| |] | _ -> xs |> Array.map (ProvidedVar.CreateNonNull ctxt) - override _.Equals (y:objnull) = match y with :? ProvidedVar as y -> x.Equals y.Handle | _ -> false + override _.Equals y = match y with :? ProvidedVar as y -> x.Equals y.Handle | _ -> false override _.GetHashCode() = x.GetHashCode() diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index f7149070768..bbbb4a3dd2f 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -467,8 +467,6 @@ type ProvidedVar = member IsMutable: bool - override Equals: objnull -> bool - override GetHashCode: unit -> int /// Get the provided expression for a particular use of a method. From 3a0a07f568e703d01c3bbab266a2a36ed00c441e Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 15:24:26 +0100 Subject: [PATCH 36/52] x --- src/Compiler/TypedTree/TypedTree.fsi | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index 452a3a6f8fb..28ef5776e5a 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -4050,8 +4050,6 @@ type NamedDebugPointKey = interface IComparable - override Equals: yobj: objnull -> bool - override GetHashCode: unit -> int /// Represents a complete typechecked implementation file, including its inferred or explicit signature. From 148bde85e5c9a4593be4f45d81438851c75cf7c0 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 15:29:56 +0100 Subject: [PATCH 37/52] fantomas and fantomasignore because of nullness --- .fantomasignore | 3 +++ src/Compiler/Checking/SignatureConformance.fsi | 8 +++++--- src/Compiler/CodeGen/IlxGen.fs | 4 ++-- src/Compiler/Driver/CompilerConfig.fs | 2 +- src/Compiler/Driver/CompilerDiagnostics.fs | 12 ++++++------ src/Compiler/Interactive/fsi.fs | 4 ++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.fantomasignore b/.fantomasignore index b901c74bd99..1225a6d2d32 100644 --- a/.fantomasignore +++ b/.fantomasignore @@ -121,6 +121,9 @@ src/Compiler/SyntaxTree/LexerStore.fs src/Compiler/Driver/GraphChecking/Graph.fsi src/Compiler/Driver/GraphChecking/Graph.fs +src/Compiler/DependencyManager/NativeDllResolveHandler.fsi +src/Compiler/DependencyManager/AssemblyResolveHandler.fsi + # Fantomas limitations on implementation files (to investigate) src/Compiler/AbstractIL/ilwrite.fs diff --git a/src/Compiler/Checking/SignatureConformance.fsi b/src/Compiler/Checking/SignatureConformance.fsi index c35a4ec119b..136cedce94f 100644 --- a/src/Compiler/Checking/SignatureConformance.fsi +++ b/src/Compiler/Checking/SignatureConformance.fsi @@ -13,12 +13,14 @@ open FSharp.Compiler.TypedTree open FSharp.Compiler.TypedTreeOps open FSharp.Compiler.InfoReader -type TypeMismatchSource = NullnessOnlyMismatch | RegularMismatch +type TypeMismatchSource = + | NullnessOnlyMismatch + | RegularMismatch exception RequiredButNotSpecified of DisplayEnv * ModuleOrNamespaceRef * string * (StringBuilder -> unit) * range exception ValueNotContained of - kind:TypeMismatchSource * + kind: TypeMismatchSource * DisplayEnv * InfoReader * ModuleOrNamespaceRef * @@ -31,7 +33,7 @@ exception UnionCaseNotContained of DisplayEnv * InfoReader * Tycon * UnionCase * exception FSharpExceptionNotContained of DisplayEnv * InfoReader * Tycon * Tycon * (string * string -> string) exception FieldNotContained of - kind:TypeMismatchSource * + kind: TypeMismatchSource * DisplayEnv * InfoReader * Tycon * diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index db6623c56f7..02533dc985f 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -12172,7 +12172,7 @@ let LookupGeneratedValue (cenv: cenv) (ctxt: ExecutionContext) eenv (v: Val) = // Lookup the compiled v value (as an object). match StorageForVal v.Range v eenv with | StaticPropertyWithField(fspec, _, hasLiteralAttr, ilContainerTy, _, _, ilGetterMethRef, _, _) -> - let obj : objnull = + let obj: objnull = if hasLiteralAttr then let staticTy = ctxt.LookupTypeRef fspec.DeclaringTypeRef // Checked: This FieldInfo (FieldBuilder) supports GetValue(). @@ -12190,7 +12190,7 @@ let LookupGeneratedValue (cenv: cenv) (ctxt: ExecutionContext) eenv (v: Val) = Some(obj, objTyp ()) | StaticProperty(ilGetterMethSpec, _) -> - let obj : objnull = + let obj: objnull = let staticTy = ctxt.LookupTypeRef ilGetterMethSpec.MethodRef.DeclaringTypeRef // We can't call .Invoke on the ILMethodRef's MethodInfo, // because it is the MethodBuilder and that does not support Invoke. diff --git a/src/Compiler/Driver/CompilerConfig.fs b/src/Compiler/Driver/CompilerConfig.fs index 782bac68ce8..cf875be4959 100644 --- a/src/Compiler/Driver/CompilerConfig.fs +++ b/src/Compiler/Driver/CompilerConfig.fs @@ -317,7 +317,7 @@ type AssemblyReference = member x.ProjectReference = (let (AssemblyReference(_, _, contents)) = x in contents) - member x.SimpleAssemblyNameIs (name:string) = + member x.SimpleAssemblyNameIs(name: string) = (String.Compare(FileSystemUtils.fileNameWithoutExtensionWithValidate false x.Text, name, StringComparison.OrdinalIgnoreCase) = 0) || not (x.Text.Contains "/") && not (x.Text.Contains "\\") diff --git a/src/Compiler/Driver/CompilerDiagnostics.fs b/src/Compiler/Driver/CompilerDiagnostics.fs index 39986ea4590..4b284a357d5 100644 --- a/src/Compiler/Driver/CompilerDiagnostics.fs +++ b/src/Compiler/Driver/CompilerDiagnostics.fs @@ -159,8 +159,8 @@ type Exception with | IndeterminateType m | TyconBadArgs(_, _, _, m) -> Some m - | FieldNotContained(_,_, _, _, _, arf, _, _) -> Some arf.Range - | ValueNotContained(_,_, _, _, aval, _, _) -> Some aval.Range + | FieldNotContained(_, _, _, _, _, arf, _, _) -> Some arf.Range + | ValueNotContained(_, _, _, _, aval, _, _) -> Some aval.Range | UnionCaseNotContained(_, _, _, aval, _, _) -> Some aval.Id.idRange | FSharpExceptionNotContained(_, _, aexnc, _, _) -> Some aexnc.Range @@ -256,8 +256,8 @@ type Exception with | LetRecUnsound _ -> 31 | FieldsFromDifferentTypes _ -> 32 | TyconBadArgs _ -> 33 - | FieldNotContained(kind=TypeMismatchSource.NullnessOnlyMismatch) -> 3261 - | ValueNotContained (kind=TypeMismatchSource.NullnessOnlyMismatch) -> 3261 + | FieldNotContained(kind = TypeMismatchSource.NullnessOnlyMismatch) -> 3261 + | ValueNotContained(kind = TypeMismatchSource.NullnessOnlyMismatch) -> 3261 | ValueNotContained _ -> 34 | Deprecated _ -> 35 | UnionCaseNotContained _ -> 36 @@ -1620,7 +1620,7 @@ type Exception with | UnionPatternsBindDifferentNames _ -> os.AppendString(UnionPatternsBindDifferentNamesE().Format) - | ValueNotContained(_,denv, infoReader, mref, implVal, sigVal, f) -> + | ValueNotContained(_, denv, infoReader, mref, implVal, sigVal, f) -> let text1, text2 = NicePrint.minimalStringsOfTwoValues denv infoReader (mkLocalValRef implVal) (mkLocalValRef sigVal) @@ -1644,7 +1644,7 @@ type Exception with ) ) - | FieldNotContained(_,denv, infoReader, enclosingTycon, _, v1, v2, f) -> + | FieldNotContained(_, denv, infoReader, enclosingTycon, _, v1, v2, f) -> let enclosingTcref = mkLocalEntityRef enclosingTycon os.AppendString( diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 263e43dae13..4b98ee1a8cb 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -114,14 +114,14 @@ module internal Utilities = { new IAnyToLayoutCall with member _.AnyToLayout(options, o: objnull, ty: Type) = match o with - | null -> Display.any_to_layout options (o,ty) + | null -> Display.any_to_layout options (o, ty) | o -> let n = pointerToNativeInt o Display.any_to_layout options (n, n.GetType()) member _.FsiAnyToLayout(options, o: objnull, ty: Type) = match o with - | null -> Display.any_to_layout options (o,ty) + | null -> Display.any_to_layout options (o, ty) | o -> let n = pointerToNativeInt o Display.any_to_layout options (n, n.GetType()) From 105f27aacd6dcf2db25200e06ae9ff2d48dfaa83 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 16:06:46 +0100 Subject: [PATCH 38/52] show more warnings! --- src/Compiler/Driver/fsc.fs | 2 +- src/Compiler/Facilities/DiagnosticsLogger.fsi | 1 + src/Compiler/Interactive/fsi.fs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Driver/fsc.fs b/src/Compiler/Driver/fsc.fs index 696761f43da..0e26f2db4ac 100644 --- a/src/Compiler/Driver/fsc.fs +++ b/src/Compiler/Driver/fsc.fs @@ -164,7 +164,7 @@ let TypeCheck CheckClosedInputSet( ctok, - diagnosticsLogger.CheckForErrors, + (fun () -> diagnosticsLogger.CheckForRealErrorsIgnoringWarnings), tcConfig, tcImports, tcGlobals, diff --git a/src/Compiler/Facilities/DiagnosticsLogger.fsi b/src/Compiler/Facilities/DiagnosticsLogger.fsi index e5a4c8e7f8a..da7a6a66ca8 100644 --- a/src/Compiler/Facilities/DiagnosticsLogger.fsi +++ b/src/Compiler/Facilities/DiagnosticsLogger.fsi @@ -207,6 +207,7 @@ type DiagnosticsLogger = abstract ErrorCount: int /// Checks if ErrorCount > 0 + [] member CheckForErrors: unit -> bool abstract CheckForRealErrorsIgnoringWarnings: bool diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 4b98ee1a8cb..eaba5aa6582 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -2204,7 +2204,7 @@ type internal FsiDynamicCompiler lock tcLockObject (fun _ -> CheckClosedInputSet( ctok, - diagnosticsLogger.CheckForErrors, + (fun () -> diagnosticsLogger.CheckForRealErrorsIgnoringWarnings), tcConfig, tcImports, tcGlobals, From a4a689e54ae22cc1cf0c732b59f1a452da19df17 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 13 Jan 2025 16:32:22 +0100 Subject: [PATCH 39/52] Dont expose overrides in .fsi --- src/Compiler/Checking/import.fsi | 1 - src/FSharp.Core/map.fsi | 1 - src/FSharp.Core/quotations.fsi | 2 -- src/FSharp.Core/set.fsi | 1 - 4 files changed, 5 deletions(-) diff --git a/src/Compiler/Checking/import.fsi b/src/Compiler/Checking/import.fsi index b341dd06dff..c387558fcba 100644 --- a/src/Compiler/Checking/import.fsi +++ b/src/Compiler/Checking/import.fsi @@ -54,7 +54,6 @@ type TTypeCacheKey = val ty2: TType val canCoerce: CanCoerce val tcGlobals: TcGlobals - override Equals: other: objnull -> bool override GetHashCode: unit -> int /// Represents a context used for converting AbstractIL .NET and provided types to F# internal compiler data structures. diff --git a/src/FSharp.Core/map.fsi b/src/FSharp.Core/map.fsi index 5b982141a34..2fdabdbb29f 100644 --- a/src/FSharp.Core/map.fsi +++ b/src/FSharp.Core/map.fsi @@ -215,7 +215,6 @@ type Map<[] 'Key, [> interface IReadOnlyDictionary<'Key, 'Value> - override Equals: objnull -> bool /// Contains operations for working with values of type . [] diff --git a/src/FSharp.Core/quotations.fsi b/src/FSharp.Core/quotations.fsi index ebb3d1021ef..a01ee58b914 100644 --- a/src/FSharp.Core/quotations.fsi +++ b/src/FSharp.Core/quotations.fsi @@ -187,8 +187,6 @@ type Expr = /// member CustomAttributes: Expr list - override Equals: obj: objnull -> bool - /// Builds an expression that represents getting the address of a value. /// /// The target expression. diff --git a/src/FSharp.Core/set.fsi b/src/FSharp.Core/set.fsi index 1be1ad557df..d60432fcd0b 100644 --- a/src/FSharp.Core/set.fsi +++ b/src/FSharp.Core/set.fsi @@ -234,7 +234,6 @@ type Set<[] 'T when 'T: comparison> = interface System.IComparable interface System.Collections.IStructuralEquatable interface IReadOnlyCollection<'T> - override Equals: objnull -> bool #if NETSTANDARD2_1_OR_GREATER /// Contains methods for compiler use related to sets. From 311f415d444e5be80fa7edfda5f260cd5544f77f Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 20 Jan 2025 18:16:42 +0100 Subject: [PATCH 40/52] fix --- src/Compiler/DependencyManager/DependencyProvider.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/DependencyManager/DependencyProvider.fs b/src/Compiler/DependencyManager/DependencyProvider.fs index 1bf72a76e5b..6e641af607b 100644 --- a/src/Compiler/DependencyManager/DependencyProvider.fs +++ b/src/Compiler/DependencyManager/DependencyProvider.fs @@ -564,7 +564,7 @@ type DependencyProvider new() = new DependencyProvider(None, None, true) /// Returns a formatted help messages for registered dependencymanagers for the host to present - member _.GetRegisteredDependencyManagerHelpText(compilerTools, outputDir, errorReport) = + member _.GetRegisteredDependencyManagerHelpText(compilerTools, outputDir : string | null, errorReport) = [| let managers = RegisteredDependencyManagers compilerTools (Option.ofString outputDir) errorReport @@ -575,7 +575,7 @@ type DependencyProvider |] /// Clear the DependencyManager results caches - member _.ClearResultsCache(compilerTools, outputDir, errorReport) = + member _.ClearResultsCache(compilerTools, outputDir : string | null, errorReport) = let managers = RegisteredDependencyManagers compilerTools (Option.ofString outputDir) errorReport From ebe86b34f4fac8699d3ae7a7fafd6b601ab2fc48 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 23 Jan 2025 11:32:03 +0100 Subject: [PATCH 41/52] fix infinity recursion in SRTP typar equivalence resolutio --- src/Compiler/TypedTree/TypedTreeOps.fs | 9 ++++++--- .../Nullness/HasSignatureWithMissingOverride.fs | 11 +++++++++++ .../Nullness/HasSignatureWithMissingOverride.fsi | 5 +++++ .../EmittedIL/Nullness/NullnessMetadata.fs | 7 +++++++ 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 6a88e16c23d..a4476ed8e5a 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -1008,7 +1008,10 @@ type TypeEquivEnv with aenv.BindTyparsToTypes tps tys member aenv.FromEquivTypars tps1 tps2 = - aenv.BindEquivTypars tps1 tps2 + aenv.BindEquivTypars tps1 tps2 + + member anev.ResetEquiv = + if anev.NullnessMustEqual then typeEquivCheckNullness else typeEquivEnvEmpty let rec traitsAEquivAux erasureFlag g aenv traitInfo1 traitInfo2 = let (TTrait(tys1, nm, mf1, argTys, retTy, _, _)) = traitInfo1 @@ -1095,8 +1098,8 @@ and typeAEquivAux erasureFlag g aenv ty1 ty2 = | TType_var (tp1, n1), _ -> match aenv.EquivTypars.TryFind tp1 with | Some tpTy1 -> - let tpTy1 = addNullnessToTy n1 tpTy1 - typeAEquivAux erasureFlag g aenv tpTy1 ty2 + let tpTy1 = if (nullnessEqual aenv n1 g.knownWithoutNull) then tpTy1 else addNullnessToTy n1 tpTy1 + typeAEquivAux erasureFlag g aenv.ResetEquiv tpTy1 ty2 | None -> false | TType_app (tcref1, tinst1, n1), TType_app (tcref2, tinst2, n2) -> diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs new file mode 100644 index 00000000000..764781c15d2 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs @@ -0,0 +1,11 @@ +module SignatureWithMissingOverride + +[] +type MyCollection(count:int) = + member Count =count + // This changes nullable annotation from nullable to non-nullable + override _.ToString() : string = "MyCollection" + // This does not change anything + override _.GetHashCode() = 0 + // This must keep the inferred argument as nullable obj! + override _.Equals(obj) = false \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi new file mode 100644 index 00000000000..300e1fe6b68 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi @@ -0,0 +1,5 @@ +module SignatureWithMissingOverride + +[] +type MyCollection = + member Count : int \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs index bc2bcbf9154..c7d65a258d5 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs @@ -123,6 +123,13 @@ module NullnessMetadata = |> withNoWarn 52 |> verifyCompilation DoNotOptimize + [] + let ``Override missing in signature`` () = + FsFromPath (__SOURCE_DIRECTORY__ ++ "HasSignatureWithMissingOverride.fsi") + |> withAdditionalSourceFile (SourceFromPath (__SOURCE_DIRECTORY__ ++ "HasSignatureWithMissingOverride.fs")) + |> withNoWarn 52 + |> verifyCompilation DoNotOptimize + [] let ``Downcasting and typetests`` compilation = compilation From e62ef151decf238f4311effa3407de08457675e5 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 23 Jan 2025 14:03:23 +0100 Subject: [PATCH 42/52] Cosmetics --- src/Compiler/TypedTree/TypeProviders.fs | 6 ++---- src/Compiler/TypedTree/TypeProviders.fsi | 4 ++-- .../HasSignatureWithMissingOverride.fs | 3 +-- .../HasSignatureWithMissingOverride.fs.il.bsl | 0 .../HasSignatureWithMissingOverride.fsi | 6 +++--- .../EmittedIL/Nullness/NullnessMetadata.fs | 17 +++++++++++++--- .../Nullness/NullableRegressionTests.fs | 20 +++++++++---------- tests/FSharp.Test.Utilities/Compiler.fs | 4 +++- 8 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 1a048b8d72e..af205291542 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -871,10 +871,8 @@ type ProvidedPropertyInfo (x: PropertyInfo, ctxt) = | Null -> null | NonNull x -> ProvidedPropertyInfo (x, ctxt) - static member CreateArray ctxt (xs: PropertyInfo[] MaybeNull) : ProvidedPropertyInfo[] MaybeNull = - match xs with - | Null -> null - | NonNull xs -> xs |> Array.map (ProvidedPropertyInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: PropertyInfo[]) : ProvidedPropertyInfo[] = + xs |> Array.map (ProvidedPropertyInfo.CreateNonNull ctxt) member _.Handle = x diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index bbbb4a3dd2f..4811f4fdff7 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -128,7 +128,7 @@ type ProvidedType = member GetField: string -> ProvidedFieldInfo MaybeNull - member GetProperties: unit -> ProvidedPropertyInfo[] MaybeNull + member GetProperties: unit -> ProvidedPropertyInfo[] member GetProperty: string -> ProvidedPropertyInfo MaybeNull @@ -422,7 +422,7 @@ type ProvidedExprType = | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr[] - | ProvidedConstantExpr of obj MaybeNull * ProvidedType + | ProvidedConstantExpr of objnull * ProvidedType | ProvidedDefaultExpr of ProvidedType diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs index 764781c15d2..fd383440611 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs @@ -1,8 +1,7 @@ module SignatureWithMissingOverride -[] type MyCollection(count:int) = - member Count =count + member _.Count =count // This changes nullable annotation from nullable to non-nullable override _.ToString() : string = "MyCollection" // This does not change anything diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi index 300e1fe6b68..f633d1de875 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fsi @@ -1,5 +1,5 @@ module SignatureWithMissingOverride - -[] +[] type MyCollection = - member Count : int \ No newline at end of file + member Count : int + override ToString: unit -> string \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs index c7d65a258d5..e517c97f507 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/NullnessMetadata.fs @@ -9,14 +9,18 @@ open FSharp.Test.Compiler module NullnessMetadata = type Optimize = Optimize | DoNotOptimize - let verifyCompilation (o:Optimize) compilation = + let addOptions (o:Optimize) compilation = compilation |> withOptions ["--checknulls"] |> (match o with | Optimize -> withOptimize | DoNotOptimize -> withNoOptimize) |> withNoDebug |> withNoInterfaceData |> withNoOptimizationData - |> asLibrary + |> asLibrary + + let verifyCompilation (o:Optimize) compilation = + compilation + |> addOptions o |> verifyILBaseline [] @@ -128,7 +132,14 @@ module NullnessMetadata = FsFromPath (__SOURCE_DIRECTORY__ ++ "HasSignatureWithMissingOverride.fsi") |> withAdditionalSourceFile (SourceFromPath (__SOURCE_DIRECTORY__ ++ "HasSignatureWithMissingOverride.fs")) |> withNoWarn 52 - |> verifyCompilation DoNotOptimize + |> addOptions DoNotOptimize + |> compile + |> withILContains + [".method public hidebysig virtual instance string ToString() cil managed" + ".method public hidebysig virtual instance int32 GetHashCode() cil managed" + "hidebysig virtual instance bool Equals(object obj) cil managed" + ] + |> shouldSucceed [] let ``Downcasting and typetests`` compilation = diff --git a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs index 18058469dd4..9bf4730e404 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/Nullness/NullableRegressionTests.fs @@ -42,31 +42,31 @@ let ``Signature conformance`` langVersion checknulls = |> compile |> shouldFail |> withDiagnostics - [(Error 34, Line 4, Col 5, Line 4, Col 10, "Module 'M' contains + [(Warning 3261, Line 4, Col 5, Line 4, Col 10, "Nullness warning: Module 'M' contains val test2: x: string | null -> unit but its signature specifies val test2: string -> unit - The types differ"); - (Error 34, Line 3, Col 5, Line 3, Col 10, "Module 'M' contains + The types differ in their nullness annotations"); + (Warning 3261, Line 3, Col 5, Line 3, Col 10, "Nullness warning: Module 'M' contains val test1: x: string -> unit but its signature specifies val test1: string | null -> unit - The types differ"); - (Error 34, Line 6, Col 5, Line 6, Col 17, "Module 'M' contains + The types differ in their nullness annotations"); + (Warning 3261, Line 6, Col 5, Line 6, Col 17, "Nullness warning: Module 'M' contains val iRejectNulls: x: string | null -> string but its signature specifies val iRejectNulls: string -> string - The types differ"); - (Error 34, Line 14, Col 14, Line 14, Col 21, "Module 'M' contains + The types differ in their nullness annotations"); + (Warning 3261, Line 14, Col 14, Line 14, Col 21, "Nullness warning: Module 'M' contains member GenericContainer.GetNull: unit -> 'T but its signature specifies member GenericContainer.GetNull: unit -> 'T | null - The types differ"); - (Error 34, Line 15, Col 14, Line 15, Col 24, "Module 'M' contains + The types differ in their nullness annotations"); + (Warning 3261, Line 15, Col 14, Line 15, Col 24, "Nullness warning: Module 'M' contains member GenericContainer.GetNotNull: unit -> 'T | null but its signature specifies member GenericContainer.GetNotNull: unit -> 'T - The types differ")] + The types differ in their nullness annotations")] [] let ``Existing positive v8 disabled`` compilation = diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index b485e0ff266..74ce39ecda9 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1298,7 +1298,9 @@ Actual: | Some p -> match ILChecker.verifyILAndReturnActual [] p expected with | true, _, _ -> result - | false, errorMsg, _actualIL -> CompilationResult.Failure( {s with Output = Some (ExecutionOutput {Outcome = NoExitCode; StdOut = errorMsg; StdErr = "" })} ) + | false, errorMsg, _actualIL -> + eprintfn "%s" errorMsg + CompilationResult.Failure( {s with Output = Some (ExecutionOutput {Outcome = NoExitCode; StdOut = errorMsg; StdErr = ""})} ) | CompilationResult.Failure f -> printfn "Failure:" printfn $"{f}" From 09768246abbee1217139d40557e659bbc8117867 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 3 Feb 2025 14:40:34 +0100 Subject: [PATCH 43/52] ilverify update --- ...rify_FSharp.Compiler.Service_Debug_net9.0.bsl | 14 +++++++------- ...fy_FSharp.Compiler.Service_Release_net9.0.bsl | 14 +++++++------- ...p.Compiler.Service_Release_netstandard2.0.bsl | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl index 41e393f5f30..b35cabc8732 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl @@ -21,14 +21,14 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x00000082][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-786::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-787::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. [IL]: Error [UnmanagedPointer]: : FSharp.Compiler.Interactive.Shell+Utilities+pointerToNativeInt@110::Invoke(object)][offset 0x00000007] Unmanaged pointers are not a verifiable type. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+dataTipOfReferences@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000084][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000082][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000008B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000094][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000082][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000008B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000094][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.StaticLinking+TypeForwarding::followTypeForwardForILTypeRef([FSharp.Compiler.Service]FSharp.Compiler.AbstractIL.IL+ILTypeRef)][offset 0x00000010][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CompilerOptions::getCompilerOption([FSharp.Compiler.Service]FSharp.Compiler.CompilerOptions+CompilerOption, [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1)][offset 0x000000E6][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CompilerOptions::AddPathMapping([FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, string)][offset 0x0000000B][found Char] Unexpected type on the stack. @@ -59,7 +59,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000CD][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@546::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@558::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000037][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000043][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl index d1ac4690f8b..d6741222edd 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl @@ -21,13 +21,13 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x00000082][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-830::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-831::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+GetReferenceResolutionStructuredToolTipText@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000076][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000064][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000006D][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000076][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000064][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000006D][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000076][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Driver+ProcessCommandLineFlags@301-1::Invoke(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Driver+ProcessCommandLineFlags@301-1::Invoke(string)][offset 0x00000014][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.StaticLinking+TypeForwarding::followTypeForwardForILTypeRef([FSharp.Compiler.Service]FSharp.Compiler.AbstractIL.IL+ILTypeRef)][offset 0x00000010][found Char] Unexpected type on the stack. @@ -85,7 +85,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000B6][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@546::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@558::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000035][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000041][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl index 15bc7aba394..72c6eb47adc 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl @@ -28,17 +28,17 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiStdinSyphon::GetLine(string, int32)][offset 0x00000032][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-830::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-831::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiInteractionProcessor::CompletionsForPartialLID([FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompilerState, string)][offset 0x00000024][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+GetReferenceResolutionStructuredToolTipText@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000076][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.AssemblyContent+traverseMemberFunctionAndValues@176::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Symbols.FSharpMemberOrFunctionOrValue)][offset 0x0000002B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.AssemblyContent+traverseEntity@218::GenerateNext([S.P.CoreLib]System.Collections.Generic.IEnumerable`1&)][offset 0x000000BB][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.ParsedInput+visitor@1423-11::VisitExpr([FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, [FSharp.Compiler.Service]FSharp.Compiler.Syntax.SynExpr)][offset 0x00000620][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000064][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000006D][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-529::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000076][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000064][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000006D][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000076][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Symbols+fullName@2495-3::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000030][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Driver+ProcessCommandLineFlags@301-1::Invoke(string)][offset 0x0000000B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Driver+ProcessCommandLineFlags@301-1::Invoke(string)][offset 0x00000014][found Char] Unexpected type on the stack. @@ -108,10 +108,10 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseNamed@5290(uint8[], [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>, int32, int32)][offset 0x0000007E][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Collections.Utils::shortPath(string)][offset 0x00000016][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment::probePathForDotnetHost@320([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x0000002A][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment::probePathForDotnetHost@321([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x0000002A][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.SimulatedMSBuildReferenceResolver+SimulatedMSBuildResolver@68::FSharp.Compiler.CodeAnalysis.ILegacyReferenceResolver.Resolve([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyResolutionEnvironment, [S.P.CoreLib]System.Tuple`2[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>)][offset 0x000002F5][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000B6][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@546::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@558::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000035][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000041][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. From b08f7e5a146138558ee63b6872d199a560dd3548 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 3 Feb 2025 14:56:42 +0100 Subject: [PATCH 44/52] adjust test framework sensitivity to consequitive whitespace in diag strings --- tests/FSharp.Test.Utilities/Compiler.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 85a68ed2eb6..eb3755c4a10 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1586,8 +1586,8 @@ Actual: if not (List.exists (fun (el: ErrorInfo) -> (getErrorNumber el.Error) = exp) source) then failwith (sprintf "Mismatch in ErrorNumber, expected '%A' was not found during compilation.\nAll errors:\n%A" exp (List.map getErrorInfo source)) - let consequtiveWhiteSpaceTrimmer = new Regex(@"\s\s+") - let trimExtraSpaces s = consequtiveWhiteSpaceTrimmer.Replace(s," ") + let consequtiveWhiteSpaceTrimmer = new Regex(@"(\r\n|\n|\ |\t)(\ )+") + let trimExtraSpaces s = consequtiveWhiteSpaceTrimmer.Replace(s,"$1") let private assertErrors (what: string) libAdjust (source: ErrorInfo list) (expected: ErrorInfo list) : unit = From 030b003bd36db6979a99ed38b0bcf4bf4f148e68 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 3 Feb 2025 15:46:33 +0100 Subject: [PATCH 45/52] Fix TP ResolveTypeName nullness --- src/Compiler/TypedTree/TypeProviders.fs | 2 +- src/FSharp.Core/fslib-extra-pervasives.fs | 2 +- src/FSharp.Core/fslib-extra-pervasives.fsi | 2 +- .../FSharp.Compiler.ComponentTests.fsproj | 1 + .../Miscellaneous/MigratedTypeProviderTests.fs | 15 +++++++++++++++ tests/fsharp/tests.fs | 5 ----- 6 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 2c4cb21e1db..8ad4a890e03 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -1261,7 +1261,7 @@ let ResolveProvidedType (resolver: Tainted, m, moduleOrNamespace: // Check if the provided namespace name is an exact match of the required namespace name if displayName = providedNamespaceName then - let resolvedType = providedNamespace.PApply((fun providedNamespace -> ProvidedType.CreateNoContext(providedNamespace.ResolveTypeName typeName)), range=m) + let resolvedType = providedNamespace.PApply((fun providedNamespace -> ProvidedType.Create ProvidedTypeContext.Empty (providedNamespace.ResolveTypeName typeName)), range=m) match resolvedType with | Tainted.Null -> None | Tainted.NonNull result -> diff --git a/src/FSharp.Core/fslib-extra-pervasives.fs b/src/FSharp.Core/fslib-extra-pervasives.fs index 8ce025606eb..c0b0bc05a04 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fs +++ b/src/FSharp.Core/fslib-extra-pervasives.fs @@ -473,7 +473,7 @@ type IProvidedNamespace = abstract GetTypes: unit -> Type array - abstract ResolveTypeName: typeName: string -> Type + abstract ResolveTypeName: typeName: string -> (Type|null) type ITypeProvider = inherit System.IDisposable diff --git a/src/FSharp.Core/fslib-extra-pervasives.fsi b/src/FSharp.Core/fslib-extra-pervasives.fsi index aff5d162b0a..898cb94eb55 100644 --- a/src/FSharp.Core/fslib-extra-pervasives.fsi +++ b/src/FSharp.Core/fslib-extra-pervasives.fsi @@ -509,7 +509,7 @@ namespace Microsoft.FSharp.Core.CompilerServices /// Resolver should return a type called name in namespace NamespaceName or null if the type is unknown. /// /// - abstract ResolveTypeName : typeName: string -> Type + abstract ResolveTypeName : typeName: string -> (Type|null) /// /// Represents an instantiation of a type provider component. diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 9eb31c35e0d..5f1115154fc 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -317,6 +317,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs new file mode 100644 index 00000000000..f0af8a4045a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs @@ -0,0 +1,15 @@ +module Miscellaneous.MigratedTypeProviderTests + +open Xunit +open FSharp.Test +open FSharp.Test.ScriptHelpers +open System.Runtime.InteropServices +open Miscellaneous.FsharpSuiteMigrated.TestFrameworkAdapter + + + +[] +let ``13219-bug-FSI`` () = singleTestBuildAndRun "regression/13219" FSI + +[] +let ``multi-package-type-provider-test-FSI`` () = singleTestBuildAndRun "regression/13710" FSI \ No newline at end of file diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index 0dc078e506c..1cca3988af0 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1643,16 +1643,11 @@ module RegressionTests = [] let ``12383-FSC_OPTIMIZED`` () = singleTestBuildAndRun "regression/12383" FSC_OPTIMIZED - [] - let ``13219-bug-FSI`` () = singleTestBuildAndRun "regression/13219" FSI - [] let ``4715-optimized`` () = let cfg = testConfig "regression/4715" fsc cfg "%s -o:test.exe --optimize+" cfg.fsc_flags ["date.fs"; "env.fs"; "main.fs"] - [] - let ``multi-package-type-provider-test-FSI`` () = singleTestBuildAndRun "regression/13710" FSI #if NETCOREAPP [] From 30fcf6fca254faf4ec4f7ca9be71f13d82ca3a22 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 3 Feb 2025 15:52:19 +0100 Subject: [PATCH 46/52] Update .fantomasignore --- .fantomasignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.fantomasignore b/.fantomasignore index fd441420456..9c12ffa8e2c 100644 --- a/.fantomasignore +++ b/.fantomasignore @@ -42,6 +42,8 @@ src/Compiler/Checking/TypeRelations.fs # nullness-related problems src/Compiler/DependencyManager/DependencyProvider.fs +src/FSharp.Core/fslib-extra-pervasives.fs +src/FSharp.Core/fslib-extra-pervasives.fsi # Incorrectly formatted: https://github.com/dotnet/fsharp/pull/14645/commits/49443a67ea8a17670c8a7c80c8bdf91f82231e91 or https://github.com/fsprojects/fantomas/issues/2733 # This CompilerImports.fs behavior is not fixed yet, following up in https://github.com/fsprojects/fantomas/issues/2733 From 8cc5186d956854cc40caef099ddf10dece15ca4a Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Mon, 3 Feb 2025 16:48:19 +0100 Subject: [PATCH 47/52] move tests back to fsharp suite --- .../FSharp.Compiler.ComponentTests.fsproj | 1 - .../Miscellaneous/MigratedTypeProviderTests.fs | 15 --------------- tests/fsharp/tests.fs | 5 +++++ 3 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 5f1115154fc..9eb31c35e0d 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -317,7 +317,6 @@ - diff --git a/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs b/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs deleted file mode 100644 index f0af8a4045a..00000000000 --- a/tests/FSharp.Compiler.ComponentTests/Miscellaneous/MigratedTypeProviderTests.fs +++ /dev/null @@ -1,15 +0,0 @@ -module Miscellaneous.MigratedTypeProviderTests - -open Xunit -open FSharp.Test -open FSharp.Test.ScriptHelpers -open System.Runtime.InteropServices -open Miscellaneous.FsharpSuiteMigrated.TestFrameworkAdapter - - - -[] -let ``13219-bug-FSI`` () = singleTestBuildAndRun "regression/13219" FSI - -[] -let ``multi-package-type-provider-test-FSI`` () = singleTestBuildAndRun "regression/13710" FSI \ No newline at end of file diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index 1cca3988af0..0dc078e506c 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1643,11 +1643,16 @@ module RegressionTests = [] let ``12383-FSC_OPTIMIZED`` () = singleTestBuildAndRun "regression/12383" FSC_OPTIMIZED + [] + let ``13219-bug-FSI`` () = singleTestBuildAndRun "regression/13219" FSI + [] let ``4715-optimized`` () = let cfg = testConfig "regression/4715" fsc cfg "%s -o:test.exe --optimize+" cfg.fsc_flags ["date.fs"; "env.fs"; "main.fs"] + [] + let ``multi-package-type-provider-test-FSI`` () = singleTestBuildAndRun "regression/13710" FSI #if NETCOREAPP [] From 4fda992e683927c88b9c07a67b995e049a834c39 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 4 Feb 2025 12:55:26 +0100 Subject: [PATCH 48/52] fix NRE reporting for type providers --- src/Compiler/Checking/InfoReader.fs | 3 +- src/Compiler/Checking/MethodCalls.fs | 6 +-- src/Compiler/Checking/NicePrint.fs | 2 +- src/Compiler/Checking/import.fs | 2 +- src/Compiler/Checking/infos.fs | 4 +- src/Compiler/TypedTree/TypeProviders.fs | 53 ++++++++++++++---------- src/Compiler/TypedTree/TypeProviders.fsi | 41 +++++++++--------- src/Compiler/TypedTree/tainted.fs | 6 +++ src/Compiler/TypedTree/tainted.fsi | 3 ++ 9 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/Compiler/Checking/InfoReader.fs b/src/Compiler/Checking/InfoReader.fs index 77fb623efb0..b8a0efd14af 100644 --- a/src/Compiler/Checking/InfoReader.fs +++ b/src/Compiler/Checking/InfoReader.fs @@ -63,7 +63,8 @@ let rec GetImmediateIntrinsicMethInfosOfTypeAux (optFilter, ad) g amap m withExp let st = info.ProvidedType let meths = match optFilter with - | Some name -> st.PApplyArray ((fun st -> st.GetMethods() |> Array.filter (fun mi -> mi.Name = name) ), "GetMethods", m) + | Some name -> + st.PApplyFilteredArray ((fun st -> st.GetMethods()),(fun mi -> mi.Name = name), "GetMethods", m) | None -> st.PApplyArray ((fun st -> st.GetMethods()), "GetMethods", m) [ for mi in meths -> ProvidedMeth(amap, mi.Coerce(m), None, m) ] #endif diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index 76e13156dec..41d731f007e 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -1120,7 +1120,7 @@ let TryImportProvidedMethodBaseAsLibraryIntrinsic (amap: Import.ImportMap, m: ra match tryTcrefOfAppTy amap.g declaringType with | ValueSome declaringEntity -> if not declaringEntity.IsLocalRef && ccuEq declaringEntity.nlr.Ccu amap.g.fslibCcu then - let n = mbase.PUntaint((fun x -> x.GetParameters().Length), m) + let n = mbase.PApplyArray((fun x -> x.GetParameters()),"GetParameters", m).Length match amap.g.knownIntrinsics.TryGetValue ((declaringEntity.LogicalName, None, methodName, n)) with | true, vref -> Some vref | _ -> @@ -1863,7 +1863,7 @@ module ProvidedMethodCalls = allArgs: Exprs, paramVars: Tainted[], g, amap, mut, isProp, isSuperInit, m, - expr: Tainted) = + expr: Tainted) = let varConv = // note: Assuming the size based on paramVars @@ -1873,7 +1873,7 @@ module ProvidedMethodCalls = dict.Add(v, (None, e)) dict - let rec exprToExprAndWitness top (ea: Tainted) = + let rec exprToExprAndWitness top (ea: Tainted) = let fail() = error(Error(FSComp.SR.etUnsupportedProvidedExpression(ea.PUntaint((fun etree -> etree.UnderlyingExpressionString), m)), m)) match ea with | Tainted.Null -> error(Error(FSComp.SR.etNullProvidedExpression(ea.TypeProviderDesignation), m)) diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 45c8c5bfb12..0cc1810c38e 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -2177,7 +2177,7 @@ module TastDefinitionPrinting = match tcref.TypeReprInfo with | TProvidedTypeRepr info -> [ - for nestedType in info.ProvidedType.PApplyArray((fun sty -> sty.GetNestedTypes() |> Array.filter (fun t -> t.IsPublic || t.IsNestedPublic)), "GetNestedTypes", m) do + for nestedType in info.ProvidedType.PApplyFilteredArray((fun sty -> sty.GetNestedTypes()),(fun t -> t.IsPublic || t.IsNestedPublic), "GetNestedTypes", m) do yield nestedType.PUntaint((fun t -> t.IsClass, t.Name), m) ] |> List.sortBy snd diff --git a/src/Compiler/Checking/import.fs b/src/Compiler/Checking/import.fs index 1ae2f8b4af9..c87d6cdad03 100644 --- a/src/Compiler/Checking/import.fs +++ b/src/Compiler/Checking/import.fs @@ -648,7 +648,7 @@ let ImportProvidedMethodBaseAsILMethodRef (env: ImportMap) (m: range) (mbase: Ta let genericArity = if mbase.PUntaint((fun x -> x.IsGenericMethod), m) then - mbase.PUntaint((fun x -> x.GetGenericArguments().Length), m) + mbase.PApplyArray((fun x -> x.GetGenericArguments()),"GetGenericArguments", m).Length else 0 let callingConv = (if mbase.PUntaint((fun x -> x.IsStatic), m) then ILCallingConv.Static else ILCallingConv.Instance) diff --git a/src/Compiler/Checking/infos.fs b/src/Compiler/Checking/infos.fs index e0d20bbb3f2..3fe1ba2f7b1 100644 --- a/src/Compiler/Checking/infos.fs +++ b/src/Compiler/Checking/infos.fs @@ -859,7 +859,7 @@ type MethInfo = | MethInfoWithModifiedReturnType(mi, _) -> mi.NumArgs | DefaultStructCtor _ -> [0] #if !NO_TYPEPROVIDERS - | ProvidedMeth(_, mi, _, m) -> [mi.PUntaint((fun mi -> mi.GetParameters().Length), m)] // Why is this a list? Answer: because the method might be curried + | ProvidedMeth(_, mi, _, m) -> [mi.PApplyArray((fun mi -> mi.GetParameters()),"GetParameters", m).Length] // Why is this a list? Answer: because the method might be curried #endif /// Indicates if the property is a IsABC union case tester implied by a union case definition @@ -2030,7 +2030,7 @@ type PropInfo = failwith "unreachable" #if !NO_TYPEPROVIDERS | ProvidedProp(_, pi, m) -> - pi.PUntaint((fun pi -> pi.GetIndexParameters().Length), m)>0 + pi.PApplyArray((fun pi -> pi.GetIndexParameters()),"GetIndexParameters", m).Length>0 #endif /// Indicates if this is an F# property compiled as a CLI event, e.g. a [] property. diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 8ad4a890e03..7c1aa7f12c9 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -22,6 +22,12 @@ open FSharp.Compiler.Text open FSharp.Compiler.Text.Range type TypeProviderDesignation = TypeProviderDesignation of string +type 'a ProvidedArray= ('a[]) MaybeNull +module ProvidedArray = + let map f (arr:_ ProvidedArray) : _ ProvidedArray = + match arr with + | null -> null + | notNull -> notNull |> Array.map f exception ProvidedTypeResolution of range * exn @@ -403,7 +409,7 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = /// Type.BaseType can be null when Type is interface or object member _.BaseType = x.BaseType |> ProvidedType.Create ctxt - member _.GetStaticParameters(provider: ITypeProvider) : ProvidedParameterInfo[] = provider.GetStaticParameters x |> ProvidedParameterInfo.CreateArray ctxt + member _.GetStaticParameters(provider: ITypeProvider) : ProvidedParameterInfo ProvidedArray = provider.GetStaticParameters x |> ProvidedParameterInfo.CreateArray ctxt /// Type.GetElementType can be null if i.e. Type is not array\pointer\byref type member _.GetElementType() = x.GetElementType() |> ProvidedType.Create ctxt @@ -616,8 +622,8 @@ type ProvidedParameterInfo (x: ParameterInfo, ctxt) = static member CreateNonNull ctxt x = ProvidedParameterInfo (x, ctxt) - static member CreateArray ctxt (xs: ParameterInfo[]) : ProvidedParameterInfo[] = - xs |> Array.map (ProvidedParameterInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: ParameterInfo ProvidedArray) : ProvidedParameterInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedParameterInfo.CreateNonNull ctxt) interface IProvidedCustomAttributeProvider with member _.GetHasTypeProviderEditorHideMethodsAttribute provider = @@ -703,7 +709,7 @@ type ProvidedMethodBase (x: MethodBase, ctxt) = static member TaintedEquals (pt1: Tainted, pt2: Tainted) = Tainted.EqTainted (pt1.PApplyNoFailure(fun st -> st.Handle)) (pt2.PApplyNoFailure(fun st -> st.Handle)) - member _.GetStaticParametersForMethod(provider: ITypeProvider) : ProvidedParameterInfo[] = + member _.GetStaticParametersForMethod(provider: ITypeProvider) : ProvidedParameterInfo ProvidedArray = let bindingFlags = BindingFlags.Instance ||| BindingFlags.NonPublic ||| BindingFlags.Public let staticParams = @@ -769,8 +775,8 @@ type ProvidedFieldInfo (x: FieldInfo, ctxt) = | Null -> null | NonNull x -> ProvidedFieldInfo (x, ctxt) - static member CreateArray ctxt (xs: FieldInfo[]) : ProvidedFieldInfo[] = - xs |> Array.map (ProvidedFieldInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: FieldInfo ProvidedArray) : ProvidedFieldInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedFieldInfo.CreateNonNull ctxt) member _.IsInitOnly = x.IsInitOnly @@ -823,8 +829,8 @@ type ProvidedMethodInfo (x: MethodInfo, ctxt) = | NonNull x -> ProvidedMethodInfo (x, ctxt) - static member CreateArray ctxt (xs: MethodInfo[]) : ProvidedMethodInfo[] = - xs |> Array.map (ProvidedMethodInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: MethodInfo ProvidedArray) : ProvidedMethodInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedMethodInfo.CreateNonNull ctxt) member _.Handle = x @@ -861,8 +867,8 @@ type ProvidedPropertyInfo (x: PropertyInfo, ctxt) = | Null -> null | NonNull x -> ProvidedPropertyInfo (x, ctxt) - static member CreateArray ctxt (xs: PropertyInfo[]) : ProvidedPropertyInfo[] = - xs |> Array.map (ProvidedPropertyInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: PropertyInfo ProvidedArray) : ProvidedPropertyInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedPropertyInfo.CreateNonNull ctxt) member _.Handle = x @@ -899,8 +905,8 @@ type ProvidedEventInfo (x: EventInfo, ctxt) = | Null -> null | NonNull x -> ProvidedEventInfo (x, ctxt) - static member CreateArray ctxt (xs: EventInfo[]) : ProvidedEventInfo[] = - xs |> Array.map (ProvidedEventInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: EventInfo ProvidedArray) : ProvidedEventInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedEventInfo.CreateNonNull ctxt) member _.Handle = x @@ -930,8 +936,8 @@ type ProvidedConstructorInfo (x: ConstructorInfo, ctxt) = | Null -> null | NonNull x -> ProvidedConstructorInfo (x, ctxt) - static member CreateArray ctxt (xs: ConstructorInfo[]) : ProvidedConstructorInfo[] = - xs |> Array.map (ProvidedConstructorInfo.CreateNonNull ctxt) + static member CreateArray ctxt (xs: ConstructorInfo ProvidedArray) : ProvidedConstructorInfo ProvidedArray = + xs |> ProvidedArray.map (ProvidedConstructorInfo.CreateNonNull ctxt) member _.Handle = x @@ -940,19 +946,19 @@ type ProvidedConstructorInfo (x: ConstructorInfo, ctxt) = override _.GetHashCode() = assert false; x.GetHashCode() type ProvidedExprType = - | ProvidedNewArrayExpr of ProvidedType * ProvidedExpr[] - | ProvidedNewObjectExpr of ProvidedConstructorInfo * ProvidedExpr[] + | ProvidedNewArrayExpr of ProvidedType * ProvidedExpr ProvidedArray + | ProvidedNewObjectExpr of ProvidedConstructorInfo * ProvidedExpr ProvidedArray | ProvidedWhileLoopExpr of ProvidedExpr * ProvidedExpr - | ProvidedNewDelegateExpr of ProvidedType * ProvidedVar[] * ProvidedExpr + | ProvidedNewDelegateExpr of ProvidedType * ProvidedVar ProvidedArray * ProvidedExpr | ProvidedForIntegerRangeLoopExpr of ProvidedVar * ProvidedExpr * ProvidedExpr * ProvidedExpr | ProvidedSequentialExpr of ProvidedExpr * ProvidedExpr | ProvidedTryWithExpr of ProvidedExpr * ProvidedVar * ProvidedExpr * ProvidedVar * ProvidedExpr | ProvidedTryFinallyExpr of ProvidedExpr * ProvidedExpr | ProvidedLambdaExpr of ProvidedVar * ProvidedExpr - | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr[] + | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr ProvidedArray | ProvidedConstantExpr of objnull * ProvidedType | ProvidedDefaultExpr of ProvidedType - | ProvidedNewTupleExpr of ProvidedExpr[] + | ProvidedNewTupleExpr of ProvidedExpr ProvidedArray | ProvidedTupleGetExpr of ProvidedExpr * int | ProvidedTypeAsExpr of ProvidedExpr * ProvidedType | ProvidedTypeTestExpr of ProvidedExpr * ProvidedType @@ -1063,7 +1069,7 @@ type ProvidedVar (x: Var, ctxt) = /// Get the provided invoker expression for a particular use of a method. let GetInvokerExpression (provider: ITypeProvider, methodBase: ProvidedMethodBase, paramExprs: ProvidedVar[]) = - provider.GetInvokerExpression(methodBase.Handle, [| for p in paramExprs -> Quotations.Expr.Var p.Handle |]) |> ProvidedExpr.CreateNonNull methodBase.Context + provider.GetInvokerExpression(methodBase.Handle, [| for p in paramExprs -> Quotations.Expr.Var p.Handle |]) |> ProvidedExpr.Create methodBase.Context /// Compute the Name or FullName property of a provided type, reporting appropriate errors let CheckAndComputeProvidedNameProperty(m, st: Tainted, proj, propertyString) = @@ -1242,7 +1248,7 @@ let ValidateProvidedTypeDefinition(m, st: Tainted, expectedPath: s | -1 -> () | n -> errorR(Error(FSComp.SR.etIllegalCharactersInTypeName(string expectedName[n], expectedName), m)) - let staticParameters : Tainted = st.PApplyWithProvider((fun (st, provider) -> st.GetStaticParameters provider), range=m) + let staticParameters = st.PApplyWithProvider((fun (st, provider) -> st.GetStaticParameters provider), range=m) if staticParameters.PUntaint((fun a -> (nonNull a).Length), m) = 0 then ValidateProvidedTypeAfterStaticInstantiation(m, st, expectedPath, expectedName) @@ -1322,7 +1328,8 @@ let TryApplyProvidedMethod(methBeforeArgs: Tainted, staticAr else let mangledName = let nm = methBeforeArgs.PUntaint((fun x -> x.Name), m) - let staticParams = methBeforeArgs.PApplyWithProvider((fun (mb, resolver) -> mb.GetStaticParametersForMethod resolver), range=m) + let staticParams = + methBeforeArgs.PApplyWithProvider((fun (mb, resolver) -> mb.GetStaticParametersForMethod resolver |> nonNull), range=m) let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgs, staticParams, m) mangledName match methBeforeArgs.PApplyWithProvider((fun (mb, provider) -> mb.ApplyStaticArgumentsForMethod(provider, mangledName, staticArgs)), range=m) with @@ -1348,7 +1355,7 @@ let TryApplyProvidedType(typeBeforeArguments: Tainted, optGenerate // Otherwise, use the full path of the erased type, including mangled arguments let nm = typeBeforeArguments.PUntaint((fun x -> x.Name), m) let enc, _ = ILPathToProvidedType (typeBeforeArguments, m) - let staticParams : Tainted = typeBeforeArguments.PApplyWithProvider((fun (st, resolver) -> st.GetStaticParameters resolver |> nonNull), range=m) + let staticParams = typeBeforeArguments.PApplyWithProvider((fun (st, resolver) -> st.GetStaticParameters resolver |> nonNull), range=m) let mangledName = ComputeMangledNameForApplyStaticParameters(nm, staticArgs, staticParams, m) enc @ [ mangledName ] diff --git a/src/Compiler/TypedTree/TypeProviders.fsi b/src/Compiler/TypedTree/TypeProviders.fsi index 4811f4fdff7..b8ec2158ea4 100755 --- a/src/Compiler/TypedTree/TypeProviders.fsi +++ b/src/Compiler/TypedTree/TypeProviders.fsi @@ -15,6 +15,7 @@ open FSharp.Compiler.AbstractIL.IL open FSharp.Compiler.Text type TypeProviderDesignation = TypeProviderDesignation of string +type 'a ProvidedArray= ('a[]) MaybeNull /// Raised when a type provider has thrown an exception. exception ProvidedTypeResolution of range * exn @@ -110,7 +111,7 @@ type ProvidedType = member IsArray: bool - member GetInterfaces: unit -> ProvidedType[] + member GetInterfaces: unit -> ProvidedType ProvidedArray member Assembly: ProvidedAssembly MaybeNull @@ -118,27 +119,27 @@ type ProvidedType = member GetNestedType: string -> ProvidedType MaybeNull - member GetNestedTypes: unit -> ProvidedType[] + member GetNestedTypes: unit -> ProvidedType ProvidedArray - member GetAllNestedTypes: unit -> ProvidedType[] + member GetAllNestedTypes: unit -> ProvidedType ProvidedArray - member GetMethods: unit -> ProvidedMethodInfo[] + member GetMethods: unit -> ProvidedMethodInfo ProvidedArray - member GetFields: unit -> ProvidedFieldInfo[] + member GetFields: unit -> ProvidedFieldInfo ProvidedArray member GetField: string -> ProvidedFieldInfo MaybeNull - member GetProperties: unit -> ProvidedPropertyInfo[] + member GetProperties: unit -> ProvidedPropertyInfo ProvidedArray member GetProperty: string -> ProvidedPropertyInfo MaybeNull - member GetEvents: unit -> ProvidedEventInfo[] + member GetEvents: unit -> ProvidedEventInfo ProvidedArray member GetEvent: string -> ProvidedEventInfo MaybeNull - member GetConstructors: unit -> ProvidedConstructorInfo[] + member GetConstructors: unit -> ProvidedConstructorInfo ProvidedArray - member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo[] + member GetStaticParameters: ITypeProvider -> ProvidedParameterInfo ProvidedArray member GetGenericTypeDefinition: unit -> ProvidedType @@ -172,7 +173,7 @@ type ProvidedType = member GetElementType: unit -> ProvidedType MaybeNull - member GetGenericArguments: unit -> ProvidedType[] + member GetGenericArguments: unit -> ProvidedType ProvidedArray member GetArrayRank: unit -> int @@ -275,11 +276,11 @@ type ProvidedMethodBase = member IsConstructor: bool - member GetParameters: unit -> ProvidedParameterInfo[] + member GetParameters: unit -> ProvidedParameterInfo ProvidedArray - member GetGenericArguments: unit -> ProvidedType[] + member GetGenericArguments: unit -> ProvidedType ProvidedArray - member GetStaticParametersForMethod: ITypeProvider -> ProvidedParameterInfo[] + member GetStaticParametersForMethod: ITypeProvider -> ProvidedParameterInfo ProvidedArray static member TaintedGetHashCode: Tainted -> int @@ -363,7 +364,7 @@ type ProvidedPropertyInfo = member GetSetMethod: unit -> ProvidedMethodInfo MaybeNull - member GetIndexParameters: unit -> ProvidedParameterInfo[] + member GetIndexParameters: unit -> ProvidedParameterInfo ProvidedArray member CanRead: bool @@ -402,13 +403,13 @@ type ProvidedConstructorInfo = type ProvidedExprType = - | ProvidedNewArrayExpr of ProvidedType * ProvidedExpr[] + | ProvidedNewArrayExpr of ProvidedType * ProvidedExpr ProvidedArray - | ProvidedNewObjectExpr of ProvidedConstructorInfo * ProvidedExpr[] + | ProvidedNewObjectExpr of ProvidedConstructorInfo * ProvidedExpr ProvidedArray | ProvidedWhileLoopExpr of ProvidedExpr * ProvidedExpr - | ProvidedNewDelegateExpr of ProvidedType * ProvidedVar[] * ProvidedExpr + | ProvidedNewDelegateExpr of ProvidedType * ProvidedVar ProvidedArray * ProvidedExpr | ProvidedForIntegerRangeLoopExpr of ProvidedVar * ProvidedExpr * ProvidedExpr * ProvidedExpr @@ -420,13 +421,13 @@ type ProvidedExprType = | ProvidedLambdaExpr of ProvidedVar * ProvidedExpr - | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr[] + | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr ProvidedArray | ProvidedConstantExpr of objnull * ProvidedType | ProvidedDefaultExpr of ProvidedType - | ProvidedNewTupleExpr of ProvidedExpr[] + | ProvidedNewTupleExpr of ProvidedExpr ProvidedArray | ProvidedTupleGetExpr of ProvidedExpr * int @@ -470,7 +471,7 @@ type ProvidedVar = override GetHashCode: unit -> int /// Get the provided expression for a particular use of a method. -val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr +val GetInvokerExpression: ITypeProvider * ProvidedMethodBase * ProvidedVar[] -> ProvidedExpr MaybeNull /// Validate that the given provided type meets some of the rules for F# provided types val ValidateProvidedTypeAfterStaticInstantiation: diff --git a/src/Compiler/TypedTree/tainted.fs b/src/Compiler/TypedTree/tainted.fs index d23b5183a53..76a0ba131e4 100644 --- a/src/Compiler/TypedTree/tainted.fs +++ b/src/Compiler/TypedTree/tainted.fs @@ -138,6 +138,12 @@ type internal Tainted<'T> (context: TaintedContext, value: 'T) = | Null -> raise <| TypeProviderError(FSComp.SR.etProviderReturnedNull(methodName), this.TypeProviderDesignation, range) | NonNull a -> a |> Array.map (fun u -> Tainted(context,u)) + member this.PApplyFilteredArray(factory, filter, methodName, range:range) = + let a : 'U[] MaybeNull = this.Protect factory range + match a with + | Null -> raise <| TypeProviderError(FSComp.SR.etProviderReturnedNull(methodName), this.TypeProviderDesignation, range) + | NonNull a -> a |> Array.filter filter |> Array.map (fun u -> Tainted(context,u)) + member this.PApplyOption(f, range: range) = let a = this.Protect f range match a with diff --git a/src/Compiler/TypedTree/tainted.fsi b/src/Compiler/TypedTree/tainted.fsi index 61392794b5f..d066eefd3b2 100644 --- a/src/Compiler/TypedTree/tainted.fsi +++ b/src/Compiler/TypedTree/tainted.fsi @@ -80,6 +80,9 @@ type internal Tainted<'T> = /// Apply an operation that returns an array. Unwrap array. Any exception will be attributed to the type provider with an error located at the given range. String is method name of thing-returning-array, to diagnostically attribute if it is null member PApplyArray: ('T -> 'U[] MaybeNull) * string * range: range -> Tainted<'U>[] + /// Apply an operation that returns an array. Filter the array. Unwrap array. Any exception will be attributed to the type provider with an error located at the given range. String is method name of thing-returning-array, to diagnostically attribute if it is null + member PApplyFilteredArray: ('T -> 'U[] MaybeNull) * ('U -> bool) *string * range: range -> Tainted<'U>[] + /// Apply an operation that returns an option. Unwrap option. Any exception will be attributed to the type provider with an error located at the given range member PApplyOption: ('T -> 'U option) * range: range -> Tainted<'U> option From 9e05a4c6c2b2152151d87396221789f5f4d8004a Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 4 Feb 2025 13:38:32 +0100 Subject: [PATCH 49/52] fix --- src/Compiler/TypedTree/TypeProviders.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/TypedTree/TypeProviders.fs b/src/Compiler/TypedTree/TypeProviders.fs index 7c1aa7f12c9..42caa723619 100644 --- a/src/Compiler/TypedTree/TypeProviders.fs +++ b/src/Compiler/TypedTree/TypeProviders.fs @@ -482,8 +482,8 @@ type ProvidedType (x: Type, ctxt: ProvidedTypeContext) = | null -> nullArg name | t -> ProvidedType (t, ctxt) - static member CreateArray ctxt (xs: Type[] ) : ProvidedType[] = - xs |> Array.map (ProvidedType.CreateNonNull ctxt) + static member CreateArray ctxt (xs:_ ProvidedArray) = + xs |> ProvidedArray.map (ProvidedType.CreateNonNull ctxt) static member CreateNoContext (x:Type) = ProvidedType.CreateNonNull ProvidedTypeContext.Empty x From 096c9e87f44574610ca3149424f810d38f154fcc Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 4 Feb 2025 13:52:10 +0100 Subject: [PATCH 50/52] ilverify --- ...rify_FSharp.Compiler.Service_Debug_net9.0.bsl | 2 +- ...arp.Compiler.Service_Debug_netstandard2.0.bsl | 16 ++++++++-------- ...fy_FSharp.Compiler.Service_Release_net9.0.bsl | 2 +- ...p.Compiler.Service_Release_netstandard2.0.bsl | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl index 98b935a0d0f..c2263a4f259 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_net9.0.bsl @@ -21,7 +21,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x00000082][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-788::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-789::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. [IL]: Error [UnmanagedPointer]: : FSharp.Compiler.Interactive.Shell+Utilities+pointerToNativeInt@110::Invoke(object)][offset 0x00000007] Unmanaged pointers are not a verifiable type. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+dataTipOfReferences@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000084][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl index 1e0df962a05..18045d70b31 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Debug_netstandard2.0.bsl @@ -28,18 +28,18 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiStdinSyphon::GetLine(string, int32)][offset 0x00000039][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-788::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-789::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001E5][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiInteractionProcessor::CompletionsForPartialLID([FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompilerState, string)][offset 0x0000001B][found Char] Unexpected type on the stack. [IL]: Error [UnmanagedPointer]: : FSharp.Compiler.Interactive.Shell+Utilities+pointerToNativeInt@110::Invoke(object)][offset 0x00000007] Unmanaged pointers are not a verifiable type. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+dataTipOfReferences@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000084][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.AssemblyContent+traverseMemberFunctionAndValues@176::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Symbols.FSharpMemberOrFunctionOrValue)][offset 0x00000059][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.AssemblyContent+traverseEntity@218::GenerateNext([S.P.CoreLib]System.Collections.Generic.IEnumerable`1&)][offset 0x000000DA][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.ParsedInput+visitor@1423-6::VisitExpr([FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, [FSharp.Compiler.Service]FSharp.Compiler.Syntax.SynExpr)][offset 0x00000605][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000082][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000008B][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-508::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000094][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000082][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000008B][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-509::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000094][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Symbols+fullName@2495-1::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000015][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CreateILModule+MainModuleBuilder::ConvertProductVersionToILVersionInfo(string)][offset 0x00000011][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.StaticLinking+TypeForwarding::followTypeForwardForILTypeRef([FSharp.Compiler.Service]FSharp.Compiler.AbstractIL.IL+ILTypeRef)][offset 0x00000010][found Char] Unexpected type on the stack. @@ -81,10 +81,10 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL::parseILVersion(string)][offset 0x00000021][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.AbstractIL.IL+parseNamed@5291::Invoke([FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>, int32, int32)][offset 0x00000087][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.Collections.Utils::shortPath(string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment+probePathForDotnetHost@321::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000028][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : Internal.Utilities.FSharpEnvironment+probePathForDotnetHost@322::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000028][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.SimulatedMSBuildReferenceResolver+Pipe #6 input at line 68@68::FSharp.Compiler.CodeAnalysis.ILegacyReferenceResolver.Resolve([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyResolutionEnvironment, [S.P.CoreLib]System.Tuple`2[], string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, string, [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, string, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>)][offset 0x0000034D][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharp.Compiler.DiagnosticsLogger::.cctor()][offset 0x000000CD][found Char] Unexpected type on the stack. -[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@546::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. +[IL]: Error [CallVirtOnValueType]: : FSharp.Compiler.Text.RangeModule+comparer@558::System.Collections.Generic.IEqualityComparer.GetHashCode([FSharp.Compiler.Service]FSharp.Compiler.Text.Range)][offset 0x00000002] Callvirt on a value type method. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000037][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : Internal.Utilities.PathMapModule::applyDir([FSharp.Compiler.Service]Internal.Utilities.PathMap, string)][offset 0x00000043][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$Internal.Utilities.XmlAdapters::.cctor()][offset 0x0000000A][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl index 0782f6c1ecf..7fb77b391ec 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_net9.0.bsl @@ -21,7 +21,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x00000082][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-832::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-833::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+GetReferenceResolutionStructuredToolTipText@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000076][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x00000032][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$ServiceLexing+clo@921-530::Invoke([FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,Microsoft.FSharp.Core.Unit>)][offset 0x0000003B][found Char] Unexpected type on the stack. diff --git a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl index 47a24476c65..c3f513d5c7c 100644 --- a/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl +++ b/tests/ILVerify/ilverify_FSharp.Compiler.Service_Release_netstandard2.0.bsl @@ -28,7 +28,7 @@ [IL]: Error [StackUnexpected]: : FSharp.Compiler.CodeAnalysis.Hosted.CompilerHelpers::fscCompile([FSharp.Compiler.Service]FSharp.Compiler.CodeAnalysis.LegacyReferenceResolver, string, string[])][offset 0x0000008B][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiStdinSyphon::GetLine(string, int32)][offset 0x00000032][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+MagicAssemblyResolution::ResolveAssemblyCore([FSharp.Compiler.Service]Internal.Utilities.Library.CompilationThreadToken, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, [FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, [FSharp.Compiler.Service]FSharp.Compiler.CompilerImports+TcImports, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompiler, [FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiConsoleOutput, string)][offset 0x00000015][found Char] Unexpected type on the stack. -[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3510-832::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. +[IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+clo@3516-833::Invoke([S.P.CoreLib]System.Tuple`3)][offset 0x000001C7][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.Interactive.Shell+FsiInteractionProcessor::CompletionsForPartialLID([FSharp.Compiler.Service]FSharp.Compiler.Interactive.Shell+FsiDynamicCompilerState, string)][offset 0x00000024][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : .$FSharpCheckerResults+GetReferenceResolutionStructuredToolTipText@2205::Invoke([FSharp.Core]Microsoft.FSharp.Core.Unit)][offset 0x00000076][found Char] Unexpected type on the stack. [IL]: Error [StackUnexpected]: : FSharp.Compiler.EditorServices.AssemblyContent+traverseMemberFunctionAndValues@176::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Symbols.FSharpMemberOrFunctionOrValue)][offset 0x0000002B][found Char] Unexpected type on the stack. From 5974aa756379d5d82d09230ffb5c7177f72d841c Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Tue, 4 Feb 2025 13:54:16 +0100 Subject: [PATCH 51/52] release notes --- docs/release-notes/.FSharp.Compiler.Service/9.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md index 683c8dc0f5c..67d43dbf18e 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/9.0.300.md @@ -10,6 +10,7 @@ ### Added * Added missing type constraints in FCS. ([PR #18241](https://github.com/dotnet/fsharp/pull/18241)) * The 'use' keyword can be used on IDisposable|null without nullness warnings ([PR #18262](https://github.com/dotnet/fsharp/pull/18262)) +* Nullness warnings are issued for signature<>implementation conformance ([PR #18186](https://github.com/dotnet/fsharp/pull/18186)) ### Changed From 245c837d1e88031a9f8bc6a396589cb210e62ce6 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 6 Feb 2025 11:46:33 +0100 Subject: [PATCH 52/52] PR feedback addressed --- src/Compiler/Checking/NicePrint.fs | 2 +- .../Nullness/HasSignatureWithMissingOverride.fs.il.bsl | 0 tests/FSharp.Test.Utilities/Compiler.fs | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl diff --git a/src/Compiler/Checking/NicePrint.fs b/src/Compiler/Checking/NicePrint.fs index 0cc1810c38e..282773b6b8b 100644 --- a/src/Compiler/Checking/NicePrint.fs +++ b/src/Compiler/Checking/NicePrint.fs @@ -2930,7 +2930,7 @@ let minimalStringsOfTwoTypes denv ty1 ty2 = let denv = denv.SetOpenPaths [] let denv = { denv with includeStaticParametersInTypeNames=true } let makeName t = - let assemblyName = PrintTypes.layoutAssemblyName denv t |> function | "" -> "" | name -> sprintf " (%s)" name + let assemblyName = PrintTypes.layoutAssemblyName denv t |> function | "" -> "" | name -> $" (%s{name})" sprintf "%s%s" (stringOfTy denv t) assemblyName (makeName ty1, makeName ty2, stringOfTyparConstraints denv tpcs) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Nullness/HasSignatureWithMissingOverride.fs.il.bsl deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index eb3755c4a10..c6346cb30f2 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1301,7 +1301,6 @@ Actual: match ILChecker.verifyILAndReturnActual [] p expected with | true, _, _ -> result | false, errorMsg, _actualIL -> - eprintfn "%s" errorMsg CompilationResult.Failure( {s with Output = Some (ExecutionOutput {Outcome = NoExitCode; StdOut = errorMsg; StdErr = ""})} ) | CompilationResult.Failure f -> printfn "Failure:"