summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <cdome@bk.ru>2018-10-11 08:54:50 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-10-11 09:54:50 +0200
commit7a5b614edc148a2b8fafecacecd6949a0744e8b3 (patch)
treec362cc8a84e06eeffc53a3bebc17cfd2edc380d5
parenta58c982a494fbc8712067828f53b5c58ab6b3279 (diff)
downloadNim-7a5b614edc148a2b8fafecacecd6949a0744e8b3.tar.gz
fixes #9297 (#9298)
* fixes #9297

* improve spacing
-rw-r--r--compiler/ccgstmts.nim2
-rw-r--r--compiler/ccgtypes.nim7
-rw-r--r--compiler/semtypes.nim10
-rw-r--r--tests/ccgbugs/tcgbug.nim42
4 files changed, 50 insertions, 11 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index df8f95b75..6c2e8ebc8 100644
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -71,7 +71,7 @@ proc genVarTuple(p: BProc, n: PNode) =
       field.r = "$1.Field$2" % [rdLoc(tup), rope(i)]
     else:
       if t.n.sons[i].kind != nkSym: internalError(p.config, n.info, "genVarTuple")
-      field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym, t)]
+      field.r = "$1.$2" % [rdLoc(tup), mangleRecFieldName(p.module, t.n.sons[i].sym)]
     putLocIntoDest(p, v.loc, field)
 
 proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false)
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 3420a893d..985178f90 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -430,9 +430,8 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope,
   else: add(params, ")")
   params = "(" & params
 
-proc mangleRecFieldName(m: BModule; field: PSym, rectype: PType): Rope =
-  if (rectype.sym != nil) and
-      ({sfImportc, sfExportc} * rectype.sym.flags != {}):
+proc mangleRecFieldName(m: BModule; field: PSym): Rope =
+  if {sfImportc, sfExportc} * field.flags != {}:
     result = field.loc.r
   else:
     result = rope(mangleField(m, field.name))
@@ -484,7 +483,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
     let field = n.sym
     if field.typ.kind == tyVoid: return
     #assert(field.ast == nil)
-    let sname = mangleRecFieldName(m, field, rectype)
+    let sname = mangleRecFieldName(m, field)
     let ae = if accessExpr != nil: "$1.$2" % [accessExpr, sname]
              else: sname
     fillLoc(field.loc, locField, n, ae, OnUnknown)
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index a96b46baa..f35a7d5cd 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -587,12 +587,12 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
     checkForOverlap(c, t, i, branchIndex)
 
 proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
-                      father: PNode, rectype: PType)
+                      father: PNode, rectype: PType, hasCaseFields = false)
 proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
                    father: PNode, rectype: PType) =
   var a = copyNode(n)
   checkMinSonsLen(n, 2, c.config)
-  semRecordNodeAux(c, n.sons[0], check, pos, a, rectype)
+  semRecordNodeAux(c, n.sons[0], check, pos, a, rectype, hasCaseFields = true)
   if a.sons[0].kind != nkSym:
     internalError(c.config, "semRecordCase: discriminant is no symbol")
     return
@@ -619,13 +619,13 @@ proc semRecordCase(c: PContext, n: PNode, check: var IntSet, pos: var int,
       checkSonsLen(b, 1, c.config)
     else: illFormedAst(n, c.config)
     delSon(b, sonsLen(b) - 1)
-    semRecordNodeAux(c, lastSon(n.sons[i]), check, pos, b, rectype)
+    semRecordNodeAux(c, lastSon(n.sons[i]), check, pos, b, rectype, hasCaseFields = true)
   if chckCovered and covered != lengthOrd(c.config, a.sons[0].typ):
     localError(c.config, a.info, "not all cases are covered")
   addSon(father, a)
 
 proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
-                      father: PNode, rectype: PType) =
+                      father: PNode, rectype: PType, hasCaseFields = false) =
   if n == nil: return
   case n.kind
   of nkRecWhen:
@@ -694,7 +694,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
       f.position = pos
       if fieldOwner != nil and
          {sfImportc, sfExportc} * fieldOwner.flags != {} and
-         f.loc.r == nil:
+         not hasCaseFields and f.loc.r == nil:
         f.loc.r = rope(f.name.s)
         f.flags = f.flags + ({sfImportc, sfExportc} * fieldOwner.flags)
       inc(pos)
diff --git a/tests/ccgbugs/tcgbug.nim b/tests/ccgbugs/tcgbug.nim
index 1c6466c87..ffaa91ff3 100644
--- a/tests/ccgbugs/tcgbug.nim
+++ b/tests/ccgbugs/tcgbug.nim
@@ -1,6 +1,8 @@
 discard """
   file: "tcgbug.nim"
-  output: "success"
+  output: '''success
+M1 M2
+'''
 """
 
 type
@@ -36,3 +38,41 @@ type
 
 var k = PFuture[void]()
 
+
+##bug #9297
+import strutils
+
+type
+  MyKind = enum
+    M1, M2, M3
+
+  MyObject {.exportc: "ExtObject"} = object
+    case kind: MyKind
+      of M1: a:int
+      of M2: b:float
+      of M3: c:cstring
+
+  MyObjectRef {.exportc: "ExtObject2"} = ref object
+    case kind: MyKind
+      of M1: a:int
+      of M2: b:float
+      of M3: c:cstring
+
+proc newMyObject(kind: MyKind, val: string): MyObject =
+  result.kind = kind
+
+  case kind
+    of M1: result.a = parseInt(val)
+    of M2: result.b = parseFloat(val)
+    of M3: result.c = val
+
+proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
+  new(result)
+  result.kind = kind
+  case kind
+    of M1: result.a = parseInt(val)
+    of M2: result.b = parseFloat(val)
+    of M3: result.c = val
+
+ 
+echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
\ No newline at end of file