Commit 78e2d12d
78e2d12da4c2Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
respond_to? compile-time approximation
respond_to?(:m) now lowers to a compile-time boolean: a universal method set (to_s, class, inspect, nil?, dup, ...) is always true; an object or class-constant receiver consults its instance / class-method chain. The analyzer types respond_to? as Bool for every receiver. A primitive or otherwise unresolved receiver with a non-universal method is left to the fall-through rather than answering a possibly-wrong false.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 78e2d12da4c2
- Parent
- 04e58d9cb7c2
src/analyze.cmodifiedView file
@@ -620,6 +620,7 @@
620620
if ((!strcmp(name, "-@") || !strcmp(name, "+@")) && recv >= 0 && argc == 0)621621
return ty_is_numeric(rt) ? rt : TY_UNKNOWN;622622
if (!strcmp(name, "!")) return TY_BOOL;623+
if (!strcmp(name, "respond_to?") && recv >= 0) return TY_BOOL;623624
624625
if (recv >= 0 && argc == 1 && is_arith_op(name)) {625626
if (rt == TY_STRING) {src/codegen.cmodifiedView file
Loading diff…