Skip to content

Fix recursive aliases with Record references#1641

Open
xianjianlf2 wants to merge 1 commit into
arktypeio:mainfrom
xianjianlf2:fix/recursive-record-array-union-1640
Open

Fix recursive aliases with Record references#1641
xianjianlf2 wants to merge 1 commit into
arktypeio:mainfrom
xianjianlf2:fix/recursive-record-array-union-1640

Conversation

@xianjianlf2

Copy link
Copy Markdown

Fixes #1640.

When bootstrapping alias references, preserve references already present on the current node instead of overwriting them with same-id references from another scope. This keeps a recursive $Array alias bound to the user scope when another alias references Record<string, Node>.

Tests:

  • pnpm testTyped ark/type/__tests__/realWorld.test.ts --grep "cyclic discriminated union with record reference"
  • pnpm testTyped ark/type/__tests__/realWorld.test.ts --grep "cyclic discriminated union"
  • pnpm testTyped ark/type/__tests__/discrimination.test.ts
  • pnpm testTyped ark/schema/__tests__/scope.test.ts ark/type/__tests__/scope.test.ts

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — Replaces Object.assign with a ??=-based merge for alias reference bootstrapping, preventing recursive aliases from being overwritten when a Record<string, Node> reference creates same-id references in a different scope.

  • addReferences preserves existing referencesObject.assign in bootstrapAliasReferences would overwrite an alias node's scope-bound references with same-id entries from a generic resolution's scope (e.g. Record<string, Node>). The new addReferences helper uses ??= so the existing (scope-correct) reference wins.
  • Test: cyclic discriminated union with record reference — covers the exact scenario from #1640 where Node, Array { item: "Node" }, and Container { things: "Record<string, Node>" } are defined together in a scope.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@xianjianlf2
xianjianlf2 force-pushed the fix/recursive-record-array-union-1640 branch from bab380f to 7e73a31 Compare July 24, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

1 participant