summary refs log tree commit diff stats
path: root/tests/notnil/tnotnil1.nim
blob: 73472752c78dc2a500e7d43cc7a43d384c05b1c4 (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
discard """
  errormsg: "'y' is provably nil"
  line:38
"""

import strutils


type
  TObj = object
    x, y: int

type
  superstring = string not nil


proc q(s: superstring) =
  echo s

proc p2() =
  var  a: string = "I am not nil"
  q(a) # but this should and does not

p2()

proc q(x: pointer not nil) =
  nil

proc p() =
  var x: pointer
  if not x.isNil:
    q(x)

  let y = x
  if not y.isNil:
    q(y)
  else:
    q(y)

p()