Commit 6313ab74
6313ab74d277Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
analyze: don't DCE a class method just for sharing a specialized name
When a class method is specialized into subclasses (e.g. Base.find copied to
Article.find / Comment.find), the original is marked a transplanted source
and dropped from emission. The "was this specialized?" check matched only on
the method name, so an unrelated class's class method that happens to share
that name (e.g. an adapter's Sqlite.find(table, id) reached via a
class-valued accessor) was falsely flagged and DCE'd -- then called but never
emitted, yielding an undefined reference / implicit-int return.
Require the same-named copy to live in a descendant of the source's class (is_descendant), so only genuine inheritance specializations count.
Refs #1314
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 6313ab74d277
- Parent
- 7107a59dff7a
src/analyze_internal.hmodifiedView file
/* Defined in codegen.c; the analyzer uses it to specialize/type a `rescue <UserExc> => e` binding (#1415). */int class_is_exc_subclass(Compiler *c, int ci);/* Defined in codegen_fold.c; 1 if class `k` is `anc` or a descendant of it. */int is_descendant(Compiler *c, int k, int anc);#endifsrc/analyze_scope.cmodifiedView file
Loading diff…
test/cls_method_name_collision_dce.rbaddedView file
Loading diff…
test/cls_method_name_collision_dce.rb.expectedaddedView file
Loading diff…