Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core/prim-types-prelude.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...]" #)
Expand Down
3 changes: 3 additions & 0 deletions src/fsharp/FSharp.Core/prim-types-prelude.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace Microsoft.FSharp.Core
/// <summary>An abbreviation for the CLI type <c>System.Int32</c>.</summary>
type int = int32

/// <summary>An abbreviation for the CLI type <c>System.UInt32</c>.</summary>
type uint = uint32

/// <summary>Single dimensional, zero-based arrays, written <c>int[]</c>, <c>string[]</c> etc.</summary>
/// <remarks>Use the values in the <c>Array</c> module to manipulate values
/// of this type, or the notation <c>arr.[x]</c> to get/set array
Expand Down
5 changes: 4 additions & 1 deletion src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3731,7 +3731,10 @@ namespace Microsoft.FSharp.Core
when ^T : byte = (# "conv.i4" value : int32 #)

[<CompiledName("ToInt")>]
let inline int value = int32 value
let inline int value = int32 value

[<CompiledName("ToUInt")>]
let inline uint value = uint32 value

[<CompiledName("ToEnum")>]
let inline enum< ^T when ^T : enum<int32> > (value:int32) : ^T = EnumOfValue value
Expand Down
9 changes: 9 additions & 0 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,15 @@ namespace Microsoft.FSharp.Core
[<CompiledName("ToInt")>]
val inline int : value:^T -> int when ^T : (static member op_Explicit : ^T -> int) and default ^T : int

/// <summary>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 <c>UInt32.Parse()</c>
/// with InvariantCulture settings. Otherwise the operation requires an appropriate
/// static conversion method on the input type.</summary>
/// <param name="value">The input value.</param>
/// <returns>The converted int</returns>
[<CompiledName("ToUInt")>]
val inline uint: value:^T -> uint when ^T: (static member op_Explicit: ^T -> uint) and default ^T: uint

/// <summary>Converts the argument to a particular enum type.</summary>
/// <param name="value">The input value.</param>
/// <returns>The converted enum type.</returns>
Expand Down
6 changes: 6 additions & 0 deletions tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ type m
[<TestFixture>]
type LanguagePrimitivesModule() =

[<Test>]
member _.CastingUint () =
let expected = 12u
let actual = uint 12
Assert.AreEqual(expected, actual)

[<Test>]
member this.CastingUnits() =
let f = 2.5
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.coreclr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/FSharp.Core.UnitTests/SurfaceArea.net40.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/fsharp/Compiler/Language/UIntTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace FSharp.Compiler.UnitTests

open NUnit.Framework

[<TestFixture>]
module UIntTests =
let ``uint type abbreviation works`` () =
let src = "let x = uint 12"
let expectedErrors = [||]
CompilerAssert.TypeCheckWithErrors src expectedErrors
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<Compile Include="Compiler\Warnings\ExperimentalAttributeTests.fs" />
<Compile Include="Compiler\Warnings\PatternMatchingWarningTests.fs" />
<Compile Include="Compiler\SourceTextTests.fs" />
<Compile Include="Compiler\Language\UIntTests.fs" />
<Compile Include="Compiler\Language\FixedIndexSliceTests.fs" />
<Compile Include="Compiler\Language\SlicingQuotationTests.fs" />
<Compile Include="Compiler\Language\CustomCollectionTests.fs" />
Expand Down