From 56ac8b8b2be57e9d6ddc7fa907c03ce814fd913d Mon Sep 17 00:00:00 2001 From: Paulmichael Blasucci Date: Mon, 16 Nov 2020 20:25:43 +0100 Subject: [PATCH] Extend Unsigned Integers to Carry Units of Measure (#9978) --- src/fsharp/CheckExpressions.fs | 27 ++- src/fsharp/FSComp.txt | 3 +- src/fsharp/FSharp.Core/prim-types.fs | 51 +++++- src/fsharp/FSharp.Core/prim-types.fsi | 172 +++++++++++++++++- src/fsharp/LanguageFeatures.fs | 3 + src/fsharp/LanguageFeatures.fsi | 1 + src/fsharp/LexFilter.fs | 2 +- src/fsharp/TcGlobals.fs | 42 +++-- src/fsharp/import.fs | 11 ++ src/fsharp/xlf/FSComp.txt.cs.xlf | 7 +- src/fsharp/xlf/FSComp.txt.de.xlf | 7 +- src/fsharp/xlf/FSComp.txt.es.xlf | 7 +- src/fsharp/xlf/FSComp.txt.fr.xlf | 7 +- src/fsharp/xlf/FSComp.txt.it.xlf | 7 +- src/fsharp/xlf/FSComp.txt.ja.xlf | 41 +++-- src/fsharp/xlf/FSComp.txt.ko.xlf | 7 +- src/fsharp/xlf/FSComp.txt.pl.xlf | 7 +- src/fsharp/xlf/FSComp.txt.pt-BR.xlf | 7 +- src/fsharp/xlf/FSComp.txt.ru.xlf | 9 +- src/fsharp/xlf/FSComp.txt.tr.xlf | 9 +- src/fsharp/xlf/FSComp.txt.zh-Hans.xlf | 7 +- src/fsharp/xlf/FSComp.txt.zh-Hant.xlf | 7 +- .../FSharp.Core/PrimTypes.fs | 34 +++- tests/FSharp.Core.UnitTests/SurfaceArea.fs | 6 + .../LanguagePrimitives/CastToUnitsTests.fs | 19 +- .../queriesLeafExpressionConvert/test.fsx | 11 +- tests/fsharp/tools/eval/test.fsx | 10 +- .../Constants/E_UnsupportedTypes01.fs | 10 +- .../Diagnostics/E_UnsupportedType01.fs | 16 +- 29 files changed, 454 insertions(+), 93 deletions(-) diff --git a/src/fsharp/CheckExpressions.fs b/src/fsharp/CheckExpressions.fs index 2ab22e7f411..5de2ff1d4b9 100644 --- a/src/fsharp/CheckExpressions.fs +++ b/src/fsharp/CheckExpressions.fs @@ -774,9 +774,15 @@ let TcConst cenv ty m env c = | _ -> mkAppTy tcr [TType_measure Measure.One] unif measureTy + let expandedMeasurablesEnabled = + cenv.g.langVersion.SupportsFeature LanguageFeature.ExpandedMeasurables + match c with | SynConst.Unit -> unif cenv.g.unit_ty; Const.Unit | SynConst.Bool i -> unif cenv.g.bool_ty; Const.Bool i + | SynConst.Single f -> unif cenv.g.float32_ty; Const.Single f + | SynConst.Double f -> unif cenv.g.float_ty; Const.Double f + | SynConst.Decimal f -> unif (mkAppTy cenv.g.decimal_tcr []); Const.Decimal f | SynConst.SByte i -> unif cenv.g.sbyte_ty; Const.SByte i | SynConst.Int16 i -> unif cenv.g.int16_ty; Const.Int16 i | SynConst.Int32 i -> unif cenv.g.int_ty; Const.Int32 i @@ -787,18 +793,23 @@ let TcConst cenv ty m env c = | SynConst.UInt32 i -> unif cenv.g.uint32_ty; Const.UInt32 i | SynConst.UInt64 i -> unif cenv.g.uint64_ty; Const.UInt64 i | SynConst.UIntPtr i -> unif cenv.g.unativeint_ty; Const.UIntPtr i - | SynConst.Measure(SynConst.Single f, _) | SynConst.Single f -> unifyMeasureArg (f=0.0f) cenv.g.pfloat32_tcr c; Const.Single f - | SynConst.Measure(SynConst.Double f, _) | SynConst.Double f -> unifyMeasureArg (f=0.0) cenv.g.pfloat_tcr c; Const.Double f - | SynConst.Measure(SynConst.Decimal s, _) | SynConst.Decimal s -> unifyMeasureArg false cenv.g.pdecimal_tcr c; Const.Decimal s - | SynConst.Measure(SynConst.SByte i, _) | SynConst.SByte i -> unifyMeasureArg (i=0y) cenv.g.pint8_tcr c; Const.SByte i - | SynConst.Measure(SynConst.Int16 i, _) | SynConst.Int16 i -> unifyMeasureArg (i=0s) cenv.g.pint16_tcr c; Const.Int16 i - | SynConst.Measure(SynConst.Int32 i, _) | SynConst.Int32 i -> unifyMeasureArg (i=0) cenv.g.pint_tcr c; Const.Int32 i - | SynConst.Measure(SynConst.Int64 i, _) | SynConst.Int64 i -> unifyMeasureArg (i=0L) cenv.g.pint64_tcr c; Const.Int64 i + | SynConst.Measure(SynConst.Single f, _) -> unifyMeasureArg (f=0.0f) cenv.g.pfloat32_tcr c; Const.Single f + | SynConst.Measure(SynConst.Double f, _) -> unifyMeasureArg (f=0.0) cenv.g.pfloat_tcr c; Const.Double f + | SynConst.Measure(SynConst.Decimal f, _) -> unifyMeasureArg false cenv.g.pdecimal_tcr c; Const.Decimal f + | SynConst.Measure(SynConst.SByte i, _) -> unifyMeasureArg (i=0y) cenv.g.pint8_tcr c; Const.SByte i + | SynConst.Measure(SynConst.Int16 i, _) -> unifyMeasureArg (i=0s) cenv.g.pint16_tcr c; Const.Int16 i + | SynConst.Measure(SynConst.Int32 i, _) -> unifyMeasureArg (i=0) cenv.g.pint_tcr c; Const.Int32 i + | SynConst.Measure(SynConst.Int64 i, _) -> unifyMeasureArg (i=0L) cenv.g.pint64_tcr c; Const.Int64 i + | SynConst.Measure(SynConst.IntPtr i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0L) cenv.g.pnativeint_tcr c; Const.IntPtr i + | SynConst.Measure(SynConst.Byte i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0uy) cenv.g.puint8_tcr c; Const.Byte i + | SynConst.Measure(SynConst.UInt16 i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0us) cenv.g.puint16_tcr c; Const.UInt16 i + | SynConst.Measure(SynConst.UInt32 i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0u) cenv.g.puint_tcr c; Const.UInt32 i + | SynConst.Measure(SynConst.UInt64 i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0UL) cenv.g.puint64_tcr c; Const.UInt64 i + | SynConst.Measure(SynConst.UIntPtr i, _) when expandedMeasurablesEnabled -> unifyMeasureArg (i=0UL) cenv.g.punativeint_tcr c; Const.UIntPtr i | SynConst.Char c -> unif cenv.g.char_ty; Const.Char c | SynConst.String (s, _) -> unif cenv.g.string_ty; Const.String s | SynConst.UserNum _ -> error (InternalError(FSComp.SR.tcUnexpectedBigRationalConstant(), m)) | SynConst.Measure _ -> error (Error(FSComp.SR.tcInvalidTypeForUnitsOfMeasure(), m)) - | SynConst.UInt16s _ -> error (InternalError(FSComp.SR.tcUnexpectedConstUint16Array(), m)) | SynConst.Bytes _ -> error (InternalError(FSComp.SR.tcUnexpectedConstByteArray(), m)) diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 85defc1dbf6..dd5488d7edc 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -477,7 +477,7 @@ parsSyntaxModuleSigEndDeprecated,"The syntax 'module ... : sig .. end' is not us 634,tcNonZeroConstantCannotHaveGenericUnit,"Non-zero constants cannot have generic units. For generic zero, write 0.0<_>." 635,tcSeqResultsUseYield,"In sequence expressions, results are generated using 'yield'" tcUnexpectedBigRationalConstant,"Unexpected big rational constant" -636,tcInvalidTypeForUnitsOfMeasure,"Units-of-measure supported only on float, float32, decimal and signed integer types" +636,tcInvalidTypeForUnitsOfMeasure,"Units-of-measure are only supported on float, float32, decimal, and integer types." tcUnexpectedConstUint16Array,"Unexpected Const_uint16array" tcUnexpectedConstByteArray,"Unexpected Const_bytearray" 640,tcParameterRequiresName,"A parameter with attributes must also be given a name, e.g. '[] Name : Type'" @@ -1227,6 +1227,7 @@ invalidFullNameForProvidedType,"invalid full name for provided type" 3086,tcCustomOperationMayNotBeUsedHere,"A custom operation may not be used in conjunction with 'use', 'try/with', 'try/finally', 'if/then/else' or 'match' operators within this computation expression" 3087,tcCustomOperationMayNotBeOverloaded,"The custom operation '%s' refers to a method which is overloaded. The implementations of custom operations may not be overloaded." featureOverloadsForCustomOperations,"overloads for custom operations" +featureExpandedMeasurables,"more types support units of measure" 3090,tcIfThenElseMayNotBeUsedWithinQueries,"An if/then/else expression may not be used within queries. Consider using either an if/then expression, or use a sequence expression instead." 3091,ilxgenUnexpectedArgumentToMethodHandleOfDuringCodegen,"Invalid argument to 'methodhandleof' during codegen" 3092,etProvidedTypeReferenceMissingArgument,"A reference to a provided type was missing a value for the static parameter '%s'. You may need to recompile one or more referenced assemblies." diff --git a/src/fsharp/FSharp.Core/prim-types.fs b/src/fsharp/FSharp.Core/prim-types.fs index 307fd22c20a..6f619b045b3 100644 --- a/src/fsharp/FSharp.Core/prim-types.fs +++ b/src/fsharp/FSharp.Core/prim-types.fs @@ -369,11 +369,42 @@ namespace Microsoft.FSharp.Core [] type sbyte<[] 'Measure> = sbyte [] type int16<[] 'Measure> = int16 [] type int64<[] 'Measure> = int64 + + [] + [] + type nativeint<[] 'Measure> = nativeint + + [] + [] + type uint<[] 'Measure> = uint + + [] + [] + type byte<[] 'Measure> = byte + + [] + [] + type uint16<[] 'Measure> = uint16 + + [] + [] + type uint64<[] 'Measure> = uint64 + + [] + [] + type unativeint<[] 'Measure> = unativeint + + [] type double<[] 'Measure> = float<'Measure> + [] type single<[] 'Measure> = float32<'Measure> + [] type int8<[] 'Measure> = sbyte<'Measure> + [] type int32<[] 'Measure> = int<'Measure> + [] type uint8<[] 'Measure> = byte<'Measure> + [] type uint32<[] 'Measure> = uint<'Measure> /// Represents a managed pointer in F# code. type byref<'T> = (# "!0&" #) - /// Represents a managed pointer in F# code. + /// Represents a managed pointer in F# code. type byref<'T, 'Kind> = (# "!0&" #) /// Represents the types of byrefs in F# 4.5+ @@ -2256,6 +2287,24 @@ namespace Microsoft.FSharp.Core let inline Int16WithMeasure (f : int16) : int16<'Measure> = retype f let inline SByteWithMeasure (f : sbyte) : sbyte<'Measure> = retype f let inline Int64WithMeasure (f : int64) : int64<'Measure> = retype f + + [] + let inline IntPtrWithMeasure (f : nativeint) : nativeint<'Measure> = retype f + + [] + let inline UInt32WithMeasure (f : uint) : uint<'Measure> = retype f + + [] + let inline UInt16WithMeasure (f : uint16) : uint16<'Measure> = retype f + + [] + let inline UInt64WithMeasure (f : uint64) : uint64<'Measure> = retype f + + [] + let inline ByteWithMeasure (f : byte) : byte<'Measure> = retype f + + [] + let inline UIntPtrWithMeasure (f : unativeint) : unativeint<'Measure> = retype f let inline formatError() = raise (new System.FormatException(SR.GetString(SR.badFormatString))) diff --git a/src/fsharp/FSharp.Core/prim-types.fsi b/src/fsharp/FSharp.Core/prim-types.fsi index d02b058b226..064b621e56a 100644 --- a/src/fsharp/FSharp.Core/prim-types.fsi +++ b/src/fsharp/FSharp.Core/prim-types.fsi @@ -921,8 +921,8 @@ namespace Microsoft.FSharp.Core member Path: string [] - /// The type of floating point numbers, annotated with a unit of measure. The unit - /// of measure is erased in compiled code and when values of this type + /// The type of double-precision floating point numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type /// are analyzed using reflection. The type is representationally equivalent to /// . /// @@ -930,8 +930,8 @@ namespace Microsoft.FSharp.Core type float<[] 'Measure> = float [] - /// The type of floating point numbers, annotated with a unit of measure. The unit - /// of measure is erased in compiled code and when values of this type + /// The type of single-precision floating point numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type /// are analyzed using reflection. The type is representationally equivalent to /// . /// @@ -956,7 +956,7 @@ namespace Microsoft.FSharp.Core /// /// Basic Types with Units of Measure type int<[] 'Measure> = int - + [] /// The type of 8-bit signed integer numbers, annotated with a unit of measure. The unit /// of measure is erased in compiled code and when values of this type @@ -984,6 +984,120 @@ namespace Microsoft.FSharp.Core /// Basic Types with Units of Measure type int64<[] 'Measure> = int64 + [] + [] + /// The type of machine-sized signed integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type nativeint<[] 'Measure> = nativeint + + [] + [] + /// The type of 32-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type uint<[] 'Measure> = uint + + [] + [] + /// The type of 8-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type byte<[] 'Measure> = byte + + [] + [] + /// The type of 16-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type uint16<[] 'Measure> = uint16 + + [] + [] + /// The type of 64-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type uint64<[] 'Measure> = uint64 + + [] + [] + /// The type of machine-sized unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type unativeint<[] 'Measure> = unativeint + + [] + /// The type of double-precision floating point numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type double<[] 'Measure> = float<'Measure> + + [] + /// The type of single-precision floating point numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type single<[] 'Measure> = float32<'Measure> + + [] + /// The type of 8-bit signed integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type int8<[] 'Measure> = sbyte<'Measure> + + [] + /// The type of 32-bit signed integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type int32<[] 'Measure> = int<'Measure> + + [] + /// The type of 8-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type uint8<[] 'Measure> = byte<'Measure> + + [] + /// The type of 32-bit unsigned integer numbers, annotated with a unit of measure. + /// The unit of measure is erased in compiled code and when values of this type + /// are analyzed using reflection. The type is representationally equivalent to + /// . + /// + /// Basic Types with Units of Measure + type uint32<[] 'Measure> = uint<'Measure> + /// Represents a managed pointer in F# code. #if BUILDING_WITH_LKG || BUILD_FROM_SOURCE [] @@ -1278,6 +1392,54 @@ namespace Microsoft.FSharp.Core /// The sbyte with units-of-measure. val inline SByteWithMeasure : input: sbyte -> sbyte<'Measure> + [] + /// Creates a nativeint value with units-of-measure + /// + /// The input nativeint. + /// + /// The nativeint with units-of-measure. + val inline IntPtrWithMeasure : input: nativeint -> nativeint<'Measure> + + [] + /// Creates a uint value with units-of-measure + /// + /// The input uint. + /// + /// The uint with units-of-measure. + val inline UInt32WithMeasure : input: uint -> uint<'Measure> + + [] + /// Creates a uint64 value with units-of-measure + /// + /// The input uint64. + /// + /// The uint64 with units-of-measure. + val inline UInt64WithMeasure : input: uint64 -> uint64<'Measure> + + [] + /// Creates a uint16 value with units-of-measure + /// + /// The input uint16. + /// + /// The uint16 with units-of-measure. + val inline UInt16WithMeasure : input: uint16 -> uint16<'Measure> + + [] + /// Creates a byte value with units-of-measure + /// + /// The input byte. + /// + /// The byte with units-of-measure. + val inline ByteWithMeasure : input: byte -> byte<'Measure> + + [] + /// Creates a unativeint value with units-of-measure + /// + /// The input unativeint. + /// + /// The unativeint with units-of-measure. + val inline UIntPtrWithMeasure : input: unativeint -> unativeint<'Measure> + /// Parse an int32 according to the rules used by the overloaded 'int32' conversion operator when applied to strings /// /// The input string. diff --git a/src/fsharp/LanguageFeatures.fs b/src/fsharp/LanguageFeatures.fs index ec017f56e49..96c4f6baa5c 100644 --- a/src/fsharp/LanguageFeatures.fs +++ b/src/fsharp/LanguageFeatures.fs @@ -35,6 +35,7 @@ type LanguageFeature = | InterfacesWithMultipleGenericInstantiation | StringInterpolation | OverloadsForCustomOperations + | ExpandedMeasurables /// LanguageVersion management type LanguageVersion (specifiedVersionAsString) = @@ -74,6 +75,7 @@ type LanguageVersion (specifiedVersionAsString) = // F# preview LanguageFeature.OverloadsForCustomOperations, previewVersion + LanguageFeature.ExpandedMeasurables, previewVersion LanguageFeature.FromEndSlicing, previewVersion ] @@ -147,6 +149,7 @@ type LanguageVersion (specifiedVersionAsString) = | LanguageFeature.InterfacesWithMultipleGenericInstantiation -> FSComp.SR.featureInterfacesWithMultipleGenericInstantiation() | LanguageFeature.StringInterpolation -> FSComp.SR.featureStringInterpolation() | LanguageFeature.OverloadsForCustomOperations -> FSComp.SR.featureOverloadsForCustomOperations() + | LanguageFeature.ExpandedMeasurables -> FSComp.SR.featureExpandedMeasurables() /// Get a version string associated with the given feature. member _.GetFeatureVersionString feature = diff --git a/src/fsharp/LanguageFeatures.fsi b/src/fsharp/LanguageFeatures.fsi index 38847502e0c..b914016d9a5 100644 --- a/src/fsharp/LanguageFeatures.fsi +++ b/src/fsharp/LanguageFeatures.fsi @@ -23,6 +23,7 @@ type LanguageFeature = | InterfacesWithMultipleGenericInstantiation | StringInterpolation | OverloadsForCustomOperations + | ExpandedMeasurables /// LanguageVersion management type LanguageVersion = diff --git a/src/fsharp/LexFilter.fs b/src/fsharp/LexFilter.fs index 00461a5d423..795d715f82e 100644 --- a/src/fsharp/LexFilter.fs +++ b/src/fsharp/LexFilter.fs @@ -2240,7 +2240,7 @@ type LexFilterImpl (lightStatus: LightSyntaxStatus, compilingFsLib, lexer, lexbu true // Insert HIGH_PRECEDENCE_TYAPP if needed - | (DELEGATE | IDENT _ | IEEE64 _ | IEEE32 _ | DECIMAL _ | INT8 _ | INT16 _ | INT32 _ | INT64 _ | NATIVEINT _ | UINT8 _ | UINT16 _ | UINT32 _ | UINT64 _ | BIGNUM _) when peekAdjacentTypars false tokenTup -> + | (DELEGATE | IDENT _ | IEEE64 _ | IEEE32 _ | DECIMAL _ | INT8 _ | INT16 _ | INT32 _ | INT64 _ | NATIVEINT _ | UINT8 _ | UINT16 _ | UINT32 _ | UINT64 _ | UNATIVEINT _ | BIGNUM _) when peekAdjacentTypars false tokenTup -> let lessTokenTup = popNextTokenTup() delayToken (pool.UseLocation(lessTokenTup, match lessTokenTup.Token with LESS _ -> LESS true | _ -> failwith "unreachable")) diff --git a/src/fsharp/TcGlobals.fs b/src/fsharp/TcGlobals.fs index d2b66a921fb..b275bc8188d 100755 --- a/src/fsharp/TcGlobals.fs +++ b/src/fsharp/TcGlobals.fs @@ -217,12 +217,18 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d let v_char_tcr = mk_MFCore_tcref fslibCcu "char" let v_float_tcr = mk_MFCore_tcref fslibCcu "float" let v_float32_tcr = mk_MFCore_tcref fslibCcu "float32" - let v_pfloat_tcr = mk_MFCore_tcref fslibCcu "float`1" - let v_pfloat32_tcr = mk_MFCore_tcref fslibCcu "float32`1" - let v_pint_tcr = mk_MFCore_tcref fslibCcu "int`1" - let v_pint8_tcr = mk_MFCore_tcref fslibCcu "sbyte`1" - let v_pint16_tcr = mk_MFCore_tcref fslibCcu "int16`1" - let v_pint64_tcr = mk_MFCore_tcref fslibCcu "int64`1" + let v_pfloat_tcr = mk_MFCore_tcref fslibCcu "float`1" + let v_pfloat32_tcr = mk_MFCore_tcref fslibCcu "float32`1" + let v_pint_tcr = mk_MFCore_tcref fslibCcu "int`1" + let v_pint8_tcr = mk_MFCore_tcref fslibCcu "sbyte`1" + let v_pint16_tcr = mk_MFCore_tcref fslibCcu "int16`1" + let v_pint64_tcr = mk_MFCore_tcref fslibCcu "int64`1" + let v_pnativeint_tcr = mk_MFCore_tcref fslibCcu "nativeint`1" + let v_puint_tcr = mk_MFCore_tcref fslibCcu "uint`1" + let v_puint8_tcr = mk_MFCore_tcref fslibCcu "byte`1" + let v_puint16_tcr = mk_MFCore_tcref fslibCcu "uint16`1" + let v_puint64_tcr = mk_MFCore_tcref fslibCcu "uint64`1" + let v_punativeint_tcr = mk_MFCore_tcref fslibCcu "unativeint`1" let v_byref_tcr = mk_MFCore_tcref fslibCcu "byref`1" let v_byref2_tcr = mk_MFCore_tcref fslibCcu "byref`2" let v_outref_tcr = mk_MFCore_tcref fslibCcu "outref`1" @@ -963,18 +969,24 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d member __.char_tcr = v_char_tcr member __.float_tcr = v_float_tcr member __.float32_tcr = v_float32_tcr - member __.pfloat_tcr = v_pfloat_tcr - member __.pfloat32_tcr = v_pfloat32_tcr - member __.pint_tcr = v_pint_tcr - member __.pint8_tcr = v_pint8_tcr - member __.pint16_tcr = v_pint16_tcr - member __.pint64_tcr = v_pint64_tcr + member __.pfloat_tcr = v_pfloat_tcr + member __.pfloat32_tcr = v_pfloat32_tcr + member __.pint_tcr = v_pint_tcr + member __.pint8_tcr = v_pint8_tcr + member __.pint16_tcr = v_pint16_tcr + member __.pint64_tcr = v_pint64_tcr + member __.pnativeint_tcr = v_pnativeint_tcr + member __.puint_tcr = v_puint_tcr + member __.puint8_tcr = v_puint8_tcr + member __.puint16_tcr = v_puint16_tcr + member __.puint64_tcr = v_puint64_tcr + member __.punativeint_tcr = v_punativeint_tcr member __.byref_tcr = v_byref_tcr - member __.byref2_tcr = v_byref2_tcr - member __.outref_tcr = v_outref_tcr + member __.byref2_tcr = v_byref2_tcr + member __.outref_tcr = v_outref_tcr member __.inref_tcr = v_inref_tcr member __.nativeptr_tcr = v_nativeptr_tcr - member __.voidptr_tcr = v_voidptr_tcr + member __.voidptr_tcr = v_voidptr_tcr member __.ilsigptr_tcr = v_ilsigptr_tcr member __.fastFunc_tcr = v_fastFunc_tcr member __.tcref_IQueryable = v_tcref_IQueryable diff --git a/src/fsharp/import.fs b/src/fsharp/import.fs index daa94b6470a..90734e9ee39 100644 --- a/src/fsharp/import.fs +++ b/src/fsharp/import.fs @@ -290,13 +290,24 @@ let rec ImportProvidedType (env: ImportMap) (m: range) (* (tinst: TypeInst) *) ( /// Adjust for the known primitive numeric types that accept units of measure. let tcref = if genericArgsLength = 1 then + // real if tyconRefEq g tcref g.system_Double_tcref then g.pfloat_tcr elif tyconRefEq g tcref g.system_Single_tcref then g.pfloat32_tcr elif tyconRefEq g tcref g.system_Decimal_tcref then g.pdecimal_tcr + // signed elif tyconRefEq g tcref g.system_Int16_tcref then g.pint16_tcr elif tyconRefEq g tcref g.system_Int32_tcref then g.pint_tcr elif tyconRefEq g tcref g.system_Int64_tcref then g.pint64_tcr elif tyconRefEq g tcref g.system_SByte_tcref then g.pint8_tcr + // unsigned + elif tyconRefEq g tcref g.system_UInt16_tcref then g.puint16_tcr + elif tyconRefEq g tcref g.system_UInt32_tcref then g.puint_tcr + elif tyconRefEq g tcref g.system_UInt64_tcref then g.puint64_tcr + elif tyconRefEq g tcref g.system_Byte_tcref then g.puint8_tcr + //native + elif tyconRefEq g tcref g.system_IntPtr_tcref then g.pnativeint_tcr + elif tyconRefEq g tcref g.system_UIntPtr_tcref then g.punativeint_tcr + // other else tcref else tcref diff --git a/src/fsharp/xlf/FSComp.txt.cs.xlf b/src/fsharp/xlf/FSComp.txt.cs.xlf index 1d832f082b6..03a8d81b8fa 100644 --- a/src/fsharp/xlf/FSComp.txt.cs.xlf +++ b/src/fsharp/xlf/FSComp.txt.cs.xlf @@ -92,6 +92,11 @@ literál float32 bez tečky + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d řez 3d/4d s pevným indexem @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Měrné jednotky se podporují jenom u typů float, float32, decimal a signed integer. diff --git a/src/fsharp/xlf/FSComp.txt.de.xlf b/src/fsharp/xlf/FSComp.txt.de.xlf index fa86bdc48cb..d8bb9846d21 100644 --- a/src/fsharp/xlf/FSComp.txt.de.xlf +++ b/src/fsharp/xlf/FSComp.txt.de.xlf @@ -92,6 +92,11 @@ punktloses float32-Literal + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d Segment 3D/4D mit feststehendem Index @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Maßeinheiten werden nur für die Typen "float", "float32", "decimal" und "signed integer" unterstützt. diff --git a/src/fsharp/xlf/FSComp.txt.es.xlf b/src/fsharp/xlf/FSComp.txt.es.xlf index 91ef240a031..42340a24428 100644 --- a/src/fsharp/xlf/FSComp.txt.es.xlf +++ b/src/fsharp/xlf/FSComp.txt.es.xlf @@ -92,6 +92,11 @@ literal float32 sin punto + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d segmento de índice fijo 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Solo se admiten unidades de medida en los tipos float, float32, decimal y de entero firmado. diff --git a/src/fsharp/xlf/FSComp.txt.fr.xlf b/src/fsharp/xlf/FSComp.txt.fr.xlf index 026ca3395ea..59e62c8fed5 100644 --- a/src/fsharp/xlf/FSComp.txt.fr.xlf +++ b/src/fsharp/xlf/FSComp.txt.fr.xlf @@ -92,6 +92,11 @@ littéral float32 sans point + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d section à index fixe 3D/4D @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Unités de mesure prises en charge uniquement pour les types float, float32, decimal et integer signés diff --git a/src/fsharp/xlf/FSComp.txt.it.xlf b/src/fsharp/xlf/FSComp.txt.it.xlf index 09fd1062f75..05ef18523c8 100644 --- a/src/fsharp/xlf/FSComp.txt.it.xlf +++ b/src/fsharp/xlf/FSComp.txt.it.xlf @@ -92,6 +92,11 @@ valore letterale float32 senza punti + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d sezione a indice fisso 3D/4D @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Unità di misura supportata solo in tipi float, float32, decimal e Integer con segno diff --git a/src/fsharp/xlf/FSComp.txt.ja.xlf b/src/fsharp/xlf/FSComp.txt.ja.xlf index 8742a693fd5..3adc36bec24 100644 --- a/src/fsharp/xlf/FSComp.txt.ja.xlf +++ b/src/fsharp/xlf/FSComp.txt.ja.xlf @@ -87,9 +87,9 @@ 既定のインターフェイス メンバーの消費 - - dotless float32 literal - ドットなしの float32 リテラル + + more types support units of measure + more types support units of measure @@ -97,6 +97,16 @@ 固定インデックス スライス 3d/4d + + The {0} definitions for type '{1}' in the signature and implementation are not compatible because the implementation type is not sealed but signature implies it is. Consider adding the [<Sealed>] attribute to the implementation. + The {0} definitions for type '{1}' in the signature and implementation are not compatible because the implementation type is not sealed but signature implies it is. Consider adding the [<Sealed>] attribute to the implementation. + + + + dotless float32 literal + ドットなしの float32 リテラル + + from-end slicing 開始と終了を指定したスライス @@ -1062,11 +1072,6 @@ シグネチャと実装の型 '{1}' の {0} 定義に互換性がありません。実装の種類はシールドですが、シグネチャではシールドが暗黙的に示されていません。シグネチャに [<Sealed>] 属性を追加してください。 - - The {0} definitions for type '{1}' in the signature and implementation are not compatible because the implementation type is not sealed but signature implies it is. Consider adding the [<Sealed>] attribute to the implementation. - シグネチャと実装の種類 '{1}' の {0} 定義に互換性がありません。実装の種類はシールド型ではありませんが、シグネチャは暗黙的にシールド型に設定されています。実装に [<Sealed>] 属性を追加することを検討してください。 - - The {0} definitions for type '{1}' in the signature and implementation are not compatible because the implementation is an abstract class but the signature is not. Consider adding the [<AbstractClass>] attribute to the signature. シグネチャと実装の型 '{1}' の {0} 定義に互換性がありません。実装は抽象クラスですが、シグネチャは抽象クラスではありません。シグネチャに [<AbstractClass>] 属性を追加してください。 @@ -2712,6 +2717,16 @@ / に続く暗黙的な単位の積 + + Units-of-measure are only supported on float, float32, decimal, and integer types. + float 型、float32 型、decimal 型、および符号付き整数型でのみサポートされる単位です + + + + Used for sequence expressions and, in verbose syntax, to separate expressions from bindings. + Used for sequence expressions and, in verbose syntax, to separate expressions from bindings. + + Unexpected SynMeasure.Anon 予期しない SynMeasure.Anon です: @@ -2732,11 +2747,6 @@ 有理定数が大きすぎます: - - Units-of-measure supported only on float, float32, decimal and signed integer types - float 型、float32 型、decimal 型、および符号付き整数型でのみサポートされる単位です - - Unexpected Const_uint16array 予期しない Const_uint16array です: @@ -7082,11 +7092,6 @@ 条件分岐のコンストラクトで使用します。 - - Used for sequence expressions and, in verbose syntax, to separate expressions from bindings. - 冗語構文で、式のバインディングを分離するためにシーケンス式に使用します。 - - Used to specify a base class or base interface. 基底クラスまたは基底インターフェイスを指定するために使用します。 diff --git a/src/fsharp/xlf/FSComp.txt.ko.xlf b/src/fsharp/xlf/FSComp.txt.ko.xlf index 210d5006157..f6ffb005724 100644 --- a/src/fsharp/xlf/FSComp.txt.ko.xlf +++ b/src/fsharp/xlf/FSComp.txt.ko.xlf @@ -92,6 +92,11 @@ 점이 없는 float32 리터럴 + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d 고정 인덱스 슬라이스 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. 측정 단위는 float, float32, decimal 및 부호 있는 정수 형식에 대해서만 지원됩니다. diff --git a/src/fsharp/xlf/FSComp.txt.pl.xlf b/src/fsharp/xlf/FSComp.txt.pl.xlf index d3fb07e46fb..864f5c4311a 100644 --- a/src/fsharp/xlf/FSComp.txt.pl.xlf +++ b/src/fsharp/xlf/FSComp.txt.pl.xlf @@ -92,6 +92,11 @@ bezkropkowy literał float32 + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d część o stałym indeksie 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Jednostki miary są obsługiwane tylko w przypadku typów float, float32, decimal i signed integer diff --git a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf index e44ffdca717..3094b5667cb 100644 --- a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf +++ b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf @@ -92,6 +92,11 @@ literal float32 sem ponto + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d fatia de índice fixo 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. Unidades de medida só são suportadas em tipos float, float32, decimal e inteiro com sinal diff --git a/src/fsharp/xlf/FSComp.txt.ru.xlf b/src/fsharp/xlf/FSComp.txt.ru.xlf index 8ee0737485f..4ec729e8634 100644 --- a/src/fsharp/xlf/FSComp.txt.ru.xlf +++ b/src/fsharp/xlf/FSComp.txt.ru.xlf @@ -92,6 +92,11 @@ литерал float32 без точки + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d срез с фиксированным индексом 3d/4d @@ -2708,8 +2713,8 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types - Единицы измерения поддерживаются только с типами float, float32, decimal и signed integer + Units-of-measure are only supported on float, float32, decimal, and integer types. + Единицы измерения поддерживаются только с типами float, float32, decimal и signed integer diff --git a/src/fsharp/xlf/FSComp.txt.tr.xlf b/src/fsharp/xlf/FSComp.txt.tr.xlf index 75fcd4f1111..26c5f366c95 100644 --- a/src/fsharp/xlf/FSComp.txt.tr.xlf +++ b/src/fsharp/xlf/FSComp.txt.tr.xlf @@ -92,6 +92,11 @@ noktasız float32 sabit değeri + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d sabit dizinli dilim 3d/4d @@ -2708,8 +2713,8 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types - Ölçü birimleri yalnızca kayan, float32, ondalık ve işaretli tamsayı türlerinde desteklenir + Units-of-measure are only supported on float, float32, decimal, and integer types. + Ölçü birimleri yalnızca kayan, float32, ondalık ve işaretli tamsayı türlerinde desteklenir diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf index b8413551ca0..048c1927452 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf @@ -92,6 +92,11 @@ 无点 float32 文本 + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d 固定索引切片 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. 仅 float、float32、decimal 和带符号整数类型支持度量单位 diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf index a371105797f..35b740d7195 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf @@ -92,6 +92,11 @@ 無點號的 float32 常值 + + more types support units of measure + more types support units of measure + + fixed-index slice 3d/4d 固定索引切割 3d/4d @@ -2708,7 +2713,7 @@ - Units-of-measure supported only on float, float32, decimal and signed integer types + Units-of-measure are only supported on float, float32, decimal, and integer types. 只有 float、float32、decimal 和有正負號的整數類型支援測量單位 diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs index 733a6af7d6e..67f887e051a 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs @@ -43,6 +43,38 @@ type LanguagePrimitivesModule() = let y = 2y Assert.AreEqual(y, y |> LanguagePrimitives.SByteWithMeasure |> sbyte) + + let n = 2n + Assert.AreEqual(n, n |> LanguagePrimitives.IntPtrWithMeasure |> nativeint) + + let i = 2u + Assert.AreEqual(i, i |> LanguagePrimitives.UInt32WithMeasure |> uint) + + let l = 2UL + Assert.AreEqual(l, l |> LanguagePrimitives.UInt64WithMeasure |> uint64) + + let s = 2us + Assert.AreEqual(s, s |> LanguagePrimitives.UInt16WithMeasure |> uint16) + + let uy = 2uy + Assert.AreEqual(uy, uy |> LanguagePrimitives.ByteWithMeasure |> byte) + + let n = 2un + Assert.AreEqual(n, n |> LanguagePrimitives.UIntPtrWithMeasure |> unativeint) + + [] + member _.MeasurableAliases() = + let f (x: int) y: int32 = x + y // should be: `int -> int -> int32` + let g (x: int) (y:int32) = x * y // should be: `int -> int32 -> int` + let h (x: int) y = x * y + let i (x: int32) y = x * y + + let tres = 3 + let ocho : int32 = 8 + + Assert.Equal(ocho, f tres 5) + Assert.Equal(64, g ocho ocho) + Assert.Equal(h ocho tres, i tres ocho) [] member this.MaxMinNan() = @@ -884,4 +916,4 @@ type NonStructuralComparisonTests() = let x = 32 |> float32 let y = 32 |> float32 let comparison = compare x y - Assert.AreEqual(0, comparison) \ No newline at end of file + Assert.AreEqual(0, comparison) diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.fs index d660d4ff422..b94afff6f37 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.fs @@ -1844,6 +1844,7 @@ Microsoft.FSharp.Core.LanguagePrimitives: Boolean GenericGreaterThan[T](T, T) Microsoft.FSharp.Core.LanguagePrimitives: Boolean GenericLessOrEqual[T](T, T) Microsoft.FSharp.Core.LanguagePrimitives: Boolean GenericLessThan[T](T, T) Microsoft.FSharp.Core.LanguagePrimitives: Boolean PhysicalEquality[T](T, T) +Microsoft.FSharp.Core.LanguagePrimitives: Byte ByteWithMeasure(Byte) Microsoft.FSharp.Core.LanguagePrimitives: Double FloatWithMeasure(Double) Microsoft.FSharp.Core.LanguagePrimitives: Int16 Int16WithMeasure(Int16) Microsoft.FSharp.Core.LanguagePrimitives: Int32 GenericComparisonWithComparer[T](System.Collections.IComparer, T, T) @@ -1856,6 +1857,7 @@ Microsoft.FSharp.Core.LanguagePrimitives: Int32 ParseInt32(System.String) Microsoft.FSharp.Core.LanguagePrimitives: Int32 PhysicalHash[T](T) Microsoft.FSharp.Core.LanguagePrimitives: Int64 Int64WithMeasure(Int64) Microsoft.FSharp.Core.LanguagePrimitives: Int64 ParseInt64(System.String) +Microsoft.FSharp.Core.LanguagePrimitives: IntPtr IntPtrWithMeasure(IntPtr) Microsoft.FSharp.Core.LanguagePrimitives: Microsoft.FSharp.Core.LanguagePrimitives+ErrorStrings Microsoft.FSharp.Core.LanguagePrimitives: Microsoft.FSharp.Core.LanguagePrimitives+HashCompare Microsoft.FSharp.Core.LanguagePrimitives: Microsoft.FSharp.Core.LanguagePrimitives+IntrinsicFunctions @@ -1890,6 +1892,10 @@ Microsoft.FSharp.Core.LanguagePrimitives: TResult CheckedMultiplyDynamic[T1,T2,T Microsoft.FSharp.Core.LanguagePrimitives: TResult MultiplyDynamic[T1,T2,TResult](T1, T2) Microsoft.FSharp.Core.LanguagePrimitives: UInt32 ParseUInt32(System.String) Microsoft.FSharp.Core.LanguagePrimitives: UInt64 ParseUInt64(System.String) +Microsoft.FSharp.Core.LanguagePrimitives: UInt16 UInt16WithMeasure(UInt16) +Microsoft.FSharp.Core.LanguagePrimitives: UInt32 UInt32WithMeasure(UInt32) +Microsoft.FSharp.Core.LanguagePrimitives: UInt64 UInt64WithMeasure(UInt64) +Microsoft.FSharp.Core.LanguagePrimitives: UIntPtr UIntPtrWithMeasure(UIntPtr) Microsoft.FSharp.Core.LiteralAttribute: Void .ctor() Microsoft.FSharp.Core.MatchFailureException: Boolean Equals(System.Object) Microsoft.FSharp.Core.MatchFailureException: Boolean Equals(System.Object, System.Collections.IEqualityComparer) diff --git a/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs index f5eff5d7be4..b36481fb338 100644 --- a/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs +++ b/tests/fsharp/Compiler/Libraries/Core/LanguagePrimitives/CastToUnitsTests.fs @@ -10,7 +10,7 @@ module ``Cast to Units Tests`` = [] let ``Casting to Measures should compile``() = - CompilerAssert.Pass + CompilerAssert.PassWithOptions [| "--langversion:preview" |] """ module M @@ -23,7 +23,18 @@ let r1 = SByteWithMeasure 1y + 2y let r2 = Int16WithMeasure 2s - 2s let r3 = Int32WithMeasure 3 * 3 let r4 = Int64WithMeasure 5L / 5L -let r5 = FloatWithMeasure 11.11 + 1.1 -let r6 = Float32WithMeasure 22.22f - 11.11f -let r7 = DecimalWithMeasure 33.33M * 44.44M +let r5a = FloatWithMeasure 11.11 + 1.1 +let r5b = FloatWithMeasure 0x0000000000000010LF + 0x0000000000000001LF +let r6a = Float32WithMeasure 22.22f - 11.11f +let r6b = Float32WithMeasure 22.22F - 11.11F +let r6c = Float32WithMeasure 0x00000010lf - 0x00000001lf +let r7a = DecimalWithMeasure 33.33M * 44.44M +let r7b = DecimalWithMeasure 33.33m * 44.44m +let r8 = ByteWithMeasure 1uy + 2uy +let r9 = UInt16WithMeasure 1us + 2us +let r10a = UInt32WithMeasure 1u + 2u +let r10b = UInt32WithMeasure 1ul + 2ul +let r11 = UInt64WithMeasure 1UL + 2UL +let r12 = IntPtrWithMeasure 1n + 2n +let r13 = UIntPtrWithMeasure 1un + 2un """ diff --git a/tests/fsharp/core/queriesLeafExpressionConvert/test.fsx b/tests/fsharp/core/queriesLeafExpressionConvert/test.fsx index 5bc75468288..24420815309 100644 --- a/tests/fsharp/core/queriesLeafExpressionConvert/test.fsx +++ b/tests/fsharp/core/queriesLeafExpressionConvert/test.fsx @@ -664,7 +664,15 @@ module LeafExpressionEvaluationTests = checkEval "castingunits5" (<@ 2L |> LanguagePrimitives.Int64WithMeasure |> int64 @>) 2L checkEval "castingunits6" (<@ 2s |> LanguagePrimitives.Int16WithMeasure |> int16 @>) 2s checkEval "castingunits7" (<@ 2y |> LanguagePrimitives.SByteWithMeasure |> sbyte @>) 2y - + checkEval "castingunits8" (<@ 2ul |> LanguagePrimitives.UInt32WithMeasure |> uint @>) 2ul + checkEval "castingunits9" (<@ 2UL |> LanguagePrimitives.UInt64WithMeasure |> uint64 @>) 2UL + checkEval "castingunits10" (<@ 2us |> LanguagePrimitives.UInt16WithMeasure |> uint16 @>) 2us + checkEval "castingunits11" (<@ 2uy |> LanguagePrimitives.ByteWithMeasure |> byte @>) 2uy + + //NOTE quotations currently *DO NOT* support native integers + //TODO revisit when the test scaffolding is changed/migrated! + // checkEval "castingunits12" (<@ 2n |> LanguagePrimitives.IntPtrWithMeasure |> nativeint @>) 2n + // checkEval "castingunits13" (<@ 2un |> LanguagePrimitives.UIntPtrWithMeasure |> unativeint @>) 2un module LargerAutomaticDiferentiationTest_FSharp_1_0_Bug_3498 = @@ -1003,4 +1011,3 @@ let aa = exit 1 #endif - diff --git a/tests/fsharp/tools/eval/test.fsx b/tests/fsharp/tools/eval/test.fsx index 67dd74111cf..8956413a1bd 100644 --- a/tests/fsharp/tools/eval/test.fsx +++ b/tests/fsharp/tools/eval/test.fsx @@ -1750,6 +1750,15 @@ module EvaluationTests = checkEval "castingunits5" (<@ 2L |> LanguagePrimitives.Int64WithMeasure |> int64 @>) 2L checkEval "castingunits6" (<@ 2s |> LanguagePrimitives.Int16WithMeasure |> int16 @>) 2s checkEval "castingunits7" (<@ 2y |> LanguagePrimitives.SByteWithMeasure |> sbyte @>) 2y + checkEval "castingunits8" (<@ 2ul |> LanguagePrimitives.UInt32WithMeasure |> uint32 @>) 2ul + checkEval "castingunits9" (<@ 2UL |> LanguagePrimitives.UInt64WithMeasure |> uint64 @>) 2UL + checkEval "castingunits10" (<@ 2us |> LanguagePrimitives.UInt16WithMeasure |> uint16 @>) 2us + checkEval "castingunits11" (<@ 2uy |> LanguagePrimitives.ByteWithMeasure |> byte @>) 2uy + + //NOTE quotations currently *DO NOT* support native integers + //TODO revisit when the test scaffolding is changed/migrated! + // checkEval "castingunits12" (<@ 2n |> LanguagePrimitives.IntPtrWithMeasure |> nativeint @>) 2n + // checkEval "castingunits13" (<@ 2un |> unativeint |> LanguagePrimitives.UIntPtrWithMeasure |> unativeint @>) 2un module QuotationTests = open Microsoft.FSharp.Quotations @@ -2759,4 +2768,3 @@ let _ = stdout.WriteLine "Test Passed"; System.IO.File.WriteAllText("test.ok","ok"); exit 0 - diff --git a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Constants/E_UnsupportedTypes01.fs b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Constants/E_UnsupportedTypes01.fs index 25d9a0c1ac7..47eef066ae0 100644 --- a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Constants/E_UnsupportedTypes01.fs +++ b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Constants/E_UnsupportedTypes01.fs @@ -2,11 +2,8 @@ // Constants with measures // unsupported types // Loosely related to regression tests for FSHARP1.0:2918 -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types +//Units-of-measure are only supported on float, float32, decimal, and integer types. +//Units-of-measure are only supported on float, float32, decimal, and integer types. module M [] type kg @@ -24,6 +21,3 @@ let _ = 4L // Err let _ = 4I let _ = 4N -let _ = 4UL -let _ = 4u -let _ = 4us diff --git a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Diagnostics/E_UnsupportedType01.fs b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Diagnostics/E_UnsupportedType01.fs index f79ae83f076..fcda0d5bd7c 100644 --- a/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Diagnostics/E_UnsupportedType01.fs +++ b/tests/fsharpqa/Source/Conformance/UnitsOfMeasure/Diagnostics/E_UnsupportedType01.fs @@ -1,21 +1,9 @@ // #Regression #Conformance #UnitsOfMeasure #Diagnostics // Regression test for FSHARP1.0:2345 -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types -//Units-of-measure supported only on float, float32, decimal and signed integer types +//Units-of-measure are only supported on float, float32, decimal, and integer types. [] type Kg let x = 1 // ok -let a = 1ul // unsigned int64 -let b = 1u // unsigned int=int32 -let c = 1us // unsigned int16 -let d = 1uy // unsigned int8 - - - - - - +let a = 1I // BigInt