Skip to content

Commit 37a8f92

Browse files
cartermpbaronfel
authored andcommitted
[RFC 1082] - uint type abbreviation (#8185)
* Add uint type abbreviation * Add uint casting function and test * Update surface area tests * update
1 parent d6d7727 commit 37a8f92

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

src/fsharp/FSharp.Core/prim-types-prelude.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace Microsoft.FSharp.Core
2828
type bool = System.Boolean
2929
type decimal = System.Decimal
3030
type int = int32
31+
type uint = uint32
3132

3233
type ``[]``<'T> = (# "!0[]" #)
3334
type ``[,]``<'T> = (# "!0[0 ...,0 ...]" #)

src/fsharp/FSharp.Core/prim-types-prelude.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ namespace Microsoft.FSharp.Core
7878
/// <summary>An abbreviation for the CLI type <c>System.Int32</c>.</summary>
7979
type int = int32
8080

81+
/// <summary>An abbreviation for the CLI type <c>System.UInt32</c>.</summary>
82+
type uint = uint32
83+
8184
/// <summary>Single dimensional, zero-based arrays, written <c>int[]</c>, <c>string[]</c> etc.</summary>
8285
/// <remarks>Use the values in the <c>Array</c> module to manipulate values
8386
/// of this type, or the notation <c>arr.[x]</c> to get/set array

src/fsharp/FSharp.Core/prim-types.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3731,7 +3731,10 @@ namespace Microsoft.FSharp.Core
37313731
when ^T : byte = (# "conv.i4" value : int32 #)
37323732

37333733
[<CompiledName("ToInt")>]
3734-
let inline int value = int32 value
3734+
let inline int value = int32 value
3735+
3736+
[<CompiledName("ToUInt")>]
3737+
let inline uint value = uint32 value
37353738

37363739
[<CompiledName("ToEnum")>]
37373740
let inline enum< ^T when ^T : enum<int32> > (value:int32) : ^T = EnumOfValue value

src/fsharp/FSharp.Core/prim-types.fsi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,15 @@ namespace Microsoft.FSharp.Core
26392639
[<CompiledName("ToInt")>]
26402640
val inline int : value:^T -> int when ^T : (static member op_Explicit : ^T -> int) and default ^T : int
26412641

2642+
/// <summary>Converts the argument to an unsigned 32-bit integer. This is a direct conversion for all
2643+
/// primitive numeric types. For strings, the input is converted using <c>UInt32.Parse()</c>
2644+
/// with InvariantCulture settings. Otherwise the operation requires an appropriate
2645+
/// static conversion method on the input type.</summary>
2646+
/// <param name="value">The input value.</param>
2647+
/// <returns>The converted int</returns>
2648+
[<CompiledName("ToUInt")>]
2649+
val inline uint: value:^T -> uint when ^T: (static member op_Explicit: ^T -> uint) and default ^T: uint
2650+
26422651
/// <summary>Converts the argument to a particular enum type.</summary>
26432652
/// <param name="value">The input value.</param>
26442653
/// <returns>The converted enum type.</returns>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace FSharp.Compiler.UnitTests
2+
3+
open NUnit.Framework
4+
5+
[<TestFixture>]
6+
module UIntTests =
7+
let ``uint type abbreviation works`` () =
8+
let src = "let x = uint 12"
9+
let expectedErrors = [||]
10+
CompilerAssert.TypeCheckWithErrors src expectedErrors

0 commit comments

Comments
 (0)