Skip to content

Commit a3aee68

Browse files
committed
Fix #4272: make OrderingConstraint.&.mergeEntries symmetric
Debugging revealed that in the failing testcase `e2: TypeBounds` while `e1: TypeRef`, and it's not clear why it should be otherwise.
1 parent c9b9780 commit a3aee68

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,13 @@ 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+
// Must be symmetric
522523
def mergeEntries(e1: Type, e2: Type): Type =
523524
(e1, e2) match {
524525
case _ if e1 eq e2 => e1
525526
case (e1: TypeBounds, e2: TypeBounds) => e1 & e2
526527
case (e1: TypeBounds, _) if e1 contains e2 => e2
528+
case (_, e2: TypeBounds) if e2 contains e1 => e1
527529
case (tv1: TypeVar, tv2: TypeVar) if tv1.instanceOpt eq tv2.instanceOpt => e1
528530
case _ =>
529531
throw new AssertionError(i"cannot merge $this with $other, mergeEntries($e1, $e2) failed")

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)