You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Intersection throws "Unmergable intersection" when both sides produce the same NaN #6639
mergeValues decides two outputs are the same with a === b, which is false for NaN. When both sides of an intersection produce NaN, the merge is classed as unmergable and safeParse throws instead of returning a result:
The changelog reserves that throw for "an intersection of two incompatible types". Two NaNs from the same input aren't incompatible, and z.nan().and(z.nan()) currently can't accept any value. The compiled path reuses mergeValues, so it throws too.
Reproduced on main at 2bf7b06. A one-line fix, a === b || (Number.isNaN(a) && Number.isNaN(b)), with a test, is on a branch since PRs are limited to collaborators: main...andrewstellman:zod:intersection-nan-merge. 0 and -0 still merge as before (Object.is would have split them).
Found by Quality Playbook, an AI code-review tool, with Claude; I reviewed the change.
This implements andrewstellman’s proposed NaN equality condition while preserving 0/-0 behavior. Regressions fail before and pass afterward for sync/async parsing and nested object/array outputs; incompatible outputs still fail. Local object-intersection timings were approximately 209 ns before/after, retained schema memory was unchanged within measurement noise, and gzip bundle growth was 10 bytes for classic and 9 for Mini.
All 8,323 tests, type checks, build, lint/format, and resolution/integration checks passed locally with Nub 0.8.3 and pinned Node 24.21.0; hooks were not bypassed. Performance numbers are local estimates, and hosted CI has not run. Prepared with AI assistance and verified locally.
Activity
anuj-hrcg commentedon Oct 1, 2026
Could a maintainer review this independent fix and cherry-pick it if suitable? GitHub denied my account permission to create an upstream PR.
Compare · Commit
This implements andrewstellman’s proposed NaN equality condition while preserving
0/-0behavior. Regressions fail before and pass afterward for sync/async parsing and nested object/array outputs; incompatible outputs still fail. Local object-intersection timings were approximately 209 ns before/after, retained schema memory was unchanged within measurement noise, and gzip bundle growth was 10 bytes for classic and 9 for Mini.All 8,323 tests, type checks, build, lint/format, and resolution/integration checks passed locally with Nub 0.8.3 and pinned Node 24.21.0; hooks were not bypassed. Performance numbers are local estimates, and hosted CI has not run. Prepared with AI assistance and verified locally.