Commit 7e0197f6
7e0197f6ee21Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 9 files · +1 added · ~2 modified
Description
fix(analyze,codegen): built-in and nested classes as values
Followup to #404. The flat-user-class arm of ConstantReadNode already lowered to an sp_Class compound literal; built-in exception classes and nested user classes fell through to a bare C identifier that gcc rejected as undeclared.
- Append the Exception family to @builtin_class_names / @builtin_class_parents / @builtin_class_includes so they carry cls_ids (21..45). sp_class_for_poly's hardcoded primitive cls_ids stay valid because the new entries land after the last hardcoded slot (Proc = 20).
- is_builtin_class_const_name recognises the same exception names so infer_type returns "class" for them, which lets call- site widening pick the right ptype.
- ConstantPathNode's value-emit now resolves cpname through find_class_idx / find_module_idx_local / builtin_class_id_for_name before falling through to the bare-identifier path, mirroring the ConstantReadNode arm.
Also rename the test/.expected fixtures added in this issue
batch to the project's <n>.rb.expected convention; they were
silently ignored by the make rule (which kept generating expected
output via ruby, which happened to match spinel for those cases).
Fixes #637.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 7e0197f6ee21
- Parent
- 82be610f7cb7
spinel_analyze.rbmodifiedView file
if name == "Module" || name == "Class" || name == "Complex" || name == "Proc" return 1 end # Exception family — the codegen builtin table carries cls_ids # for these so `c = StandardError` lowers to an sp_Class value # rather than the undeclared bare identifier. Issue #637 shape A. if name == "Exception" || name == "StandardError" || name == "RuntimeError" return 1 end if name == "ArgumentError" || name == "TypeError" || name == "IndexError" || name == "KeyError" return 1 end if name == "RangeError" || name == "FloatDomainError" || name == "NameError" || name == "NoMethodError" return 1 end if name == "ZeroDivisionError" || name == "IOError" || name == "EOFError" || name == "FrozenError" return 1 end if name == "ScriptError" || name == "NotImplementedError" || name == "LoadError" || name == "SyntaxError" return 1 end if name == "StopIteration" || name == "RegexpError" || name == "EncodingError" || name == "SystemCallError" return 1 end if name == "LocalJumpError" || name == "FiberError" return 1 end 0 endspinel_codegen.rbmodifiedView file
Loading diff…
test/class_value_builtin_and_nested.rbaddedView file
Loading diff…
test/destructure_typed_ptr_array_return.rb.expectedrenamedView file
Loading diff…
test/interpolation_symbol_name.rb.expectedrenamedView file
Loading diff…
test/isa_hash_narrow_typed_param.rb.expectedrenamedView file
Loading diff…
test/ivar_same_shape_string_new_no_widen.rb.expectedrenamedView file
Loading diff…
test/nil_default_param_widens_to_poly.rb.expectedrenamedView file
Loading diff…
test/regexp_backspace_in_class.rb.expectedrenamedView file
Loading diff…