summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2019-12-06 08:56:54 +0000
committerAndreas Rumpf <rumpf_a@web.de>2019-12-06 09:56:54 +0100
commit7213969901a4232013a6e6732d7b434970922510 (patch)
treebfc275eba678c10040345b43fbed38197d1db144 /compiler
parent1db21721ec816e01ef91633941e0295f7724e1f7 (diff)
downloadNim-7213969901a4232013a6e6732d7b434970922510.tar.gz
fixes #12821 (#12822)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/enumtostr.nim15
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/enumtostr.nim b/compiler/enumtostr.nim
index 35bf64a49..42d844609 100644
--- a/compiler/enumtostr.nim
+++ b/compiler/enumtostr.nim
@@ -41,20 +41,26 @@ proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph): PSym =
   result.ast = n
   incl result.flags, sfFromGeneric
 
-proc searchObjCase(obj: PNode; field: PSym): PNode =
+proc searchObjCaseImpl(obj: PNode; field: PSym): PNode =
   case obj.kind
   of nkSym:
     result = nil
   of nkElse, nkOfBranch:
-    result = searchObjCase(obj.lastSon, field)
+    result = searchObjCaseImpl(obj.lastSon, field)
   else:
     if obj.kind == nkRecCase and obj[0].kind == nkSym and obj[0].sym == field:
       result = obj
     else:
       for x in obj:
-        result = searchObjCase(x, field)
+        result = searchObjCaseImpl(x, field)
         if result != nil: break
 
+proc searchObjCase(t: PType; field: PSym): PNode =
+  result = searchObjCaseImpl(t.n, field)
+  if result == nil and t.len > 0:
+    result = searchObjCase(t[0].skipTypes({tyAlias, tyGenericInst, tyRef, tyPtr}), field)
+  doAssert result != nil
+
 proc genCaseObjDiscMapping*(t: PType; field: PSym; info: TLineInfo; g: ModuleGraph): PSym =
   result = newSym(skProc, getIdent(g.cache, "objDiscMapping"), t.owner, info)
 
@@ -75,8 +81,7 @@ proc genCaseObjDiscMapping*(t: PType; field: PSym; info: TLineInfo; g: ModuleGra
   var caseStmt = newNodeI(nkCaseStmt, info)
   caseStmt.add(newSymNode dest)
 
-  let subObj = searchObjCase(t.n, field)
-  doAssert subObj != nil
+  let subObj = searchObjCase(t, field)
   for i in 1..<subObj.len:
     let ofBranch = subObj[i]
     var newBranch = newNodeI(ofBranch.kind, ofBranch.info)