forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 14127 js from int to int casting (nim-lang#15918)
* fix nim-lang#14127 from int to int casting * add test for nim-lang#14127 * use template for test, also test uint2int * move to tests/types/t14127_cast_number.nim targets:c cpp js
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
discard """ | ||
targets: "c cpp js" | ||
""" | ||
block: # bug #14127 | ||
template int2uint(T) = | ||
var a = -1 | ||
let b = cast[T](a) | ||
doAssert b < 0 | ||
let c = b + 1 | ||
doAssert c is T | ||
doAssert c == 0 | ||
|
||
int2uint(int8) | ||
int2uint(int16) | ||
int2uint(int32) | ||
int2uint(int64) | ||
|
||
block: # maybe related | ||
template uint2int(T) = | ||
var a = 3 | ||
let b = cast[T](a) | ||
doAssert b > 0 | ||
let c = b - 1 | ||
doAssert c is T | ||
doAssert c == 2 | ||
|
||
uint2int(uint8) | ||
uint2int(uint16) | ||
uint2int(uint32) | ||
uint2int(uint64) |