Files
Nim/tests/distinct/tnil.nim
ringabout 1182216381 remove a special case in sigmatch; distinct pointer types no longer match nil type (#20251)
* remove a special case in sigmatch; distinct pointer types no longer match `nil` type

* add tests

* fixes tests

* Update changelog.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-08-23 19:27:20 +02:00

23 lines
465 B
Nim

{.experimental: "notnil".}
type
MyPointer = distinct pointer
MyString = distinct string
MyInt = distinct int
proc foo(a: MyPointer): int =
# workaround a Windows 'repr' difference:
cast[int](a)
doAssert foo(cast[MyPointer](1)) == 1
doAssert foo(cast[MyPointer](nil)) == 0
doAssert foo(MyPointer(nil)) == 0
var p: MyPointer
p = cast[MyPointer](1)
p = cast[MyPointer](nil)
p = nil.MyPointer
var i: MyInt
i = 1.MyInt
doAssert(compiles(i = nil) == false)