Repository navigation
fix(schema): preserve morph input narrows in unions - #1657
ShuviSchwarze wants to merge 1 commit into
Conversation
54aec7d to
2364060
Compare
There was a problem hiding this comment.
ℹ️ 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 usesmatchingMorph.inner.in.rawOr(node.inner.in)when both branches have aninner.in, so narrows/predicates on the piped input survive the union merge; declared morphs (which may lackinner.in) still take therawIn.rawOrfallback. - #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 tofalse), 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 absentinner.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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (incremental)
- Prettier formatting of the #1608 regression test —
ark/type/__tests__/narrow.test.ts: thePipedItemchain is now wrapped the waypnpm prettierformats it, sopnpm checkPrettier/pnpm prCheckspass. 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Problem
When normalizing an unordered union, equal morph branches are merged into one morph. The current implementation rebuilds the merged morph's executable
invalidator fromrawIn.rawInintentionally 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.invalidators when both are available, preserving their full validation paths. Declared morphs intentionally may not haveinner.in, so the existingrawInmerge remains as a fallback for that case.Tests
inner.in.pnpm testTyped --skipTypes ark/schema/__tests__/morphs.test.ts ark/type/__tests__/narrow.test.ts(1,722 passing)Fixes #1608