( l: Intersection.Inner, r: Intersection.Inner, ctx: IntersectionContext, flatten = flattenConstraints )
| 111 | } |
| 112 | |
| 113 | const intersectIntersections = ( |
| 114 | l: Intersection.Inner, |
| 115 | r: Intersection.Inner, |
| 116 | ctx: IntersectionContext, |
| 117 | flatten = flattenConstraints |
| 118 | ): BaseRoot | Disjoint => { |
| 119 | const baseInner: Intersection.Inner.mutable = {} |
| 120 | |
| 121 | const lBasis = l.proto ?? l.domain |
| 122 | const rBasis = r.proto ?? r.domain |
| 123 | const basisResult = |
| 124 | lBasis ? |
| 125 | rBasis ? |
| 126 | (intersectOrPipeNodes( |
| 127 | lBasis, |
| 128 | rBasis, |
| 129 | ctx |
| 130 | ) as nodeOfKind<Intersection.BasisKind>) |
| 131 | : lBasis |
| 132 | : rBasis |
| 133 | if (basisResult instanceof Disjoint) return basisResult |
| 134 | |
| 135 | if (basisResult) baseInner[basisResult.kind] = basisResult as never |
| 136 | |
| 137 | const lConstraints = flatten(l) |
| 138 | const rConstraints = flatten(r) |
| 139 | |
| 140 | if (lBasis ? !rBasis : rBasis) { |
| 141 | const disjoint = |
| 142 | lBasis ? |
| 143 | disjointFromImplied(rConstraints, lBasis, ctx)?.invert() |
| 144 | : disjointFromImplied(lConstraints, rBasis!, ctx) |
| 145 | if (disjoint) return disjoint |
| 146 | } |
| 147 | |
| 148 | return intersectConstraints({ |
| 149 | kind: "intersection", |
| 150 | baseInner, |
| 151 | l: lConstraints, |
| 152 | r: rConstraints, |
| 153 | roots: [], |
| 154 | ctx |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | // a discriminant prunes the basis its case has checked, leaving constraints |
| 159 | // that hold only of what the basis they imply allows, so they're disjoint from |
no test coverage detected