Commit afc75997

afc75997ae0eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): warn when poly dispatch produces no user-class arm

compile_poly_method_call's user-class dispatch loop can emit zero arms when the receiver is a poly value whose type system can't pin down any matching class. Common cause: an RBS-typed singleton accessor (def self.adapter: () -> Iface) for an abstract class with no concrete implementors in scope, never assigned at a compile-time-visible point. The result temp keeps its default 0 and downstream code consuming the result as the receiver's RBS- declared type emits ill-typed C (mrb_int 0 passed to a pointer parameter). Other elision sites in the same compile already emit warning: cannot resolve call to 'X' on Y (emitting 0); this one was silent.

Track the user-class arm emit count across the dispatch loop's three branches (method, attr_reader, attr_writer) and, after the SP_TAG_OBJ block closes, emit warn_unresolved_call when the count is zero. The runtime behavior is unchanged (the temp still collapses to 0); the warning surfaces the latent bad-emit so apple clang 21's -Wint-conversion -> fatal-error default doesn't kill the build with no explanation.

Fixes #623

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
afc75997ae0e
Parent
763c2cd12d01

spinel_codegen.rbmodifiedView file

@@ -20958,6 +20958,7 @@
2095820958 # poly_dispatch_return_type already consults this set; the
2095920959 # emit loop just needed the matching skip.
2096020960 dispatch_narrow_set = poly_dispatch_narrow_class_set(nid)
20961+ poly_dispatch_arms_emitted = 0
2096120962 i = 0
2096220963 while i < @cls_names.length
2096320964 if dispatch_narrow_set != "" && poly_dispatch_class_in_set(dispatch_narrow_set, i) == 0
@@ -21080,6 +21081,7 @@
2108021081 # skip
2108121082 else
2108221083 emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") " + tmp + " = " + rhs + ";")
21084+ poly_dispatch_arms_emitted = poly_dispatch_arms_emitted + 1
2108321085 end
2108421086 elsif cls_has_attr_reader(i, mname) == 1
2108521087 # An auto-registered attr_reader doesn't appear in
@@ -21095,6 +21097,7 @@
2109521097 # skip non-int attr_reader arms on a narrowed `[]`
2109621098 else
2109721099 emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") " + tmp + " = " + rhs + ";")
21100+ poly_dispatch_arms_emitted = poly_dispatch_arms_emitted + 1
2109821101 end
2109921102 elsif mname.length > 1 && mname[mname.length - 1] == "=" && cls_has_attr_writer(i, mname[0, mname.length - 1]) == 1
2110021103 # An auto-registered attr_writer setter (`obj.x = v`) on a
@@ -21129,12 +21132,25 @@
2112921132 rhs_for_tmp = box_val_to_poly(store_val, slot_t)
2113021133 end
2113121134 emit(" if (" + recv_tmp + ".cls_id == " + cls_id_for_user_internal(i).to_s + ") { " + ivar_lhs + " = " + store_val + "; " + tmp + " = " + rhs_for_tmp + "; }")
21135+ poly_dispatch_arms_emitted = poly_dispatch_arms_emitted + 1
2113221136 end
2113321137 i = i + 1
2113421138 end
2113521139 # Built-in type dispatch (cls_id < 0).
2113621140 emit_poly_builtin_dispatch(recv_tmp, mname, arg_compiled, arg_types, tmp, is_poly_ret, narrowed_int_idx)
2113721141 emit(" }")
21142+ # Warn when the user-class dispatch loop emitted zero arms. The
21143+ # result temp keeps its default (0) and downstream code consuming
21144+ # the result as the receiver's RBS-declared type emits ill-typed
21145+ # C (e.g. mrb_int 0 passed to a pointer parameter). Common cause:
21146+ # an RBS-typed singleton accessor (`def self.adapter: () -> Iface`)
21147+ # for an abstract class with no concrete implementors in scope is
21148+ # never assigned before the call. Issue #623. Matches the existing
21149+ # `cannot resolve call to 'X' on Y (emitting 0)` pattern so editors
21150+ # / CI grep for compile noise still surface this case.
21151+ if poly_dispatch_arms_emitted == 0
21152+ warn_unresolved_call(mname, "poly (no concrete user-class arm)")
21153+ end
2113821154 tmp
2113921155 end
2114021156