Skip to content

Commit d0ae726

Browse files
oderskymichelou
authored andcommitted
Improve orDominator
Merge applied type arguments also for abstract and opaque type constructors Fixes scala#12264
1 parent 9094579 commit d0ae726

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
19811981
* @note We do not admit singleton types in or-types as lubs.
19821982
*/
19831983
def lub(tp1: Type, tp2: Type, canConstrain: Boolean = false): Type = /*>|>*/ trace(s"lub(${tp1.show}, ${tp2.show}, canConstrain=$canConstrain)", subtyping, show = true) /*<|<*/ {
1984-
19851984
if (tp1 eq tp2) tp1
19861985
else if (!tp1.exists) tp1
19871986
else if (!tp2.exists) tp2

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ object TypeOps:
343343

344344
tp match {
345345
case tp: OrType =>
346-
approximateOr(tp.tp1, tp.tp2)
346+
(tp.tp1.dealias, tp.tp2.dealias) match
347+
case (tp1 @ AppliedType(tycon1, args1), tp2 @ AppliedType(tycon2, args2)) if tycon1 eq tycon2 =>
348+
mergeRefinedOrApplied(tp1, tp2)
349+
case (tp1, tp2) =>
350+
approximateOr(tp1, tp2)
347351
case _ =>
348352
tp
349353
}

tests/pos/i12264.scala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
object test1:
2+
3+
object Html {
4+
final opaque type Tag[+N] = String
5+
def apply[N](name: String): Tag[N] = ???
6+
}
7+
8+
object HtmlTags {
9+
final def br: Html.Tag[Int] = Html("br")
10+
final def p = Html[Long]("p")
11+
}
12+
13+
object Test {
14+
type Expect = Html.Tag[Any]
15+
16+
val x = List[Expect](HtmlTags.br, HtmlTags.p) // ok
17+
18+
val y = List(HtmlTags.br, HtmlTags.p)
19+
y: List[Expect] // was error
20+
}
21+
22+
class test2:
23+
type Tag[+N]
24+
object Html:
25+
def apply[N](name: String): Tag[N] = ???
26+
27+
object HtmlTags {
28+
final def br: Tag[Int] = Html("br")
29+
final def p = Html[Long]("p")
30+
}
31+
32+
object Test {
33+
type Expect = Tag[Any]
34+
35+
val x = List[Expect](HtmlTags.br, HtmlTags.p) // ok
36+
37+
val y = List(HtmlTags.br, HtmlTags.p)
38+
y: List[Expect] // was error
39+
}
40+

0 commit comments

Comments
 (0)