Skip to content

Commit b6d19de

Browse files
committed
Fix erasure of curried polymorphic function types
Fixes #6678 Fixes #8921 Fixes #13304 Fixes #13426
1 parent 8c3e7a2 commit b6d19de

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,11 @@ object Erasure {
700700
// PolyFunction apply Selects will not have a symbol, so deduce the owner
701701
// from the typed qual.
702702
val owner = qual1.tpe.typeSymbol
703-
if defn.isFunctionClass(owner) then owner else NoSymbol
703+
if defn.isFunctionClass(owner) && false then owner
704+
else
705+
val alt = erasure(tree.qualifier.typeOpt).typeSymbol
706+
if defn.isFunctionClass(alt) then alt
707+
else NoSymbol
704708
else
705709
val owner = sym.maybeOwner
706710
if defn.specialErasure.contains(owner) then

tests/pos/i13426.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
val f = [R] => () => [A] => (a: A => R, b: A) => a(b)
2+
val x = f[Int]()(_, 3)

tests/pos/i6678.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object O {
2+
val f = (i:Int) => [T] => (s:String) => 2
3+
def m = f(1)("a")
4+
}

tests/pos/i8921.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type R[F[_], A] =[B] => (A => F[B]) => F[B]
2+
3+
type M[F[_]] =[A, B] => (A => F[B]) => F[A] => F[B]
4+
5+
def mr[F[_]]: M[[A] =>> R[F, A]] =
6+
[A, B] => (f: A => R[F, B]) => (m: R[F, A]) =>
7+
[C] => (k: B => F[C]) => m(a => f(a)(k))

tests/run/i13304.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

tests/run/i13304.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Zero[F[_]]:
2+
def zero[A]: F[A]
3+
4+
given Zero[List] with
5+
def zero[A] = List.empty[A]
6+
7+
given Zero[Option] with
8+
def zero[A] = Option.empty[A]
9+
10+
11+
@main def Test =
12+
val test = [F[_]] => (f: Zero[F]) ?=> [G[_]] => (g: Zero[G]) ?=> println("foo")
13+
test[List][Option]

0 commit comments

Comments
 (0)