summary refs log tree commit diff stats
path: root/tests/distinct/tnil.nim
blob: 5bdb97f375293f423608615ad536c7fc0b2728fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
discard """
output: '''
1
0
0
'''
"""
{.experimental: "notnil".}
type
  MyPointer = distinct pointer
  MyString = distinct string
  MyInt = distinct int

proc foo(a: MyPointer) =
  # workaround a Windows 'repr' difference:
  echo cast[int](a)

foo(cast[MyPointer](1))
foo(cast[MyPointer](nil))
foo(nil)

var p: MyPointer
p = cast[MyPointer](1)
p = cast[MyPointer](nil)
p = nil.MyPointer
p = nil

var i: MyInt
i = 1.MyInt
doAssert(compiles(i = nil) == false)