Skip to content

Commit 9723748

Browse files
authored
Merge pull request #4276 from dotty-staging/fix-4272
Fix #4272: make OrderingConstraint.&.mergeEntries symmetric
2 parents 74bcfd2 + a3aee68 commit 9723748

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,23 +519,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
519519
def mergeParams(ps1: List[TypeParamRef], ps2: List[TypeParamRef]) =
520520
(ps1 /: ps2)((ps1, p2) => if (ps1.contains(p2)) ps1 else p2 :: ps1)
521521

522-
def mergeEntries(e1: Type, e2: Type): Type = e1 match {
523-
case e1: TypeBounds =>
524-
e2 match {
525-
case e2: TypeBounds => e1 & e2
526-
case _ if e1 contains e2 => e2
527-
case _ => mergeError
528-
}
529-
case tv1: TypeVar =>
530-
e2 match {
531-
case tv2: TypeVar if tv1.instanceOpt eq tv2.instanceOpt => e1
532-
case _ => mergeError
533-
}
522+
// Must be symmetric
523+
def mergeEntries(e1: Type, e2: Type): Type =
524+
(e1, e2) match {
534525
case _ if e1 eq e2 => e1
535-
case _ => mergeError
536-
}
537-
538-
def mergeError = throw new AssertionError(i"cannot merge $this with $other")
526+
case (e1: TypeBounds, e2: TypeBounds) => e1 & e2
527+
case (e1: TypeBounds, _) if e1 contains e2 => e2
528+
case (_, e2: TypeBounds) if e2 contains e1 => e1
529+
case (tv1: TypeVar, tv2: TypeVar) if tv1.instanceOpt eq tv2.instanceOpt => e1
530+
case _ =>
531+
throw new AssertionError(i"cannot merge $this with $other, mergeEntries($e1, $e2) failed")
532+
}
539533

540534
val that = other.asInstanceOf[OrderingConstraint]
541535
new OrderingConstraint(

tests/neg/i4272.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Main {
2+
def f(m: Map[String, Boolean]) = {}
3+
println(f(Map('a' -> true))) // error
4+
println(this.f(Map('a' -> true))) // error
5+
}

0 commit comments

Comments
 (0)