From ee76fda79d446a2d6db51cb4af032a8e92936013 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 15 Dec 2015 14:05:46 +0100 Subject: Dont push `|' inside refined types. As the comment explains, this is not sound. --- src/dotty/tools/dotc/core/TypeComparer.scala | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/dotty/tools/dotc/core/TypeComparer.scala') diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 163fa4919..b3d926a29 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1106,18 +1106,15 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { NoType } - /** Try to distribute `|` inside type, detect and handle conflicts */ + /** Try to distribute `|` inside type, detect and handle conflicts. + * Note that, unlike for `&`, a disjunction cannot be pushed into + * a refined or applied type. Example: + * + * List[T] | List[U] is not the same as List[T | U]. + * + * The rhs is a proper supertype of the lhs. + */ private def distributeOr(tp1: Type, tp2: Type): Type = tp1 match { - case tp1: RefinedType => - tp2 match { - case tp2: RefinedType if tp1.refinedName == tp2.refinedName => - tp1.derivedRefinedType( - tp1.parent | tp2.parent, - tp1.refinedName, - tp1.refinedInfo | tp2.refinedInfo.substRefinedThis(tp2, RefinedThis(tp1))) - case _ => - NoType - } case tp1: TypeBounds => tp2 match { case tp2: TypeBounds => tp1 | tp2 -- cgit v1.2.3