Skip to content

Commit

Permalink
Merge pull request #9488 from dotty-staging/widen-union-hk
Browse files Browse the repository at this point in the history
Fix #9479: Widen unions in inferred type lambdas
  • Loading branch information
odersky committed Aug 6, 2020
2 parents ab68d43 + cdc8435 commit b8825a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 7 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Types.scala
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
@@ -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))
}

0 comments on commit b8825a2

Please sign in to comment.