Commit a4e5db6
fix(ruby): distinguish parameterless and private constructors in codegen
The initializer fallback emitted a single catch-all `initialize(*args)`
passthrough for two very different cases:
- Parameterless constructors (initializer entry with no parameters):
stray arguments were silently forwarded to the kernel. Now emitted
with exact zero arity, matching how parameterized signatures are
enforced.
- No initializer entry at all: jsii emits this for classes whose
constructor is private — instances only come from factory methods,
hydrated via allocate (which never calls #initialize). The
passthrough also silently skipped any base-class coercion/checks,
relying on the unstated invariant that the jsii compiler propagates
initializer entries onto instantiable subclasses (verified: all 27
such classes in jsii-calc have private ctors). Constructing one from
Ruby is now an eager NoMethodError naming the class and pointing at
the factories, instead of a less helpful kernel rejection.
Verified no spec instantiates any of the 27 private-ctor fixture
classes. Tests pin zero-arity enforcement, the raising stub, and the
unaffected factory path. Full suite: 240 examples, 0 failures;
compliance report unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent fcf8a59 commit a4e5db6
2 files changed
Lines changed: 36 additions & 1 deletion
File tree
- packages
- @jsii/ruby-runtime-test/spec/unit
- jsii-pacmak/lib/targets
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
110 | 129 | | |
111 | 130 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
624 | 624 | | |
625 | 625 | | |
626 | 626 | | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
627 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
628 | 644 | | |
629 | 645 | | |
630 | | - | |
| 646 | + | |
631 | 647 | | |
632 | 648 | | |
633 | 649 | | |
| |||
0 commit comments