void object fields are now ignored by codegen and fields/fieldPairs iterator (#10144)
* Codegen now ignores object fields of type void * Fix `$` bug for objects/tuples where it does not add a comma * fields/fieldPairs iterators now ignore void types * Use `isEmptyType` instead of checking for `tyVoid` directly
This commit is contained in:
parent
6389271d1c
commit
d998cb58dd
5 changed files with 25 additions and 0 deletions
|
|
@ -1041,6 +1041,8 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
|
||||||
else: internalError(m.config, n.info, "genObjectFields(nkRecCase)")
|
else: internalError(m.config, n.info, "genObjectFields(nkRecCase)")
|
||||||
of nkSym:
|
of nkSym:
|
||||||
var field = n.sym
|
var field = n.sym
|
||||||
|
# Do not produce code for void types
|
||||||
|
if isEmptyType(field.typ): return
|
||||||
if field.bitsize == 0:
|
if field.bitsize == 0:
|
||||||
if field.loc.r == nil: fillObjectFields(m, typ)
|
if field.loc.r == nil: fillObjectFields(m, typ)
|
||||||
if field.loc.t == nil:
|
if field.loc.t == nil:
|
||||||
|
|
|
||||||
|
|
@ -1502,6 +1502,8 @@ proc createRecordVarAux(p: PProc, rec: PNode, excludedFieldIDs: IntSet, output:
|
||||||
for i in countup(1, sonsLen(rec) - 1):
|
for i in countup(1, sonsLen(rec) - 1):
|
||||||
createRecordVarAux(p, lastSon(rec.sons[i]), excludedFieldIDs, output)
|
createRecordVarAux(p, lastSon(rec.sons[i]), excludedFieldIDs, output)
|
||||||
of nkSym:
|
of nkSym:
|
||||||
|
# Do not produce code for void types
|
||||||
|
if isEmptyType(rec.sym.typ): return
|
||||||
if rec.sym.id notin excludedFieldIDs:
|
if rec.sym.id notin excludedFieldIDs:
|
||||||
if output.len > 0: output.add(", ")
|
if output.len > 0: output.add(", ")
|
||||||
output.addf("$#: ", [mangleName(p.module, rec.sym)])
|
output.addf("$#: ", [mangleName(p.module, rec.sym)])
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,9 @@ type
|
||||||
c: PContext
|
c: PContext
|
||||||
|
|
||||||
proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
|
proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode =
|
||||||
|
if c.field != nil and isEmptyType(c.field.typ):
|
||||||
|
result = newNode(nkEmpty)
|
||||||
|
return
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
|
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
|
||||||
of nkIdent, nkSym:
|
of nkIdent, nkSym:
|
||||||
|
|
|
||||||
|
|
@ -2700,6 +2700,7 @@ proc `$`*[T: tuple|object](x: T): string =
|
||||||
firstElement = false
|
firstElement = false
|
||||||
else:
|
else:
|
||||||
result.add("...")
|
result.add("...")
|
||||||
|
firstElement = false
|
||||||
when not isNamed:
|
when not isNamed:
|
||||||
if count == 1:
|
if count == 1:
|
||||||
result.add(",") # $(1,) should print as the semantically legal (1,)
|
result.add(",") # $(1,) should print as the semantically legal (1,)
|
||||||
|
|
|
||||||
17
tests/objects/t3734.nim
Normal file
17
tests/objects/t3734.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
discard """
|
||||||
|
output: "i0"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
Application = object
|
||||||
|
config: void
|
||||||
|
i: int
|
||||||
|
f: void
|
||||||
|
|
||||||
|
proc printFields(rec: Application) =
|
||||||
|
for k, v in fieldPairs(rec):
|
||||||
|
echo k, v
|
||||||
|
|
||||||
|
var app: Application
|
||||||
|
|
||||||
|
printFields(app)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue