Commit 6eeb7cf1

6eeb7cf1b818Merged

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

Description

Merge pull request #1491 from ryanseys/rs-class-allocate

Implement Class#allocate

Details

Commit
6eeb7cf1b818
Parent
ed6b75edcd21
Merge parent
912e2671aba9

src/analyze_infer.cmodifiedView file

@@ -657,6 +657,17 @@
657657 if (self && self->class_id >= 0) return ty_object(self->class_id);
658658 }
659659
660+ /* Class#allocate -> a bare instance of that class (no initialize run). */
661+ if (recv >= 0 && !strcmp(name, "allocate") && argc == 0) {
662+ const char *rty = nt_type(nt, recv);
663+ if (rty && (!strcmp(rty, "ConstantReadNode") || !strcmp(rty, "ConstantPathNode"))) {
664+ int ci = comp_class_index(c, nt_str(nt, recv, "name"));
665+ /* Use the same exception-subclass predicate as codegen (class_is_exc_subclass)
666+ so inference and emission agree on which classes take the allocate path. */
667+ if (ci >= 0 && !class_is_exc_subclass(c, ci)) return ty_object(ci);
668+ }
669+ }
670+
660671 /* Class.new(...) -> an instance of that class; built-in .new constructors */
661672 if (recv >= 0 && !strcmp(name, "new")) {
662673 const char *rty = nt_type(nt, recv);