Commit 67c06880

67c068808b20Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: box a concrete scalar in a poly-returning implicit-return tail

emit_tail_value emitted a poly-return tail value with a bare emit_expr, which is correct only when the node is already poly. For the implicit-return path (a method's last expression), a concrete scalar (e.g. 1 from a method widened to poly under promote) must be boxed. The explicit-return caller already boxes upstream, and an already-poly node boxes to itself, so this only adds coverage.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
67c068808b20
Parent
360eab89cf40

src/codegen_stmt.cmodifiedView file

@@ -1870,7 +1870,15 @@
18701870 any other emission (e.g. a poly-dispatch `({...})`) is passed through
18711871 unchanged. */
18721872 static void emit_tail_value(Compiler *c, int node, Buf *b) {
1873- if (g_ret_type == TY_POLY) { emit_expr(c, node, b); return; }
1873+ if (g_ret_type == TY_POLY) {
1874+ /* a poly-returning tail must yield an sp_RbVal: box a concrete scalar value
1875+ (e.g. an implicit `return 1` from a method widened under promote). The
1876+ explicit-return caller already boxes, so this only adds coverage for the
1877+ implicit-return path; a node that is already poly boxes to itself. */
1878+ if (comp_ntype(c, node) != TY_POLY) emit_boxed(c, node, b);
1879+ else emit_expr(c, node, b);
1880+ return;
1881+ }
18741882 /* An empty `{}` literal defaults to StrPolyHash, but in a hash-returning tail
18751883 it must take the return type (e.g. a SymPolyHash-returning method whose
18761884 other branch is `{ a: 1 }`); otherwise the StrPolyHash* return is an