From 96ddf6972d088e0e389840e718da7ca498129142 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 23 Nov 2017 03:12:09 +0100 Subject: [PATCH] fixes #3993 --- compiler/sempass2.nim | 3 ++- tests/notnil/tmust_compile.nim | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 051f215e0c..2bdfaea3ff 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -525,7 +525,8 @@ proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) = # addr(x[]) can't be proven, but addr(x) can: if not containsNode(n, {nkDerefExpr, nkHiddenDeref}): return elif (n.kind == nkSym and n.sym.kind in routineKinds) or - n.kind in procDefs+{nkObjConstr, nkBracket, nkClosure}: + (n.kind in procDefs+{nkObjConstr, nkBracket, nkClosure}) or + (n.kind in nkCallKinds and n[0].kind == nkSym and n[0].sym.magic == mArrToSeq): # 'p' is not nil obviously: return case impliesNotNil(tracked.guards, n) diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim index 117921a57e..10da154f00 100644 --- a/tests/notnil/tmust_compile.nim +++ b/tests/notnil/tmust_compile.nim @@ -62,3 +62,17 @@ proc parse(cts: CTS, jn: JsonNode) = proc p(x: proc(){.closure.} not nil) = discard p(proc(){.closure.} = discard) + +# bug #3993 + +type + List[T] = seq[T] not nil + +proc `^^`[T](v: T, lst: List[T]): List[T] = + result = @[v] + result.add(lst) + +proc Nil[T](): List[T] = @[] + +when isMainModule: + let lst = 1 ^^ 2 ^^ Nil[int]()