You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
constructor.name of a generic-class instance reports the mangled specialization (Gen$num), not Gen #7632
(new Gen<number>()).constructor.name reports the MANGLED specialization name Gen$num where node reports Gen.
Repro
classBase{}classGen<T>extendsBase{}classGenNoExtends<T>{}consta=newGen<number>();constb=newGen();// no type argumentsconstc=newGenNoExtends<number>();console.log(a.constructor.name,b.constructor.name,c.constructor.name);
$ node --experimental-strip-types t.ts
Gen Gen GenNoExtends
$ ./t
Gen$num Gen GenNoExtends$num
Only the instantiation WITH type arguments is affected — that is the one that
gets monomorphized.
Perry specializes generic classes: new Gen<number>() emits a second class named Gen$num (crates/perry-hir/src/monomorph/mangle.rs, generate_specialized_name) and constructs THAT. #7575 (PR #7631) fixed the instanceof half by recording Class::specialized_from in the HIR and teaching
the instanceof chain walk a specialization→generic edge. The user-visible class
NAME is the other half of the same leak, and was deliberately left out of that
PR: it flows through the class display-name registry rather than the class-id
chain, and it can change error-message text (TypeError: ... is not a constructor, Object.prototype.toString, stack frames), so it wants its own
parity sweep rather than being bundled into an instanceof fix.
Class::specialized_from already carries what is needed (Some("Gen") on the
specialization), so the likely shape is to register the ORIGIN name as the
class's display name — the class_display_names mechanism in crates/perry-codegen/src/codegen/string_pool.rs already exists for #5592's
uniquified class-expression bindings.
Worth checking in the same pass
Gen.name read off the constructor itself, not an instance.
Activity
docs(changelog): reference #7632 for the constructor.name follow-up
docs(changelog): reference #7632 for the constructor.name follow-up
docs(changelog): reference #7632 for the constructor.name follow-up
fix(monomorph): a specialized generic class reports the generic's nam…
fix(monomorph): a specialized generic class reports the generic's nam…
fix(monomorph): a specialized generic class reports the generic's nam…
fix(runtime): a generic specialization answers with its generic's con…
fix: static this is the constructor; class name/toString/inspect repo…