mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user