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

@@ -7271,6 +7271,30 @@
72717271 if name == "Module" || name == "Class" || name == "Complex" || name == "Proc"
72727272 return 1
72737273 end
7274+ # Exception family — the codegen builtin table carries cls_ids
7275+ # for these so `c = StandardError` lowers to an sp_Class value
7276+ # rather than the undeclared bare identifier. Issue #637 shape A.
7277+ if name == "Exception" || name == "StandardError" || name == "RuntimeError"
7278+ return 1
7279+ end
7280+ if name == "ArgumentError" || name == "TypeError" || name == "IndexError" || name == "KeyError"
7281+ return 1
7282+ end
7283+ if name == "RangeError" || name == "FloatDomainError" || name == "NameError" || name == "NoMethodError"
7284+ return 1
7285+ end
7286+ if name == "ZeroDivisionError" || name == "IOError" || name == "EOFError" || name == "FrozenError"
7287+ return 1
7288+ end
7289+ if name == "ScriptError" || name == "NotImplementedError" || name == "LoadError" || name == "SyntaxError"
7290+ return 1
7291+ end
7292+ if name == "StopIteration" || name == "RegexpError" || name == "EncodingError" || name == "SystemCallError"
7293+ return 1
7294+ end
7295+ if name == "LocalJumpError" || name == "FiberError"
7296+ return 1
7297+ end
72747298 0
72757299 end
72767300