summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-12-22 09:13:22 +0100
committerAndreas Rumpf <rumpf_a@web.de>2016-12-22 09:13:22 +0100
commit7bd473c59b9c54aca18b85efd78d484e0306c7be (patch)
treedcfc2e95a9127e487736cb35d38824388023519d
parent4e481cc316229436b87aaf035d70f686d0aaee5f (diff)
downloadNim-7bd473c59b9c54aca18b85efd78d484e0306c7be.tar.gz
fixes #5137
-rw-r--r--compiler/ccgtypes.nim33
-rw-r--r--tests/ccgbugs/tcodegenbug1.nim9
2 files changed, 28 insertions, 14 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index fa0d20509..914368423 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -122,18 +122,27 @@ proc typeName(typ: PType): Rope =
            else:
              ~"TY"
 
+const
+  irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation,
+                          tyDistinct, tyRange, tyStatic, tyAlias}
+
 proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
-  let typ = if typ.kind == tyAlias: typ.lastSon else: typ
-  if typ.sym != nil and {sfImportc, sfExportc} * typ.sym.flags != {}:
-    result = typ.sym.loc.r
-  else:
-    if typ.loc.r == nil:
-      typ.loc.r = typ.typeName & $sig
+  var typ = typ
+  while true:
+    if typ.sym != nil and {sfImportc, sfExportc} * typ.sym.flags != {}:
+      return typ.sym.loc.r
+
+    if typ.kind in irrelevantForBackend:
+      typ = typ.lastSon
     else:
-      when defined(debugSigHashes):
-        # check consistency:
-        assert($typ.loc.r == $(typ.typeName & $sig))
-    result = typ.loc.r
+      break
+  if typ.loc.r == nil:
+    typ.loc.r = typ.typeName & $sig
+  else:
+    when defined(debugSigHashes):
+      # check consistency:
+      assert($typ.loc.r == $(typ.typeName & $sig))
+  result = typ.loc.r
   if result == nil: internalError("getTypeName: " & $typ.kind)
 
 proc mapSetType(typ: PType): TCTypeKind =
@@ -574,10 +583,6 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType =
       result = if result.kind == tyGenericInst: result.sons[1]
                else: result.elemType
 
-const
-  irrelevantForBackend = {tyGenericBody, tyGenericInst, tyGenericInvocation,
-                          tyDistinct, tyRange, tyStatic, tyAlias}
-
 proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
   # returns only the type's name
   var t = origTyp.skipTypes(irrelevantForBackend)
diff --git a/tests/ccgbugs/tcodegenbug1.nim b/tests/ccgbugs/tcodegenbug1.nim
index a5cfc77cc..671974087 100644
--- a/tests/ccgbugs/tcodegenbug1.nim
+++ b/tests/ccgbugs/tcodegenbug1.nim
@@ -65,3 +65,12 @@ type
 
 # have a proc taking TFlags as param and returning object having TFlags field
 proc foo(flags: TFlags): TObj = nil
+
+
+# bug #5137
+type
+  MyInt {.importc: "int".} = object
+  MyIntDistinct = distinct MyInt
+
+proc bug5137(d: MyIntDistinct) =
+  discard d.MyInt