diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-24 05:42:08 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-24 05:42:08 +0000 |
commit | 034489b50158756b57091a04830d94160975bddb (patch) | |
tree | 4b695b2c00f7d464b893842ad8e729404b62c69b /test/files/pos | |
parent | 5dc127e69cae1d88aa6910ea6378ad5dc1aaeaab (diff) | |
download | scala-034489b50158756b57091a04830d94160975bddb.tar.gz scala-034489b50158756b57091a04830d94160975bddb.tar.bz2 scala-034489b50158756b57091a04830d94160975bddb.zip |
Added sanity check to lub calculation to preven...
Added sanity check to lub calculation to prevent invalid lubs from
emerging. The underlying cause of said lubs is that higher-order
type parameters are not handled correctly: this is why the issue
is seen so frequently in the collections. See pending test
pending/pos/those-kinds-are-high.scala for a demonstration. Until that's
fixed, we can at least raise the bar a bit.
Closes #2094, #2322, #4501. Also, some test cases in neg have been
promoted into working programs: #2179, #3774. (They're not in neg for
the "shouldn't work" reason, but out of despair.)
In some cases, such as the original reported ticket in #3528, this
only pushes the problem downfield: it still fails due to inferred type
parameters not conforming to bounds. I believe a similar issue with
higher-order type parameters underlies that.
Look at how far this takes us though. All kinds of stuff which did not
work, now works. None of these even compiled until now:
scala> :type List(mutable.Map(1 -> 1), immutable.Map(1 -> 1))
List[scala.collection.Map[Int,Int]]
scala> :type Set(List(1), mutable.Map(1 -> 1))
scala.collection.Set[Iterable[Any] with PartialFunction[Int,Int]]
scala> :type Stream(List(1), Set(1), 1 to 5)
Stream[Iterable[Int] with Int => AnyVal{def getClass(): Class[_ >: Int with Boolean <: AnyVal]}]
scala> :type Map(1 -> (1 to 10), 2 -> (1 to 10).toList)
scala.collection.immutable.Map[Int,scala.collection.immutable.Seq[Int]
]
PERFORMANCE: compiling quick.lib and quick.comp, this patch results in
an extra 27 subtype tests. Total. Time difference too small to measure.
However to be on the safe side I made it really easy to disable.
private final val verifyLubs = true // set to false
Review by moors, odersky.
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/bug2094.scala | 31 | ||||
-rw-r--r-- | test/files/pos/bug3528.scala | 8 | ||||
-rw-r--r-- | test/files/pos/bug4501.scala | 14 | ||||
-rwxr-xr-x | test/files/pos/t2179.scala | 3 | ||||
-rw-r--r-- | test/files/pos/t3774.scala | 5 |
5 files changed, 61 insertions, 0 deletions
diff --git a/test/files/pos/bug2094.scala b/test/files/pos/bug2094.scala new file mode 100644 index 0000000000..ff142117b2 --- /dev/null +++ b/test/files/pos/bug2094.scala @@ -0,0 +1,31 @@ +object Test extends App { + // compiles: + Map[Int, Value]( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // does not compile: + Map( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // Experiment.scala:10: error: type mismatch; + // found : (Int, KnownType) + // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 + // 0 -> KnownType(classOf[Object]), + // ^ + // one error found +} +sealed trait Value { + def getType: Option[Class[_]] +} + +case class UnknownValue() extends Value { + def getType = None + // compiles if changed to: + // def getType: Option[Class[_]] = None +} + +case class KnownType(typ: Class[_]) extends Value { + def getType = Some(typ) +}
\ No newline at end of file diff --git a/test/files/pos/bug3528.scala b/test/files/pos/bug3528.scala new file mode 100644 index 0000000000..ff49b3e929 --- /dev/null +++ b/test/files/pos/bug3528.scala @@ -0,0 +1,8 @@ +class A { + // 3528 - not fixed + // def f1 = List(List(1), Stream(1)) + // 3528 comments + def f2 = List(Set(1,2,3), List(1,2,3)) + // 2322 + def f3 = List(null: Range, null: List[Int]) +} diff --git a/test/files/pos/bug4501.scala b/test/files/pos/bug4501.scala new file mode 100644 index 0000000000..40628f1a4b --- /dev/null +++ b/test/files/pos/bug4501.scala @@ -0,0 +1,14 @@ +// After lub modification +import scala.collection.mutable.ListBuffer + +class A { + def foo[T](a:T, b:T):T = a + def f1 = foo(ListBuffer(), List()) + def f2 = foo(ListBuffer(), ListBuffer()) + def f3 = foo(List(), List()) + + // scalap + // def f1 : scala.collection.Seq[scala.Nothing] = { /* compiled code */ } + // def f2 : scala.collection.mutable.ListBuffer[scala.Nothing] = { /* compiled code */ } + // def f3 : scala.collection.immutable.List[scala.Nothing] = { /* compiled code */ } +}
\ No newline at end of file diff --git a/test/files/pos/t2179.scala b/test/files/pos/t2179.scala new file mode 100755 index 0000000000..89e22b6e2a --- /dev/null +++ b/test/files/pos/t2179.scala @@ -0,0 +1,3 @@ +object Test { + (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) +} diff --git a/test/files/pos/t3774.scala b/test/files/pos/t3774.scala new file mode 100644 index 0000000000..2869925b01 --- /dev/null +++ b/test/files/pos/t3774.scala @@ -0,0 +1,5 @@ +// This used to hang the lub process. Now it rejects the file. This is still not correct, +// but we can solve this only after a redesign of lub a la dot. +object Hang { + Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) +} |