summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAdam Strzelecki <ono@java.pl>2015-09-06 20:03:38 +0200
committerAdam Strzelecki <ono@java.pl>2015-09-06 20:17:06 +0200
commit167acf453039263fa46a21e7967cec7b5ef39c2f (patch)
tree71179f61e41cea8c5900ccc0e33d8dcaf4727278
parentd7996a9edef4d8c51466495696bd2c0a3a2c03be (diff)
downloadNim-167acf453039263fa46a21e7967cec7b5ef39c2f.tar.gz
typeToString: Fix shared/not nil on complex types
Previously `not nil` flag was not shown on `cstring or nil` or `PType not nil`,
where `type PType = ref Type`, eg. when showing compiler diagnostics.
-rw-r--r--compiler/types.nim17
1 files changed, 11 insertions, 6 deletions
diff --git a/compiler/types.nim b/compiler/types.nim
index af103bc3c..5f3a74aca 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -411,6 +411,10 @@ const
 
 const preferToResolveSymbols = {preferName, preferModuleInfo, preferGenericArg}
 
+proc addTypeFlags(name: var string, typ: PType) {.inline.} =
+  if tfShared in typ.flags: name = "shared " & name
+  if tfNotNil in typ.flags: name.add(" not nil")
+
 proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
   var t = typ
   result = ""
@@ -418,11 +422,13 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
   if prefer in preferToResolveSymbols and t.sym != nil and
        sfAnon notin t.sym.flags:
     if t.kind == tyInt and isIntLit(t):
-      return t.sym.name.s & " literal(" & $t.n.intVal & ")"
-    if prefer == preferName or t.sym.owner.isNil:
-      return t.sym.name.s
+      result = t.sym.name.s & " literal(" & $t.n.intVal & ")"
+    elif prefer == preferName or t.sym.owner.isNil:
+      result = t.sym.name.s
     else:
-      return t.sym.owner.name.s & '.' & t.sym.name.s
+      result = t.sym.owner.name.s & '.' & t.sym.name.s
+    result.addTypeFlags(t)
+    return
   case t.kind
   of tyInt:
     if not isIntLit(t) or prefer == preferExported:
@@ -563,8 +569,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
     result = typeToStr[t.kind] % typeToString(t.sons[0])
   else:
     result = typeToStr[t.kind]
-  if tfShared in t.flags: result = "shared " & result
-  if tfNotNil in t.flags: result.add(" not nil")
+  result.addTypeFlags(t)
 
 proc resultType(t: PType): PType =
   assert(t.kind == tyProc)