mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 09:54:49 +00:00
* 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>
23 lines
465 B
Nim
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)
|