Commit e7bbaf3e
e7bbaf3efdd4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): dispatch nullable receivers as their base type
compile_call_expr compared recv_type strictly against "string",
"mutable_str", etc. A local widened to a nullable variant via
def f(file_path = nil) later being passed a string ("nil + string"
→ "string?" via detect_poly_in_node) missed every per-type dispatcher
and fell through to the "0" fallback at the bottom of compile_call_expr.
Strip the ? from recv_type once after the early constructor /
operator / fiber dispatch. The null check is the caller's
responsibility, matching Ruby's NoMethodError on a nil receiver. The
is_obj_type dispatcher already operates this way (it accepts both
obj_T and obj_T? and uses base_type internally).
Add test/optional_string_param_method.rb covering the issue's exact
shape plus the alternate branches (file_path absent, longer source).
Closes #60
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- e7bbaf3efdd4
- Parent
- d06c99ef5a0f
spinel_codegen.rbmodifiedView file
end recv_type = infer_type(recv) # Nullable receiver: dispatch identically to the base type. The # null check is the caller's responsibility, matching Ruby's # NoMethodError semantics on a nil receiver. Without this, a # local typed `string?` (e.g. an opt param `f = nil` later passed # a string) misses every per-type dispatcher and falls through # to the "0" fallback. Issue #60. if is_nullable_type(recv_type) == 1 recv_type = base_type(recv_type) end rc = compile_expr_gc_rooted(recv) # Root receiver if it may be collected during argument evaluation if expr_may_gc(recv) == 1 && type_is_pointer(recv_type) == 1test/optional_string_param_method.rbaddedView file
Loading diff…