summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-12-02 20:02:42 +0100
committerAraq <rumpf_a@web.de>2012-12-02 20:02:42 +0100
commit8948a97151fc000414aee7cd4064881ef646a26c (patch)
tree89b5deb1448d0281028f3a02ca28ee11dec09f25 /compiler
parent0916137287b1d1468810f0ad4cf638eed5436f5e (diff)
downloadNim-8948a97151fc000414aee7cd4064881ef646a26c.tar.gz
bugfix: 'not nil' and 'shared' types
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/semtypes.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 9efeba5b7..6478c1ec6 100755
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -787,6 +787,12 @@ proc semTypeExpr(c: PContext, n: PNode): PType =
   else:
     LocalError(n.info, errTypeExpected, n.renderTree)
 
+proc freshType(res, prev: PType): PType {.inline.} =
+  if prev.isNil:
+    result = copyType(result, result.owner, keepId=false)
+  else:
+    result = res
+
 proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
   result = nil
   if gCmd == cmdIdeTools: suggestExpr(c, n)
@@ -825,7 +831,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
         checkSonsLen(n, 3)
         result = semTypeNode(c, n.sons[1], prev)
         if result.kind in NilableTypes and n.sons[2].kind == nkNilLit:
-          # XXX this is wrong for tyString at least
+          result = freshType(result, prev)
           result.flags.incl(tfNotNil)
         else:
           LocalError(n.info, errGenerated, "invalid type")
@@ -920,6 +926,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
   of nkSharedTy:
     checkSonsLen(n, 1)
     result = semTypeNode(c, n.sons[0], prev)
+    result = freshType(result, prev)
     result.flags.incl(tfShared)
   else:
     LocalError(n.info, errTypeExpected)