fix: make initializeNewAccount polymorphic so subclasses get their own runtime type - #208
Conversation
…n runtime type Fixes #116
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughSafeAccountV0_3_0.initializeNewAccount is converted to a polymorphic generic static factory (explicit this: T, returns InstanceType) that instantiates via the calling ctor (with a SafeAccountV0_3_0 fallback for detached calls). SafeAccountV1_5_0_M_0_3_0 delegates to the polymorphic base factory; tests and a changelog entry validate and document the runtime behavior. ChangesPolymorphic Static Factory Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8274c1c8f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| const safe = new SafeAccountV0_3_0(accountAddress, { | ||
| // biome-ignore lint/complexity/noThisInStatic: polymorphic factory; subclasses must get their own type back | ||
| const safe: SafeAccountV0_3_0 = new this(accountAddress, { |
There was a problem hiding this comment.
When JavaScript consumers cache or destructure this public factory (for example, const init = SafeAccountV0_3_0.initializeNewAccount; init([owner])), the static this value is undefined, so new this(...) now throws TypeError: this is not a constructor. The previous hard-coded constructor path worked in that scenario, so this is a runtime breaking change for existing JS/CommonJS callers that use the factory as a callback or extracted function.
Useful? React with 👍 / 👎.
Fixes #116
Red/green verified:
test/safe/initializeNewAccountRuntimeType.test.jsreproducesinstanceof SafeAccountV1_5_0_M_0_3_0 === falseon pre-fix dev (2 failed) and passes with the fix.createAccountAddress/createFactoryAddressAndDatamentioned in the issue return strings, not instances, so they were unaffected.Follow-up: detached calls (
const init = SafeAccountV0_3_0.initializeNewAccount; init([owner]), where strict-modethisis undefined) would have thrownTypeError: this is not a constructorwith the polymorphic factory. They now fall back to constructing the base class, preserving pre-PR behavior for plain-JS callers; covered by two detached-call regression tests (red/green verified against the previous commit of this branch).Summary by CodeRabbit
Bug Fixes
Tests