summary refs log blame commit diff stats
path: root/tests/notnil/tnotnil1.nim
blob: 7f9d0229582dd42299aba5088f7bbc2598d03366 (plain) (tree)
1
2
3
4
5
6
7

                                 
         


               
                          




               







                              
                                



                                     
                            
         


                

                 
 






                 
discard """
  errormsg: "'y' is provably nil"
  line:38
"""

import strutils
{.experimental: "notnil".}

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) =
  discard

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

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

p()