Commit 0693c84d
0693c84d88d4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Emit the return-type default for a bare return in a foreign-obj method
A bare return emitted return self whenever the method's inferred
return type was any obj class (with self in scope). When inference
types the return as a class DIFFERENT from self -- e.g. a side-effect
method whose last expression is x.attr = Other.new -- return self
returns self's type into the other class's pointer slot
(incompatible-pointer-types). A recent return-type-inference change
surfaced this: bm_ao_render's Plane#intersect is typed sp_Vec * (its
tail is isect.pl = Vec.new(...)) but its bare return emitted
return self (a Plane). A bare return is Ruby nil, so emit the type
default (NULL) unless the return type is actually self's own class
(the constructor / returns-self case).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 0693c84d88d4
- Parent
- 8e272bd092cb
spinel_codegen.rbmodifiedView file
# functions don't have self; their bare returns fall through # to `c_return_default` (value-type classes get # `(sp_<C>){0}`, pointer-typed obj returns get NULL). if @current_method_has_self == 1 # Only return `self` when the method's return type is actually # self's own class (the constructor-synthesis / returns-self case). # When inference typed the return as a DIFFERENT obj class (e.g. a # side-effect method whose last expression is `x.attr = Other.new`), # `return self` would return self's type into the other class's slot # (incompatible-pointer-types). A bare `return` is Ruby nil, so emit # the type default (NULL) there. if @current_method_has_self == 1 && @current_class_idx >= 0 && @current_method_return == "obj_" + @cls_names[@current_class_idx] emit(" return self;") else emit(" return " + c_return_default(@current_method_return) + ";")