From e4b1d8eebcbb176ad0dad509b5b0039fe10de287 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 6 Mar 2026 06:08:51 +0800 Subject: [PATCH] fix #25508; ignores void types in the backends (#25550) fix #25508 --- compiler/ccgexprs.nim | 11 ++++++++++- compiler/ccgtypes.nim | 25 +++++++++++++++++++------ compiler/jsgen.nim | 6 +++++- tests/typerel/tvoid.nim | 5 +++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 11fe0673f3..9f2ac2ff9b 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -216,6 +216,8 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = flags let t = skipTypes(dest.t, abstractInst).getUniqueType() for i, t in t.ikids: + # Do not produce code for void types + if isEmptyType(t): continue let field = "Field$1" % [i.rope] genAssignment(p, optAsgnLoc(dest, t, field), optAsgnLoc(src, t, field), newflags) @@ -3207,6 +3209,8 @@ proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) = for i in 0.. 0: + var tmp = getTempName(m) & "_" & $nonVoidKids + genTNimNodeArray(m, tmp, nonVoidKids) + var j = 0 for i, a in typ.ikids: + # Do not produce code for void types + if isEmptyType(a): continue var tmp2 = getNimNode(m) let fieldTypInfo = genTypeInfoV1(m, a, info) - m.s[cfsTypeInit3].addSubscriptAssignment(tmp, cIntValue(i), cAddr(tmp2)) + m.s[cfsTypeInit3].addSubscriptAssignment(tmp, cIntValue(j), cAddr(tmp2)) m.s[cfsTypeInit3].addFieldAssignment(tmp2, "kind", 1) m.s[cfsTypeInit3].addFieldAssignmentWithValue(tmp2, "offset"): m.s[cfsTypeInit3].addOffsetof(getTypeDesc(m, origType, dkVar), "Field" & $i) m.s[cfsTypeInit3].addFieldAssignment(tmp2, "typ", fieldTypInfo) m.s[cfsTypeInit3].addFieldAssignment(tmp2, "name", "\"Field" & $i & "\"") - m.s[cfsTypeInit3].addFieldAssignment(expr, "len", typ.kidsLen) + inc j + m.s[cfsTypeInit3].addFieldAssignment(expr, "len", nonVoidKids) m.s[cfsTypeInit3].addFieldAssignment(expr, "kind", 2) m.s[cfsTypeInit3].addFieldAssignment(expr, "sons", cAddr(subscript(tmp, cIntValue(0)))) else: - m.s[cfsTypeInit3].addFieldAssignment(expr, "len", typ.kidsLen) + m.s[cfsTypeInit3].addFieldAssignment(expr, "len", cIntValue(0)) m.s[cfsTypeInit3].addFieldAssignment(expr, "kind", 2) m.s[cfsTypeInit3].addFieldAssignment(tiNameForHcr(m, name), "node", cAddr(expr)) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 99582b0fd6..98153490df 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2018,8 +2018,12 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope = if indirect: result = "[$1]" % [result] of tyTuple: result = rope("{") + var first = true for i in 0.. 0: result.add(", ") + # Do not produce code for void types + if isEmptyType(t[i]): continue + if not first: result.add(", ") + first = false result.addf("Field$1: $2", [i.rope, createVar(p, t[i], false)]) result.add("}") diff --git a/tests/typerel/tvoid.nim b/tests/typerel/tvoid.nim index 8bb5691b88..e00f34168d 100644 --- a/tests/typerel/tvoid.nim +++ b/tests/typerel/tvoid.nim @@ -4,6 +4,7 @@ empty he, no return type; abc a string ha''' + target: "c js" """ proc ReturnT[T](x: T): T = @@ -96,3 +97,7 @@ block: # typeof(stmt) block: template bad2 = echo (nonexistent; discard) doAssert not compiles(bad2()) + +block: + discard default(tuple[b: void]) + discard default((void,))