summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-11-26 14:26:33 +1000
committerJason Zaugg <jzaugg@gmail.com>2016-02-01 13:23:20 +1000
commit6f8c05722ba4452279e353df2d81b58f260277d2 (patch)
tree2388344a8a22a4a059977e0d021bbb589017c254 /test
parent907fe03e57b3cac4d0a67663edcd2b3b040e6ff8 (diff)
downloadscala-6f8c05722ba4452279e353df2d81b58f260277d2.tar.gz
scala-6f8c05722ba4452279e353df2d81b58f260277d2.tar.bz2
scala-6f8c05722ba4452279e353df2d81b58f260277d2.zip
SI-9542 Unify different reprs. of module type refs
The new unit test shows failures in transitivity of subtyping and type equivalence, which boil down the the inconsistent handling of the semantically equivalent: ThisType(pre, ModuleClass) ModuleTypeRef(pre, ModuleClass) SingleType(pre, Module) This commit: - adds a case to `normalizePlus` to unwrap a `ThisType` to a `ModuleTypeRef` - Use `normalizePlus` more widely during subtype comparison - refactor `fourthTry` (part of `isSubType`) to remove code that becomes obviated by the use of `normalizePlus`. This fixes the regression in the extension methods phase which was triggered by https://github.com/scala/scala/pull/4749. We can also fix that regression by tweaking the extension methods phase itself to emit the `ThisType` representation of the owner of the value class, as before. I plan to demonstrate the two approaches to fixing the regression on separate branches, and the propose that the merged result of these two is useds.
Diffstat (limited to 'test')
-rw-r--r--test/files/pos/t9542.scala8
-rw-r--r--test/junit/scala/reflect/internal/TypesTest.scala28
2 files changed, 35 insertions, 1 deletions
diff --git a/test/files/pos/t9542.scala b/test/files/pos/t9542.scala
new file mode 100644
index 0000000000..d65f7ac4c6
--- /dev/null
+++ b/test/files/pos/t9542.scala
@@ -0,0 +1,8 @@
+object O {
+ trait T
+
+ class VC(val self: Any) extends AnyVal {
+ def extMethod(f: F1[T, Any]) = ()
+ }
+}
+trait F1[A, B]
diff --git a/test/junit/scala/reflect/internal/TypesTest.scala b/test/junit/scala/reflect/internal/TypesTest.scala
index 95194ef0a4..05a77cfb47 100644
--- a/test/junit/scala/reflect/internal/TypesTest.scala
+++ b/test/junit/scala/reflect/internal/TypesTest.scala
@@ -1,9 +1,10 @@
package scala.reflect.internal
import org.junit.Assert._
-import org.junit.Test
+import org.junit.{Assert, Test}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import scala.collection.mutable
import scala.tools.nsc.symtab.SymbolTableForUnitTesting
@RunWith(classOf[JUnit4])
@@ -32,4 +33,29 @@ class TypesTest {
val uniquelyNarrowed2 = refinedType(boolWithString1narrow2 :: Nil, NoSymbol)
assert(uniquelyNarrowed1 =:= uniquelyNarrowed2)
}
+
+ @Test
+ def testTransitivityWithModuleTypeRef(): Unit = {
+ import rootMirror.EmptyPackageClass
+ val (module, moduleClass) = EmptyPackageClass.newModuleAndClassSymbol(TermName("O"), NoPosition, 0L)
+ val minfo = ClassInfoType(List(ObjectTpe), newScope, moduleClass)
+ module.moduleClass setInfo minfo
+ module setInfo module.moduleClass.tpe
+ val tp1 = TypeRef(ThisType(EmptyPackageClass), moduleClass, Nil)
+ val tp2 = SingleType(ThisType(EmptyPackageClass), module)
+ val tp3 = ThisType(moduleClass)
+ val tps = List(tp1, tp2, tp3)
+ val results = mutable.Buffer[String]()
+ tps.permutations.foreach {
+ case ts @ List(a, b, c) =>
+ def tsShownRaw = ts.map(t => showRaw(t)).mkString(", ")
+ if (a <:< b && b <:< c && !(a <:< c)) results += s"<:< intransitive: $tsShownRaw"
+ if (a =:= b && b =:= c && !(a =:= c)) results += s"=:= intransitive: $tsShownRaw"
+ }
+ results.toList match {
+ case Nil => // okay
+ case xs =>
+ Assert.fail(xs.mkString("\n"))
+ }
+ }
}