Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
else: internalError(m.config, n.info, "genObjectFields(nkRecCase)")
of nkSym:
var field = n.sym
# Do not produce code for void types
if isEmptyType(field.typ): return
if field.bitsize == 0:
if field.loc.r == nil: fillObjectFields(m, typ)
if field.loc.t == nil:
Expand Down
2 changes: 2 additions & 0 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,8 @@ proc createRecordVarAux(p: PProc, rec: PNode, excludedFieldIDs: IntSet, output:
for i in countup(1, sonsLen(rec) - 1):
createRecordVarAux(p, lastSon(rec.sons[i]), excludedFieldIDs, output)
of nkSym:
# Do not produce code for void types
if isEmptyType(rec.sym.typ): return
if rec.sym.id notin excludedFieldIDs:
if output.len > 0: output.add(", ")
output.addf("$#: ", [mangleName(p.module, rec.sym)])
Expand Down
3 changes: 3 additions & 0 deletions compiler/semfields.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type
c: PContext

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
of nkEmpty..pred(nkIdent), succ(nkSym)..nkNilLit: result = n
of nkIdent, nkSym:
Expand Down
1 change: 1 addition & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2700,6 +2700,7 @@ proc `$`*[T: tuple|object](x: T): string =
firstElement = false
else:
result.add("...")
firstElement = false
when not isNamed:
if count == 1:
result.add(",") # $(1,) should print as the semantically legal (1,)
Expand Down
17 changes: 17 additions & 0 deletions tests/objects/t3734.nim
Original file line number Diff line number Diff line change
@@ -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)