diff options
author | Araq <rumpf_a@web.de> | 2015-01-11 02:57:36 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-01-11 02:57:36 +0100 |
commit | 9dfd8fea126edd1f962694c09b1b0fbb66c20602 (patch) | |
tree | f94eb55b3505a987af5c51f26ef578af8433d583 | |
parent | fd10866ae301c43adff35ac427b6765f80689478 (diff) | |
download | Nim-9dfd8fea126edd1f962694c09b1b0fbb66c20602.tar.gz |
fixes #1901
-rw-r--r-- | compiler/ccgtypes.nim | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 460cb9297..9c26bebd8 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -392,7 +392,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, uname = toRope(mangle(n.sons[0].sym.name.s) & 'U') if accessExpr != nil: ae = ropef("$1.$2", [accessExpr, uname]) else: ae = uname - app(result, "union {" & tnl) + var unionBody: PRope = nil for i in countup(1, sonsLen(n) - 1): case n.sons[i].kind of nkOfBranch, nkElse: @@ -402,13 +402,14 @@ proc genRecordFieldsAux(m: BModule, n: PNode, a = genRecordFieldsAux(m, k, ropef("$1.$2", [ae, sname]), rectype, check) if a != nil: - app(result, "struct {") - app(result, a) - appf(result, "} $1;$n", [sname]) - else: - app(result, genRecordFieldsAux(m, k, ae, rectype, check)) + app(unionBody, "struct {") + app(unionBody, a) + appf(unionBody, "} $1;$n", [sname]) + else: + app(unionBody, genRecordFieldsAux(m, k, ae, rectype, check)) else: internalError("genRecordFieldsAux(record case branch)") - appf(result, "} $1;$n", [uname]) + if unionBody != nil: + appf(result, "union{$n$1} $2;$n", [unionBody, uname]) of nkSym: field = n.sym if field.typ.kind == tyEmpty: return |