Skip to content
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
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ trait ImplicitRunInfo:
case t: TypeVar => apply(t.underlying)
case t: ParamRef => applyToUnderlying(t)
case t: ConstantType => apply(t.underlying)
case t @ AppliedType(tycon, args) if !tycon.typeSymbol.isClass =>
// To prevent arguments to be reduced away when re-applying the tycon bounds,
// we collect all parts as elements of a tuple. See i21951.scala for a test case.
apply(defn.tupleType(tycon :: args))
case t => mapOver(t)
end liftToAnchors
val liftedTp = liftToAnchors(tp)
Expand Down
33 changes: 33 additions & 0 deletions tests/pos/i21951.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class A
object A:
given g[F[_]]: F[A] = ???

object Test:
summon[List[A]] // ok
def foo[F[_]] =
summon[F[A]] // error

final case class X(val i: Int)
object X {
implicit final class XOps[F[_]](xs: F[X]) {
def unpack(implicit ev: F[X] <:< Iterable[X]): Iterable[Int] = xs.map(_.i)
}
}

object App extends App {
// good
val ys: List[X] = List(X(1))
println(ys.unpack)

// bad
def printPolymorphic[F[_]](xs: F[X])(implicit ev: F[X] <:< Iterable[X]) = {
locally {
// implicit XOps is correct
import X.XOps
println(xs.unpack) // found
}
// but it's not being searched for in the companion object of X
println(xs.unpack) // error: unpack is not a member of F[X]
}
printPolymorphic[List](ys)
}
Loading