Skip to content

Fix #4272: make OrderingConstraint.&.mergeEntries symmetric #4276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -519,23 +519,17 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
def mergeParams(ps1: List[TypeParamRef], ps2: List[TypeParamRef]) =
(ps1 /: ps2)((ps1, p2) => if (ps1.contains(p2)) ps1 else p2 :: ps1)

def mergeEntries(e1: Type, e2: Type): Type = e1 match {
case e1: TypeBounds =>
e2 match {
case e2: TypeBounds => e1 & e2
case _ if e1 contains e2 => e2
case _ => mergeError
}
case tv1: TypeVar =>
e2 match {
case tv2: TypeVar if tv1.instanceOpt eq tv2.instanceOpt => e1
case _ => mergeError
}
// Must be symmetric
def mergeEntries(e1: Type, e2: Type): Type =
(e1, e2) match {
case _ if e1 eq e2 => e1
case _ => mergeError
}

def mergeError = throw new AssertionError(i"cannot merge $this with $other")
case (e1: TypeBounds, e2: TypeBounds) => e1 & e2
case (e1: TypeBounds, _) if e1 contains e2 => e2
case (_, e2: TypeBounds) if e2 contains e1 => e1
case (tv1: TypeVar, tv2: TypeVar) if tv1.instanceOpt eq tv2.instanceOpt => e1
case _ =>
throw new AssertionError(i"cannot merge $this with $other, mergeEntries($e1, $e2) failed")
}

val that = other.asInstanceOf[OrderingConstraint]
new OrderingConstraint(
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i4272.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Main {
def f(m: Map[String, Boolean]) = {}
println(f(Map('a' -> true))) // error
println(this.f(Map('a' -> true))) // error
}