Skip to content

Commit

Permalink
fix tests/vm/tcastint.nim which used non-sensical `when defined nimVM…
Browse files Browse the repository at this point in the history
…` (and contained wrong tests) (nim-lang#17954)
  • Loading branch information
timotheecour authored May 7, 2021
1 parent fb677bf commit 6ab911a
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tests/vm/tcastint.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import macros

from stdtest/testutils import disableVM
type
Dollar = distinct int
XCoord = distinct int32
Expand All @@ -11,6 +11,12 @@ proc `==`(x, y: XCoord): bool {.borrow.}

proc dummy[T](x: T): T = x

template roundTrip(a, T) =
let a2 = a # sideeffect safe
let b = cast[T](a2)
let c = cast[type(a2)](b)
doAssert c == a2

proc test() =
let U8 = 0b1011_0010'u8
let I8 = 0b1011_0010'i8
Expand Down Expand Up @@ -98,17 +104,21 @@ proc test() =
doAssert(cast[int](digit) == raw)
doAssert(cast[Digit](raw) == digit)

when defined nimvm:
doAssert(not compiles(cast[float](I64A)))
doAssert(not compiles(cast[float32](I64A)))

doAssert(not compiles(cast[char](I64A)))
doAssert(not compiles(cast[uint16](I64A)))
doAssert(not compiles(cast[uint32](I64A)))
block:
roundTrip(I64A, float)
roundTrip(I8, uint16)
roundTrip(I8, uint32)
roundTrip(I8, uint64)
doAssert cast[uint16](I8) == 65458'u16
doAssert cast[uint32](I8) == 4294967218'u32
doAssert cast[uint64](I8) == 18446744073709551538'u64
doAssert cast[uint32](I64A) == 2571663889'u32
doAssert cast[uint16](I64A) == 31249
doAssert cast[char](I64A).ord == 17
doAssert compiles(cast[float32](I64A))

doAssert(not compiles(cast[uint16](I8)))
doAssert(not compiles(cast[uint32](I8)))
doAssert(not compiles(cast[uint64](I8)))
disableVM: # xxx Error: VM does not support 'cast' from tyInt64 to tyFloat32
doAssert cast[uint32](cast[float32](I64A)) == 2571663889'u32

const prerecordedResults = [
# cast to char
Expand Down

0 comments on commit 6ab911a

Please sign in to comment.