Skip to content

Commit 22f50b8

Browse files
authored
Fix LiftToAnchors for higher-kinded type applications (#23672)
Fixes #21951
2 parents 99b24d7 + 2029803 commit 22f50b8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,10 @@ trait ImplicitRunInfo:
844844
case t: TypeVar => apply(t.underlying)
845845
case t: ParamRef => applyToUnderlying(t)
846846
case t: ConstantType => apply(t.underlying)
847+
case t @ AppliedType(tycon, args) if !tycon.typeSymbol.isClass =>
848+
// To prevent arguments to be reduced away when re-applying the tycon bounds,
849+
// we collect all parts as elements of a tuple. See i21951.scala for a test case.
850+
apply(defn.tupleType(tycon :: args))
847851
case t => mapOver(t)
848852
end liftToAnchors
849853
val liftedTp = liftToAnchors(tp)

tests/pos/i21951.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class A
2+
object A:
3+
given g[F[_]]: F[A] = ???
4+
5+
object Test:
6+
summon[List[A]] // ok
7+
def foo[F[_]] =
8+
summon[F[A]] // error
9+
10+
final case class X(val i: Int)
11+
object X {
12+
implicit final class XOps[F[_]](xs: F[X]) {
13+
def unpack(implicit ev: F[X] <:< Iterable[X]): Iterable[Int] = xs.map(_.i)
14+
}
15+
}
16+
17+
object App extends App {
18+
// good
19+
val ys: List[X] = List(X(1))
20+
println(ys.unpack)
21+
22+
// bad
23+
def printPolymorphic[F[_]](xs: F[X])(implicit ev: F[X] <:< Iterable[X]) = {
24+
locally {
25+
// implicit XOps is correct
26+
import X.XOps
27+
println(xs.unpack) // found
28+
}
29+
// but it's not being searched for in the companion object of X
30+
println(xs.unpack) // error: unpack is not a member of F[X]
31+
}
32+
printPolymorphic[List](ys)
33+
}

0 commit comments

Comments
 (0)