summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-06-11 09:24:54 +0200
committerJason Zaugg <jzaugg@gmail.com>2014-06-11 09:24:54 +0200
commita7046785e98db823a25eaaa975e571baed89690a (patch)
treeec187b5b7bbaaf3b6b2fdacd38169015e7e30d36 /test
parentfdc3812b0f61942f7682db0ba2dcfcf5658a0894 (diff)
parent7046d73e2a1d88273a8382f27a4fb0af6f87db3b (diff)
downloadscala-a7046785e98db823a25eaaa975e571baed89690a.tar.gz
scala-a7046785e98db823a25eaaa975e571baed89690a.tar.bz2
scala-a7046785e98db823a25eaaa975e571baed89690a.zip
Merge pull request #3781 from retronym/topic/8611
SI-8611 Avoid accidental patmat unification with refinement types
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t8611a.flags1
-rw-r--r--test/files/run/t8611a.scala16
-rw-r--r--test/files/run/t8611b.flags1
-rw-r--r--test/files/run/t8611b.scala54
-rw-r--r--test/files/run/t8611c.flags1
-rw-r--r--test/files/run/t8611c.scala21
-rw-r--r--test/junit/scala/reflect/internal/TypesTest.scala35
7 files changed, 129 insertions, 0 deletions
diff --git a/test/files/run/t8611a.flags b/test/files/run/t8611a.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/run/t8611a.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/run/t8611a.scala b/test/files/run/t8611a.scala
new file mode 100644
index 0000000000..99304df762
--- /dev/null
+++ b/test/files/run/t8611a.scala
@@ -0,0 +1,16 @@
+trait K
+trait L
+
+object O {
+ type LK = K with L
+ val A: LK = new K with L
+ val B: LK = new K with L
+}
+
+object Test extends App {
+ val scrut: O.LK = O.B
+ scrut match {
+ case O.A => ???
+ case O.B => // spurious unreachable
+ }
+}
diff --git a/test/files/run/t8611b.flags b/test/files/run/t8611b.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/run/t8611b.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/run/t8611b.scala b/test/files/run/t8611b.scala
new file mode 100644
index 0000000000..2df17c9ca0
--- /dev/null
+++ b/test/files/run/t8611b.scala
@@ -0,0 +1,54 @@
+sealed trait KrafsDescription
+
+abstract class NotWorkingEnum extends Enumeration {
+
+ type ExtendedValue = Value with KrafsDescription
+
+ def Enum(inDescription: String): ExtendedValue = {
+ new Val(nextId) with KrafsDescription {
+ }
+ }
+}
+
+abstract class WorkingEnum extends Enumeration {
+
+ type ExtendedValue = Value
+
+ def Enum(inDescription: String): ExtendedValue = {
+ new Val(nextId) {
+ }
+ }
+}
+
+object NotWorkingTab extends NotWorkingEnum {
+ val a = Enum("A")
+ val b = Enum("B")
+}
+
+object WorkingTab extends WorkingEnum {
+ val a = Enum("A")
+ val b = Enum("B")
+}
+
+object Test extends App {
+ testGris()
+ testWorking()
+
+ def testGris() {
+ val pipp = NotWorkingTab.b
+ pipp match {
+ case NotWorkingTab.a => ???
+ case NotWorkingTab.b =>
+ case _ => ???
+ }
+ }
+
+ def testWorking() {
+ val stuff = WorkingTab.a
+ stuff match {
+ case WorkingTab.a =>
+ case WorkingTab.b => ???
+ case _ => ???
+ }
+ }
+}
diff --git a/test/files/run/t8611c.flags b/test/files/run/t8611c.flags
new file mode 100644
index 0000000000..85d8eb2ba2
--- /dev/null
+++ b/test/files/run/t8611c.flags
@@ -0,0 +1 @@
+-Xfatal-warnings
diff --git a/test/files/run/t8611c.scala b/test/files/run/t8611c.scala
new file mode 100644
index 0000000000..2bd17f29a5
--- /dev/null
+++ b/test/files/run/t8611c.scala
@@ -0,0 +1,21 @@
+trait K
+trait L
+
+object O {
+ type LK = K with L
+}
+
+object Test extends App {
+ local
+
+ def local = {
+ val A: O.LK = new K with L
+ val B: O.LK = new K with L
+ val scrut: O.LK = A
+ scrut match {
+ case B if "".isEmpty => ???
+ case A =>
+ case B => ???
+ }
+ }
+}
diff --git a/test/junit/scala/reflect/internal/TypesTest.scala b/test/junit/scala/reflect/internal/TypesTest.scala
new file mode 100644
index 0000000000..95194ef0a4
--- /dev/null
+++ b/test/junit/scala/reflect/internal/TypesTest.scala
@@ -0,0 +1,35 @@
+package scala.reflect.internal
+
+import org.junit.Assert._
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+import scala.tools.nsc.symtab.SymbolTableForUnitTesting
+
+@RunWith(classOf[JUnit4])
+class TypesTest {
+
+ object symbolTable extends SymbolTableForUnitTesting
+ import symbolTable._, definitions._
+
+ @Test
+ def testRefinedTypeSI8611(): Unit = {
+ def stringNarrowed = StringTpe.narrow
+ assert(stringNarrowed != stringNarrowed)
+ assert(!(stringNarrowed =:= stringNarrowed))
+
+ def boolWithString = refinedType(BooleanTpe :: StringTpe :: Nil, NoSymbol)
+ assert(boolWithString != boolWithString)
+ assert(boolWithString =:= boolWithString)
+
+ val boolWithString1 = boolWithString
+ val boolWithString1narrow1 = boolWithString1.narrow
+ val boolWithString1narrow2 = boolWithString1.narrow
+ // Two narrowings of the same refinement end up =:=. This was the root
+ // cause of SI-8611. See `narrowUniquely` in `Logic` for the workaround.
+ assert(boolWithString1narrow1 =:= boolWithString1narrow2)
+ val uniquelyNarrowed1 = refinedType(boolWithString1narrow1 :: Nil, NoSymbol)
+ val uniquelyNarrowed2 = refinedType(boolWithString1narrow2 :: Nil, NoSymbol)
+ assert(uniquelyNarrowed1 =:= uniquelyNarrowed2)
+ }
+}