Skip to content

fix(schema): preserve morph input narrows in unions - #1657

Closed
ShuviSchwarze wants to merge 1 commit into
arktypeio:mainfrom
ShuviSchwarze:fix/preserve-morph-input-narrows
Closed

ShuviSchwarze wants to merge 1 commit into
arktypeio:mainfrom
ShuviSchwarze:fix/preserve-morph-input-narrows

Conversation

@ShuviSchwarze

Copy link
Copy Markdown
Contributor

Problem

When normalizing an unordered union, equal morph branches are merged into one morph. The current implementation rebuilds the merged morph's executable in validator from rawIn. rawIn intentionally strips transforms and predicates for schema algebra and introspection, so this can silently remove prior .narrow() validation.

This causes #1608: a piped branch narrow is no longer executed after the union is intersected with another piped/narrowed type.

Fix

Merge the branches' executable inner.in validators when both are available, preserving their full validation paths. Declared morphs intentionally may not have inner.in, so the existing rawIn merge remains as a fallback for that case.

Tests

  • Adds a Pipe in Intersection after Union drops previous narrowing conditions #1608 regression: a narrowed piped union branch remains rejected after intersection.
  • Adds coverage for unioning declared morphs, verifying the fallback does not attempt to access an absent inner.in.
  • pnpm testTyped --skipTypes ark/schema/__tests__/morphs.test.ts ark/type/__tests__/narrow.test.ts (1,722 passing)

Fixes #1608

@github-project-automation github-project-automation Bot moved this to To do in arktypeio Sep 18, 2026
@ShuviSchwarze
ShuviSchwarze marked this pull request as draft September 18, 2026 07:52
@ShuviSchwarze
ShuviSchwarze force-pushed the fix/preserve-morph-input-narrows branch from 54aec7d to 2364060 Compare September 18, 2026 07:54
@github-project-automation github-project-automation Bot moved this from To do to Done (merged or closed) in arktypeio Sep 18, 2026
@ShuviSchwarze
ShuviSchwarze deleted the fix/preserve-morph-input-narrows branch September 18, 2026 07:56

@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 critical issues — one formatting fix needed for CI.

Reviewed changes

  • Preserve executable input validators when merging morph branches — ark/schema/roots/union.ts: the merged morph now uses matchingMorph.inner.in.rawOr(node.inner.in) when both branches have an inner.in, so narrows/predicates on the piped input survive the union merge; declared morphs (which may lack inner.in) still take the rawIn.rawOr fallback.
  • #1608 regression test — ark/type/__tests__/narrow.test.ts: a piped + narrowed union branch remains rejected after the union is intersected with another piped/narrowed type. I confirmed this test fails against the pre-fix implementation (the assertion flips to false), so it genuinely pins the behavior.
  • Declared-morph union coverage — ark/schema/__tests__/morphs.test.ts: unioning two declared morphs exercises the fallback branch without touching an absent inner.in.

The fallback condition is sound: a branch without inner.in is either declared or permissive, so falling back to the rawIn union does not drop a real narrow. pnpm testTyped --skipTypes is green (1,743 passing), and eslint is clean on the changed files.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread ark/type/__tests__/narrow.test.ts Outdated

@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 (incremental)

  • Prettier formatting of the #1608 regression test — ark/type/__tests__/narrow.test.ts: the PipedItem chain is now wrapped the way pnpm prettier formats it, so pnpm checkPrettier / pnpm prChecks pass. No behavioral change.

This is the only delta since the prior review (54aec7d → 2364060), and it resolves the single formatting finding from that review. The union-merge fix and the two tests are unchanged; pnpm prettier --check now reports all three changed files clean.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done (merged or closed)

Development

Successfully merging this pull request may close these issues.

Pipe in Intersection after Union drops previous narrowing conditions

2 participants