Commit 17cffcb5
17cffcb5507bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 8 files · +6 added · ~2 modified
Description
fix(codegen,analyze): primitive .class + respond_to? + middle splat param
Three independent issues with shared root cause: the codegen arms for
.class, respond_to?, and rest-param handling only fired for
obj-typed receivers (or the trivial rest-only case).
-
.class(#715): added a primitive arm in compile_call that emits(sp_Class){<builtin_id>}for int / bigint / float / string / symbol / nil / range / time / array / hash / proc / lambda. Bool emits a ternary so the runtime cls_id picks TrueClass vs FalseClass. analyze.rb mirrors with a "class" return type so callers can read the result as an sp_Class. -
respond_to?(#716): primitive recv goes through a conservative allowlist (to_s/to_i/to_f/inspect/class/nil?/is_a?/kind_of?/ instance_of?/==/!=/hash/respond_to?/frozen?/freeze/dup/clone/ tap/then). Returns TRUE for known names. Compile-time can't introspect each primitive's method table fully, so the allowlist trades exhaustive accuracy for the common cases users actually probe. -
middle splat param
def f(a, *b, c)(#710): the rest-arg loop used to greedily consume positional_ids[k..end] into the splat tmp, then re-enter the outer loop at k+1 reading ptypes[k+1..] from the now-empty tail. Two changes:- leave the trailing positional_ids[splat_end..] for the fixed
params after the rest slot (trailing_after_rest = pnames.length
- 1 - rest_param_idx);
- rebuild positional_ids with [pre-splat, placeholder, trailing]
so the outer loop's k+1.. indexing keeps aligning with the
remaining ptypes.
Also fire treat_as_rest unconditionally when this is a middle
rest slot (is_last_param == 0) so
g(100, 200)withdef g(a, *b, c)produces an empty *b instead of dropping 200 into b's slot.
- leave the trailing positional_ids[splat_end..] for the fixed
params after the rest slot (trailing_after_rest = pnames.length
Regression tests: test/class_of_primitive.rb - .class for 9 primitives test/respond_to_primitive.rb - respond_to? allowlist test/middle_splat_param.rb - 4 middle-splat shapes
454+2 -> 456 tests pass; optcarrot checksum 59662.
Closes #710 Closes #715 Closes #716
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 17cffcb5507b
- Parent
- c80632fb44fb
spinel_analyze.rbmodifiedView file
if is_obj_type(rt) == 1 return "class" end # Primitive .class -- Integer / Float / String / Symbol / # NilClass / TrueClass / FalseClass / Range / Time / Array / # Hash / Proc -- all return a `class` value. Issue #715. bt_pc = base_type(rt) if bt_pc == "int" || bt_pc == "bigint" || bt_pc == "float" || bt_pc == "string" || bt_pc == "mutable_str" || bt_pc == "symbol" || bt_pc == "bool" || bt_pc == "nil" || bt_pc == "range" || bt_pc == "time" || is_array_type(bt_pc) == 1 || is_hash_type(bt_pc) == 1 || bt_pc == "proc" || bt_pc == "lambda" return "class" end end end # `<obj>.class.<cmeth>` chained dispatch. When thespinel_codegen.rbmodifiedView file
Loading diff…
test/class_of_primitive.rbaddedView file
Loading diff…
test/class_of_primitive.rb.expectedaddedView file
Loading diff…
test/middle_splat_param.rbaddedView file
Loading diff…
test/middle_splat_param.rb.expectedaddedView file
Loading diff…
test/respond_to_primitive.rbaddedView file
Loading diff…
test/respond_to_primitive.rb.expectedaddedView file
Loading diff…