Skip to content

Commit ee76fda

Browse files
committed
Dont push `|' inside refined types.
As the comment explains, this is not sound.
1 parent 3009924 commit ee76fda

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

+8-11
Original file line numberDiff line numberDiff line change
@@ -1106,18 +1106,15 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
11061106
NoType
11071107
}
11081108

1109-
/** Try to distribute `|` inside type, detect and handle conflicts */
1109+
/** Try to distribute `|` inside type, detect and handle conflicts.
1110+
* Note that, unlike for `&`, a disjunction cannot be pushed into
1111+
* a refined or applied type. Example:
1112+
*
1113+
* List[T] | List[U] is not the same as List[T | U].
1114+
*
1115+
* The rhs is a proper supertype of the lhs.
1116+
*/
11101117
private def distributeOr(tp1: Type, tp2: Type): Type = tp1 match {
1111-
case tp1: RefinedType =>
1112-
tp2 match {
1113-
case tp2: RefinedType if tp1.refinedName == tp2.refinedName =>
1114-
tp1.derivedRefinedType(
1115-
tp1.parent | tp2.parent,
1116-
tp1.refinedName,
1117-
tp1.refinedInfo | tp2.refinedInfo.substRefinedThis(tp2, RefinedThis(tp1)))
1118-
case _ =>
1119-
NoType
1120-
}
11211118
case tp1: TypeBounds =>
11221119
tp2 match {
11231120
case tp2: TypeBounds => tp1 | tp2

0 commit comments

Comments
 (0)