Commit 640eb2a
committed
fix(zod): tighten guards in tryBuildDiscriminatedUnion and buildDiscriminatorExpression
- Add `items?.length` check before `every()` to prevent vacuous-truth on
empty `or.items` array (would have emitted invalid `z.enum([])`)
- Add `value.length > 0` guard in `buildDiscriminatorExpression` for the
same reason — function is exported so the guard is worth keeping locally
- Collapse single-element arrays to `z.literal(value[0])` ahead of the
array branches (more ergonomic, consistent with scalar path)
All three cases are unreachable today (IR collapses single-item `or` and
only emits `or` when `valueSchemas.length > 1`), but tightening keeps the
invariants local to the functions rather than relying on upstream guarantees.1 parent 6de0b51 commit 640eb2a
1 file changed
Lines changed: 10 additions & 3 deletions
File tree
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
102 | | - | |
| 103 | + | |
| 104 | + | |
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
111 | 118 | | |
112 | 119 | | |
113 | 120 | | |
| |||
0 commit comments