diff --git a/src/fsharp/FSharp.Core/prim-types-prelude.fs b/src/fsharp/FSharp.Core/prim-types-prelude.fs index 74c84101707..b95933a7aa3 100644 --- a/src/fsharp/FSharp.Core/prim-types-prelude.fs +++ b/src/fsharp/FSharp.Core/prim-types-prelude.fs @@ -28,6 +28,7 @@ namespace Microsoft.FSharp.Core type bool = System.Boolean type decimal = System.Decimal type int = int32 + type uint = uint32 type ``[]``<'T> = (# "!0[]" #) type ``[,]``<'T> = (# "!0[0 ...,0 ...]" #) diff --git a/src/fsharp/FSharp.Core/prim-types-prelude.fsi b/src/fsharp/FSharp.Core/prim-types-prelude.fsi index ed68965bf28..f4dd023159b 100644 --- a/src/fsharp/FSharp.Core/prim-types-prelude.fsi +++ b/src/fsharp/FSharp.Core/prim-types-prelude.fsi @@ -78,6 +78,9 @@ namespace Microsoft.FSharp.Core /// An abbreviation for the CLI type System.Int32. type int = int32 + /// An abbreviation for the CLI type System.UInt32. + type uint = uint32 + /// Single dimensional, zero-based arrays, written int[], string[] etc. /// Use the values in the Array module to manipulate values /// of this type, or the notation arr.[x] to get/set array diff --git a/src/fsharp/FSharp.Core/prim-types.fs b/src/fsharp/FSharp.Core/prim-types.fs index 51c38a9642c..4bff05856c9 100644 --- a/src/fsharp/FSharp.Core/prim-types.fs +++ b/src/fsharp/FSharp.Core/prim-types.fs @@ -3731,7 +3731,10 @@ namespace Microsoft.FSharp.Core when ^T : byte = (# "conv.i4" value : int32 #) [] - let inline int value = int32 value + let inline int value = int32 value + + [] + let inline uint value = uint32 value [] let inline enum< ^T when ^T : enum > (value:int32) : ^T = EnumOfValue value diff --git a/src/fsharp/FSharp.Core/prim-types.fsi b/src/fsharp/FSharp.Core/prim-types.fsi index fd6c7557ef1..afa0719602c 100644 --- a/src/fsharp/FSharp.Core/prim-types.fsi +++ b/src/fsharp/FSharp.Core/prim-types.fsi @@ -2639,6 +2639,15 @@ namespace Microsoft.FSharp.Core [] val inline int : value:^T -> int when ^T : (static member op_Explicit : ^T -> int) and default ^T : int + /// Converts the argument to an unsigned 32-bit integer. This is a direct conversion for all + /// primitive numeric types. For strings, the input is converted using UInt32.Parse() + /// with InvariantCulture settings. Otherwise the operation requires an appropriate + /// static conversion method on the input type. + /// The input value. + /// The converted int + [] + val inline uint: value:^T -> uint when ^T: (static member op_Explicit: ^T -> uint) and default ^T: uint + /// Converts the argument to a particular enum type. /// The input value. /// The converted enum type. diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs index 9d92d474cff..4470df289d4 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs @@ -16,6 +16,12 @@ type m [] type LanguagePrimitivesModule() = + [] + member _.CastingUint () = + let expected = 12u + let actual = uint 12 + Assert.AreEqual(expected, actual) + [] member this.CastingUnits() = let f = 2.5 diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs index 75461964f29..ecfc236088f 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs @@ -2077,6 +2077,7 @@ Microsoft.FSharp.Core.Operators: Int32 Sign[T](T) Microsoft.FSharp.Core.Operators: Int32 SizeOf[T]() Microsoft.FSharp.Core.Operators: Int32 ToInt32[T](T) Microsoft.FSharp.Core.Operators: Int32 ToInt[T](T) +Microsoft.FSharp.Core.Operators: UInt32 ToUInt[T](T) Microsoft.FSharp.Core.Operators: Int32 limitedHash[T](Int32, T) Microsoft.FSharp.Core.Operators: Int64 ToInt64[T](T) Microsoft.FSharp.Core.Operators: IntPtr ToIntPtr[T](T) diff --git a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs index 5b9b5f43888..3acb5879d89 100644 --- a/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs +++ b/tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs @@ -2077,6 +2077,7 @@ Microsoft.FSharp.Core.Operators: Int32 Sign[T](T) Microsoft.FSharp.Core.Operators: Int32 SizeOf[T]() Microsoft.FSharp.Core.Operators: Int32 ToInt32[T](T) Microsoft.FSharp.Core.Operators: Int32 ToInt[T](T) +Microsoft.FSharp.Core.Operators: UInt32 ToUInt[T](T) Microsoft.FSharp.Core.Operators: Int32 limitedHash[T](Int32, T) Microsoft.FSharp.Core.Operators: Int64 ToInt64[T](T) Microsoft.FSharp.Core.Operators: IntPtr ToIntPtr[T](T) diff --git a/tests/fsharp/Compiler/Language/UIntTests.fs b/tests/fsharp/Compiler/Language/UIntTests.fs new file mode 100644 index 00000000000..c317f96e02f --- /dev/null +++ b/tests/fsharp/Compiler/Language/UIntTests.fs @@ -0,0 +1,10 @@ +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework + +[] +module UIntTests = + let ``uint type abbreviation works`` () = + let src = "let x = uint 12" + let expectedErrors = [||] + CompilerAssert.TypeCheckWithErrors src expectedErrors \ No newline at end of file diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index 0daec217daa..66ae7d66b0b 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -59,6 +59,7 @@ +