diff options
author | Paul Phillips <paulp@improving.org> | 2013-08-17 09:58:54 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-08-17 10:58:14 -0700 |
commit | 1cd7a9e840158dab17a3aafc0ce849605706a561 (patch) | |
tree | 3777a5c8bdfe0edcdcd45aa453d28704242a8702 /test/files/neg | |
parent | 8f05647ca53da781b420be0723faf1cdbf14b2ff (diff) | |
download | scala-1cd7a9e840158dab17a3aafc0ce849605706a561.tar.gz scala-1cd7a9e840158dab17a3aafc0ce849605706a561.tar.bz2 scala-1cd7a9e840158dab17a3aafc0ce849605706a561.zip |
New tests for name-based pattern matcher.
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/t7214neg.check | 7 | ||||
-rw-r--r-- | test/files/neg/t7214neg.scala | 57 | ||||
-rw-r--r-- | test/files/neg/t7721.check | 21 | ||||
-rw-r--r-- | test/files/neg/t7721.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t7721.scala | 140 |
5 files changed, 226 insertions, 0 deletions
diff --git a/test/files/neg/t7214neg.check b/test/files/neg/t7214neg.check new file mode 100644 index 0000000000..0660cccd02 --- /dev/null +++ b/test/files/neg/t7214neg.check @@ -0,0 +1,7 @@ +t7214neg.scala:28: error: wrong number of patterns for object Extractor offering Any: expected 1, found 0 + case Extractor() => + ^ +t7214neg.scala:28: error: wrong number of patterns for object Extractor offering Any: expected 1, found 0 + case Extractor() => + ^ +two errors found diff --git a/test/files/neg/t7214neg.scala b/test/files/neg/t7214neg.scala new file mode 100644 index 0000000000..ff1ea8082d --- /dev/null +++ b/test/files/neg/t7214neg.scala @@ -0,0 +1,57 @@ +// pattern matcher crashes here trying to synthesize an uneeded outer test. +// no-symbol does not have an owner +// at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:49) +// at scala.tools.nsc.Global.abort(Global.scala:253) +// at scala.reflect.internal.Symbols$NoSymbol.owner(Symbols.scala:3248) +// at scala.reflect.internal.Symbols$Symbol.effectiveOwner(Symbols.scala:678) +// at scala.reflect.internal.Symbols$Symbol.isDefinedInPackage(Symbols.scala:664) +// at scala.reflect.internal.TreeGen.mkAttributedSelect(TreeGen.scala:188) +// at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:124) +// at scala.tools.nsc.ast.TreeDSL$CODE$.REF(TreeDSL.scala:308) +// at scala.tools.nsc.typechecker.PatternMatching$TreeMakers$TypeTestTreeMaker$treeCondStrategy$.outerTest(PatternMatching.scala:1209) +class Crash { + type Alias = C#T + + val c = new C + val t = new c.T + + // Crash via a Typed Pattern... + (t: Any) match { + case e: Alias => + } + + // ... or via a Typed Extractor Pattern. + object Extractor { + def unapply(a: Alias): Option[Any] = None + } + (t: Any) match { + case Extractor() => + case _ => + } + + // checking that correct outer tests are applied when + // aliases for path dependent types are involved. + val c2 = new C + type CdotT = c.T + type C2dotT = c2.T + + val outerField = t.getClass.getDeclaredFields.find(_.getName contains ("outer")).get + outerField.setAccessible(true) + + (t: Any) match { + case _: C2dotT => + println(s"!!! wrong match. t.outer=${outerField.get(t)} / c2 = $c2") // this matches on 2.10.0 + case _: CdotT => + case _ => + println(s"!!! wrong match. t.outer=${outerField.get(t)} / c = $c") + } +} + +class C { + class T +} + +object Test extends App { + new Crash +} + diff --git a/test/files/neg/t7721.check b/test/files/neg/t7721.check new file mode 100644 index 0000000000..e056b9a293 --- /dev/null +++ b/test/files/neg/t7721.check @@ -0,0 +1,21 @@ +t7721.scala:11: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Concrete => x.bippy + x.conco + ^ +t7721.scala:15: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Concrete with Foo => x.bippy + x.conco + ^ +t7721.scala:19: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Bar => x.bippy + x.barry + ^ +t7721.scala:39: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Concrete => x.bippy + x.dingo + x.conco + ^ +t7721.scala:43: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Concrete with Foo => x.bippy + x.dingo + x.conco + ^ +t7721.scala:47: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/test/files/neg/t7721.flags b/test/files/neg/t7721.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t7721.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t7721.scala b/test/files/neg/t7721.scala new file mode 100644 index 0000000000..27884c9e35 --- /dev/null +++ b/test/files/neg/t7721.scala @@ -0,0 +1,140 @@ +import scala.language.reflectiveCalls + +trait A { + trait Concrete { def conco: Int = 1 } + type Foo <: { def bippy: Int } + type Bar <: { def barry: Int } + + implicit def barTag: scala.reflect.ClassTag[Bar] + + def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.conco + case _ => -1 + } + def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.conco + case _ => -1 + } + def f3(x: Any) = x match { + case x: Foo with Bar => x.bippy + x.barry + case _ => -1 + } + def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy // warns, suppressed + case _ => -1 + } + def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +trait B extends A { + type Foo <: { def bippy: Int ; def dingo: Int } + type Bar <: { def barry: Int ; def bongo: Int } + + override implicit def barTag: scala.reflect.ClassTag[Bar] + + override def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f3(x: Any) = x match { + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + case _ => -1 + } + override def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy + x.dingo // warns, suppressed + case _ => -1 + } + override def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry + x.bongo // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +object Test { + abstract class Base extends A { + trait Foo { + def bippy = 2 + def dingo = 3 + } + trait Bar { + def barry = 2 + def bongo = 3 + } + implicit def barTag: scala.reflect.ClassTag[Bar] = scala.reflect.ClassTag(classOf[Bar]) + + def run() { + println("f1") + wrap(f1(new Concrete {})) + wrap(f1(new Foo {})) + wrap(f1(new Bar {})) + wrap(f1(new Foo with Concrete {})) + wrap(f1(new Concrete with Foo {})) + + println("\nf2") + wrap(f2(new Concrete {})) + wrap(f2(new Foo {})) + wrap(f2(new Bar {})) + wrap(f2(new Foo with Concrete {})) + wrap(f2(new Concrete with Foo {})) + wrap(f2(new Bar with Concrete {})) + wrap(f2(new Concrete with Bar {})) + wrap(f2(new Concrete with Foo with Bar {})) + wrap(f2(new Foo with Bar with Concrete {})) + + println("\nf3") + wrap(f3(new Concrete {})) + wrap(f3(new Foo {})) + wrap(f3(new Bar {})) + wrap(f3(new Foo with Concrete {})) + wrap(f3(new Concrete with Foo {})) + wrap(f3(new Bar with Concrete {})) + wrap(f3(new Concrete with Bar {})) + wrap(f3(new Concrete with Foo with Bar {})) + wrap(f3(new Foo with Bar with Concrete {})) + + println("\nf4") + wrap(f4(new Concrete {})) + wrap(f4(new Foo {})) + wrap(f4(new Bar {})) + wrap(f4(new Foo with Concrete {})) + wrap(f4(new Concrete with Foo {})) + wrap(f4(new Bar with Concrete {})) + wrap(f4(new Concrete with Bar {})) + wrap(f4(new Concrete with Foo with Bar {})) + wrap(f4(new Foo with Bar with Concrete {})) + + println("\nf5") + wrap(f5(new Concrete {})) + wrap(f5(new Foo {})) + wrap(f5(new Bar {})) + wrap(f5(new Foo with Concrete {})) + wrap(f5(new Concrete with Foo {})) + wrap(f5(new Bar with Concrete {})) + wrap(f5(new Concrete with Bar {})) + wrap(f5(new Concrete with Foo with Bar {})) + wrap(f5(new Foo with Bar with Concrete {})) + } + } + + object ao extends Base + object bo extends Base with B + + private def wrap(body: => Any) { + try println(body) + catch { case ex: NoSuchMethodException => println(ex) } + } + + def main(args: Array[String]) { + ao.run() + bo.run() + } +} + +// java.lang.NoSuchMethodException: Test$$anon$1.bippy()
\ No newline at end of file |