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>
This commit is contained in:
parent
7d7886b729
commit
1182216381
4 changed files with 30 additions and 15 deletions
|
|
@ -1,29 +1,21 @@
|
|||
discard """
|
||||
output: '''
|
||||
1
|
||||
0
|
||||
0
|
||||
'''
|
||||
"""
|
||||
{.experimental: "notnil".}
|
||||
type
|
||||
MyPointer = distinct pointer
|
||||
MyString = distinct string
|
||||
MyInt = distinct int
|
||||
|
||||
proc foo(a: MyPointer) =
|
||||
proc foo(a: MyPointer): int =
|
||||
# workaround a Windows 'repr' difference:
|
||||
echo cast[int](a)
|
||||
cast[int](a)
|
||||
|
||||
foo(cast[MyPointer](1))
|
||||
foo(cast[MyPointer](nil))
|
||||
foo(nil)
|
||||
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
|
||||
p = nil
|
||||
|
||||
var i: MyInt
|
||||
i = 1.MyInt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue