Skip to content

Commit c352fde

Browse files
authored
Merge pull request #3567 from dotty-staging/fix-#3467
Fix #3467: Don't pre-check kinds in TypeAssigner
2 parents 5e360d6 + b2618bb commit c352fde

File tree

8 files changed

+62
-13
lines changed

8 files changed

+62
-13
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import NameOps._
1313
import collection.mutable
1414
import reporting.diagnostic.Message
1515
import reporting.diagnostic.messages._
16-
import Checking.{preCheckKind, preCheckKinds, checkNoPrivateLeaks}
16+
import Checking.checkNoPrivateLeaks
1717

1818
trait TypeAssigner {
1919
import tpd._
@@ -375,7 +375,7 @@ trait TypeAssigner {
375375
else if (!paramNames.contains(name))
376376
ctx.error(UndefinedNamedTypeParameter(name, paramNames), arg.pos)
377377
else
378-
namedArgMap(name) = preCheckKind(arg, paramBoundsByName(name.asTypeName)).tpe
378+
namedArgMap(name) = arg.tpe
379379

380380
// Holds indexes of non-named typed arguments in paramNames
381381
val gapBuf = new mutable.ListBuffer[Int]
@@ -408,7 +408,7 @@ trait TypeAssigner {
408408
}
409409
}
410410
else {
411-
val argTypes = preCheckKinds(args, pt.paramInfos).tpes
411+
val argTypes = args.tpes
412412
if (sameLength(argTypes, paramNames)) pt.instantiate(argTypes)
413413
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
414414
}

tests/neg/i2771.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ trait C { type M <: A }
44
trait D { type M >: B }
55

66
object Test {
7-
def test(x: C with D): Unit = {
8-
def f(y: x.M)(z: y.L[y.L]) = z // error: y.L has wrong kind
9-
f(new B { type L[F[_]] = F[F] })(1) // error: F has wrong kind
10-
}
11-
127
type LB[F[_]]
138

149
type LL[F[_]] <: LB[F] // ok
1510

1611
def foo[X[_] <: Any]() = ()
17-
foo[Int]() // error: Int has wrong kind
12+
foo[Int]() // error: Type argument Int does not conform to upper bound
1813

1914
def bar[X, Y]() = ()
20-
bar[List, Int]() // error: List has wrong kind
15+
bar[List, Int]() // error: missing type parameter(s) for List
2116

22-
bar[Y = List, X = Int]() // error: List has wrong kind
17+
bar[Y = List, X = Int]() // error: missing type parameter(s) for List
2318

2419
}

tests/neg/i2771a.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait A { type L[X] }
2+
trait B { type L }
3+
trait C { type M <: A }
4+
trait D { type M >: B }
5+
6+
object Test {
7+
def test(x: C with D): Unit = {
8+
def f(y: x.M)(z: y.L[y.L]) = z // error: y.L has wrong kind
9+
f(new B { type L[F[_]] = F[F] })(1) // error: F has wrong kind
10+
}
11+
}

tests/neg/kinds1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Test {
2+
3+
class C[T]
4+
class C2[T[X]]
5+
6+
class B
7+
8+
val x: C[C] = ??? // error: Type argument has not the same kind as its bound
9+
val y: C2[C] = ???
10+
11+
def f[T] = ???
12+
13+
def f2[T[X]] = ???
14+
15+
f2[C]
16+
}

tests/neg/kinds.scala renamed to tests/neg/kinds2.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ object Test {
55

66
class B
77

8-
val x: C[C] = ??? // error: missing type parameter(s)
98
val y: C2[C] = ???
109

1110
def f[T] = ???

tests/neg/tcpoly_overloaded.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ trait Test {
2121
def flatMap[S]
2222
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
2323
}
24-
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: wrong kind
24+
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
2525
}

tests/pos/i3467/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package collection
2+
3+
class Test {
4+
def test(xs: Array[Int]): Unit = {
5+
new ArrayOps(xs)
6+
}
7+
}

tests/pos/i3467/collection_1.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package collection
2+
3+
abstract class WithFilter[+A, +CC[_]]
4+
5+
trait IndexedSeq[+A] extends Any with IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
6+
7+
trait IndexedSeqOps[+A, +CC[X] <: IndexedSeq[X], +C] extends Any {
8+
def withFilter(p: A => Boolean): WithFilter[A, CC] = ???
9+
}
10+
11+
package immutable {
12+
trait IndexedSeq[+A] extends collection.IndexedSeq[A] with collection.IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
13+
}
14+
15+
object ArrayOps {
16+
abstract class WithFilter[A] extends collection.WithFilter[A, immutable.IndexedSeq]
17+
}
18+
19+
class ArrayOps[A](val xs: Array[A]) extends AnyVal with IndexedSeqOps[A, immutable.IndexedSeq, Array[A]] {
20+
override def withFilter(p: A => Boolean): ArrayOps.WithFilter[A] = ???
21+
}

0 commit comments

Comments
 (0)