Commit 723057ab

723057abc6dcMerged

Ryan Seys <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

codegen: diagnose dynamic method_defined? intent

method_defined? is answered at compile time when the receiver is a class constant and the name is a literal symbol/string (this already works). The fully dynamic form -- a class held in a variable, or a runtime method name -- cannot be answered ahead of time: there is no runtime reflection table, and builtin classes have no enumerable method set. It previously fell through to the generic unsupported-call node dump.

Emit a specific diagnostic naming the requirement (a compile-time-known class and literal method name) so the limitation is actionable rather than opaque. This covers an implicit-self call as well (the compile-time resolution likewise only fires for an explicit class-constant receiver, so implicit self is never resolved there). The successful compile-time path is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
723057abc6dc
Parent
913a83318df6

src/codegen_call.cmodifiedView file

@@ -6864,6 +6864,16 @@
68646864 }
68656865 }
68666866
6867+ /* The fully dynamic form (class held in a variable, or a non-literal method
6868+ name) cannot be answered ahead of time: there is no runtime reflection
6869+ table, and builtin classes have no enumerable method set. Emit a specific
6870+ diagnostic rather than a generic unsupported-call node dump. Covers both an
6871+ explicit receiver and an implicit-self call (recv < 0). */
6872+ if (!strcmp(name, "method_defined?")) {
6873+ unsupported(c, id, "method_defined? (needs a compile-time-known class and literal method name)");
6874+ return;
6875+ }
6876+
68676877 /* Class.const_defined?(:K): compile-time presence check. Constants are
68686878 recorded in a flat namespace, so this consults the global const and class
68696879 tables rather than the receiver's own constants. */