-
Notifications
You must be signed in to change notification settings - Fork 5
Fix create
#134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xisk
merged 11 commits into
OpenZeppelin:main
from
andrew-fleming:fix-create-improve-type-check
Jul 29, 2026
Merged
Fix create
#134
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93e4674
fix create method
andrew-fleming 9d4281e
move emit to build.json, fold test sims into the types check
andrew-fleming ed07aec
revert typecheck refactor
andrew-fleming 3d5a189
Merge branch 'main' into fix-create-improve-type-check
0xisk 1740ef4
add _create type sibling
andrew-fleming d9fea4f
improve doc on overriding create
andrew-fleming 734256d
fix return doc in create
andrew-fleming ac8152b
add named alias (so it looks intentional)
andrew-fleming 636322f
add regression guard
andrew-fleming 3899581
Merge remote-tracking branch 'origin/fix-create-improve-type-check' i…
andrew-fleming b0293b4
Merge branch 'main' into fix-create-improve-type-check
andrew-fleming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Type-level regression guard for the static `create` / `_create` contract. | ||
| * | ||
| * `yarn types` compiles `src/**` but NOT `test/**` (the sample simulators import | ||
| * generated, gitignored contract artifacts), and `vitest` strips types without | ||
| * checking them — so a regression in the `create` / `_create` typing would | ||
| * otherwise pass CI. This file reproduces the subclass-override pattern against a | ||
| * synthetic contract type, so `yarn types` fails on a regression. | ||
| * | ||
| * It exports nothing and is imported by nothing (inert at runtime). The build | ||
| * config (`tsconfig.json`) excludes `*.type-test.ts` from emit, so it never | ||
| * reaches `dist`; the type check runs it via `tsconfig.types.json`. | ||
| * | ||
| * Typechecking the real test simulators (which need the generated artifacts) is a | ||
| * separate, larger effort; this is the minimal guard for the contract that | ||
| * actually regressed. | ||
| */ | ||
| import { createSimulator } from './factory/createSimulator.js'; | ||
| import type { SimulatorConfig } from './factory/SimulatorConfig.js'; | ||
| import type { IMinimalContract } from './types/Contract.js'; | ||
|
|
||
| type GuardPrivateState = { readonly value: number }; | ||
| type GuardArgs = readonly [a: number, b: string]; | ||
|
|
||
| // A synthetic config — never executed, only used to instantiate the factory's | ||
| // generics for the type-level checks below. | ||
| const config = {} as unknown as SimulatorConfig< | ||
| GuardPrivateState, | ||
| unknown, | ||
| unknown, | ||
| IMinimalContract, | ||
| GuardArgs | ||
| >; | ||
|
|
||
| class Guard extends createSimulator(config) { | ||
| // A concrete `Promise<Guard>` return must stay assignable to the base static | ||
| // side. If `create`'s return goes generic again, this fails the static-side | ||
| // `extends` check (TS2417). | ||
| static async create(a: number, b: string, options = {}): Promise<Guard> { | ||
| // biome-ignore lint/complexity/noThisInStatic: super._create must keep the subclass `this` | ||
| return super._create([a, b], options) as Promise<Guard>; | ||
| } | ||
|
|
||
| // `_create` must type its args tuple against `GuardArgs`. If that check | ||
| // regresses (e.g. `_create` widens to `...args: unknown[]`), the wrong-arity | ||
| // call below stops erroring and the `@ts-expect-error` becomes unused → CI red. | ||
| static async _argCheck(): Promise<unknown> { | ||
| // Call via the class name (not `super`) so this negative assertion needs | ||
| // only the `@ts-expect-error` below — no `noThisInStatic` ignore to stack. | ||
| // @ts-expect-error a 1-element tuple must not satisfy `[number, string]`. | ||
| return Guard._create([1], {}); | ||
| } | ||
|
|
||
| // A subclass-only member. Without it, `Guard`'s instance type would equal the | ||
| // base `Simulator`'s and the call-site check below would pass even if `create` | ||
| // stopped narrowing to the subclass. This mirrors real subclasses, which add | ||
| // circuit methods that a base-typed return would hide. | ||
| public marker(): string { | ||
| return 'guard'; | ||
| } | ||
| } | ||
|
|
||
| // The override must narrow the call-site return to the subclass, not widen to | ||
| // the base `Simulator` (which lacks `marker`). | ||
| async function _callSiteSubtype(): Promise<void> { | ||
| const instance: Guard = await Guard.create(1, 'x'); | ||
| void instance.marker(); | ||
| } | ||
|
|
||
| void Guard; | ||
| void _callSiteSubtype; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| "exclude": [ | ||
| "node_modules", | ||
| "dist", | ||
| "tests" | ||
| "tests", | ||
| "src/**/*.type-test.ts" | ||
| ] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| // Typecheck-only project used by `yarn types`. | ||
| // | ||
| // Identical to the build config (`tsconfig.json`) except it (a) never emits and | ||
| // (b) re-includes the `*.type-test.ts` regression guards, which the build config | ||
| // excludes from emit so they don't ship in `dist`. Keeping them in the type | ||
| // check is the whole point: they fail CI if the guarded contracts regress. | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": true | ||
| }, | ||
| "include": ["src/**/*"], | ||
| "exclude": ["node_modules", "dist", "tests"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.