diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index d0736fa504..9dd2281d8b 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -27,6 +27,7 @@ ### Added * FSharpType: add ImportILType ([PR #19300](https://github.com/dotnet/fsharp/pull/19300)) * Type checker: recover on argument/overload checking ([PR #19314](https://github.com/dotnet/fsharp/pull/19314)) +* FSharpType: add more predefined type checks ([PR #19325](https://github.com/dotnet/fsharp/pull/19325)) ### Changed diff --git a/src/Compiler/Symbols/Symbols.fs b/src/Compiler/Symbols/Symbols.fs index d7db3ecd19..c44e47efd9 100644 --- a/src/Compiler/Symbols/Symbols.fs +++ b/src/Compiler/Symbols/Symbols.fs @@ -2557,24 +2557,59 @@ type FSharpType(cenv, ty:TType) = member _.IsMeasureType = isResolved() && - protect <| fun () -> - match stripTyparEqns ty with - | TType_measure _ -> true - | _ -> false + protect <| fun () -> isMeasureTy cenv.g ty member _.IsTupleType = isResolved() && - protect <| fun () -> - match stripTyparEqns ty with - | TType_tuple _ -> true - | _ -> false + protect <| fun () -> isAnyTupleTy cenv.g ty + + member _.IsReferenceTupleType = + isResolved() && + protect <| fun () -> isRefTupleTy cenv.g ty member _.IsStructTupleType = isResolved() && - protect <| fun () -> - match stripTyparEqns ty with - | TType_tuple (tupInfo, _) -> evalTupInfoIsStruct tupInfo - | _ -> false + protect <| fun () -> isStructTupleTy cenv.g ty + + member _.IsUnitType = + isResolved () && + protect <| fun () -> isUnitTy cenv.g ty + + member _.IsArrayType = + isResolved () && + protect <| fun () -> isArrayTy cenv.g ty + + member _.IsNativePointerType = + isResolved () && + protect <| fun () -> isNativePtrTy cenv.g ty + + member _.IsFSharpList = + isResolved () && + protect <| fun () -> isListTy cenv.g ty + + member _.IsFSharpChoice = + isResolved () && + protect <| fun () -> isChoiceTy cenv.g ty + + member _.IsFSharpOption = + isResolved () && + protect <| fun () -> isOptionTy cenv.g ty + + member _.IsFSharpValueOption = + isResolved () && + protect <| fun () -> isValueOptionTy cenv.g ty + + member _.IsStringType = + isResolved () && + protect <| fun () -> isStringTy cenv.g ty + + member _.IsObjectType = + isResolved () && + protect <| fun () -> isObjTyAnyNullness cenv.g ty + + member _.IsBooleanType = + isResolved () && + protect <| fun () -> isBoolTy cenv.g ty member _.TypeDefinition = protect <| fun () -> @@ -2633,17 +2668,11 @@ type FSharpType(cenv, ty:TType) = member _.IsFunctionType = isResolved() && - protect <| fun () -> - match stripTyparEqns ty with - | TType_fun _ -> true - | _ -> false + protect <| fun () -> isFunTy cenv.g ty member _.IsAnonRecordType = isResolved() && - protect <| fun () -> - match stripTyparEqns ty with - | TType_anon _ -> true - | _ -> false + protect <| fun () -> isAnonRecdTy cenv.g ty member _.AnonRecordTypeDetails = protect <| fun () -> @@ -2676,7 +2705,7 @@ type FSharpType(cenv, ty:TType) = GetSuperTypeOfType cenv.g cenv.amap range0 ty |> Option.map (fun ty -> FSharpType(cenv, ty)) - member x.ErasedType= + member x.ErasedType = FSharpType(cenv, stripTyEqnsWrtErasure EraseAll cenv.g ty) member x.BasicQualifiedName = diff --git a/src/Compiler/Symbols/Symbols.fsi b/src/Compiler/Symbols/Symbols.fsi index c416016583..8c8a47a3df 100644 --- a/src/Compiler/Symbols/Symbols.fsi +++ b/src/Compiler/Symbols/Symbols.fsi @@ -1120,9 +1120,23 @@ type FSharpType = /// Indicates if the type is a tuple type (reference or struct). The GenericArguments property returns the elements of the tuple type. member IsTupleType: bool + /// Indicates if the type is a reference tuple type. The GenericArguments property returns the elements of the tuple type. + member IsReferenceTupleType: bool + /// Indicates if the type is a struct tuple type. The GenericArguments property returns the elements of the tuple type. member IsStructTupleType: bool + member IsArrayType: bool + member IsNativePointerType: bool + member IsUnitType: bool + member IsFSharpList: bool + member IsFSharpChoice: bool + member IsFSharpOption: bool + member IsFSharpValueOption: bool + member IsStringType: bool + member IsObjectType: bool + member IsBooleanType: bool + /// Indicates if the type is a function type. The GenericArguments property returns the domain and range of the function type. member IsFunctionType: bool diff --git a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl index feecc4eecd..4f9ce2ce71 100644 --- a/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl +++ b/tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl @@ -5847,23 +5847,45 @@ FSharp.Compiler.Symbols.FSharpType: Boolean HasNullAnnotation FSharp.Compiler.Symbols.FSharpType: Boolean HasTypeDefinition FSharp.Compiler.Symbols.FSharpType: Boolean IsAbbreviation FSharp.Compiler.Symbols.FSharpType: Boolean IsAnonRecordType +FSharp.Compiler.Symbols.FSharpType: Boolean IsArrayType +FSharp.Compiler.Symbols.FSharpType: Boolean IsBooleanType +FSharp.Compiler.Symbols.FSharpType: Boolean IsFSharpChoice +FSharp.Compiler.Symbols.FSharpType: Boolean IsFSharpList +FSharp.Compiler.Symbols.FSharpType: Boolean IsFSharpOption +FSharp.Compiler.Symbols.FSharpType: Boolean IsFSharpValueOption FSharp.Compiler.Symbols.FSharpType: Boolean IsFunctionType FSharp.Compiler.Symbols.FSharpType: Boolean IsGenericParameter FSharp.Compiler.Symbols.FSharpType: Boolean IsMeasureType +FSharp.Compiler.Symbols.FSharpType: Boolean IsNativePointerType FSharp.Compiler.Symbols.FSharpType: Boolean IsNullAmbivalent +FSharp.Compiler.Symbols.FSharpType: Boolean IsObjectType +FSharp.Compiler.Symbols.FSharpType: Boolean IsReferenceTupleType +FSharp.Compiler.Symbols.FSharpType: Boolean IsStringType FSharp.Compiler.Symbols.FSharpType: Boolean IsStructTupleType FSharp.Compiler.Symbols.FSharpType: Boolean IsTupleType +FSharp.Compiler.Symbols.FSharpType: Boolean IsUnitType FSharp.Compiler.Symbols.FSharpType: Boolean IsUnresolved FSharp.Compiler.Symbols.FSharpType: Boolean get_HasNullAnnotation() FSharp.Compiler.Symbols.FSharpType: Boolean get_HasTypeDefinition() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsAbbreviation() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsAnonRecordType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsArrayType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsBooleanType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsFSharpChoice() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsFSharpList() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsFSharpOption() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsFSharpValueOption() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsFunctionType() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsGenericParameter() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsMeasureType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsNativePointerType() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsNullAmbivalent() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsObjectType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsReferenceTupleType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsStringType() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsStructTupleType() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsTupleType() +FSharp.Compiler.Symbols.FSharpType: Boolean get_IsUnitType() FSharp.Compiler.Symbols.FSharpType: Boolean get_IsUnresolved() FSharp.Compiler.Symbols.FSharpType: FSharp.Compiler.Symbols.FSharpAnonRecordTypeDetails AnonRecordTypeDetails FSharp.Compiler.Symbols.FSharpType: FSharp.Compiler.Symbols.FSharpAnonRecordTypeDetails get_AnonRecordTypeDetails()