aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-12-01 12:32:59 +0100
committerMartin Odersky <odersky@gmail.com>2015-12-06 16:09:19 +0100
commitdf00eb195d86a3d1425029f2f2436029a757ee5d (patch)
tree8ecba17ee7babf69f3dbe18f960c21abb95a412d
parent4c8db87e499e3a0f56a89ed0824b27230db32997 (diff)
downloaddotty-df00eb195d86a3d1425029f2f2436029a757ee5d.tar.gz
dotty-df00eb195d86a3d1425029f2f2436029a757ee5d.tar.bz2
dotty-df00eb195d86a3d1425029f2f2436029a757ee5d.zip
Disallow existentially bound parameters as type parameters
Done in order to keep the basics as simple as possible. Treating existentially bound parameters as still instantiatable type parameters does not seem to add anything fundamental, and makes the type system less regular.
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala13
-rw-r--r--test/dotc/tests.scala1
-rw-r--r--tests/neg/partialApplications.scala16
-rw-r--r--tests/pickling/partialApplications.scala24
-rw-r--r--tests/pos/collections.scala2
-rw-r--r--tests/pos/partialApplications.scala17
6 files changed, 39 insertions, 34 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index 1c1717649..c2738f4be 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -69,18 +69,7 @@ class TypeApplications(val self: Type) extends AnyVal {
if (lam.exists) lam.typeParams else Nil
}
case self: RefinedType =>
- def isBoundedLambda(tp: Type): Boolean = tp match {
- case tp: TypeRef => tp.typeSymbol.isLambdaTrait
- case tp: RefinedType => tp.refinedName.isLambdaArgName && isBoundedLambda(tp.parent)
- case _ => false
- }
- val tparams = self.parent.typeParams
- self.refinedInfo match {
- case rinfo: TypeBounds if rinfo.isAlias || isBoundedLambda(self) =>
- tparams.filterNot(_.name == self.refinedName)
- case _ =>
- tparams
- }
+ self.parent.typeParams.filterNot(_.name == self.refinedName)
case self: SingletonType =>
Nil
case self: TypeProxy =>
diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala
index 0ac043daf..de4705dac 100644
--- a/test/dotc/tests.scala
+++ b/test/dotc/tests.scala
@@ -158,6 +158,7 @@ class tests extends CompilerTest {
@Test def neg_moduleSubtyping = compileFile(negDir, "moduleSubtyping", xerrors = 4)
@Test def neg_escapingRefs = compileFile(negDir, "escapingRefs", xerrors = 2)
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)
+ @Test def neg_partialApplications = compileFile(negDir, "partialApplications", xerrors = 3)
@Test def neg_selfInheritance = compileFile(negDir, "selfInheritance", xerrors = 6)
@Test def neg_selfreq = compileFile(negDir, "selfreq", xerrors = 3)
@Test def neg_singletons = compileFile(negDir, "singletons", xerrors = 8)
diff --git a/tests/neg/partialApplications.scala b/tests/neg/partialApplications.scala
new file mode 100644
index 000000000..d186273aa
--- /dev/null
+++ b/tests/neg/partialApplications.scala
@@ -0,0 +1,16 @@
+object Test2 {
+ type Histogram = Map[_, Int] // this is now an existential type!
+
+ type StringlyHistogram = Histogram[_ >: String] // Error: Test2.Histogram does not take type parameters
+
+ val xs: Histogram[String] = Map[String, Int]() // Error: Test2.Histogram does not take type parameters
+
+ val ys: StringlyHistogram[String] = xs // Error: Test2.StringlyHistogram does not take type parameters
+
+ val zs: StringlyHistogram = xs
+
+ val xs1 = xs
+ val ys1 = ys
+ val zs1 = zs
+
+}
diff --git a/tests/pickling/partialApplications.scala b/tests/pickling/partialApplications.scala
index f517011b9..c4c4328f6 100644
--- a/tests/pickling/partialApplications.scala
+++ b/tests/pickling/partialApplications.scala
@@ -1,13 +1,29 @@
-object PartialApplications {
+object partialApplications {
- type Histogram = Map[_, Int]
+ type Histogram[X] = Map[X, Int]
- type StringlyHistogram = Histogram[_ >: String]
+ type StringlyHistogram[X >: String] = Histogram[X]
val xs: Histogram[String] = Map[String, Int]()
val ys: StringlyHistogram[String] = xs
- val zs: StringlyHistogram = xs
+ def e = xs
+
+ val zs: StringlyHistogram[_] = e
+
+ type IntMap[Y] = Map[Int, Y]
+
+ val is = Map[Int, Boolean]()
+
+ val js: IntMap[Boolean] = is
+
+ val ks: IntMap[_] = is
+
+ type RMap[X, Y] = Map[Y, X]
+
+ val rs = Map[Int, Float]()
+
+ val ss: RMap[Float, Int] = rs
}
diff --git a/tests/pos/collections.scala b/tests/pos/collections.scala
index 08c3010c8..5edcff986 100644
--- a/tests/pos/collections.scala
+++ b/tests/pos/collections.scala
@@ -10,7 +10,7 @@ object collections {
val s = Set(1, 2, 3)
val ss = s map (_ + 1)
- val cbf: CanBuildFrom[List, Int, List[Int]] = scala.collection.immutable.List.canBuildFrom
+ val cbf: CanBuildFrom[List[_], Int, List[Int]] = scala.collection.immutable.List.canBuildFrom
val nil = Nil
val ints1 = 1 :: Nil
diff --git a/tests/pos/partialApplications.scala b/tests/pos/partialApplications.scala
index 696c544e7..fae6849fc 100644
--- a/tests/pos/partialApplications.scala
+++ b/tests/pos/partialApplications.scala
@@ -27,20 +27,3 @@ object Test {
val ss: RMap[Float, Int] = rs
}
-
-object Test2 {
- type Histogram = Map[_, Int]
-
- type StringlyHistogram = Histogram[_ >: String]
-
- val xs: Histogram[String] = Map[String, Int]()
-
- val ys: StringlyHistogram[String] = xs
-
- val zs: StringlyHistogram = xs
-
- val xs1 = xs
- val ys1 = ys
- val zs1 = zs
-
-}