diff options
author | Dmitry Petrashko <dark@d-d.me> | 2014-10-11 07:55:01 +0200 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2014-10-11 07:55:01 +0200 |
commit | 5f05c4be3e986b7a370f566fd4409b29463fb781 (patch) | |
tree | 6c141e687df89232b8005a48a152cbc700ee055f /tests/neg | |
parent | e0b290c1e64a134633fc804ef1f9e54ccf17d25d (diff) | |
parent | 3211985a439b4e86ef58b0709673118c84063118 (diff) | |
download | dotty-5f05c4be3e986b7a370f566fd4409b29463fb781.tar.gz dotty-5f05c4be3e986b7a370f566fd4409b29463fb781.tar.bz2 dotty-5f05c4be3e986b7a370f566fd4409b29463fb781.zip |
Merge pull request #174 from dotty-staging/reb
Pattern matcher
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/badAuxConstr.scala | 11 | ||||
-rw-r--r-- | tests/neg/cycles.scala | 4 | ||||
-rw-r--r-- | tests/neg/t1048.scala | 21 | ||||
-rw-r--r-- | tests/neg/t1131.scala | 4 | ||||
-rw-r--r-- | tests/neg/t1164.scala | 29 | ||||
-rw-r--r-- | tests/neg/t1279a.scala | 39 | ||||
-rw-r--r-- | tests/neg/typetest.scala | 7 |
7 files changed, 115 insertions, 0 deletions
diff --git a/tests/neg/badAuxConstr.scala b/tests/neg/badAuxConstr.scala new file mode 100644 index 000000000..8984f2306 --- /dev/null +++ b/tests/neg/badAuxConstr.scala @@ -0,0 +1,11 @@ +class A[S, T](s: S, t: T) { + val z: T = ??? +} + +class B[X](x: X) extends A[X, X](x, x) { + def this() = this(z) // error: not found: z + + val u: X = x + def this(x: Int) = this(u) // error: not found: u +} + diff --git a/tests/neg/cycles.scala b/tests/neg/cycles.scala new file mode 100644 index 000000000..4eaec125f --- /dev/null +++ b/tests/neg/cycles.scala @@ -0,0 +1,4 @@ +class Foo[T <: U, U <: T] + +class Bar[T >: T] + diff --git a/tests/neg/t1048.scala b/tests/neg/t1048.scala new file mode 100644 index 000000000..4b8e78b4c --- /dev/null +++ b/tests/neg/t1048.scala @@ -0,0 +1,21 @@ +trait T[U] { + def x: T[_ <: U] +} + +object T { + def unapply[U](t: T[U]): Option[T[_ <: U]] = Some(t.x) +} + +object Test { + def f[W](t: T[W]) = t match { + case T(T(_)) => () +// Gives: +// t1048.scala:11: error: There is no best instantiation of pattern type T[Any'] +// that makes it a subtype of selector type T[_ <: W]. +// Non-variant type variable U cannot be uniquely instantiated. +// case T(T(_)) => () +// ^ +// one error found + } +} + diff --git a/tests/neg/t1131.scala b/tests/neg/t1131.scala new file mode 100644 index 000000000..f4a7b377d --- /dev/null +++ b/tests/neg/t1131.scala @@ -0,0 +1,4 @@ +trait A { self: Any { def p: Any } => + def f(b: => Unit): Unit = {} + f { p } // error: cannot access member 'p' from structural type +} diff --git a/tests/neg/t1164.scala b/tests/neg/t1164.scala new file mode 100644 index 000000000..6deedfbff --- /dev/null +++ b/tests/neg/t1164.scala @@ -0,0 +1,29 @@ +object test { + + class Foo[a](val arg : a) + + object Foo { + def apply [a](arg : a, right :a) = new Foo[a](arg) + def unapply [a](m : Foo[a]) = Some (m.arg) + } + + def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }} + // Unapply node here will have type argument [a] instantiated to scala.Nothing: + // UnApply(TypeApply(Select(Ident(Foo),unapply),List(TypeTree[TypeVar(PolyParam(a) -> TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing))])),List(),List(Bind(x,Ident(_)))) + // but the type of the UnApply node itself is correct: RefinedType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),test$)),Foo), test$$Foo$$a, TypeAlias(TypeRef(NoPrefix,a))) + // + + + // Try the same thing as above but use function as argument to Bar + // constructor + + type FunIntToA [a] = (Int) => a + class Bar[a] (var f: FunIntToA[a]) + + object Bar { + def apply[a](f: FunIntToA[a]) = new Bar[a](f) + def unapply[a](m: Bar[a]) = Some (m.f) + } + + def matchAndGetFunFromBar[a](b:Bar[a]) : FunIntToA[a] = { b match { case Bar(x) => x}} +} diff --git a/tests/neg/t1279a.scala b/tests/neg/t1279a.scala new file mode 100644 index 000000000..6d768d435 --- /dev/null +++ b/tests/neg/t1279a.scala @@ -0,0 +1,39 @@ +// covariant linked list +abstract class M { + self: M => + + type T + final type selfType = M {type T <: self.T} + type actualSelfType >: self.type <: selfType // this no longer compiles because self.type is not a subtype of selfType + + def next: selfType + + // I don't understand why this doesn't compile, but that's a separate matter + // error: method all2 cannot be accessed in M.this.selfType + // because its instance type => Stream[M{type T <: M.this.selfType#T}] + // contains a malformed type: M.this.selfType#T + def all2: Stream[M {type T <: self.T}] = Stream.cons(self: actualSelfType, next.all2) + + // compiles successfully + def all3: Stream[M {type T <: self.T}] = all3Impl(self: actualSelfType) + private def all3Impl(first: M {type T <: self.T}): Stream[M {type T <: self.T}] = Stream.cons(first, all3Impl(first.next)) + + def all4: Stream[M {type T <: self.T}] = Unrelated.all4Impl[T](self: actualSelfType) +} + +// TODO!!! fix this bug for real, it compiles successfully, but weird types are inferred +object Unrelated { + // compiles successfully + def all4Impl[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4Impl[U](first.next)) + + // should compile successfully without the [U], but: + // def all4ImplFail[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4ImplFail(first.next)) + // + // test/files/pos/t1279a.scala:31: error: type mismatch; + // found : first.selfType + // (which expands to) M{type T <: first.T} + // required: M{type T <: Nothing} + // def all4ImplFail[U](first: M {type T <: U}): Stream[M {type T <: U}] = Stream.cons(first, all4ImplFail(first.next)) + // ^ + // one error found +} diff --git a/tests/neg/typetest.scala b/tests/neg/typetest.scala new file mode 100644 index 000000000..27ecd25b2 --- /dev/null +++ b/tests/neg/typetest.scala @@ -0,0 +1,7 @@ +object Test { + + val i: Int = 1 + + println(i.isInstanceOf[Object]) +} + |