summary refs log tree commit diff stats
path: root/tests/distinct/tnil.nim
blob: ed0ac995a094339d84a1b678eb99d150a39cc4e7 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
discard """
  file: "tnil.nim"
  output: '''0x1

nil

nil

'''
"""

type
  MyPointer = distinct pointer
  MyString = distinct string
  MyStringNotNil = distinct (string not nil)
  MyInt = distinct int

proc foo(a: MyPointer) =
  echo a.repr

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 c: MyString
c = "Test".MyString
c = nil.MyString
c = nil

p = nil
doAssert(compiles(c = p) == false)

var n: MyStringNotNil = "Test".MyStringNotNil # Cannot prove warning ...
n = "Test".MyStringNotNil
doAssert(compiles(n = nil.MyStringNotNil) == false)
doAssert(compiles(n = nil.MyStringNotNil) == false)
doAssert(compiles(n = nil) == false)

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