Skip to content

Fix #2745: Dealias before either #2746

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 1 commit into from
Jun 13, 2017
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
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
}
compareTypeLambda
case OrType(tp21, tp22) =>
val tp1a = tp1.widenDealias
if (tp1a ne tp1)
// Follow the alias; this might avoid truncating the search space in the either below
// Note that it's safe to widen here because singleton types cannot be part of `|`.
return isSubType(tp1a, tp2)

// Rewrite T1 <: (T211 & T212) | T22 to T1 <: (T211 | T22) and T1 <: (T212 | T22)
// and analogously for T1 <: T21 | (T221 & T222)
// `|' types to the right of <: are problematic, because
Expand Down Expand Up @@ -591,6 +597,10 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
}
compareHKLambda
case AndType(tp11, tp12) =>
val tp2a = tp2.dealias
if (tp2a ne tp2) // Follow the alias; this might avoid truncating the search space in the either below
return isSubType(tp1, tp2a)

// Rewrite (T111 | T112) & T12 <: T2 to (T111 & T12) <: T2 and (T112 | T12) <: T2
// and analogously for T11 & (T121 | T122) & T12 <: T2
// `&' types to the left of <: are problematic, because
Expand Down
17 changes: 17 additions & 0 deletions tests/pos/i2745.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object Test {
type Result[A] = Errors | A
final case class Errors(msgs: Seq[String])

implicit class RichRes[A](val res: Result[A]) extends AnyVal {
def map[B](f: A => B): Result[B] = res match {
case xs: Errors => xs
case a: A => f(a)
}
}

var foo: Result[String] = ???
def f(str: String): Int = ???

foo.map(f(_)) // error

}