Skip to content

Fix #9479: Widen unions in inferred type lambdas #9488

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
Aug 6, 2020
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
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1118,15 +1118,15 @@ object Types {

/** Widen this type and if the result contains embedded union types, replace
* them by their joins.
* "Embedded" means: inside intersectons or recursive types, or in prefixes of refined types.
* "Embedded" means: inside type lambdas, intersections or recursive types, or in prefixes of refined types.
* If an embedded union is found, we first try to simplify or eliminate it by
* re-lubbing it while allowing type parameters to be constrained further.
* Any remaining union types are replaced by their joins.
*
* For instance, if `A` is an unconstrained type variable, then
*
* ArrayBuffer[Int] | ArrayBuffer[A]
*
* For instance, if `A` is an unconstrained type variable, then
*
* ArrayBuffer[Int] | ArrayBuffer[A]
*
* is approximated by constraining `A` to be =:= to `Int` and returning `ArrayBuffer[Int]`
* instead of `ArrayBuffer[? >: Int | A <: Int & A]`
*
Expand Down Expand Up @@ -1155,6 +1155,8 @@ object Types {
tp.derivedRefinedType(tp.parent.widenUnion, tp.refinedName, tp.refinedInfo)
case tp: RecType =>
tp.rebind(tp.parent.widenUnion)
case tp: HKTypeLambda =>
tp.derivedLambdaType(resType = tp.resType.widenUnion)
case tp =>
tp
}
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i9479.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
trait Applicative[F[_]]

def traverse[F[_]: Applicative, A, B](as: List[A])(f: A => F[B]) = ???

object Test {
implicit def eitherApplicative[A]: Applicative[[X] =>> Either[A, X]] = ???

// Used to fail looking for `Applicative[[X] =>> Right[Nothing, X] | Left[Int, X]]`
traverse(List(1, 2))(i => if (true) Right(i) else Left(i))
}