Skip to content

Commit 8627f7c

Browse files
committed
Element-wise And/Or type
1 parent 1d31192 commit 8627f7c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeUtils.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ class TypeUtils:
140140
case tp: OrType =>
141141
val lhs = tp.tp1.namedTupleElementTypesUpTo(bound, normalize)
142142
val rhs = tp.tp2.namedTupleElementTypesUpTo(bound, normalize)
143-
if (lhs != rhs) throw TypeError(em"Malformed Union Type: Named Tuple elements must be the same, but $lhs and $rhs were found.")
144-
lhs
143+
if (lhs.map(_._1) != rhs.map(_._1)) throw TypeError(em"Malformed Union Type: Named Tuple elements must be the same, but $lhs and $rhs were found.")
144+
lhs.zip(rhs).map((lhs, rhs) => (lhs._1, lhs._2 | rhs._2))
145145
case tp: AndType =>
146146
(tp.tp1.namedTupleElementTypesUpTo(bound, normalize), tp.tp2.namedTupleElementTypesUpTo(bound, normalize)) match
147147
case (Nil, rhs) => rhs
148148
case (lhs, Nil) => lhs
149149
case (lhs, rhs) =>
150-
if (lhs != rhs) throw TypeError(em"Malformed Intersection Type: Named Tuple elements must be the same, but $lhs and $rhs were found.")
151-
lhs
150+
if (lhs.map(_._1) != rhs.map(_._1)) throw TypeError(em"Malformed Intersection Type: Named Tuple elements must be the same, but $lhs and $rhs were found.")
151+
lhs.zip(rhs).map((lhs, rhs) => (lhs._1, lhs._2 & rhs._2))
152152
case t =>
153153
Nil
154154

0 commit comments

Comments
 (0)