diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-20 22:00:29 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-20 22:00:45 +0100 |
commit | e51b8845fb20fe3a4e1c655d4b72e2833906bbc2 (patch) | |
tree | 91bc16867d7a709566d8be80902b3256294cf338 /tests/invalid | |
parent | 581fee04f808d6f7759f98358e7475e6a58138e3 (diff) | |
download | dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.tar.gz dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.tar.bz2 dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.zip |
The big pending/pos test triage
Diffstat (limited to 'tests/invalid')
46 files changed, 890 insertions, 0 deletions
diff --git a/tests/invalid/pos/IterableSelfRec.scala b/tests/invalid/pos/IterableSelfRec.scala new file mode 100644 index 000000000..7fd235f12 --- /dev/null +++ b/tests/invalid/pos/IterableSelfRec.scala @@ -0,0 +1,53 @@ +// This does not currently work because it mixes higher-kinded types and raw type constructors. +package dotty.collection +package immutable + +import annotation.unchecked.uncheckedVariance + +trait Collection[T] { self => + type This <: Collection { type This <: self.This } + def companion: CollectionCompanion[This] +} + +trait Iterable[T] extends Collection[T] { self => + type This <: Iterable { type This <: self.This } + override def companion: IterableCompanion[This] = Iterable.asInstanceOf + + def iterator: Iterator[T] +} + +trait Seq[T] extends Iterable[T] { self => + type This <: Seq { type This <: self.This } + override def companion: IterableCompanion[This] = Seq.asInstanceOf + + def apply(x: Int): T +} + +abstract class CollectionCompanion[+CC[X] <: Collection[X] { type This <: CC }] + +abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] extends CollectionCompanion[CC] { + def fromIterator[T](it: Iterator[T]): CC[T] + def map[T, U](xs: Iterable[T], f: T => U): CC[U] = + fromIterator(xs.iterator.map(f)) + def filter[T](xs: Iterable[T], p: T => Boolean): CC[T] = + fromIterator(xs.iterator.filter(p)) + def flatMap[T, U](xs: Iterable[T], f: T => TraversableOnce[U]): CC[U] = + fromIterator(xs.iterator.flatMap(f)) + + implicit def transformOps[T](xs: CC[T] @uncheckedVariance): TransformOps[CC, T] = ??? // new TransformOps[CC, T](xs) +} + +class TransformOps[+CC[X] <: Iterable[X] { type This <: CC }, T] (val xs: CC[T]) extends AnyVal { + def companion[T](xs: CC[T] @uncheckedVariance): IterableCompanion[CC] = xs.companion + def map[U](f: T => U): CC[U] = companion(xs).map(xs, f) + def filter(p: T => Boolean): CC[T] = companion(xs).filter(xs, p) + def flatMap[U](f: T => TraversableOnce[U]): CC[U] = companion(xs).flatMap(xs, f) +} + +object Iterable extends IterableCompanion[Iterable] { + def fromIterator[T](it: Iterator[T]): Iterable[T] = ??? +} +object Seq extends IterableCompanion[Seq] { + def fromIterator[T](it: Iterator[T]): Seq[T] = ??? +} + diff --git a/tests/invalid/pos/contrib701.scala b/tests/invalid/pos/contrib701.scala new file mode 100644 index 000000000..6f0e53a36 --- /dev/null +++ b/tests/invalid/pos/contrib701.scala @@ -0,0 +1,3 @@ +trait B { + type A[T] >: A[A[T]] +} diff --git a/tests/invalid/pos/cycle-jsoup.flags b/tests/invalid/pos/cycle-jsoup.flags new file mode 100644 index 000000000..ca20f5517 --- /dev/null +++ b/tests/invalid/pos/cycle-jsoup.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/invalid/pos/cycle-jsoup.scala b/tests/invalid/pos/cycle-jsoup.scala new file mode 100644 index 000000000..d547ecd93 --- /dev/null +++ b/tests/invalid/pos/cycle-jsoup.scala @@ -0,0 +1,5 @@ +object Test { + def main(args : Array[String]): Unit = { + org.jsoup.Jsoup.parse(null: java.net.URL, 3000) + } +} diff --git a/tests/invalid/pos/depexists.scala b/tests/invalid/pos/depexists.scala new file mode 100644 index 000000000..dff1917a4 --- /dev/null +++ b/tests/invalid/pos/depexists.scala @@ -0,0 +1,5 @@ +object depexists { + + val c: Option[(a, b)] forSome { type a <: Number; type b <: (a, a) } = null + val d = c +} diff --git a/tests/invalid/pos/dotless-targs.scala b/tests/invalid/pos/dotless-targs.scala new file mode 100644 index 000000000..7394f361a --- /dev/null +++ b/tests/invalid/pos/dotless-targs.scala @@ -0,0 +1,10 @@ +// Type arguments on infix operators are not supported by the syntax +class A { + def fn1 = List apply 1 + def fn2 = List apply[Int] 2 + + def g1: Char = "g1" toList 0 + def g2: Char = "g2" apply 1 + + def h1 = List apply[List[Int]] (List(1), List(2)) mapConserve[List[Any]] (x => x) +} diff --git a/tests/invalid/pos/five-dot-f.flags b/tests/invalid/pos/five-dot-f.flags new file mode 100644 index 000000000..112fc720a --- /dev/null +++ b/tests/invalid/pos/five-dot-f.flags @@ -0,0 +1 @@ +-Xfuture
\ No newline at end of file diff --git a/tests/invalid/pos/five-dot-f.scala b/tests/invalid/pos/five-dot-f.scala new file mode 100644 index 000000000..8a7f86e21 --- /dev/null +++ b/tests/invalid/pos/five-dot-f.scala @@ -0,0 +1,5 @@ +class C { + implicit def ffer(x: Int) = new { def f : Long = 123L } + + val x1: Long = 5.f +} diff --git a/tests/invalid/pos/functions.scala b/tests/invalid/pos/functions.scala new file mode 100644 index 000000000..0207523dd --- /dev/null +++ b/tests/invalid/pos/functions.scala @@ -0,0 +1,12 @@ +import scala.actors.Actor + +object Test { + + def foo() = { + val x = 1; + Actor.receive { + case "abc" if x == 2 => + Console.println("hi!") + } + } +} diff --git a/tests/invalid/pos/generic-sigs.scala b/tests/invalid/pos/generic-sigs.scala new file mode 100644 index 000000000..b751e215e --- /dev/null +++ b/tests/invalid/pos/generic-sigs.scala @@ -0,0 +1,20 @@ +import language.existentials + +object A { + def f1 = List(classOf[Int], classOf[String]) + def f2 = List(classOf[String], classOf[Int]) + def f3(x: Class[_ <: Int]) = x + def f4(x: Class[_ <: String with Int]) = x + def f5(x: Class[_ <: Int with String]) = x + + class Bippy[T] + def f6(x: Int) = new Bippy[t forSome { type t <: Int }] + def f7(x: T forSome { type T <: Float }) = x + def f8(x: T forSome { type T <: Unit }) = x + def f9(x: T forSome { type T <: scala.runtime.BoxedUnit }) = x + def f10(x: Int) = new Bippy[t forSome { type t <: Unit }] + def f11(x: Int) = new Bippy[t forSome { type t >: Null }] + + class Boppy[+T1,-T2] + def g1 = new Boppy[t forSome { type t <: Int }, u forSome { type u <: String }] +} diff --git a/tests/invalid/pos/patmat.scala b/tests/invalid/pos/patmat.scala new file mode 100644 index 000000000..53e1c5f1f --- /dev/null +++ b/tests/invalid/pos/patmat.scala @@ -0,0 +1,163 @@ +// these used to be in test/files/run/patmatnew.scala +// the ticket numbers are from the old tracker, not Trac + +object ZipFun { + //just compilation + def zipFun[a, b](xs: List[a], ys: List[b]): List[Tuple2[a, b]] = ((xs, ys): @unchecked) match { + // !!! case (List(), _), (_, List()) => List() + case (x :: xs1, y :: ys1) => (x, y) :: zipFun(xs1, ys1) + } +} + +object Test1253 { // compile-only + def foo(t: (Int, String)) = t match { + case (1, "") => throw new Exception + case (r, _) => throw new Exception(r.toString) + } +} + +object Foo1258 { + case object baz + def foo(bar: AnyRef) = { + val Baz = baz + bar match { + case Baz => () + } + } +} + +object t1261 { + sealed trait Elem + case class Foo() extends Elem + case class Bar() extends Elem + trait Row extends Elem + object Row { + def unapply(r: Row) = true + + def f(elem: Elem): Unit = { + elem match { + case Bar() => ; + case Row() => ; + case Foo() => ; // used to give ERROR (unreachable code) + } + } + } +} + +sealed abstract class Tree +case class Node(l: Tree, v: Int, r: Tree) extends Tree +case object EmptyTree extends Tree + +object Ticket335 { // compile-only + def runTest(): Unit = { + (EmptyTree: Tree @unchecked) match { + case Node(_, v, _) if (v == 0) => 0 + case EmptyTree => 2 + } + } +} + +object TestIfOpt { //compile-only "test EqualsPatternClass in combination with MixTypes opt, bug #1278" + trait Token { + val offset: Int + def matching: Option[Token] + } + def go(tok: Token) = (tok.matching: @unchecked) match { + case Some(other) if true => Some(other) + case _ if true => tok.matching match { + case Some(other) => Some(other) + case _ => None + } + } +} + +object Go { // bug #1277 compile-only + trait Core { def next: Position = null } + trait Dir + val NEXT = new Dir {} + + trait Position extends Core + + (null: Core, null: Dir) match { + case (_, NEXT) if true => false // no matter whether NEXT test succeed, cannot throw column because of guard + case (at2: Position, dir) => true + } +} + +trait Outer { // bug #1282 compile-only + object No + trait File { + (null: AnyRef) match { + case No => false + } + } +} + +class Test806_818 { // #806, #811 compile only -- type of bind + // t811 + trait Core { + trait NodeImpl + trait OtherImpl extends NodeImpl + trait DoubleQuoteImpl extends NodeImpl + def asDQ(node: OtherImpl) = node match { + case dq: DoubleQuoteImpl => dq + } + } + + trait IfElseMatcher { + type Node <: NodeImpl + trait NodeImpl + trait IfImpl + private def coerceIf(node: Node) = node match { + case node: IfImpl => node // var node is of type Node with IfImpl! + case _ => null + } + } +} + +object Ticket495bis { + def signum(x: Int): Int = + x match { + case 0 => 0 + case _ if x < 0 => -1 + case _ if x > 0 => 1 + } + def pair_m(x: Int, y: Int) = + (x, y) match { + case (_, 0) => 0 + case (-1, _) => -1 + case (_, _) => 1 + } +} + +object Ticket522 { + class Term[X] + object App { + // i'm hidden + case class InternalApply[Y, Z](fun: Y => Z, arg: Y) extends Term[Z] + + def apply[Y, Z](fun: Y => Z, arg: Y): Term[Z] = + new InternalApply[Y, Z](fun, arg) + + def unapply[X](arg: Term[X]): Option[(Y => Z, Y)] forSome { type Y; type Z } = + arg match { + case i: InternalApply[y, z] => Some(i.fun, i.arg) + case _ => None + } + } + + App({ x: Int => x }, 5) match { + case App(arg, a) => + } +} + +object Ticket710 { + def method: Unit = { + sealed class Parent() + case object Child extends Parent() + val x: Parent = Child + x match { + case Child => () + } + } +} diff --git a/tests/invalid/pos/pos-bug1241.scala b/tests/invalid/pos/pos-bug1241.scala new file mode 100644 index 000000000..1038dc304 --- /dev/null +++ b/tests/invalid/pos/pos-bug1241.scala @@ -0,0 +1,8 @@ +object test extends App { + // more.. + type T = { def hello(): Unit } + //val x4 = new AnyRef { def hello() { println("4") } } // ok! + val x4: T = new { def hello(): Unit = { println("4") } } // error! + x4.hello() + // more.. +} diff --git a/tests/invalid/pos/specializes-sym-crash.scala b/tests/invalid/pos/specializes-sym-crash.scala new file mode 100644 index 000000000..e0e458170 --- /dev/null +++ b/tests/invalid/pos/specializes-sym-crash.scala @@ -0,0 +1,27 @@ +// This relies on the naming of the transformed classes which will have to change in the new stdlib. +import scala.collection._ + +trait Foo[+A, + +Coll, + +This <: SeqView[A, Coll] with SeqViewLike[A, Coll, This]] +extends Seq[A] with SeqLike[A, This] with IterableView[A, Coll] with IterableViewLike[A, Coll, This] { +self => + + trait TransformedFoo[+B] extends SeqView[B, Coll] with super.Transformed[B] { + def length: Int + def apply(idx: Int): B + override def toString = viewToString + } + trait Reversed extends TransformedFoo[A] { + override def iterator: Iterator[A] = createReversedIterator + def length: Int = self.length + def apply(idx: Int): A = self.apply(length - 1 - idx) + final override protected[this] def viewIdentifier = "R" + + private def createReversedIterator = { + var lst = List[A]() + for (elem <- self) lst ::= elem + lst.iterator + } + } +} diff --git a/tests/invalid/pos/t2782.scala b/tests/invalid/pos/t2782.scala new file mode 100644 index 000000000..3b387af80 --- /dev/null +++ b/tests/invalid/pos/t2782.scala @@ -0,0 +1,18 @@ +import scala.{collection => sc} + +object Test { + trait Foo[T] + + // Haven't managed to repro without using a CanBuild or CanBuildFrom implicit parameter + implicit def MapFoo[A, B, M[A, B] <: sc.Map[A,B]](implicit aFoo: Foo[A], bFoo: Foo[B], cb: sc.generic.CanBuild[(A, B), M[A, B]]): Test.Foo[M[A,B]] = new Foo[M[A,B]] {} + implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] // no difference if this line is uncommented + implicit def Tuple2Foo[A, B]: Test.Foo[(A, B)] = new Foo[(A, B)] {} // nor this one + + implicitly[Foo[(Int, Int)]] +} + +class A { + def x[N[X] >: M[X], M[_], G](n: N[G], m: M[G]) = null + + x(Some(3), Seq(2)) +} diff --git a/tests/invalid/pos/t3577.scala b/tests/invalid/pos/t3577.scala new file mode 100644 index 000000000..e94b69b4b --- /dev/null +++ b/tests/invalid/pos/t3577.scala @@ -0,0 +1,32 @@ +case class Check[A](val value: A) + +case class C2(checks: Check[_]*); + +object C { + def m(x : C2): Any = (null: Any) match { + case C2(_, rest : _*) => { + // Invalid: Vararg pattern cannot be split between normal and :_* patterns. + // This split also does not work for vararg arguments, so there's no + // good argument it should work for patterns + rest.map(_.value) + } + } +} + +/////////////////// + +object Container { + trait Exp[+T] + abstract class FuncExp[-S, +T] + + sealed abstract class FoundNode[T, Repr] { + def optimize[TupleT, U, That](parentNode: FlatMap[T, Repr, U, That]): Any + def optimize2[TupleT, U, That](parentNode: Any): Any + } + + class FlatMap[T, Repr, U, That] + + val Seq(fn: FoundNode[t, repr]) = Seq[FoundNode[_, _]]() + fn.optimize(null) // was: scala.MatchError: ? (of class BoundedWildcardType) @ Variances#varianceInType + fn.optimize2(null) // was: fatal error: bad type: ?(class scala.reflect.internal.Types$BoundedWildcardType) @ Pickle.putType +} diff --git a/tests/invalid/pos/t3856.scala b/tests/invalid/pos/t3856.scala new file mode 100644 index 000000000..8dfcccb5a --- /dev/null +++ b/tests/invalid/pos/t3856.scala @@ -0,0 +1,16 @@ +case class C[T](x: T) + +case class CS(xs: C[_]*) + +// t3856 +object Test { + val x = CS(C(5), C("abc")) match { case CS(C(5), xs : _*) => xs } + // Invalid: Vararg pattern cannot be split between normal and :_* patterns. + // This split also does not work for vararg arguments, so there's no + // good argument it should work for patterns + println(x) + + def foo(xs: Int*) = () + val xs = List(1, 2, 3) + foo(1, xs:_*) +} diff --git a/tests/invalid/pos/t4202.scala b/tests/invalid/pos/t4202.scala new file mode 100644 index 000000000..1bf0bf6eb --- /dev/null +++ b/tests/invalid/pos/t4202.scala @@ -0,0 +1,20 @@ +// Invalid because syntax has changed; +// template statements cannot be lambdas. +object t4202_1 { + () => { + trait T { + def t = () + } + } +} + +object t4202_2 { + () => { + trait T { + def t = () + } + object T2 extends T { + t + } + } +} diff --git a/tests/invalid/pos/t4237.scala b/tests/invalid/pos/t4237.scala new file mode 100644 index 000000000..45a505004 --- /dev/null +++ b/tests/invalid/pos/t4237.scala @@ -0,0 +1,7 @@ +// Invalid because structural types are not supported. +class A { + (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected + (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter + (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter + (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE +} diff --git a/tests/invalid/pos/t4363.scala b/tests/invalid/pos/t4363.scala new file mode 100644 index 000000000..e0ffa8fd9 --- /dev/null +++ b/tests/invalid/pos/t4363.scala @@ -0,0 +1,9 @@ +// Invalid because lambdas can no longer be tenmplate statements. +object Test { + trait Suite { def bar() = () } + + () => { + trait FunkySuite extends Suite { override def bar() = () } + class MySuite extends FunkySuite { } + } +} diff --git a/tests/invalid/pos/t4365/a_1.scala b/tests/invalid/pos/t4365/a_1.scala new file mode 100644 index 000000000..0be5ca8a1 --- /dev/null +++ b/tests/invalid/pos/t4365/a_1.scala @@ -0,0 +1,19 @@ +// Invalid because it relies on internal traits of views that will change their names. +import scala.collection._ + +trait SeqViewLike[+A, + +Coll, + +This <: SeqView[A, Coll] with SeqViewLike[A, Coll, Nothing]] + extends Seq[A] with GenSeqViewLike[A, Coll, Nothing] +{ + + trait Transformed[+B] extends super[GenSeqViewLike].Transformed[B] + + abstract class AbstractTransformed[+B] extends Seq[B] with Transformed[B] { + def underlying: Coll = error("") + } + + trait Reversed extends Transformed[A] with super[GenSeqViewLike].Reversed + + protected def newReversed: Transformed[A] = new AbstractTransformed[A] with Reversed +} diff --git a/tests/invalid/pos/t4365/b_1.scala b/tests/invalid/pos/t4365/b_1.scala new file mode 100644 index 000000000..e1423813f --- /dev/null +++ b/tests/invalid/pos/t4365/b_1.scala @@ -0,0 +1,24 @@ +import scala.collection._ + +trait GenSeqView0[+A, +Coll] + +trait GenSeqViewLike[+A, + +Coll, + +This <: GenSeqView0[A, Coll] with GenSeqViewLike[A, Coll, Nothing]] +extends GenSeq[A] { +self => + + trait Transformed[+B] { + def length: Int = 0 + def apply(idx: Int): B = error("") + } + + trait Reversed extends Transformed[A] { + def iterator: Iterator[A] = createReversedIterator + + private def createReversedIterator: Iterator[A] = { + self.foreach(_ => ()) + null + } + } +} diff --git a/tests/invalid/pos/t4553.scala b/tests/invalid/pos/t4553.scala new file mode 100644 index 000000000..48846a369 --- /dev/null +++ b/tests/invalid/pos/t4553.scala @@ -0,0 +1,12 @@ +// Invalid because hk type parameters may not appear in lower bounds +trait VectorLike[+T, +V[A] <: Vector[A]] { + def +[S, VResult[S] >: V[S]](v: VResult[S]): Unit +} + +trait Vector[+T] extends VectorLike[T, Vector] +trait ImmutableVector[T] extends Vector[T] with VectorLike[T, ImmutableVector] +trait MutableVector[T] extends Vector[T] with VectorLike[T, MutableVector] + +object Test { + def f = (null: MutableVector[Int]) + (null: ImmutableVector[Int]) +} diff --git a/tests/invalid/pos/t5022.scala b/tests/invalid/pos/t5022.scala new file mode 100644 index 000000000..5db71c656 --- /dev/null +++ b/tests/invalid/pos/t5022.scala @@ -0,0 +1,22 @@ +class ForSomeVsUnapply { + def test: Unit = { + def makeWrap: Wrap = ??? + def useRep[e](rep: (e, X[e])) = () + + val repUnapply = Wrap.unapply(makeWrap).get + useRep(repUnapply) // okay + + val Wrap(rep0) = makeWrap + useRep(rep0) // error + + val rep = makeWrap match { + case Wrap(r) => r + }; + + useRep(rep) // error + } +} + +class X[e] + +case class Wrap(rep: (e, X[e]) forSome { type e }) diff --git a/tests/invalid/pos/t5119.scala b/tests/invalid/pos/t5119.scala new file mode 100644 index 000000000..39f626e53 --- /dev/null +++ b/tests/invalid/pos/t5119.scala @@ -0,0 +1,13 @@ +import collection.mutable + +object Test { + class IMap0[K[_], V[_]](backing: Map[K[_], V[_]]) { + def mapSeparate[VL[_], VR[_]](f: V[_] => ({type l[T] = Either[VL[T], VR[T]]})#l[_] ) = { + backing.view.map { case (k,v) => f(v) match { + case Left(l) => Left((k, l)) + case Right(r) => Right((k, r)) + } + } + } + } +} diff --git a/tests/invalid/pos/t5130.scala b/tests/invalid/pos/t5130.scala new file mode 100644 index 000000000..676d3c705 --- /dev/null +++ b/tests/invalid/pos/t5130.scala @@ -0,0 +1,46 @@ +import scala.language.reflectiveCalls + +class A { + this_a => + + def b = new B + class B { def a: this_a.type = this_a } +} +trait A2 { def c = () } + +object Test { + val v1 = new A { def c = () } + val v2 = new A with A2 { } + val v3: A { def c: Unit } = null + def d1 = new A { def c = () } + def d2 = new A with A2 { } + def d3: A { def c: Unit } = null + var x1 = new A { def c = () } + var x2 = new A with A2 { } + var x3: A { def c: Unit } = null + + def main(args: Array[String]): Unit = { + val mv1 = new A { def c = () } + val mv2 = new A with A2 { } + val mv3: A { def c: Unit } = null + def md1 = new A { def c = () } + def md2 = new A with A2 { } + def md3: A { def c: Unit } = null + + v1.b.a.c + v2.b.a.c + v3.b.a.c + d1.b.a.c + d2.b.a.c + d3.b.a.c + x1.b.a.c + x2.b.a.c + x3.b.a.c + mv1.b.a.c + mv2.b.a.c + mv3.b.a.c + md1.b.a.c + md2.b.a.c + md3.b.a.c + } +} diff --git a/tests/invalid/pos/t5156.scala b/tests/invalid/pos/t5156.scala new file mode 100644 index 000000000..41b1c296e --- /dev/null +++ b/tests/invalid/pos/t5156.scala @@ -0,0 +1,21 @@ +sealed trait HList +final case class HCons[H, T <: HList](head : H, tail : T) extends HList +case object HNil extends HList + +object HList { + type ::[H, T <: HList] = HCons[H, T] + type HNil = HNil.type + + implicit def hlistOps[L <: HList](l : L): AnyRef{def ::[H](h: H): HList.::[H,L]; def last(implicit last: HList.Last[L]): Unit} = new { + def ::[H](h : H) : H :: L = HCons(h, l) + def last(implicit last : Last[L]): Unit = {} + } + + class Last[L <: HList] + implicit def hsingleLast[H]: HList.Last[HList.::[H,HList.HNil]] = new Last[H :: HNil] + implicit def hlistLast[H, T <: HList](implicit lt : Last[T]): HList.Last[HList.::[H,T]] = new Last[H :: T] + + type III = Int :: Int :: Int :: HNil + val iii : III = 0 :: 0 :: 0 :: HNil + val l = iii.last +} diff --git a/tests/invalid/pos/t533.scala b/tests/invalid/pos/t533.scala new file mode 100644 index 000000000..9bc9995d9 --- /dev/null +++ b/tests/invalid/pos/t533.scala @@ -0,0 +1,11 @@ +import scala.actors._ + +object test extends Actor { + def act(): Unit = { + receive { + case TIMEOUT => Console.println("TIMEOUT") + //case _ => Console.println("_") + } + } +} + diff --git a/tests/invalid/pos/t5626.scala b/tests/invalid/pos/t5626.scala new file mode 100644 index 000000000..c501dfbe6 --- /dev/null +++ b/tests/invalid/pos/t5626.scala @@ -0,0 +1,12 @@ +class C { + val blob = { + new { case class Foo() } + } + val blub = { + class Inner { case class Foo() } + new Inner + } + + val foo = blob.Foo() + val bar = blub.Foo() +} diff --git a/tests/invalid/pos/t5654.scala b/tests/invalid/pos/t5654.scala new file mode 100644 index 000000000..1f8d05bfe --- /dev/null +++ b/tests/invalid/pos/t5654.scala @@ -0,0 +1,13 @@ +class T(val a: Array[_]) + +class U { + val a = Array(Array(1, 2), Array("a","b")) +} + +class T1 { val a: Array[_] = Array(1) } + +case class Bomb(a: Array[_]) +case class Bomb2(a: Array[T] forSome { type T }) +class Okay1(a: Array[_]) +case class Okay2(s: Seq[_]) + diff --git a/tests/invalid/pos/t6169/Exist.java b/tests/invalid/pos/t6169/Exist.java new file mode 100644 index 000000000..dfc6b36b3 --- /dev/null +++ b/tests/invalid/pos/t6169/Exist.java @@ -0,0 +1,4 @@ +public class Exist<T extends String> { + // java helpfully re-interprets Exist<?> as Exist<? extends String> + public Exist<?> foo() { throw new RuntimeException(); } +}
\ No newline at end of file diff --git a/tests/invalid/pos/t6169/ExistF.java b/tests/invalid/pos/t6169/ExistF.java new file mode 100644 index 000000000..70fabd74c --- /dev/null +++ b/tests/invalid/pos/t6169/ExistF.java @@ -0,0 +1,4 @@ +public class ExistF<T extends ExistF<T>> { + // java helpfully re-interprets ExistF<?> as ExistF<?0 extends ExistF<?0>> + public ExistF<?> foo() { throw new RuntimeException(); } +}
\ No newline at end of file diff --git a/tests/invalid/pos/t6169/ExistIndir.java b/tests/invalid/pos/t6169/ExistIndir.java new file mode 100644 index 000000000..e66d1698c --- /dev/null +++ b/tests/invalid/pos/t6169/ExistIndir.java @@ -0,0 +1,4 @@ +public class ExistIndir<T extends String, U extends T> { + // java helpfully re-interprets ExistIndir<?> as ExistIndir<? extends String> + public ExistIndir<?, ?> foo() { throw new RuntimeException(); } +} diff --git a/tests/invalid/pos/t6169/OP.java b/tests/invalid/pos/t6169/OP.java new file mode 100644 index 000000000..15e4c5640 --- /dev/null +++ b/tests/invalid/pos/t6169/OP.java @@ -0,0 +1 @@ +public abstract class OP<T> { } diff --git a/tests/invalid/pos/t6169/Skin.java b/tests/invalid/pos/t6169/Skin.java new file mode 100644 index 000000000..780de1ee0 --- /dev/null +++ b/tests/invalid/pos/t6169/Skin.java @@ -0,0 +1 @@ +public interface Skin<C extends Skinnable> { } diff --git a/tests/invalid/pos/t6169/Skinnable.java b/tests/invalid/pos/t6169/Skinnable.java new file mode 100644 index 000000000..f91eaa30d --- /dev/null +++ b/tests/invalid/pos/t6169/Skinnable.java @@ -0,0 +1,3 @@ +public interface Skinnable { + OP<Skin<?>> skinProperty(); +} diff --git a/tests/invalid/pos/t6169/skinnable.scala b/tests/invalid/pos/t6169/skinnable.scala new file mode 100644 index 000000000..08204f29d --- /dev/null +++ b/tests/invalid/pos/t6169/skinnable.scala @@ -0,0 +1,14 @@ +object ObjectProperty { + implicit def jfxObjectProperty2sfx[T](p: OP[T]) = new ObjectProperty[T](p) +} + +class ObjectProperty[T](val delegate: OP[T]) + +trait TestWildcardBoundInference { + def delegate: Skinnable + def skin: ObjectProperty[Skin[_ /* inferred: <: Skinnable */]] = ObjectProperty.jfxObjectProperty2sfx(delegate.skinProperty) + skin: ObjectProperty[Skin[_ <: Skinnable]] + + def skinCheckInference = delegate.skinProperty + skinCheckInference: ObjectProperty[Skin[_ <: Skinnable]] +} diff --git a/tests/invalid/pos/t6169/t6169.scala b/tests/invalid/pos/t6169/t6169.scala new file mode 100644 index 000000000..84b2d2dad --- /dev/null +++ b/tests/invalid/pos/t6169/t6169.scala @@ -0,0 +1,7 @@ +class Test { + class MyExist extends ExistF[MyExist] + // SI-8197, SI-6169: java infers the bounds of existentials, so we have to as well now that SI-1786 is fixed... + def stringy: Exist[_ <: String] = (new Exist[String]).foo + def fbounded: (ExistF[t] forSome {type t <: ExistF[t] }) = (new MyExist).foo + def indir: ExistIndir[_ <: String, _ <: String] = (new ExistIndir[String, String]).foo +} diff --git a/tests/invalid/pos/t6367.scala b/tests/invalid/pos/t6367.scala new file mode 100644 index 000000000..1214be741 --- /dev/null +++ b/tests/invalid/pos/t6367.scala @@ -0,0 +1,34 @@ +package play.api.libs.json.util + +trait FunctionalCanBuild[M[_]]{ + def apply[A,B](ma:M[A], mb:M[B]):M[A ~ B] +} + +trait Variant[M[_]] + +trait Functor[M[_]] extends Variant[M]{ + def fmap[A,B](m:M[A], f: A => B): M[B] +} + +case class ~[A,B](_1:A,_2:B) + +class FunctionalBuilder[M[_]](canBuild:FunctionalCanBuild[M]){ + class CanBuild20[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20]( + m1:M[A1 ~ A2 ~ A3 ~ A4 ~ A5 ~ A6 ~ A7 ~ A8 ~ A9 ~ A10 ~ A11 ~ A12 ~ A13 ~ A14 ~ A15 ~ A16 ~ A17 ~ A18 ~ A19], + m2:M[A20] + ) { + + def ~[A21](m3:M[A21]) = new CanBuild21(canBuild(m1,m2),m3) + + def apply[B](f: (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20) => B)(implicit fu:Functor[M]): M[B] = + fu.fmap[A1 ~ A2 ~ A3 ~ A4 ~ A5 ~ A6 ~ A7 ~ A8 ~ A9 ~ A10 ~ A11 ~ A12 ~ A13 ~ A14 ~ A15 ~ A16 ~ A17 ~ A18 ~ A19 ~ A20, B]( + canBuild(m1, m2), + { case a1 ~ a2 ~ a3 ~ a4 ~ a5 ~ a6 ~ a7 ~ a8 ~ a9 ~ a10 ~ a11 ~ a12 ~ a13 ~ a14 ~ a15 ~ a16 ~ a17 ~ a18 ~ a19 ~ a20 => + f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) } + ) + } + + class CanBuild21[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21](m1:M[A1 ~ A2 ~ A3 ~ A4 ~ A5 ~ A6 ~ A7 ~ A8 ~ A9 ~ A10 ~ A11 ~ A12 ~ A13 ~ A14 ~ A15 ~ A16 ~ A17 ~ A18 ~ A19 ~ A20], m2:M[A21]){ + } + +} diff --git a/tests/invalid/pos/t711.scala b/tests/invalid/pos/t711.scala new file mode 100644 index 000000000..4dd604096 --- /dev/null +++ b/tests/invalid/pos/t711.scala @@ -0,0 +1,14 @@ +abstract class Component + +class Button extends Component { + def sayHey: Unit = Console.println("Hey, I'm a button") } + +abstract class Origin { + val delegate: Component } + +object main extends Origin with App { + val delegate: Component { + def sayHey: Unit + } = new Button + delegate.sayHey +} diff --git a/tests/invalid/pos/t7505.scala b/tests/invalid/pos/t7505.scala new file mode 100644 index 000000000..bc8c7fad6 --- /dev/null +++ b/tests/invalid/pos/t7505.scala @@ -0,0 +1,16 @@ +import scala.language.reflectiveCalls + +case class ContextProperty(value: Any) { + type HasToInt = { def toInt:Int } + + def toInt: Int = value match { + case n: HasToInt => n.toInt + } +} + +// was: +// error:7: error during expansion of this match (this is a scalac bug). +// The underlying error was: type mismatch; +// found : Boolean(true) +// required: AnyRef +// def toInt: Int = value match { diff --git a/tests/invalid/pos/t8023.scala b/tests/invalid/pos/t8023.scala new file mode 100644 index 000000000..9ce5619db --- /dev/null +++ b/tests/invalid/pos/t8023.scala @@ -0,0 +1,23 @@ +// Invalid because nested hk type parameters are no longer allowed +import language._ + + +object Test { + def foo = (null: Any) match { + case a: A[k] => + // error: kinds of the type arguments (k) do not conform to the + // expected kinds of the type parameters (type K) in class B. + new B[k]() + } +} + +class A[K[L[_]]] + +class B[K[M[_]]] + + +object Test2 { + def foo = (null: Any) match { + case a: A[k] => new B[k]() // this one worked before as the info of `A` was complete + } +} diff --git a/tests/invalid/pos/t8219b.scala b/tests/invalid/pos/t8219b.scala new file mode 100644 index 000000000..b820447ce --- /dev/null +++ b/tests/invalid/pos/t8219b.scala @@ -0,0 +1,49 @@ +trait Equalizer[T] +trait Gen[A] + +class Broken { + implicit def const[T](x: T): Gen[T] = ??? + implicit def convertToEqualizer[T](left: T): Equalizer[T] = ??? + + def in(a: Any) = () + in { + import scala.None // any import will do.. + "" == "" // no longer a problem, see pos/t8129.scala + } + + // We used to fall into the errant code path above when `Any#==` and `AnyRef#==` + // were overloaded. + // + // Real classes couldn't get away with that overloading; it would result in + // a compiler error because the variants would collapse into an overriding + // relationship after erasure. + // + // + // But, a structural type can! This triggers the same error, and served as + // a backstop for this test if we change the signatures of `AnyRef#==` to + // override `Any#==`. + type T = { + def a(a: AnyRef): Boolean + def a(a: Any): Boolean + } + + def t: T = ??? + + in { + import scala.None // any import will do.. + t.a("") + } + + // Or, we can get here with ambiguous implicits from the formal parameter + // type of the less specific overload to that of the more specific. + object T { + def foo(a: Any) = true + def foo(a: String) = true + } + in { + import scala.None + implicit def any2str1(a: Any): String = "" + implicit def any2str2(a: Any): String = "" + T.foo("") + } +} diff --git a/tests/invalid/pos/t8224.scala b/tests/invalid/pos/t8224.scala new file mode 100644 index 000000000..d893f6630 --- /dev/null +++ b/tests/invalid/pos/t8224.scala @@ -0,0 +1,13 @@ +// Invalid because nested hk type parameters are no longer allowed +import language.higherKinds + +trait P [N1, +E1[X <: N1]] +trait PIn[N2, +E2[X <: N2]] extends P[Int,Any] + +trait EI extends PIn[Int, Nothing] +trait NI extends PIn[Int, Nothing] + +object Test { + val lub = if (true) ??? : EI else ??? : NI + val pin: PIn[Int,Nothing] = lub +} diff --git a/tests/invalid/pos/ticket2251.scala b/tests/invalid/pos/ticket2251.scala new file mode 100644 index 000000000..006407247 --- /dev/null +++ b/tests/invalid/pos/ticket2251.scala @@ -0,0 +1,39 @@ + +// Martin: I am not sure this is a solvable problem right now. I'll leave it in pending. +// derived from pos/t1001 +class A +trait B[T <: B[T]] extends A +class C extends B[C] +class D extends B[D] + +class Data { + // force computing lub of C and D (printLubs enabled:) + +/* +lub of List(D, C) at depth 2 + lub of List(D, C) at depth 1 + lub of List(D, C) at depth 0 + lub of List(D, C) is A + lub of List(D, C) is B[_1] forSome { type _1 >: D with C <: A } +lub of List(D, C) is B[_2] forSome { type _2 >: D with C{} <: B[_1] forSome { type _1 >: D with C{} <: A } } +*/ +// --> result = WRONG + + // should be: B[X] forSome {type X <: B[X]} -- can this be done automatically? for now, just detect f-bounded polymorphism and fall back to more coarse approximation + + val data: List[A] = List(new C, new D) + + val data2 = List(new C, new D) + + val data3: List[B[_ <: B[_ <: A]]] = List(new C, new D) + + // Not yet -- + // val data4: List[B[X] forSome { type X <: B[X] }] = List(new C, new D) + // <console>:7: error: type mismatch; + // found : List[B[_ >: D with C <: B[_ >: D with C <: A]]] + // required: List[B[X] forSome { type X <: B[X] }] + // val data4: List[B[X] forSome { type X <: B[X] }] = List(new C, new D) + + // works + val data5 = List[B[X] forSome { type X <: B[X] }](new C, new D) +} diff --git a/tests/invalid/pos/typesafecons.scala b/tests/invalid/pos/typesafecons.scala new file mode 100644 index 000000000..524328016 --- /dev/null +++ b/tests/invalid/pos/typesafecons.scala @@ -0,0 +1,30 @@ +object Pair { + sealed trait Pair { + type First + type Second <: Pair + } + + class End extends Pair { + type First = Nothing + type Second = End + + def ::[T](v : T) : Cons[T, End] = Cons(v, this) + } + + case object End extends End + + final case class Cons[T1, T2 <: Pair](_1 : T1, _2 : T2) extends Pair { + type First = T1 + type Second = T2 + + def ::[T](v : T) : Cons[T, Cons[T1, T2]] = Cons(v, this) + def find[T](implicit finder : Cons[T1, T2] => T) = finder(this) + } + + implicit def findFirst[T1, T2 <: Pair] : Cons[T1, T2] => T1 = (p : Cons[T1, T2]) => p._1 + implicit def findSecond[T, T1, T2 <: Pair](implicit finder : T2 => T) : Cons[T1, T2] => T = (p : Cons[T1, T2]) => finder(p._2) + + val p : Cons[Int, Cons[Boolean, End]] = 10 :: false :: End +// val x : Boolean = p.find[Boolean](findSecond(findFirst)) + val x2 : Boolean = p.find[Boolean] // Doesn't compile +} diff --git a/tests/invalid/pos/unapplySeq.scala b/tests/invalid/pos/unapplySeq.scala new file mode 100644 index 000000000..cefe1cb8f --- /dev/null +++ b/tests/invalid/pos/unapplySeq.scala @@ -0,0 +1,26 @@ +object FooSeq { + def unapplySeq(x:Any): Option[Product2[Int,Seq[String]]] = { + if (x.isInstanceOf[Bar]) { + val y = x.asInstanceOf[Bar] + Some(y.size, y.name) + } else None + } + + def main(args:Array[String]) = { + val b = new Bar + b match { + case FooSeq(s:Int,_,n:String) => Console.println("size " + s +" name "+ n) + } + b.size = 54 + b.name = List("large","L") + b match { + case FooSeq(s:Int,_,n:String) => Console.println("size " + s +" name "+ n) + } + } +} + +class Bar { + var size: Int = 50 + var name: Seq[String] = List("medium","M") +} + |