Skip to content

Fix #3467: Don't pre-check kinds in TypeAssigner #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2017
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import NameOps._
import collection.mutable
import reporting.diagnostic.Message
import reporting.diagnostic.messages._
import Checking.{preCheckKind, preCheckKinds, checkNoPrivateLeaks}
import Checking.checkNoPrivateLeaks

trait TypeAssigner {
import tpd._
Expand Down Expand Up @@ -375,7 +375,7 @@ trait TypeAssigner {
else if (!paramNames.contains(name))
ctx.error(UndefinedNamedTypeParameter(name, paramNames), arg.pos)
else
namedArgMap(name) = preCheckKind(arg, paramBoundsByName(name.asTypeName)).tpe
namedArgMap(name) = arg.tpe

// Holds indexes of non-named typed arguments in paramNames
val gapBuf = new mutable.ListBuffer[Int]
Expand Down Expand Up @@ -408,7 +408,7 @@ trait TypeAssigner {
}
}
else {
val argTypes = preCheckKinds(args, pt.paramInfos).tpes
val argTypes = args.tpes
if (sameLength(argTypes, paramNames)) pt.instantiate(argTypes)
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
}
Expand Down
11 changes: 3 additions & 8 deletions tests/neg/i2771.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ trait C { type M <: A }
trait D { type M >: B }

object Test {
def test(x: C with D): Unit = {
def f(y: x.M)(z: y.L[y.L]) = z // error: y.L has wrong kind
f(new B { type L[F[_]] = F[F] })(1) // error: F has wrong kind
}

type LB[F[_]]

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

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

def bar[X, Y]() = ()
bar[List, Int]() // error: List has wrong kind
bar[List, Int]() // error: missing type parameter(s) for List

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

}
11 changes: 11 additions & 0 deletions tests/neg/i2771a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait A { type L[X] }
trait B { type L }
trait C { type M <: A }
trait D { type M >: B }

object Test {
def test(x: C with D): Unit = {
def f(y: x.M)(z: y.L[y.L]) = z // error: y.L has wrong kind
f(new B { type L[F[_]] = F[F] })(1) // error: F has wrong kind
}
}
16 changes: 16 additions & 0 deletions tests/neg/kinds1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object Test {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file and kinds2.scala are almost identitical, the other one could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinds2.scala tests another error. So I think we should keep it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not test f[C] in this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe because the error is not reported with this file:

This change required some changes in the tests because errors now get reported
at different times.


class C[T]
class C2[T[X]]

class B

val x: C[C] = ??? // error: Type argument has not the same kind as its bound
val y: C2[C] = ???

def f[T] = ???

def f2[T[X]] = ???

f2[C]
}
1 change: 0 additions & 1 deletion tests/neg/kinds.scala → tests/neg/kinds2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ object Test {

class B

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

def f[T] = ???
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/tcpoly_overloaded.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ trait Test {
def flatMap[S]
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
}
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: wrong kind
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
}
7 changes: 7 additions & 0 deletions tests/pos/i3467/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package collection

class Test {
def test(xs: Array[Int]): Unit = {
new ArrayOps(xs)
}
}
21 changes: 21 additions & 0 deletions tests/pos/i3467/collection_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package collection

abstract class WithFilter[+A, +CC[_]]

trait IndexedSeq[+A] extends Any with IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]

trait IndexedSeqOps[+A, +CC[X] <: IndexedSeq[X], +C] extends Any {
def withFilter(p: A => Boolean): WithFilter[A, CC] = ???
}

package immutable {
trait IndexedSeq[+A] extends collection.IndexedSeq[A] with collection.IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
}

object ArrayOps {
abstract class WithFilter[A] extends collection.WithFilter[A, immutable.IndexedSeq]
}

class ArrayOps[A](val xs: Array[A]) extends AnyVal with IndexedSeqOps[A, immutable.IndexedSeq, Array[A]] {
override def withFilter(p: A => Boolean): ArrayOps.WithFilter[A] = ???
}