diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 801ba332c596..a640d490699b 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1981,7 +1981,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling * @note We do not admit singleton types in or-types as lubs. */ def lub(tp1: Type, tp2: Type, canConstrain: Boolean = false): Type = /*>|>*/ trace(s"lub(${tp1.show}, ${tp2.show}, canConstrain=$canConstrain)", subtyping, show = true) /*<|<*/ { - if (tp1 eq tp2) tp1 else if (!tp1.exists) tp1 else if (!tp2.exists) tp2 diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index eb353744ae82..9fa821b914c5 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -343,7 +343,12 @@ object TypeOps: tp match { case tp: OrType => - approximateOr(tp.tp1, tp.tp2) + (tp.tp1.dealias, tp.tp2.dealias) match + case (tp1 @ AppliedType(tycon1, args1), tp2 @ AppliedType(tycon2, args2)) + if tycon1.typeSymbol == tycon2.typeSymbol && (tycon1 =:= tycon2) => + mergeRefinedOrApplied(tp1, tp2) + case (tp1, tp2) => + approximateOr(tp1, tp2) case _ => tp } diff --git a/tests/pos/i12264.scala b/tests/pos/i12264.scala new file mode 100644 index 000000000000..6be35b8e0e9f --- /dev/null +++ b/tests/pos/i12264.scala @@ -0,0 +1,40 @@ +object test1: + + object Html { + final opaque type Tag[+N] = String + def apply[N](name: String): Tag[N] = ??? + } + + object HtmlTags { + final def br: Html.Tag[Int] = Html("br") + final def p = Html[Long]("p") + } + + object Test { + type Expect = Html.Tag[Any] + + val x = List[Expect](HtmlTags.br, HtmlTags.p) // ok + + val y = List(HtmlTags.br, HtmlTags.p) + y: List[Expect] // was error + } + +class test2: + type Tag[+N] + object Html: + def apply[N](name: String): Tag[N] = ??? + + object HtmlTags { + final def br: Tag[Int] = Html("br") + final def p = Html[Long]("p") + } + + object Test { + type Expect = Tag[Any] + + val x = List[Expect](HtmlTags.br, HtmlTags.p) // ok + + val y = List(HtmlTags.br, HtmlTags.p) + y: List[Expect] // was error + } +