diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 243aa87ded9d1..23e16cb934977 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -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: diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 83d205bc29887..2f5e202e0c8a5 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -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)]) diff --git a/compiler/semfields.nim b/compiler/semfields.nim index 07321f4778ef6..d65d962cb93f0 100644 --- a/compiler/semfields.nim +++ b/compiler/semfields.nim @@ -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: diff --git a/lib/system.nim b/lib/system.nim index c68eba2e08827..ab347d0220653 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -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,) diff --git a/tests/objects/t3734.nim b/tests/objects/t3734.nim new file mode 100644 index 0000000000000..cebef60811bdf --- /dev/null +++ b/tests/objects/t3734.nim @@ -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)