Commit 55de4033

55de40337b6aMerged

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

Description

fix(codegen): keyword-arg constructor calls coerce arg to ctor param type

SomeClass.new(body: <expr>) lowered the kwarg expression via compile_expr directly when the ctor param's static type wasn't "poly". When the expression's runtime type was sp_RbVal (e.g. a <poly_recv>.<method> chain from compile_poly_method_call), the raw sp_RbVal flowed into a typed slot (const char *, sp_Hash *, sp_ *) and clang errored at the call site.

Route through compile_expr_for_expected_type which already handles the unbox / cast for poly->concrete transitions (.v.s, .v.i, ((sp_ *).v.p), etc.).

Closes the last hard error from #685's roundhouse real-blog compile: sp_ActionResponse_new(... body: controller.body ...) where controller is poly-typed and the resulting sp_RbVal flowed into the constructor's const char * body slot. With this and the two prior cls-method fixes (4df3cad, ea08236), all 5 original hard-error shapes are now resolved; remaining issues in the emit are link-time only (missing libsqlite3 dependency).

Tests: default 460/0/0, promote 460/0/0, optcarrot checksum 59662.

Closes #685

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

Details

Commit
55de40337b6a
Parent
50106f3cc3dc

spinel_codegen.rbmodifiedView file

@@ -26091,7 +26091,14 @@
2609126091 if pt == "poly"
2609226092 result = result + box_expr_to_poly(expr_id)
2609326093 else
26094- result = result + compile_expr(expr_id)
26094+ # Route through compile_expr_for_expected_type so a kwarg
26095+ # whose expression returns sp_RbVal (poly dispatch from a
26096+ # `<poly_recv>.<method>` chain) gets unboxed to the ctor
26097+ # param's expected concrete type. Without this, the raw
26098+ # sp_RbVal flows into a `const char *` slot and clang
26099+ # errors at the call site (#685, ActionResponse.new(body:
26100+ # controller.body) where controller is poly-typed).
26101+ result = result + compile_expr_for_expected_type(expr_id, pt)
2609526102 end
2609626103 found = 1
2609726104 end