Commit a9123df6

a9123df66e21Merged

Yusuke Endoh <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified

Description

fix(codegen): scope class-body bare-call return inference to no-recv

`infer_call_type` had a fallback at the end that used `cls_method_return(@current_class_idx, mname)` whenever `@current_class_idx` was set, regardless of whether the call actually had a receiver. `Fiber.yield true` inside a class body would hit this branch first, find no "yield" method on the enclosing class, fall back to the default "int", and the `mname == "yield" && recv >= 0 -> poly` branch later in the function never ran.

Symptom in optcarrot: `def wait_frame; Fiber.yield true; end` inside PPU emitted `mrb_int sp_PPU_wait_frame(...)` but the body returned a sp_RbVal — gcc rejected the body with "incompatible types when returning sp_RbVal".

Gate the fallback on `recv < 0`. Same-class self calls are no-recv, so they still resolve here; calls with an explicit receiver fall through to the receiver-aware branches below.

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
a9123df66e21
Parent
bee7e89d5b64

spinel_codegen.rbmodifiedView file

@@ -1885,8 +1885,12 @@
18851885 return @meth_return_types[mi]
18861886 end
18871887
1888- # Bare method call in class context
1889- if @current_class_idx >= 0
1888+ # Bare (no-receiver) method call resolved against the enclosing
1889+ # class's method table. Only for `recv < 0` — without that guard,
1890+ # a `Fiber.yield ...` (which has a receiver) inside a class body
1891+ # would short-circuit here returning the int default and never
1892+ # reach the Fiber.yield → poly branch further down.
1893+ if recv < 0 && @current_class_idx >= 0
18901894 mr = cls_method_return(@current_class_idx, mname)
18911895 return mr
18921896 end