Commit 58fb134e

58fb134e5ccaMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Compile-time is_a?/instance_of? on concrete objects + bool inference

obj.is_a?/kind_of?/instance_of?(Class) on a statically-typed object resolves from the class hierarchy at compile time; object ==/!=/nil?/ respond_to?/frozen?/equal? infer to bool.

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

Details

Commit
58fb134e5cca
Parent
27b32882a2de

src/analyze.cmodifiedView file

@@ -221,6 +221,9 @@
221221 if (recv >= 0 && ty_is_object(rt)) {
222222 int cid = ty_object_class(rt);
223223 ClassInfo *cls = &c->classes[cid];
224+ if (!strcmp(name, "is_a?") || !strcmp(name, "kind_of?") || !strcmp(name, "instance_of?") ||
225+ !strcmp(name, "respond_to?") || !strcmp(name, "==") || !strcmp(name, "!=") ||
226+ !strcmp(name, "nil?") || !strcmp(name, "equal?") || !strcmp(name, "frozen?")) return TY_BOOL;
224227 /* attr reader */
225228 if (comp_reader_in_chain(c, cid, name, NULL)) {
226229 char ivn[256];