summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-01-14 23:26:16 -0800
committerPaul Phillips <paulp@improving.org>2013-01-14 23:26:16 -0800
commit76b92ef78d3cb68d7e517bb4611efff45955f1e9 (patch)
tree80ae1bf02e9f2235c1cf0cdb7d950e5ea828442d
parent2d4ed8e795b814f3d71bc6bb4949e4c2a5510da8 (diff)
downloadscala-76b92ef78d3cb68d7e517bb4611efff45955f1e9.tar.gz
scala-76b92ef78d3cb68d7e517bb4611efff45955f1e9.tar.bz2
scala-76b92ef78d3cb68d7e517bb4611efff45955f1e9.zip
Modifies "maybeRewrap" to focus more on the maybe.
Existential types are rewrapped under a bunch of conditions unless the operation performed on the underlying type returns the same type by reference equality. That depends on a foundation of predictability which doesn't exist. The upshot is that existential types were rewrapped with abandon, even when the type were identical. This had both performance and correctness implications. Note where the test case output changes like so: -scala.collection.immutable.List[Any] +scala.collection.immutable.List[<?>] That's correctness.
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala9
-rw-r--r--test/files/run/t6329_repl.check32
-rw-r--r--test/files/run/t6329_repl.scala13
-rw-r--r--test/files/run/t6329_vanilla.check8
-rw-r--r--test/files/run/t6329_vanilla.scala14
5 files changed, 65 insertions, 11 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index 9d0d38913c..1f2f86c46b 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -234,7 +234,14 @@ trait Types extends api.Types { self: SymbolTable =>
* forwarded here. Some operations are rewrapped again.
*/
trait RewrappingTypeProxy extends SimpleTypeProxy {
- protected def maybeRewrap(newtp: Type) = if (newtp eq underlying) this else rewrap(newtp)
+ protected def maybeRewrap(newtp: Type) = (
+ if (newtp eq underlying) this
+ // BoundedWildcardTypes reach here during erroneous compilation: neg/t6258
+ // Higher-kinded exclusion is because [x]CC[x] compares =:= to CC: pos/t3800
+ // Otherwise, if newtp =:= underlying, don't rewrap it.
+ else if (!newtp.isWildcard && !newtp.isHigherKinded && (newtp =:= underlying)) this
+ else rewrap(newtp)
+ )
protected def rewrap(newtp: Type): Type
// the following are all operations in class Type that are overridden in some subclass
diff --git a/test/files/run/t6329_repl.check b/test/files/run/t6329_repl.check
index 8663184bde..55d689f2fb 100644
--- a/test/files/run/t6329_repl.check
+++ b/test/files/run/t6329_repl.check
@@ -3,11 +3,37 @@ Type :help for more information.
scala>
-scala> classManifest[List[_]]
+scala> import scala.reflect.classTag
+import scala.reflect.classTag
+
+scala> classManifest[scala.List[_]]
warning: there were 1 deprecation warnings; re-run with -deprecation for details
-res0: scala.reflect.ClassTag[List[_]] = scala.collection.immutable.List[Any]
+res0: scala.reflect.ClassTag[List[_]] = scala.collection.immutable.List[<?>]
-scala> scala.reflect.classTag[List[_]]
+scala> classTag[scala.List[_]]
res1: scala.reflect.ClassTag[List[_]] = scala.collection.immutable.List
+scala> classManifest[scala.collection.immutable.List[_]]
+warning: there were 1 deprecation warnings; re-run with -deprecation for details
+res2: scala.reflect.ClassTag[List[_]] = scala.collection.immutable.List[<?>]
+
+scala> classTag[scala.collection.immutable.List[_]]
+res3: scala.reflect.ClassTag[List[_]] = scala.collection.immutable.List
+
+scala> classManifest[Predef.Set[_]]
+warning: there were 1 deprecation warnings; re-run with -deprecation for details
+res4: scala.reflect.ClassTag[scala.collection.immutable.Set[_]] = scala.collection.immutable.Set[<?>]
+
+scala> classTag[Predef.Set[_]]
+res5: scala.reflect.ClassTag[scala.collection.immutable.Set[_]] = scala.collection.immutable.Set
+
+scala> classManifest[scala.collection.immutable.Set[_]]
+warning: there were 1 deprecation warnings; re-run with -deprecation for details
+res6: scala.reflect.ClassTag[scala.collection.immutable.Set[_]] = scala.collection.immutable.Set[<?>]
+
+scala> classTag[scala.collection.immutable.Set[_]]
+res7: scala.reflect.ClassTag[scala.collection.immutable.Set[_]] = scala.collection.immutable.Set
+
+scala>
+
scala>
diff --git a/test/files/run/t6329_repl.scala b/test/files/run/t6329_repl.scala
index add6d64962..f210d6512c 100644
--- a/test/files/run/t6329_repl.scala
+++ b/test/files/run/t6329_repl.scala
@@ -2,7 +2,14 @@ import scala.tools.partest.ReplTest
object Test extends ReplTest {
def code = """
- |classManifest[List[_]]
- |scala.reflect.classTag[List[_]]
- |""".stripMargin
+ |import scala.reflect.classTag
+ |classManifest[scala.List[_]]
+ |classTag[scala.List[_]]
+ |classManifest[scala.collection.immutable.List[_]]
+ |classTag[scala.collection.immutable.List[_]]
+ |classManifest[Predef.Set[_]]
+ |classTag[Predef.Set[_]]
+ |classManifest[scala.collection.immutable.Set[_]]
+ |classTag[scala.collection.immutable.Set[_]]
+ """.stripMargin
}
diff --git a/test/files/run/t6329_vanilla.check b/test/files/run/t6329_vanilla.check
index 8282afaeba..ad8f4b5c77 100644
--- a/test/files/run/t6329_vanilla.check
+++ b/test/files/run/t6329_vanilla.check
@@ -1,2 +1,8 @@
-scala.collection.immutable.List[Any]
+scala.collection.immutable.List[<?>]
scala.collection.immutable.List
+scala.collection.immutable.List[<?>]
+scala.collection.immutable.List
+scala.collection.immutable.Set[<?>]
+scala.collection.immutable.Set
+scala.collection.immutable.Set[<?>]
+scala.collection.immutable.Set
diff --git a/test/files/run/t6329_vanilla.scala b/test/files/run/t6329_vanilla.scala
index a31cd5c72e..f2d843896d 100644
--- a/test/files/run/t6329_vanilla.scala
+++ b/test/files/run/t6329_vanilla.scala
@@ -1,4 +1,12 @@
+import scala.reflect.classTag
+
object Test extends App {
- println(classManifest[List[_]])
- println(scala.reflect.classTag[List[_]])
-} \ No newline at end of file
+ println(classManifest[scala.List[_]])
+ println(classTag[scala.List[_]])
+ println(classManifest[scala.collection.immutable.List[_]])
+ println(classTag[scala.collection.immutable.List[_]])
+ println(classManifest[Predef.Set[_]])
+ println(classTag[Predef.Set[_]])
+ println(classManifest[scala.collection.immutable.Set[_]])
+ println(classTag[scala.collection.immutable.Set[_]])
+}