diff options
author | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-03-12 22:44:33 +0100 |
---|---|---|
committer | Samuel Gruetter <samuel.gruetter@epfl.ch> | 2014-03-12 22:44:33 +0100 |
commit | 9ef5f6817688f814a3450126aa7383b0928e80a0 (patch) | |
tree | 5727a2f7f7fd665cefdb312af2785c692f04377c /tests/untried/pos | |
parent | 194be919664447631ba55446eb4874979c908d27 (diff) | |
download | dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.gz dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.tar.bz2 dotty-9ef5f6817688f814a3450126aa7383b0928e80a0.zip |
add tests from scala/test/files/{pos,neg}
with explicit Unit return type
Diffstat (limited to 'tests/untried/pos')
1567 files changed, 23781 insertions, 0 deletions
diff --git a/tests/untried/pos/A.scala b/tests/untried/pos/A.scala new file mode 100644 index 000000000..fc50379d8 --- /dev/null +++ b/tests/untried/pos/A.scala @@ -0,0 +1,8 @@ +trait A extends java.lang.Object {} + +object test { + + def x: A = x; + +} + diff --git a/tests/untried/pos/CustomGlobal.scala b/tests/untried/pos/CustomGlobal.scala new file mode 100644 index 000000000..a5668bd7c --- /dev/null +++ b/tests/untried/pos/CustomGlobal.scala @@ -0,0 +1,33 @@ +package custom + +import scala.tools.nsc._, reporters._, typechecker._ + +/** Demonstration of a custom Global with a custom Typer, + * decoupled from trunk. Demonstration: + * +{{{ +scalac -d . CustomGlobal.scala && scala -nc -Yglobal-class custom.CustomGlobal \ + -e 'class Bippy(x: Int) ; def f = new Bippy(5)' + +I'm typing a Bippy! It's a ClassDef. +I'm typing a Bippy! It's a Ident. +I'm typing a Bippy! It's a DefDef. +}}} + * + */ +class CustomGlobal(currentSettings: Settings, reporter: Reporter) extends Global(currentSettings, reporter) { + override lazy val analyzer = new { + val global: CustomGlobal.this.type = CustomGlobal.this + } with Analyzer { + override def newTyper(context: Context): Typer = new CustomTyper(context) + + class CustomTyper(context : Context) extends Typer(context) { + override def typed(tree: Tree, mode: Mode, pt: Type): Tree = { + if (tree.summaryString contains "Bippy") + println("I'm typing a Bippy! It's a " + tree.shortClass + ".") + + super.typed(tree, mode, pt) + } + } + } +} diff --git a/tests/untried/pos/FPTest.scala b/tests/untried/pos/FPTest.scala new file mode 100644 index 000000000..b351b7bb9 --- /dev/null +++ b/tests/untried/pos/FPTest.scala @@ -0,0 +1,11 @@ +// On some hypothetical future day when we can test the emitted bytecode, +// should look for the fp bit. Until then, just a pos test. +import annotation.strictfp + +@strictfp class FPTest { + def main(args: Array[String]): Unit = { + val d: Double = 8e+307 + println(4.0 * d * 0.5); + println(2.0 * d); + } +} diff --git a/tests/untried/pos/List1.scala b/tests/untried/pos/List1.scala new file mode 100644 index 000000000..30ebf5e1e --- /dev/null +++ b/tests/untried/pos/List1.scala @@ -0,0 +1,45 @@ +object lists { + + abstract class List[a] { + def isEmpty: Boolean; + def head: a; + def tail: List[a]; + def prepend(x: a) = Cons[a](x, this); + } + + def Nil[b] = new List[b] { + def isEmpty: Boolean = true; + def head = sys.error("head of Nil"); + def tail = sys.error("tail of Nil"); + } + + def Cons[c](x: c, xs: List[c]): List[c] = new List[c] { + def isEmpty = false; + def head = x; + def tail = xs; + } + + def foo = { + val intnil = Nil[Int]; + val intlist = intnil.prepend(1).prepend(1+1); + val x: Int = intlist.head; + val strnil = Nil[String]; + val strlist = strnil.prepend("A").prepend("AA"); + val y: String = strlist.head; + () + } + + class IntList() extends List[Int] { + def isEmpty: Boolean = false; + def head: Int = 1; + def foo: List[Int] { def isEmpty: Boolean; def head: Int; def tail: List[Int] } = Nil[Int]; + def tail0: List[Int] = foo.prepend(1).prepend(1+1); + def tail: List[Int] = Nil[Int].prepend(1).prepend(1+1); + } + + def foo2 = { + val il1 = new IntList(); + val il2 = il1.prepend(1).prepend(2); + () + } +} diff --git a/tests/untried/pos/MailBox.scala b/tests/untried/pos/MailBox.scala new file mode 100644 index 000000000..8e27bd362 --- /dev/null +++ b/tests/untried/pos/MailBox.scala @@ -0,0 +1,84 @@ +package test; + +import scala.actors.TIMEOUT; + +class MailBox { + + private class LinkedList[a] { + var elem: a = _; + var next: LinkedList[a] = null; + } + + private def insert[a](l: LinkedList[a], x: a): LinkedList[a] = { + l.next = new LinkedList[a]; + l.next.elem = x; + l.next.next = l.next; + l + } + + private abstract class Receiver { + def isDefined(msg: Any): Boolean; + var msg: Any = null; + } + + private val sent = new LinkedList[Any]; + private var lastSent = sent; + private val receivers = new LinkedList[Receiver]; + private var lastReceiver = receivers; + + def send(msg: Any): Unit = synchronized { + var r = receivers; + var r1 = r.next; + while (r1 != null && !r1.elem.isDefined(msg)) { + r = r1; r1 = r1.next; + } + if (r1 != null) { + r.next = r1.next; r1.elem.msg = msg; r1.elem.notify(); + } else { + lastSent = insert(lastSent, msg); + } + } + + def receive[a](f: PartialFunction[Any, a]): a = { + val msg: Any = synchronized { + var s = sent; + var s1 = s.next; + while (s1 != null && !f.isDefinedAt(s1.elem)) { + s = s1; s1 = s1.next + } + if (s1 != null) { + s.next = s1.next; s1.elem + } else { + val r = insert(lastReceiver, new Receiver { + def isDefined(msg: Any) = f.isDefinedAt(msg); + }); + lastReceiver = r; + r.elem.wait(); + r.elem.msg + } + } + f(msg) + } + + def receiveWithin[a](msec: Long)(f: PartialFunction[Any, a]): a = { + val msg: Any = synchronized { + var s = sent; + var s1 = s.next; + while (s1 != null && !f.isDefinedAt(s1.elem)) { + s = s1; s1 = s1.next ; + } + if (s1 != null) { + s.next = s1.next; s1.elem + } else { + val r = insert(lastReceiver, new Receiver { + def isDefined(msg: Any) = f.isDefinedAt(msg); + }); + lastReceiver = r; + r.elem.wait(msec); + if (r.elem.msg == null) r.elem.msg = TIMEOUT; + r.elem.msg + } + } + f(msg) + } +} diff --git a/tests/untried/pos/NoCyclicReference.scala b/tests/untried/pos/NoCyclicReference.scala new file mode 100644 index 000000000..e42896661 --- /dev/null +++ b/tests/untried/pos/NoCyclicReference.scala @@ -0,0 +1,7 @@ +package test + +trait Iterable[+A] { self => + + type CC[B] <: Iterable[B] { type CC[C] = self.CC[C] } + +} diff --git a/tests/untried/pos/S1.scala b/tests/untried/pos/S1.scala new file mode 100644 index 000000000..68706e3dd --- /dev/null +++ b/tests/untried/pos/S1.scala @@ -0,0 +1,13 @@ +/* This is probably no bug, I just don't understand why +** type inference does not find the right instantiation of foo. +** Currently it reports: +** +** S1.scala:12: inferred type arguments [S1] do not conform to +** method foo's type parameter bounds [T <: S1.this.type] +** foo(this); +** ^ +*/ +class S1() { + def foo[T <: this.type](x: T) = x; + foo[this.type](this); +} diff --git a/tests/untried/pos/S3.scala b/tests/untried/pos/S3.scala new file mode 100644 index 000000000..1e0f0288b --- /dev/null +++ b/tests/untried/pos/S3.scala @@ -0,0 +1,14 @@ +/* Why does this code fail? b has type a.type, so the third +** declaration in S3 should be okay... The compiler writes instead: +** +** found : S3.this.b.type (with underlying type S3) +** required: S3.this.a.type +** val c: a.type = b; +** ^ +** Without declaration 3, everything is fine. +*/ +class S3() { + val a = new S3(); + val b: a.type = a; + val c: a.type = b; +} diff --git a/tests/untried/pos/S5.scala b/tests/untried/pos/S5.scala new file mode 100644 index 000000000..f0b66a6e6 --- /dev/null +++ b/tests/untried/pos/S5.scala @@ -0,0 +1,30 @@ +/* Here's a fragment of a Scala encoding for the Keris module system; +** the compiler claims: +** +** S5.scala:28: value n in class N of type N.this._N.n +** cannot override value n in class M of type M.this._N.n +** val system = new M() with N() {} +** ^ +** To me it seems like the code is perfectly fine... +*/ +abstract class M() { + val _N: N; + val n: _N.n; + val _M: M = this; + val m: _M.m = new _M.m(); + class m() { + // module body of M + } +} +trait N { + val _N: N = this; + val n: _N.n = new _N.n(); + val _M: M; + val m: _M.m; + class n() { + // module body of N + } +} +object O { + val system = new M() with N {} +} diff --git a/tests/untried/pos/S8.scala b/tests/untried/pos/S8.scala new file mode 100644 index 000000000..50f1df27a --- /dev/null +++ b/tests/untried/pos/S8.scala @@ -0,0 +1,19 @@ +/* I believe this code is correct, but the compiler rejects it: +** +** S8.scala:18: type mismatch; +** found : M.x.A +** required: M.x.a.B +** val y: x.a.B = new x.A(); //correct? +** ^ +** For a given value x of type S8, type x.A should be +** a subtype of x.a.B. +*/ +class S8() { + val a: S8 = this; + class A() extends a.B() {} + class B() {} +} +object M { + val x = new S8(); + val y: x.a.B = new x.A(); //correct? +} diff --git a/tests/untried/pos/SI-4012-a.scala b/tests/untried/pos/SI-4012-a.scala new file mode 100644 index 000000000..7fceeea3c --- /dev/null +++ b/tests/untried/pos/SI-4012-a.scala @@ -0,0 +1,7 @@ +trait C1[+A] { + def head: A = sys.error("") +} +trait C2[@specialized +A] extends C1[A] { + override def head: A = super.head +} +class C3 extends C2[Char] diff --git a/tests/untried/pos/SI-4012-b.scala b/tests/untried/pos/SI-4012-b.scala new file mode 100644 index 000000000..6bc859276 --- /dev/null +++ b/tests/untried/pos/SI-4012-b.scala @@ -0,0 +1,15 @@ +trait Super[@specialized(Int) A] { + def superb = 0 +} + +object Sub extends Super[Int] { + // it is expected that super[Super].superb crashes, since + // specialization does parent class rewiring, and the super + // of Sub becomes Super$mcII$sp and not Super. But I consider + // this normal behavior -- if you want, I can modify duplicatiors + // to make this work, but I consider it's best to keep this + // let the user know Super is not the superclass anymore. + // super[Super].superb - Vlad + super.superb // okay + override def superb: Int = super.superb // okay +} diff --git a/tests/untried/pos/SI-5788.scala b/tests/untried/pos/SI-5788.scala new file mode 100644 index 000000000..f29246180 --- /dev/null +++ b/tests/untried/pos/SI-5788.scala @@ -0,0 +1,3 @@ +trait Foo[@specialized(Int) A] { + final def bar(a:A):A = bar(a) +} diff --git a/tests/untried/pos/SI-7060.flags b/tests/untried/pos/SI-7060.flags new file mode 100644 index 000000000..c926ad649 --- /dev/null +++ b/tests/untried/pos/SI-7060.flags @@ -0,0 +1 @@ +-Yinline -Ydead-code diff --git a/tests/untried/pos/SI-7060.scala b/tests/untried/pos/SI-7060.scala new file mode 100644 index 000000000..c87620e02 --- /dev/null +++ b/tests/untried/pos/SI-7060.scala @@ -0,0 +1,11 @@ +object Test { + + @inline final def mbarray_apply_minibox(array: Any, tag: Byte): Long = + if (tag == 0) { + array.asInstanceOf[Array[Long]](0) + } else + array.asInstanceOf[Array[Byte]](0).toLong + + def crash_method(): Unit = + mbarray_apply_minibox(null, 0) +} diff --git a/tests/untried/pos/SI-7100.scala b/tests/untried/pos/SI-7100.scala new file mode 100644 index 000000000..7cb6356ec --- /dev/null +++ b/tests/untried/pos/SI-7100.scala @@ -0,0 +1,6 @@ +class Buffer { + def f[@specialized(Int) T](): T = 0 match { + case 0 => 0.asInstanceOf[T] + case 1 => 0.asInstanceOf[T] + } +} diff --git a/tests/untried/pos/SI-7638.scala b/tests/untried/pos/SI-7638.scala new file mode 100644 index 000000000..831475d00 --- /dev/null +++ b/tests/untried/pos/SI-7638.scala @@ -0,0 +1,51 @@ +package miniboxing.tests.compile + +trait Ordering[@specialized(Int) A] { + def eqv(x: Array[A], y: Array[A]): Boolean = false +} + +trait ArrayVectorOrder[@specialized(Int) A] extends Ordering[A] { + override def eqv(x: Array[A], y: Array[A]): Boolean = super.eqv(x, y) +} + +object vectorOrder { + implicit def arrayOrder[@specialized(Int) A]() = + /* + * Before applying patch: + * + * while compiling: SI-7638.scala + * during phase: mixin + * library version: version 2.10.3-20130625-164027-d22e8d282c + * compiler version: version 2.10.3-20130627-153946-54cb6af7db + * reconstructed args: + * + * last tree to typer: TypeTree(class Array) + * symbol: class Array in package scala (flags: final) + * symbol definition: final class Array[T >: ? <: ?] extends Object + * tpe: Array[Int] + * symbol owners: class Array -> package scala + * context owners: anonymous class anon$1 -> package compile + * + * == Expanded type of tree == + * + * TypeRef( + * TypeSymbol(final class Array[T >: ? <: ?] extends Object) + * args = List(TypeRef(TypeSymbol(final abstract class Int extends ))) + * ) + * + * unhandled exception while transforming SI-7638.scala + * error: uncaught exception during compilation: java.lang.UnsupportedOperationException + * error: java.lang.UnsupportedOperationException: tail of empty list + * at scala.collection.immutable.Nil$.tail(List.scala:339) + * at scala.collection.immutable.Nil$.tail(List.scala:334) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:123) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:122) + * at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207) + * at scala.reflect.internal.SymbolTable.afterPhase(SymbolTable.scala:216) + * at scala.tools.nsc.Global.afterPickler(Global.scala:1104) + * at scala.tools.nsc.transform.Mixin.scala$tools$nsc$transform$Mixin$$rebindSuper(Mixin.scala:122) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:339) + * at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:292) + */ + new ArrayVectorOrder[A] { } +} diff --git a/tests/untried/pos/Transactions.scala b/tests/untried/pos/Transactions.scala new file mode 100644 index 000000000..dc33e8c37 --- /dev/null +++ b/tests/untried/pos/Transactions.scala @@ -0,0 +1,113 @@ +package scala.concurrent1 + +class AbortException extends RuntimeException + +object Transaction { + private var cnt = 0L + def nextId: Long = synchronized { + cnt += 1; cnt + } + + // Transaction status constants + val Running = 0 + val Committed = 1 + val Abortable = 2 + val Aborted = 3 + val Compound = 4 + + def atomic[T](b: Transaction => T): Option[T] = + (new Transaction).run(b) +} + +class Transaction { + var status: Int = _ + + var id: Long = _ // only for real transactions + + var head: Transaction = this + var next: Transaction = null + + def this(hd: Transaction, tl: Transaction) = { this(); this.head = head; this.next = next } + + def makeAbort() = synchronized { + while (status != Transaction.Aborted && status != Transaction.Committed) { + status = Transaction.Abortable + wait() + } + } + private def abort() = synchronized { status = Transaction.Aborted; notifyAll() } + private def commit() = synchronized { status = Transaction.Committed; notifyAll() } + def run[T](b: Transaction => T): Option[T] = + try { + status = Transaction.Running + id = Transaction.nextId + val result = Some(b(this)) + commit() + result + } catch { + case ex: AbortException => abort(); None + case ex: Throwable => abort(); throw ex + } + +} + +trait Transactional { + + /** create a new snapshot */ + def checkPoint(): Unit + + /** copy back snapshot */ + def rollBack(): Unit + + var readers: Transaction + var writer: Transaction + + def currentWriter(): Transaction = null + if (writer == null) null + else if (writer.status == Transaction.Running) writer + else { + if (writer.status != Transaction.Committed) rollBack(); + writer = null; + null + } + + def getter(thisTrans: Transaction): Unit = { + if (writer == thisTrans) return + var r = readers + while (r != null && r.head.status != Transaction.Running) { r = r.next; readers = r } + while (r != null) { + if (r.head == thisTrans) return + val last = r + r = r.next + while (r != null && r.head.status != Transaction.Running) { r = r.next; last.next = r } + } + synchronized { + if (thisTrans.status == Transaction.Abortable) throw new AbortException + val w = currentWriter() + if (w != null) + if (thisTrans.id < w.id) { w.makeAbort(); rollBack(); writer = null } + else throw new AbortException + readers = if (readers == null) thisTrans else new Transaction(thisTrans, readers) + } + } + + def setter(thisTrans: Transaction): Unit = { + if (writer == thisTrans) return + synchronized { + val w = currentWriter() + if (w != null) + if (thisTrans.id < w.id) { w.makeAbort(); rollBack() } + else throw new AbortException + var r = readers + while (r != null && r.head.status != Transaction.Running) { r = r.next; readers = r } + while (r != null) { + if (r.id < thisTrans.id) throw new AbortException + else w.makeAbort() + val last = r + r = r.next + while (r != null && r.head.status != Transaction.Running) { r = r.next; last.next = r } + } + checkPoint() + } + } +} diff --git a/tests/untried/pos/X.scala b/tests/untried/pos/X.scala new file mode 100644 index 000000000..2edf010ef --- /dev/null +++ b/tests/untried/pos/X.scala @@ -0,0 +1,14 @@ +abstract class A() { + + var x: Int + +} + +abstract class B() extends A() { + + var xx: Int = 0; + + def x = xx; + def x_=(y: Int) = xx = y; +} + diff --git a/tests/untried/pos/Z.scala b/tests/untried/pos/Z.scala new file mode 100644 index 000000000..6a8e97ed1 --- /dev/null +++ b/tests/untried/pos/Z.scala @@ -0,0 +1,10 @@ +trait X { + val elem: Int = 1 +} + +object test { + + def g(x: X) = x.elem; + def f(x: AnyRef) = x.toString(); + +} diff --git a/tests/untried/pos/abstract.scala b/tests/untried/pos/abstract.scala new file mode 100644 index 000000000..2ac06e59b --- /dev/null +++ b/tests/untried/pos/abstract.scala @@ -0,0 +1,9 @@ +abstract class C() { + type t; + def copy(x: t): t = x; +} + +class D() extends C() { + type t = Int; + Console.println(copy(1)); +} diff --git a/tests/untried/pos/aliases.scala b/tests/untried/pos/aliases.scala new file mode 100644 index 000000000..b746a3586 --- /dev/null +++ b/tests/untried/pos/aliases.scala @@ -0,0 +1,25 @@ +abstract class C() { + + type t <: C; + + val x: t; + val y: x.type; + val z: x.type; + val u: z.type; + + val xt: x.t; + val yt: y.t; + val zt: z.t; + val ut: z.t; + + def fx(a: x.t): Unit; + def fy(a: y.t): Unit; + def fz(a: z.t): Unit; + def fu(a: u.t): Unit; + + fx(xt); fx(yt); fx(zt); fx(ut); + fy(xt); fy(yt); fy(zt); fy(ut); + fz(xt); fz(yt); fz(zt); fz(ut); + fu(xt); fu(yt); fu(zt); fu(ut); + +} diff --git a/tests/untried/pos/annot-inner.scala b/tests/untried/pos/annot-inner.scala new file mode 100644 index 000000000..fa9691e0b --- /dev/null +++ b/tests/untried/pos/annot-inner.scala @@ -0,0 +1,9 @@ +object test { + class annot extends scala.annotation.Annotation + + def foo: Unit = { + @annot def bar(i: Int): Int = i + @annot class Silly { } + bar(5) + } +} diff --git a/tests/untried/pos/annotDepMethType.scala b/tests/untried/pos/annotDepMethType.scala new file mode 100644 index 000000000..079ca6224 --- /dev/null +++ b/tests/untried/pos/annotDepMethType.scala @@ -0,0 +1,7 @@ +case class pc(calls: Any*) extends annotation.TypeConstraint + +object Main { + class C0 { def baz: String = "" } + class C1 { def bar(c0: C0): String @pc(c0.baz) = c0.baz } + def trans(c1: C1): String @pc(c1.bar(throw new Error())) = c1.bar(new C0) +} diff --git a/tests/untried/pos/annotated-original/C_2.scala b/tests/untried/pos/annotated-original/C_2.scala new file mode 100644 index 000000000..36a09ffe0 --- /dev/null +++ b/tests/untried/pos/annotated-original/C_2.scala @@ -0,0 +1,7 @@ +object Bug { + M.m { + def s = "" + M.m(s): @unchecked // error: macro has not been expanded. + ??? + } +} diff --git a/tests/untried/pos/annotated-original/M_1.scala b/tests/untried/pos/annotated-original/M_1.scala new file mode 100644 index 000000000..84a01bcce --- /dev/null +++ b/tests/untried/pos/annotated-original/M_1.scala @@ -0,0 +1,7 @@ +import language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object M { + def impl(c: Context)(a: c.Expr[Any]) = c.Expr[Any](c.untypecheck(a.tree)) + def m(a: Any) = macro impl +} diff --git a/tests/untried/pos/annotated-treecopy.flags b/tests/untried/pos/annotated-treecopy.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/annotated-treecopy.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/annotated-treecopy/Impls_Macros_1.scala b/tests/untried/pos/annotated-treecopy/Impls_Macros_1.scala new file mode 100644 index 000000000..986287dfa --- /dev/null +++ b/tests/untried/pos/annotated-treecopy/Impls_Macros_1.scala @@ -0,0 +1,54 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context +import collection.mutable.ListBuffer +import collection.mutable.Stack + +object Macros { + trait TypedFunction { + def tree: scala.reflect.runtime.universe.Tree + val typeIn: String + val typeOut: String + } + + def tree[T,U](f:Function1[T,U]): Function1[T,U] = macro tree_impl[T,U] + + def tree_impl[T:c.WeakTypeTag,U:c.WeakTypeTag](c: Context) + (f:c.Expr[Function1[T,U]]): c.Expr[Function1[T,U]] = { + import c.universe._ + import internal._ + val ttag = c.weakTypeTag[U] + f match { + case Expr(Function(List(ValDef(_,n,tp,_)),b)) => + // normalize argument name + var b1 = new Transformer { + override def transform(tree: Tree): Tree = tree match { + case Ident(x) if (x==n) => Ident(TermName("_arg")) + case tt: TypeTree if tt.original != null => setOriginal(TypeTree(tt.tpe), transform(tt.original)) + // without the fix to LazyTreeCopier.Annotated, we would need to uncomment the line below to make the macro work + // that's because the pattern match in the input expression gets expanded into Typed(<x>, TypeTree(<Int @unchecked>)) + // with the original of the TypeTree being Annotated(<@unchecked>, Ident(<x>)) + // then the macro tries to replace all Ident(<x>) trees with Ident(<_arg>), recurs into the original of the TypeTree, changes it, + // but leaves the <@unchecked> part untouched. this signals the misguided LazyTreeCopier that the Annotated tree hasn't been modified, + // so the original tree should be copied over and returned => crash when later <x: @unchecked> re-emerges from TypeTree.original + // case Annotated(annot, arg) => treeCopy.Annotated(tree, transform(annot).duplicate, transform(arg)) + case _ => super.transform(tree) + } + }.transform(b) + + val reifiedTree = c.reifyTree(gen.mkRuntimeUniverseRef, EmptyTree, b1) + val reifiedExpr = c.Expr[scala.reflect.runtime.universe.Expr[T => U]](reifiedTree) + val template = + c.universe.reify(new (T => U) with TypedFunction { + override def toString = c.Expr[String](q"""${tp+" => "+ttag.tpe+" { "+b1.toString+" } "}""").splice // DEBUG + def tree = reifiedExpr.splice.tree + val typeIn = c.Expr[String](q"${tp.toString}").splice + val typeOut = c.Expr[String](q"${ttag.tpe.toString}").splice + def apply(_arg: T): U = c.Expr[U](b1)(ttag.asInstanceOf[c.WeakTypeTag[U]]).splice + }) + val untyped = c.untypecheck(template.tree) + + c.Expr[T => U](untyped) + case _ => sys.error("Bad function type") + } + } +} diff --git a/tests/untried/pos/annotated-treecopy/Test_2.scala b/tests/untried/pos/annotated-treecopy/Test_2.scala new file mode 100644 index 000000000..1c6b862ef --- /dev/null +++ b/tests/untried/pos/annotated-treecopy/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + import Macros._ + // tree { (x:((Int,Int,Int),(Int,Int,Int))) => { val y=x; val ((r1,m1,c1),(r2,m2,c2))=y; (r1, m1 + m2 + r1 * c1 * c2, c2) } } + tree { (x:((Int,Int,Int),(Int,Int,Int))) => { val ((r1,m1,c1),(r2,m2,c2))=x; (r1, m1 + m2 + r1 * c1 * c2, c2) } } +} diff --git a/tests/untried/pos/annotations.scala b/tests/untried/pos/annotations.scala new file mode 100644 index 000000000..9235a1ee6 --- /dev/null +++ b/tests/untried/pos/annotations.scala @@ -0,0 +1,110 @@ +class ann(i: Int) extends scala.annotation.Annotation +class cfann(x: String) extends annotation.ClassfileAnnotation + +// annotations on abstract types +abstract class C1[@annotation.elidable(0) +T, U, V[_]] +abstract class C2[@deprecated + @ann(1) T <: Number, + V] +abstract class C3 { + @ann(2) type X <: Number +} + +object Test { + + // bug #1028 + val x = 1 + @ann(x) val a = () + @ann({val yy = 2; yy}) val b = () + val bb: Int @ann({val yy = 2; yy}) = 10 + + def c: Int @ann(x) = 1 + def d: String @ann({val z = 0; z - 1}) = "2" + def e[@deprecated T, U](x: T) = x + + //bug #1214 + val y = new (Integer @ann(0))(2) + + import scala.beans.BeanProperty + + // bug #637 + trait S { def getField(): Int } + class O extends S { @BeanProperty val field = 0 } + + // bug #1070 + trait T { @BeanProperty var field = 1 } + + // annotation on annotation constructor + @(ann @ann(100))(200) def foo() = 300 + + // #2984 + private final val NAMESPACE = "/info" + @cfann(x = NAMESPACE + "/index") def index = "success" +} + +// test forward references to getters / setters +class BeanPropertyTests { + @scala.beans.BeanProperty lazy val lv1 = 0 + + def foo(): Unit = { + val bp1 = new BeanPropertyTests1 + + println(lv1) + println(getLv1()) + println(bp1.getLv2()) + + println(getV1()) + setV1(10) + bp1.setV2(100) + } + + @scala.beans.BeanProperty var v1 = 0 + +} + +class BeanPropertyTests1 { + @scala.beans.BeanProperty lazy val lv2 = "0" + @scala.beans.BeanProperty var v2 = 0 +} + +// test mixin of getters / setters, and implementing abstract +// methods using @BeanProperty +class C extends T with BeanF { + def foo(): Unit = { + setF("doch!") + setG(true) + this.getF() + } +} + +trait T { + @scala.beans.BeanProperty var f = "nei" + @scala.beans.BooleanBeanProperty var g = false +} + +trait BeanF { + def getF(): String + def setF(n: String): Unit + + def isG(): Boolean + def setG(nb: Boolean): Unit +} + + +class Ann3(arr: Array[String]) extends annotation.ClassfileAnnotation +class Ann4(i: Int) extends annotation.ClassfileAnnotation +class Ann5(value: Class[_]) extends annotation.ClassfileAnnotation + +object Test3 { + final val i = 1083 + final val cls = classOf[String] +} + +class Test4 { + @Ann3(arr = Array("dlkfj", "DSF")) + @Ann4(i = 2908) + @Ann4(i = Test3.i) + @Ann5(value = classOf[Int]) + @Ann5(Test3.cls) + def foo: Unit = {} +} diff --git a/tests/untried/pos/annotations2.scala b/tests/untried/pos/annotations2.scala new file mode 100644 index 000000000..3bce7f8ac --- /dev/null +++ b/tests/untried/pos/annotations2.scala @@ -0,0 +1,31 @@ + +class B[T](x: (T, T)) { + def this(xx: (T, Any, Any)) = this((xx._1, xx._1)) +} +class BAnn[T](x: (T, T)) extends scala.annotation.StaticAnnotation { + def this(xx: (T, Any, Any)) = this((xx._1, xx._1)) +} +class CAnn[T](x: (T, T)) extends scala.annotation.StaticAnnotation { + def this(xx: Class[T]) = this((xx.newInstance(), xx.newInstance())) +} + +class A1 { + val b1 = new B((1, 2, 3)) + val b2 = new B((1, 2)) + val b3 = new B[Int]((1, 2, 3)) + val b4 = new B[Int]((1, 2)) +} + +class A2 { + @BAnn((1, 2, 3)) val b1 = null + @BAnn((1, 2)) val b2 = null + @BAnn[Int]((1, 2, 3)) val b3 = null + @BAnn[Int]((1, 2)) val b4 = null +} + +class A3 { + @CAnn(classOf[Int]) val b1 = null + @CAnn((1, 2)) val b2 = null + @CAnn[Int](classOf[Int]) val b3 = null + @CAnn[Int]((1, 2)) val b4 = null +} diff --git a/tests/untried/pos/array-interfaces.scala b/tests/untried/pos/array-interfaces.scala new file mode 100644 index 000000000..88b9a3f30 --- /dev/null +++ b/tests/untried/pos/array-interfaces.scala @@ -0,0 +1,9 @@ +object s { + def f(x: Cloneable) = () + def g(x: java.io.Serializable) = () + + def main(args: Array[String]): Unit = { + f(args) + g(args) + } +} diff --git a/tests/untried/pos/arrays2.scala b/tests/untried/pos/arrays2.scala new file mode 100644 index 000000000..795c486e3 --- /dev/null +++ b/tests/untried/pos/arrays2.scala @@ -0,0 +1,23 @@ +case class C(); + +object arrays2 { + + def main(args: Array[String]): Unit = { + val a: Array[Array[C]] = new Array[Array[C]](2); + a(0) = new Array[C](2); + a(0)(0) = new C(); + } +} + +// #2422 +object arrays4 { + val args = Array[String]("World") + "Hello %1$s".format(args: _*) +} + +// #2461 +object arrays3 { + import scala.collection.JavaConversions._ + def apply[X](xs : X*) : java.util.List[X] = java.util.Arrays.asList(xs: _*) +} + diff --git a/tests/untried/pos/arrays3.scala b/tests/untried/pos/arrays3.scala new file mode 100644 index 000000000..f96be0b42 --- /dev/null +++ b/tests/untried/pos/arrays3.scala @@ -0,0 +1,11 @@ +trait Foo { + type Repr <: String + def f2(x: Repr) = x.length +} +trait Fooz[Repr <: Array[_]] { + def f0(x: Repr) = x.length +} + +trait Bar[Repr <: List[_]] extends Foo with Fooz[Array[Int]] { + def f1(x: Repr) = x.length +} diff --git a/tests/untried/pos/attachments-typed-another-ident.flags b/tests/untried/pos/attachments-typed-another-ident.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/attachments-typed-another-ident.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/attachments-typed-another-ident/Impls_1.scala b/tests/untried/pos/attachments-typed-another-ident/Impls_1.scala new file mode 100644 index 000000000..98062a9c7 --- /dev/null +++ b/tests/untried/pos/attachments-typed-another-ident/Impls_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object MyAttachment + +object Macros { + def impl(c: Context) = { + import c.universe._ + import internal._ + val ident = updateAttachment(Ident(TermName("bar")), MyAttachment) + assert(attachments(ident).get[MyAttachment.type].isDefined, attachments(ident)) + val typed = c.typecheck(ident) + assert(attachments(typed).get[MyAttachment.type].isDefined, attachments(typed)) + c.Expr[Int](typed) + } + + def foo = macro impl +} diff --git a/tests/untried/pos/attachments-typed-another-ident/Macros_Test_2.scala b/tests/untried/pos/attachments-typed-another-ident/Macros_Test_2.scala new file mode 100644 index 000000000..022639bfe --- /dev/null +++ b/tests/untried/pos/attachments-typed-another-ident/Macros_Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + def bar = 2 + Macros.foo +} + diff --git a/tests/untried/pos/attachments-typed-ident.flags b/tests/untried/pos/attachments-typed-ident.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/attachments-typed-ident.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/attachments-typed-ident/Impls_1.scala b/tests/untried/pos/attachments-typed-ident/Impls_1.scala new file mode 100644 index 000000000..98062a9c7 --- /dev/null +++ b/tests/untried/pos/attachments-typed-ident/Impls_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object MyAttachment + +object Macros { + def impl(c: Context) = { + import c.universe._ + import internal._ + val ident = updateAttachment(Ident(TermName("bar")), MyAttachment) + assert(attachments(ident).get[MyAttachment.type].isDefined, attachments(ident)) + val typed = c.typecheck(ident) + assert(attachments(typed).get[MyAttachment.type].isDefined, attachments(typed)) + c.Expr[Int](typed) + } + + def foo = macro impl +} diff --git a/tests/untried/pos/attachments-typed-ident/Macros_Test_2.scala b/tests/untried/pos/attachments-typed-ident/Macros_Test_2.scala new file mode 100644 index 000000000..45a0609de --- /dev/null +++ b/tests/untried/pos/attachments-typed-ident/Macros_Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + def bar = 2 + Macros.foo +} diff --git a/tests/untried/pos/attributes.scala b/tests/untried/pos/attributes.scala new file mode 100644 index 000000000..60e00bff7 --- /dev/null +++ b/tests/untried/pos/attributes.scala @@ -0,0 +1,81 @@ +class serializable extends annotation.StaticAnnotation + +@serializable class C1; +@serializable @volatile class C2; +@serializable @volatile class C3; +@serializable @volatile @serializable class C4; + +@serializable trait T1; +@serializable @volatile trait T2; +@serializable @volatile trait T3; +@serializable @volatile @serializable trait T4; + +@serializable object O1 extends C1; +@serializable @volatile object O2 extends C2; +@serializable @volatile object O3 extends C3; +@serializable @volatile @serializable object O4 extends C4; + +object O5 { + final val n = 2; + @SerialVersionUID(0) class C1; + @SerialVersionUID(n) class C2; + @SerialVersionUID(0) @SerialVersionUID(n) class C3; + @SerialVersionUID(0) @SerialVersionUID(n) class C4; +} + +abstract class A1 { + @serializable var y1: C1; + @serializable @volatile var y2: C2; + @serializable @volatile var y3: C3; + @serializable @volatile @serializable var y4: C4; + + @serializable def foo1: C1; + @serializable @volatile def foo2: C2; + @serializable @volatile def foo3: C3; + @serializable @volatile @serializable def foo4: C4; +} + +object O6 { + @serializable val x1 = new C1; + // volatile val sensibly disallowed as of r18645 + @serializable val x2 = new C2; + @serializable val x3 = new C3; + @serializable val x4 = new C4; + + @serializable var y1: C1 = _; + @serializable @volatile var y2: C2 = _; + @serializable @volatile var y3: C3 = _; + @serializable @volatile @serializable var y4: C4 = _; + + @serializable private def foo1 = x1; + @serializable @volatile private def foo2 = x2; + @serializable @volatile protected def foo3 = x3; + @serializable @volatile @serializable protected def foo4 = x4; +} + +object myAttrs { + class a1 extends scala.annotation.Annotation; + class a2(x: Int) extends scala.annotation.Annotation; + class a3(x: a1) extends scala.annotation.Annotation; +} +class a4(ns: Array[Int]) extends scala.annotation.Annotation; +object O7 { + class a1 extends scala.annotation.Annotation; + class a2(x: Int) extends scala.annotation.Annotation; + class a3(x: a1) extends scala.annotation.Annotation; + + final val x = new a1; + @a1 class C1; + @a1 @a2(77) class C2; + @a1 @a2(88) class C3; + @a1 @a2(88) @a3(null) class C4; + + @myAttrs.a1 class A1; + @myAttrs.a1 @myAttrs.a2(99) class A2; + @myAttrs.a1 @myAttrs.a2(99) class A3; + @myAttrs.a1 @myAttrs.a2(99) @myAttrs.a3(null) class A4; + @a4(Array(1,2,3)) class A5; + @a4(Array()) class A6; + + val zero = 0 : @myAttrs.a1 +} diff --git a/tests/untried/pos/bcode_throw_null/TN.scala b/tests/untried/pos/bcode_throw_null/TN.scala new file mode 100644 index 000000000..ab04c4513 --- /dev/null +++ b/tests/untried/pos/bcode_throw_null/TN.scala @@ -0,0 +1,7 @@ +object TN { + + def pre1(b: Boolean): Unit = { + println(if (b) 1 else throw null) + } + +} diff --git a/tests/untried/pos/bounds.scala b/tests/untried/pos/bounds.scala new file mode 100644 index 000000000..26bc84a1b --- /dev/null +++ b/tests/untried/pos/bounds.scala @@ -0,0 +1,11 @@ +trait Map[A, +C] { + def ++ [B1 >: C] (kvs: Iterable[Tuple2[A, B1]]): Map[A, B1] = this + def ++ [B1 >: C] (kvs: Iterator[Tuple2[A, B1]]): Map[A, B1] = this +} + +class ListMap[A, +B] extends Map[A, B] {} + +object ListMap { + def empty[X, Y] = new ListMap[X, Y] + def apply[A1, B2](elems: Tuple2[A1, B2]*): Map[A1, B2] = empty[A1,B2].++(elems.iterator) +} diff --git a/tests/untried/pos/builders.scala b/tests/untried/pos/builders.scala new file mode 100644 index 000000000..fb0fdf0d0 --- /dev/null +++ b/tests/untried/pos/builders.scala @@ -0,0 +1,66 @@ +object builders { + + trait Builder[-From, +To, -Elem] { + def += (elem: Elem) + def result: To + } + + implicit def iterableBuilder[A, B] = new Builder[Iterable[A], Iterable[B], B] { + println("new iterable builder") + private val buf = new scala.collection.mutable.ListBuffer[B] + def += (elem: B): Unit = { buf += elem } + def result: Iterable[B] = buf.toList + } + + implicit def listBuilder[A, B] = new Builder[List[A], List[B], B] { + println("new list builder") + private val buf = new scala.collection.mutable.ListBuffer[B] + def += (elem: B): Unit = { buf += elem } + def result: List[B] = buf.toList + } +/* + def fill[A, Dim1, Dim2, Coll](n1: Int, n2: Int, elem: A)(implicit b1: Builder[Coll, Dim1, A], b2: Builder[Coll, Dim2, Dim1]) = { + for (i <- 0 until n1) { + for (j <- 0 until n2) { + b1 += elem + } + b2 += b1.result + } + b2.result + } +*/ +/* + implicit def arrayBuilder[A, B] = new Builder[Array[A], Array[B], B] { + println("new arr ay builder") + private val buf = new scala.collection.mutable.ListBuffer[B] + def += (elem: B) { buf += elem } + def result: Array[B] = buf.toArray + } +*/ + class Iter[A, C](elems: List[A]) { + def ++ [B >: A, D](xs: Iterable[B])(implicit b: Builder[C, D, B]): D = { + for (x <- elems) b += x + for (x <- xs) b += x + b.result + } + def map[B, D](f: A => B)(implicit b: Builder[C, D, B]): D = { + for (x <- elems) b += f(x) + b.result + } + } + + def main(args : Array[String]) : Unit = { + val x1 = new Iter[Int, List[Int]](List(1, 2, 3)) +// val x2 = new Iter[Int, Array[Int]](List(1, 2, 3)) + val x3 = new Iter[Int, Iterable[Int]](List(1, 2, 3)) + val y1: List[Int] = x1.map (_ + 1) +// val y2: Array[Int] = x2.map (_ + 1) + val y3: Iterable[Int] = x3.map (_ + 1) + val z1: List[Int] = y1 +// val z2: Array[Int] = y2 + val z3: Iterable[Int] = y3 + println(z1) +// println(z2) + println(z3) + } +} diff --git a/tests/untried/pos/caseClassInMethod.scala b/tests/untried/pos/caseClassInMethod.scala new file mode 100644 index 000000000..958e5dd47 --- /dev/null +++ b/tests/untried/pos/caseClassInMethod.scala @@ -0,0 +1,5 @@ +object t { + def f = { object C; case class C(); 1 } + // pending: def g = { case class D(x: Int); object D; 2 } + def h = { case class E(y: Int = 10); 3 } +} diff --git a/tests/untried/pos/caseaccs.scala b/tests/untried/pos/caseaccs.scala new file mode 100644 index 000000000..7f2c9ef2a --- /dev/null +++ b/tests/untried/pos/caseaccs.scala @@ -0,0 +1,11 @@ +class Test { + case class Foo(x: Int, private var y: Int) +} + +object Test { + val test = new Test + val x = test.Foo(1, 2) + x match { + case test.Foo(x, y) => println(x); println(y) + } +} diff --git a/tests/untried/pos/cfcrash.scala b/tests/untried/pos/cfcrash.scala new file mode 100644 index 000000000..19475ad4c --- /dev/null +++ b/tests/untried/pos/cfcrash.scala @@ -0,0 +1,4 @@ +object cfcrash { + final val zero = 0 + def blah = 3 / zero // this should not crash the compiler +} diff --git a/tests/untried/pos/chang/Outer.java b/tests/untried/pos/chang/Outer.java new file mode 100644 index 000000000..acdb4e290 --- /dev/null +++ b/tests/untried/pos/chang/Outer.java @@ -0,0 +1,11 @@ +package com.netgents.hello; + +public class Outer<A> { + + public Inner inner = new Inner(); + + public class Inner { + + public A a; + } +} diff --git a/tests/untried/pos/chang/Test.scala b/tests/untried/pos/chang/Test.scala new file mode 100644 index 000000000..f74c6355b --- /dev/null +++ b/tests/untried/pos/chang/Test.scala @@ -0,0 +1,3 @@ +object Test extends App { + new com.netgents.hello.Outer[String] +} diff --git a/tests/untried/pos/channels.scala b/tests/untried/pos/channels.scala new file mode 100644 index 000000000..b2f0cdc32 --- /dev/null +++ b/tests/untried/pos/channels.scala @@ -0,0 +1,29 @@ +class Channel[a] + +import collection.mutable.Set + +case class ![a](chan: Channel[a], data: a) + +/* +object Bang { + def unapply[a](x: ![a]): Option[{Channel[a], a}] = + Some(x.chan, x.data) +} + +*/ +object Test extends App { + object IC extends Channel[Int] + def f[b](x: ![b]): Int = x match { + case send: ![c] => + send.chan match { + case IC => send.data + } + } +} + +object Test2 extends App { + object IC extends Channel[Set[Int]] + def f[b](s: ![b]): Set[Int] = s match { + case IC ! x => x + } +} diff --git a/tests/untried/pos/classtag-pos.flags b/tests/untried/pos/classtag-pos.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/classtag-pos.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/classtag-pos.scala b/tests/untried/pos/classtag-pos.scala new file mode 100644 index 000000000..768d2e27f --- /dev/null +++ b/tests/untried/pos/classtag-pos.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +class A { + def f[T: TypeTag] = typeOf[T] match { case TypeRef(_, _, args) => args } +} diff --git a/tests/untried/pos/cls.scala b/tests/untried/pos/cls.scala new file mode 100644 index 000000000..13661990c --- /dev/null +++ b/tests/untried/pos/cls.scala @@ -0,0 +1,17 @@ +import scala._; + +package scalac.util { + +class A[X1, X2](x1: X1, x2: X2) {} +class B[Y](y1: Y, y2: Y) extends A[Y, Y](y1, y2) { + def f(x: Y, xs: B[Y]): Unit = {} + def g() = f(y1, this); +} + +object test { + val b: B[Int] = new B[Int](1, 2); + val a: A[Int, Int] = b; + val a1 = new A(1, "hello"); + val b1 = new B(1, "hello"); +} +} diff --git a/tests/untried/pos/cls1.scala b/tests/untried/pos/cls1.scala new file mode 100644 index 000000000..20ac12d59 --- /dev/null +++ b/tests/untried/pos/cls1.scala @@ -0,0 +1,9 @@ +package test; + +trait A { + type T; + + trait B extends A { + type T = A.this.T; + } +} diff --git a/tests/untried/pos/clsrefine.scala b/tests/untried/pos/clsrefine.scala new file mode 100644 index 000000000..0a016dec0 --- /dev/null +++ b/tests/untried/pos/clsrefine.scala @@ -0,0 +1,40 @@ +import scala._; + +package scalac.util { + +trait A { + type X1; + type X2; + val x1: X1; + val x2: X2; +} +trait B extends A { + type Y; + val y1, y2: Y; + type X1 = Y; + type X2 = Y; + val x1 = y1; + val x2 = y2; + def f(x: Y, xs: B): Unit = {} + def g() = f(y1, this); +} + +object test { + val b: B { type Y = Int } = new B { + type Y = Int; + val y1, y2 = 1; + } + val a: A { type X1 = Int; type X2 = Int } = b; + val a1 = new A { + type X1 = Int; + type X2 = String; + val x1 = 1; + val x2 = "hello" + } + val b1 = new B { + type Y = Any; + val y1 = 1; + val y2 = "hello"; + } +} +} diff --git a/tests/untried/pos/collectGenericCC.scala b/tests/untried/pos/collectGenericCC.scala new file mode 100644 index 000000000..b0f60de73 --- /dev/null +++ b/tests/untried/pos/collectGenericCC.scala @@ -0,0 +1,14 @@ +import scala.collection.generic.CanBuildFrom +import scala.collection._ + +object Test { + def collect[A, Res](r: Traversable[A])(implicit bf: generic.CanBuild[A, Res]) = { + val b: collection.mutable.Builder[A, Res] = bf() + r foreach ((a: A) => b += a) + b.result + } + + collect[Int, Vector[Int]](List(1,2,3,4)) + collect[Char, String](List('1','2','3','4')) + collect[Char, Array[Char]](List('1','2','3','4')) +} diff --git a/tests/untried/pos/collections.scala b/tests/untried/pos/collections.scala new file mode 100644 index 000000000..23b23d016 --- /dev/null +++ b/tests/untried/pos/collections.scala @@ -0,0 +1,15 @@ +package mixins; + +import scala.collection.mutable._; + +class Collections extends HashSet[Int] with ObservableSet[Int] { + override def +=(elem: Int): this.type = super.+=(elem); + override def -=(elem: Int): this.type = super.-=(elem); + override def clear: Unit = super.clear; + +} + +object collections extends Collections; + +//class Collections1 extends HashSet[Int] with ObservableSet[Int,Collections1]; +//object collections1 extends Collections1; diff --git a/tests/untried/pos/comp-rec-test.flags b/tests/untried/pos/comp-rec-test.flags new file mode 100644 index 000000000..ad928f52a --- /dev/null +++ b/tests/untried/pos/comp-rec-test.flags @@ -0,0 +1 @@ +-Yrecursion 1 diff --git a/tests/untried/pos/comp-rec-test.scala b/tests/untried/pos/comp-rec-test.scala new file mode 100644 index 000000000..c3e6f8c19 --- /dev/null +++ b/tests/untried/pos/comp-rec-test.scala @@ -0,0 +1,24 @@ +object Comp extends App { + + trait Family { + type T + } + + object Trivial extends Family { + type T = Unit + } + + trait Wrap extends Family { + val v : Family + type T = v.T + } + + object WrapTrivial extends Wrap { + val v = Trivial + } + + object WrapWrapTrivial extends Wrap { + val v = WrapTrivial + } + +} diff --git a/tests/untried/pos/compile.scala b/tests/untried/pos/compile.scala new file mode 100644 index 000000000..bb2526e4b --- /dev/null +++ b/tests/untried/pos/compile.scala @@ -0,0 +1,149 @@ +//############################################################################ +// Compile Time Bugs & Test Cases +//############################################################################ + +import java.lang.System; // to avoid name clash with .NET's library + +//############################################################################ +// Test 0 + +/* +class Test0Foo[X]; + +object Test0Test { + type Gen[A] = Test0Foo[A]; + class Tic(g: Test0Test.Gen[Int]); + class Tac(g: Gen[Int]); +} + +//############################################################################ +// Test 1 - Single types in lambda lift + +object Test1 { + def main(args: Array[String]): Unit = { + List[args.type](args); + } + def foo[X]: Any = { + def bar(x: X) = List(x); + 0 + } +} + +//############################################################################ +// Test 2 - Local variables owned by other local variables + +class Test2_1(i: Int) { + val t = { + val x = { + val y = { + val z = i; + z; + }; + }; + }; + val x = { + val y = { + val z = i; + z; + }; + }; + val y = { + val z = i; + z; + }; + val z2_1 = i; +} + +class Test2_2(i: Int) { + { + val t = { + val x = { + val y = { + val z = i; + z; + }; + }; + }; + val x = { + val y = { + val z = i; + z; + }; + }; + val y = { + val z = i; + z; + }; + val z2_2 = i; + 0 + } +} + +class Test2_3() { + + def this(i: Int) = { + this(); + val t = { + val x = { + val y = { + val z = i; + z; + }; + }; + }; + val x = { + val y = { + val z = i; + z; + }; + }; + val y = { + val z = i; + z; + }; + val z2_3 = i; + } + + def test(i: Int): Int = { + val t = { + val x = { + val y = { + val z = i; + z; + }; + }; + }; + val x = { + val y = { + val z = i; + z; + }; + }; + val y = { + val z = i; + z; + }; + val z_test = i; + 0 + } + +} +*/ +//############################################################################ +// Test 3 - Super Calls with Mixins + +class Test3Foo; + +trait Test3A[T] { + def fun: T = fun; +} + +class Test3B extends Test3A[Test3Foo]; + +trait Test3M extends Test3A[Test3Foo] { + override def fun: Test3Foo = super.fun; +} + +class Test3C extends Test3B with Test3M; + +//############################################################################ diff --git a/tests/untried/pos/compile1.scala b/tests/untried/pos/compile1.scala new file mode 100644 index 000000000..6886d39ca --- /dev/null +++ b/tests/untried/pos/compile1.scala @@ -0,0 +1,34 @@ +//############################################################################ +// Compile Time Bugs & Test Cases +//############################################################################ + +import java.lang.System; // to avoid name clash with .NET's library + +//############################################################################ +// Test 0 + +class Test2_2(i: Int) { + { + val t = { + val x = { + val y = { + val z = i; + z; + }; + }; + }; + val x = { + val y = { + val z = i; + z; + }; + }; + val y = { + val z = i; + z; + }; + val z2_2 = i; + 0 + } +} + diff --git a/tests/untried/pos/compound.scala b/tests/untried/pos/compound.scala new file mode 100644 index 000000000..60890f910 --- /dev/null +++ b/tests/untried/pos/compound.scala @@ -0,0 +1,9 @@ +abstract class A { type T } + +abstract class B { val xz: Any } + +abstract class Test { + var yy: A with B { type T; val xz: T } = null; + var xx: A with B { type T; val xz: T } = null; + xx = yy; +} diff --git a/tests/untried/pos/constfold.scala b/tests/untried/pos/constfold.scala new file mode 100644 index 000000000..8d431efba --- /dev/null +++ b/tests/untried/pos/constfold.scala @@ -0,0 +1,14 @@ +object A { + val x = 2; + val y = x.asInstanceOf[Byte]; + val z = 1.0 / 2; + val s = "z is " + z; +} + +object Test extends App { + + Console.println(A.x); + Console.println(A.y); + Console.println(A.z); + Console.println(A.s); +} diff --git a/tests/untried/pos/context.scala b/tests/untried/pos/context.scala new file mode 100644 index 000000000..4e11d07eb --- /dev/null +++ b/tests/untried/pos/context.scala @@ -0,0 +1,38 @@ +class Context { + object symwrap extends SymbolWrapper { + val context: Context.this.type = Context.this + } + object typewrap extends TypeWrapper { + val context: Context.this.type = Context.this + } + object symbols extends symwrap.Symbols; + object types extends typewrap.Types; +} + +abstract class SymbolWrapper { + val context: Context; + import context._; + + class Symbols { + self: context.symbols.type => + + abstract class Symbol { + def typ: types.Type; + def sym: Symbol = typ.sym; + } + } +} + +abstract class TypeWrapper { + val context: Context; + import context._; + + class Types { + self: context.types.type => + + abstract class Type { + def sym: symbols.Symbol; + def typ: Type = sym.typ; + } + } +} diff --git a/tests/untried/pos/contextbounds-implicits-new.scala b/tests/untried/pos/contextbounds-implicits-new.scala new file mode 100644 index 000000000..8389d1332 --- /dev/null +++ b/tests/untried/pos/contextbounds-implicits-new.scala @@ -0,0 +1,10 @@ +import scala.reflect.runtime.universe._ + +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: TypeTag, S: TypeTag](x: T, y: S)(implicit p: C): Unit = { } + +} diff --git a/tests/untried/pos/contextbounds-implicits-old.scala b/tests/untried/pos/contextbounds-implicits-old.scala new file mode 100644 index 000000000..084a4aaf5 --- /dev/null +++ b/tests/untried/pos/contextbounds-implicits-old.scala @@ -0,0 +1,8 @@ +/* Tests implicit parameters in the presence of context bounds. + * See Section 7.4 of the Scala Language Specification. + */ +class C { + + def f[T: Manifest, S: Manifest](x: T, y: S)(implicit p: C): Unit = { } + +} diff --git a/tests/untried/pos/contrib467.scala b/tests/untried/pos/contrib467.scala new file mode 100644 index 000000000..86d456ad3 --- /dev/null +++ b/tests/untried/pos/contrib467.scala @@ -0,0 +1,22 @@ +abstract class M +{ + val data: List[M] +} + +object Test +{ + def main(args: Array[String]): Unit = + { + object SA extends M + { + val data = List() + } + + object SB extends M + { + val data = List(SA) + } + + () + } +} diff --git a/tests/untried/pos/contrib701.scala b/tests/untried/pos/contrib701.scala new file mode 100644 index 000000000..6f0e53a36 --- /dev/null +++ b/tests/untried/pos/contrib701.scala @@ -0,0 +1,3 @@ +trait B { + type A[T] >: A[A[T]] +} diff --git a/tests/untried/pos/cycle-jsoup.flags b/tests/untried/pos/cycle-jsoup.flags new file mode 100644 index 000000000..ca20f5517 --- /dev/null +++ b/tests/untried/pos/cycle-jsoup.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/untried/pos/cycle-jsoup.scala b/tests/untried/pos/cycle-jsoup.scala new file mode 100644 index 000000000..d547ecd93 --- /dev/null +++ b/tests/untried/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/untried/pos/cycle.flags b/tests/untried/pos/cycle.flags new file mode 100644 index 000000000..ca20f5517 --- /dev/null +++ b/tests/untried/pos/cycle.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/untried/pos/cycle/J_1.java b/tests/untried/pos/cycle/J_1.java new file mode 100644 index 000000000..0cc218eeb --- /dev/null +++ b/tests/untried/pos/cycle/J_1.java @@ -0,0 +1,16 @@ +package bar; + +public class J_1 { + public void f(C.D arg) { + } +} + +class B extends J_1 { + public void g(C.D arg) { + } +} + +class C extends B { + public class D { + } +} diff --git a/tests/untried/pos/cycle/X_2.scala b/tests/untried/pos/cycle/X_2.scala new file mode 100644 index 000000000..c1840f3b9 --- /dev/null +++ b/tests/untried/pos/cycle/X_2.scala @@ -0,0 +1,3 @@ +import bar.J_1._ //<--- illegal cyclic reference involving + +class X diff --git a/tests/untried/pos/cyclics-pos.scala b/tests/untried/pos/cyclics-pos.scala new file mode 100644 index 000000000..395e88815 --- /dev/null +++ b/tests/untried/pos/cyclics-pos.scala @@ -0,0 +1,26 @@ +trait Param[T] +trait Abs { type T } +trait Cyclic1[A <: Param[A]] // works +trait Cyclic2[A <: Abs { type T <: A }] +trait Cyclic3 { type A <: Abs { type T = A } } +trait Cyclic4 { type A <: Param[A] } // works +trait Cyclic5 { type AA <: Abs; type A <: AA { type T = A } } + + +trait IterableTemplate { + type Elem + type Constr <: IterableTemplate + type ConstrOf[A] = Constr { type Elem = A } + + def iterator: Iterator[Elem] + + def map [B] (f: Elem => B): ConstrOf[B] + + def foreach(f: Elem => Unit) = iterator.foreach(f) +} + + +trait Iterable[A] extends IterableTemplate { self => + type Elem + type Constr <: Iterable[A] { type Constr <: Iterable.this.Constr } +} diff --git a/tests/untried/pos/debug-reset-local-attrs.flags b/tests/untried/pos/debug-reset-local-attrs.flags new file mode 100644 index 000000000..9c7d6400f --- /dev/null +++ b/tests/untried/pos/debug-reset-local-attrs.flags @@ -0,0 +1 @@ +-Ydebug diff --git a/tests/untried/pos/debug-reset-local-attrs.scala b/tests/untried/pos/debug-reset-local-attrs.scala new file mode 100644 index 000000000..834865796 --- /dev/null +++ b/tests/untried/pos/debug-reset-local-attrs.scala @@ -0,0 +1 @@ +case class FT(f : Float) diff --git a/tests/untried/pos/delambdafy-lambdalift.scala b/tests/untried/pos/delambdafy-lambdalift.scala new file mode 100644 index 000000000..e9da24ef3 --- /dev/null +++ b/tests/untried/pos/delambdafy-lambdalift.scala @@ -0,0 +1,8 @@ +class LambdaLift { + + def enclosingMethod(capturedArg: Int): Unit = { + def innerMethod(x: Int): Int = x + capturedArg + val f = (y: Int) => innerMethod(y) + } + +} diff --git a/tests/untried/pos/delambdafy-patterns.scala b/tests/untried/pos/delambdafy-patterns.scala new file mode 100644 index 000000000..95d498629 --- /dev/null +++ b/tests/untried/pos/delambdafy-patterns.scala @@ -0,0 +1,15 @@ +class DelambdafyPatterns { + def bar: Unit = () + def wildcardPatternInTryCatch: Unit => Unit = (x: Unit) => + // patterns in try..catch are preserved so we need to be + // careful when it comes to free variable detction + // in particular a is _not_ free variable, also the + // `_` identifier has no symbol attached to it + try bar catch { + case a@(_:java.lang.reflect.InvocationTargetException) => + // refer to a so we trigger a bug where a is considered + // to be a free variable for enclosing lambda + val b = a + () + } +} diff --git a/tests/untried/pos/delambdafy_t6260_method.check b/tests/untried/pos/delambdafy_t6260_method.check new file mode 100644 index 000000000..f5cd6947d --- /dev/null +++ b/tests/untried/pos/delambdafy_t6260_method.check @@ -0,0 +1,13 @@ +delambdafy_t6260_method.scala:3: error: bridge generated for member method apply: (bx: Object)Object in class map$extension1 +which overrides method apply: (v1: Object)Object in trait Function1 +clashes with definition of the member itself; +both have erased type (bx: Object)Object + ((bx: Box[X]) => new Box(f(bx.x)))(this) + ^ +delambdafy_t6260_method.scala:8: error: bridge generated for member method apply: (bx: Object)Object in class map21 +which overrides method apply: (v1: Object)Object in trait Function1 +clashes with definition of the member itself; +both have erased type (bx: Object)Object + ((bx: Box[X]) => new Box(f(bx.x)))(self) + ^ +two errors found diff --git a/tests/untried/pos/delambdafy_t6260_method.flags b/tests/untried/pos/delambdafy_t6260_method.flags new file mode 100644 index 000000000..48b438ddf --- /dev/null +++ b/tests/untried/pos/delambdafy_t6260_method.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/tests/untried/pos/delambdafy_t6260_method.scala b/tests/untried/pos/delambdafy_t6260_method.scala new file mode 100644 index 000000000..8edfe4ac3 --- /dev/null +++ b/tests/untried/pos/delambdafy_t6260_method.scala @@ -0,0 +1,17 @@ +class Box[X](val x: X) extends AnyVal { + def map[Y](f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(this) +} + +object Test { + def map2[X, Y](self: Box[X], f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(self) + + def main(args: Array[String]): Unit = { + val f = (x: Int) => x + 1 + val g = (x: String) => x + x + + map2(new Box(42), f) + new Box("abc") map g + } +} diff --git a/tests/untried/pos/depexists.scala b/tests/untried/pos/depexists.scala new file mode 100644 index 000000000..dff1917a4 --- /dev/null +++ b/tests/untried/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/untried/pos/depmet_1_pos.scala b/tests/untried/pos/depmet_1_pos.scala new file mode 100644 index 000000000..2b4f443e6 --- /dev/null +++ b/tests/untried/pos/depmet_1_pos.scala @@ -0,0 +1,6 @@ +object Test { + def precise(x: String)(y: x.type): x.type = y + val foo = "foo" + val fun : foo.type => foo.type = precise(foo) + val bar : foo.type = precise(foo)(foo) +} diff --git a/tests/untried/pos/depmet_implicit_chaining_zw.scala b/tests/untried/pos/depmet_implicit_chaining_zw.scala new file mode 100644 index 000000000..ce5ea476d --- /dev/null +++ b/tests/untried/pos/depmet_implicit_chaining_zw.scala @@ -0,0 +1,28 @@ +trait Zero +trait Succ[N] + +trait ZipWith[N, S] { + type T + val x: T = sys.error("") +} + +object ZipWith { + implicit def ZeroZipWith[S] = new ZipWith[Zero, S] { + type T = Stream[S] + } + + implicit def SuccZipWith[N, S, R](implicit zWith : ZipWith[N, R]) = new ZipWith[Succ[N], S => R] { + type T = Stream[S] => zWith.T // dependent types replace the associated types functionality + } + + // can't use implicitly[ZipWith[Succ[Succ[Zero]], Int => String => Boolean]], + // since that will chop of the {type T = ... } refinement in adapt (pt = ZipWith[Succ[Succ[Zero]], Int => String => Boolean]) + // this works + // def zipWith(implicit zw: ZipWith[Succ[Succ[Zero]], Int => String => Boolean]): zw.T = zw.x + // thus, I present ?: implicitly on steroids! + def ?[T <: AnyRef](implicit w: T): w.type = w + + type _2 = Succ[Succ[Zero]] + val zw = ?[ZipWith[_2, Int => String => Boolean]].x // : Stream[Int] => Stream[String] => Stream[Boolean] + // val zw = implicitly[ZipWith[Succ[Succ[Zero]], Int => String => Boolean]{type T = Stream[Int] => Stream[String] => Stream[Boolean]}].x +} diff --git a/tests/untried/pos/depmet_implicit_norm_ret.scala b/tests/untried/pos/depmet_implicit_norm_ret.scala new file mode 100644 index 000000000..0c587cf16 --- /dev/null +++ b/tests/untried/pos/depmet_implicit_norm_ret.scala @@ -0,0 +1,29 @@ +object Test{ + def ?[S <: AnyRef](implicit w : S) : w.type = w + + // fallback, lower priority (overloading rules apply: pick alternative in subclass lowest in subtyping lattice) + class ZipWithDefault { + implicit def ZeroZipWith[S] = new ZipWith[S] { + type T = Stream[S] + } + } + + object ZipWith extends ZipWithDefault { + // def apply[S: ZipWith](s : S) = ?[ZipWith[S]].zipWith(s) // TODO: bug return type should be inferred + def apply[S](s : S)(implicit zw: ZipWith[S]): zw.T = zw.zipWith(s) + + implicit def SuccZipWith[S,R](implicit zWith : ZipWith[R]) = new ZipWith[S => R] { + type T = Stream[S] => zWith.T // dependent types replace the associated types functionality + } + } + + trait ZipWith[S] { + type T + def zipWith : S => T = sys.error("") + } + + // bug: inferred return type = (Stream[A]) => java.lang.Object with Test.ZipWith[B]{type T = Stream[B]}#T + // this seems incompatible with vvvvvvvvvvvvvvvvvvvvvv -- #3731 + def map[A,B](f : A => B) /* : Stream[A] => Stream[B]*/ = ZipWith(f) + val tst: Stream[Int] = map{x: String => x.length}(Stream("a")) +} diff --git a/tests/untried/pos/depmet_implicit_oopsla_session.scala b/tests/untried/pos/depmet_implicit_oopsla_session.scala new file mode 100644 index 000000000..7e51861d6 --- /dev/null +++ b/tests/untried/pos/depmet_implicit_oopsla_session.scala @@ -0,0 +1,63 @@ +object Sessions { + trait Session[This] { + type Dual + type HasDual[D] = Session[This]{type Dual=D} + def run(p: This, dp: Dual): Unit + } + + implicit object StopSession extends Session[Stop] { + type Dual = Stop + + def run(p: Stop, dp: Stop): Unit = {} + } + + implicit def InDual[A, B](implicit sessionDIn: Session[B]) = + new Session[In[A, B]] { + type Dual = Out[A, sessionDIn.Dual] + + def run(p: In[A, B], dp: Dual): Unit = + sessionDIn.run(p.func(dp.x), dp.y) + } + + implicit def OutDual[A, B](implicit sessionDOut: Session[B]) = + new Session[Out[A, B]] { + type Dual = In[A, sessionDOut.Dual] + + def run(p: Out[A, B], dp: Dual): Unit = + sessionDOut.run(p.y, dp.func(p.x)) + } + + sealed case class Stop() + sealed case class In[-A, +B](func: A => B) + sealed case class Out[+A, +B](x: A, y: B) + + def addServer = + In{x: Int => + In{y: Int => System.out.println("Thinking") + Out(x+y, + Stop())}} + + def addClient = + Out(3, + Out(4, { System.out.println("Waiting") + In{z: Int => System.out.println(z) + Stop()}})) + + def runSession[S, D: Session[S]#HasDual](p: S, dp: D) = + implicitly[Session[S]#HasDual[D]].run(p, dp) + + // def runSession[S, D](p: S, dp: D)(implicit s: Session[S]#HasDual[D]) = + // s.run(p, dp) + // + // def runSession[S, D](p: S, dp: D)(implicit s: Session[S]{type Dual=D}) = + // s.run(p, dp) + + // TODO: can we relax the ordering restrictions on dependencies so that we can use + // def runSession[S](p: S, dp: s.Dual)(implicit s: Session[S]) = + // s.run(p, dp) + // to emphasise similarity of type parameters and implicit arguments: + // def runSession[S][val s: Session[S]](p: S, dp: s.Dual) = + // s.run(p, dp) + + def myRun = runSession(addServer, addClient) +} diff --git a/tests/untried/pos/depmet_implicit_oopsla_session_2.scala b/tests/untried/pos/depmet_implicit_oopsla_session_2.scala new file mode 100644 index 000000000..598d3454c --- /dev/null +++ b/tests/untried/pos/depmet_implicit_oopsla_session_2.scala @@ -0,0 +1,87 @@ +object Sessions { + def ?[T <: AnyRef](implicit w: T): w.type = w + + // session states + sealed case class Stop() + sealed case class In[-Data, +Cont](recv: Data => Cont) + sealed case class Out[+Data, +Cont](data: Data, cont: Cont) + + // the type theory of communicating sessions: + + // an instance of type Session[S]{type Dual=D} is evidence that S and D are duals + // such a value witnesses this fact by describing how to compose an instance of S with an instance of D (through the run method) + trait Session[S] { type Self = S + type Dual + type HasDual[D] = Session[Self]{type Dual=D} + def run(self: Self, dual: Dual): Unit + } + + // friendly interface to the theory + def runSession[S, D: Session[S]#HasDual](session: S, dual: D) = + ?[Session[S]#HasDual[D]].run(session, dual) + + // facts in the theory: + + // ------------------------[StopDual] + // Stop is the dual of Stop + implicit object StopDual extends Session[Stop] { + type Dual = Stop + + def run(self: Self, dual: Dual): Unit = {} + } + + // CD is the dual of Cont + // -------------------------------------------[InDual] + // Out[Data, CD] is the dual of In[Data, Cont] + implicit def InDual[Data, Cont](implicit cont: Session[Cont]) = new Session[In[Data, Cont]] { + type Dual = Out[Data, cont.Dual] + + def run(self: Self, dual: Dual): Unit = + cont.run(self.recv(dual.data), dual.cont) + } + + // CD is the dual of Cont + // -------------------------------------------[OutDual] + // In[Data, CD] is the dual of Out[Data, Cont] + implicit def OutDual[Data, Cont](implicit cont: Session[Cont]) = new Session[Out[Data, Cont]] { + type Dual = In[Data, cont.Dual] + + def run(self: Self, dual: Dual): Unit = + cont.run(self.cont, dual.recv(self.data)) + } + + // a concrete session + def addServer = + In{x: Int => + In{y: Int => System.out.println("Thinking") + Out(x+y, + Stop())}} + + def addClient = + Out(3, + Out(4, { System.out.println("Waiting") + In{z: Int => System.out.println(z) + Stop()}})) + + def myRun = runSession(addServer, addClient) +} + +/* future improvements: + + + // def runSession[S, D](p: S, dp: D)(implicit s: Session[S]#HasDual[D]) = + // s.run(p, dp) + // + // def runSession[S, D](p: S, dp: D)(implicit s: Session[S]{type Dual=D}) = + // s.run(p, dp) + + // TODO: can we relax the ordering restrictions on dependencies so that we can write + // one possibility: graph of dependencies between arguments must be acyclic + // def runSession[S](p: S, dp: s.Dual)(implicit s: Session[S]) = + // s.run(p, dp) + // to emphasise similarity of type parameters and implicit arguments: + // def runSession[S][val s: Session[S]](p: S, dp: s.Dual) = + // s.run(p, dp) + + +*/ diff --git a/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala b/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala new file mode 100644 index 000000000..04b8f94e6 --- /dev/null +++ b/tests/untried/pos/depmet_implicit_oopsla_session_simpler.scala @@ -0,0 +1,44 @@ +object Sessions { + trait Session { + type Dual <: Session + + def run(dp: Dual): Unit + } + + sealed case class Stop() extends Session { + type Dual = Stop + + def run(dp: Dual): Unit = {} + } + + // can't write B <: Session{type Dual = BDual} due to limitations in type inference algorithm + // (type variables cannot occur on both sides of <:) + // using B#Dual instead of BDual is too imprecise, since it is disconnected from the actual argument that is passed for B + // would be nice if we could introduce a universal quantification over BDual that is not part of the + // type parameter list + sealed case class In[A, B <: Session, BDual <: Session](recv: A => B)(implicit dual: B <:< Session{type Dual=BDual}) extends Session { + type Dual = Out[A, BDual] + + def run(dp: Dual): Unit = recv(dp.data) run dp.cont + } + + sealed case class Out[A, B <: Session](data: A, cont: B) extends Session { + type Dual = In[A, cont.Dual, cont.Dual#Dual] + + def run(dp: Dual): Unit = cont run dp.recv(data) + } + + def addServer = + In{x: Int => + In{y: Int => System.out.println("Thinking") + Out(x+y, + Stop())}} + + def addClient = + Out(3, + Out(4, { System.out.println("Waiting") + In{z: Int => System.out.println(z) + Stop()}})) + + def myRun = addServer run addClient +} diff --git a/tests/untried/pos/depmet_implicit_oopsla_zipwith.scala b/tests/untried/pos/depmet_implicit_oopsla_zipwith.scala new file mode 100644 index 000000000..c034e3ef5 --- /dev/null +++ b/tests/untried/pos/depmet_implicit_oopsla_zipwith.scala @@ -0,0 +1,44 @@ +case class Zero() +case class Succ[N](x: N) +import Stream.{cons, continually} + +trait ZipWith[N, S] { + type T + + def manyApp: N => Stream[S] => T + def zipWith: N => S => T = n => f => manyApp(n)(continually(f)) +} +object ZipWith { + implicit def ZeroZipWith[S] = new ZipWith[Zero, S] { + type T = Stream[S] + + def manyApp = n => xs => xs + } + + implicit def SuccZipWith[N, S, R](implicit zw: ZipWith[N, R]) = + new ZipWith[Succ[N],S => R] { + type T = Stream[S] => zw.T + + def zapp[A, B](xs: Stream[A => B], ys: Stream[A]): Stream[B] = (xs, ys) match { + case (cons(f, fs), cons(s, ss)) => cons(f(s),zapp(fs, ss)) + case (_, _) => Stream.empty + } + + def manyApp = n => xs => ss => n match { + case Succ(i) => zw.manyApp(i)(zapp(xs, ss)) + } + } +} + +object Test { + def zWith[N, S](n: N, s: S)(implicit zw: ZipWith[N, S]): zw.T = zw.zipWith(n)(s) + + def zipWith0: Stream[Int] = zWith(Zero(),0) + +// (Stream[A]) => java.lang.Object with ZipWith[Zero,B]{type T = Stream[B]}#T +// should normalise to: Stream[A] => Stream[B] + def map[A, B](f: A => B) = zWith(Succ(Zero()),f) + + def zipWith3[A, B, C, D](f: A => B => C => D) = //: Stream[A] => Stream[B] => Stream[C] => Stream[D] = // BUG why do we need a return type? + zWith(Succ(Succ(Succ(Zero()))),f) +} diff --git a/tests/untried/pos/depmet_implicit_tpbetareduce.scala b/tests/untried/pos/depmet_implicit_tpbetareduce.scala new file mode 100644 index 000000000..f4da54949 --- /dev/null +++ b/tests/untried/pos/depmet_implicit_tpbetareduce.scala @@ -0,0 +1,12 @@ +trait HOSeq { + trait Accumulator[+coll[x], elT] + trait Iterable[+t] { + type m[+x] + def accumulator[t]: Accumulator[m, t] + } + implicit def listAccumulator[elT]: Accumulator[List, elT] = new Accumulator[List, elT] {} + trait List[+t] extends Iterable[t] { + type m[+x] = List[x] + def accumulator[t]: Accumulator[List, t] = listAccumulator[t] + } +} diff --git a/tests/untried/pos/dotless-targs.scala b/tests/untried/pos/dotless-targs.scala new file mode 100644 index 000000000..8c0e244e4 --- /dev/null +++ b/tests/untried/pos/dotless-targs.scala @@ -0,0 +1,9 @@ +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/untried/pos/elidable-tparams.scala b/tests/untried/pos/elidable-tparams.scala new file mode 100644 index 000000000..d65478bcb --- /dev/null +++ b/tests/untried/pos/elidable-tparams.scala @@ -0,0 +1,10 @@ +import annotation._ +import elidable._ + +class ElidableCrashTest { + trait My + + @elidable(MINIMUM) def foo[a >: My <: My]: scala.Unit = () + + foo[My] // crash +} diff --git a/tests/untried/pos/erasure-nsquared.scala b/tests/untried/pos/erasure-nsquared.scala new file mode 100644 index 000000000..b0e30ade5 --- /dev/null +++ b/tests/untried/pos/erasure-nsquared.scala @@ -0,0 +1,35 @@ +trait BigCast { + def bar(x: Int): AnyRef = ( + null + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + .asInstanceOf[List[AnyRef]].head + ) +} diff --git a/tests/untried/pos/escapes2.scala b/tests/untried/pos/escapes2.scala new file mode 100644 index 000000000..b94066936 --- /dev/null +++ b/tests/untried/pos/escapes2.scala @@ -0,0 +1,5 @@ +object Test { + class C3[T](val elem: T) + class D3[T](val elemD: T) extends C3[T](elemD) + def f[T](x: C3[T]) = x match { case d: D3[t] => d.elemD } +} diff --git a/tests/untried/pos/eta.scala b/tests/untried/pos/eta.scala new file mode 100644 index 000000000..2dd2970ee --- /dev/null +++ b/tests/untried/pos/eta.scala @@ -0,0 +1,5 @@ +object test { + +def sum(f: Int => Int)(x: Int, y: Int): Int = 0; +def g: (Int => Int) => (Int, Int) => Int = sum; +} diff --git a/tests/untried/pos/exbound.scala b/tests/untried/pos/exbound.scala new file mode 100644 index 000000000..243d5832c --- /dev/null +++ b/tests/untried/pos/exbound.scala @@ -0,0 +1,7 @@ +class A[T <: A[T]] { + +} + +object Test { + val x: A[X] forSome { type X } = null +} diff --git a/tests/untried/pos/exhaust_2.scala b/tests/untried/pos/exhaust_2.scala new file mode 100644 index 000000000..4f4e47c43 --- /dev/null +++ b/tests/untried/pos/exhaust_2.scala @@ -0,0 +1,54 @@ +object ExhaustivityWarnBugReportMinimal { + //sealed is needed for the warning + sealed trait FoundNode[T]/*presence of parameters is irrelevant*/ + // This also causes a warning: + // sealed abstract class FoundNode[T]/*presence of parameters is irrelevant*/ + case class FoundFilter[T](/*presence of parameters is irrelevant*/) extends FoundNode[T] + case class FoundTypeCase[T](/*presence of parameters is irrelevant*/) extends FoundNode[T] + val f: Some[_] = ??? + f match { + case x: Some[t] => //no warning + } + //With these variants, no warnings: + //val v: (Some[Int], FoundNode[_]) = (???, ???) + //val v: (Some[AnyRef], FoundNode[_]) = (???, ???) + //val v: (Some[String], FoundNode[_]) = (???, ???) + + val v: (Some[_], FoundNode[_]) = (???, ???) + //Warning here: + v match { + case (x: Some[t], _: FoundNode[_]) => + } + v match { + case (x: Some[t], _) => + } + + v match { + case (x: Some[_], _) => + } + case class Foo[T]() + + val vp: (Foo[_], FoundNode[_]) = (???, ???) + vp match { + case (x: Foo[_], _) => + } + + //No warning here: + v match { + case (Some(y), _) => + } + + v match { + case (x, _) => + } + + val v2: (Some[_], Int) = (???, ???) + v2 match { + case (x: Some[t], _) => + } + + val v3: (Option[_], FoundNode[_]) = (???, ???) + v match { + case (x: Option[_], _) => + } +} diff --git a/tests/untried/pos/exhaust_alternatives.flags b/tests/untried/pos/exhaust_alternatives.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/exhaust_alternatives.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/exhaust_alternatives.scala b/tests/untried/pos/exhaust_alternatives.scala new file mode 100644 index 000000000..7fdecffa7 --- /dev/null +++ b/tests/untried/pos/exhaust_alternatives.scala @@ -0,0 +1,10 @@ +sealed abstract class X +sealed case class A(x: Boolean) extends X +case object B extends X + +object Test { + def test(x: X) = x match { + case A(true) => + case A(false) | B => + } +} diff --git a/tests/untried/pos/exhaustive_heuristics.scala b/tests/untried/pos/exhaustive_heuristics.scala new file mode 100644 index 000000000..5fb709c52 --- /dev/null +++ b/tests/untried/pos/exhaustive_heuristics.scala @@ -0,0 +1,26 @@ +// tests exhaustivity doesn't give warnings (due to its heuristic rewrites kicking in or it backing off) +object Test { + // List() => Nil + List(1) match { + case List() => + case x :: xs => + } + + // we don't look into guards + val turnOffChecks = true + List(1) match { + case _ if turnOffChecks => + } + + // we back off when there are any user-defined extractors + // in fact this is exhaustive, but we pretend we don't know since List's unapplySeq is not special to the compiler + // to compensate our ignorance, we back off + // well, in truth, we do rewrite List() to Nil, but otherwise we do nothing + // the full rewrite List(a, b) to a :: b :: Nil, for example is planned (but not sure it's a good idea) + List(true, false) match { + case List(_, _, _*) => + case List(node, _*) => + case Nil => + } + +} diff --git a/tests/untried/pos/existential-java-case-class/Client.scala b/tests/untried/pos/existential-java-case-class/Client.scala new file mode 100644 index 000000000..368899820 --- /dev/null +++ b/tests/untried/pos/existential-java-case-class/Client.scala @@ -0,0 +1,3 @@ +case class CC(x: J[_]) + +case class CC1(x: Any => J[_]) diff --git a/tests/untried/pos/existential-java-case-class/J.java b/tests/untried/pos/existential-java-case-class/J.java new file mode 100644 index 000000000..7fd784828 --- /dev/null +++ b/tests/untried/pos/existential-java-case-class/J.java @@ -0,0 +1 @@ +public class J<T extends String> {} diff --git a/tests/untried/pos/existentials-harmful.scala b/tests/untried/pos/existentials-harmful.scala new file mode 100644 index 000000000..8722852e8 --- /dev/null +++ b/tests/untried/pos/existentials-harmful.scala @@ -0,0 +1,54 @@ +// a.scala +// Mon Jul 11 14:18:26 PDT 2011 + +object ExistentialsConsideredHarmful { + class Animal(val name: String) + object Dog extends Animal("Dog") + object Sheep extends Animal("Sheep") + + trait Tools[A] { + def shave(a: A): A + } + def tools[A](a: A): Tools[A] = null // dummy + + case class TransportBox[A <: Animal](animal: A, tools: Tools[A]) { + def label: String = animal.name + } + + // 1. + def carry[A <: Animal](box: TransportBox[A]): Unit = { + println(box.animal.name+" got carried away") + } + + val aBox = + if (math.random < 0.5) + TransportBox(Dog, tools(Dog)) + else + TransportBox(Sheep, tools(Sheep)) + + // 2. + //aBox.tools.shave(aBox.animal) + + // Use pattern match to avoid opening the existential twice + aBox match { + case TransportBox(animal, tools) => tools.shave(animal) + } + + abstract class BoxCarrier[R <: Animal](box: TransportBox[R]) { + def speed: Int + + def talkToAnimal: Unit = println("The carrier says hello to"+box.animal.name) + } + + // 3. + //val bc = new BoxCarrier(aBox) { + + // Use pattern match to avoid opening the existential twice + // Type annotation on bc is required ... possible compiler bug? + // val bc : BoxCarrier[_ <: Animal] = aBox match { + val bc = aBox match { + case tb : TransportBox[a] => new BoxCarrier(tb) { + def speed: Int = 12 + } + } +} diff --git a/tests/untried/pos/existentials.scala b/tests/untried/pos/existentials.scala new file mode 100644 index 000000000..9ca86d13d --- /dev/null +++ b/tests/untried/pos/existentials.scala @@ -0,0 +1,22 @@ +/** All of these should work, some don't yet. + * !!! + */ +class A { + def f() = { case class Bob(); Bob } + + val quux0 = f() + def quux1 = f() + // lazy val quux2 = f() + // def quux3 = { + // lazy val quux3a = f() + // quux3a + // } + + val bippy0 = f _ + def bippy1 = f _ + // lazy val bippy2 = f _ + // val bippy3 = { + // lazy val bippy3a = f _ + // bippy3a + // } +} diff --git a/tests/untried/pos/exponential-spec.scala b/tests/untried/pos/exponential-spec.scala new file mode 100644 index 000000000..54515c1d2 --- /dev/null +++ b/tests/untried/pos/exponential-spec.scala @@ -0,0 +1,47 @@ +// a.scala +// Sat Jun 30 19:51:17 PDT 2012 + +trait Exp[T] + +object Test { + def f[T](exp: Exp[T]): Exp[T] = ( + f[T] _ + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] // 4s + compose f[T] // 5s + compose f[T] // 5s + compose f[T] // 6s + compose f[T] // 7s + compose f[T] // 8s + compose f[T] // 11s + compose f[T] // 17s + compose f[T] // 29s + compose f[T] // 54s + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + compose f[T] + )(exp) +} diff --git a/tests/untried/pos/extractor-types.scala b/tests/untried/pos/extractor-types.scala new file mode 100644 index 000000000..200279be6 --- /dev/null +++ b/tests/untried/pos/extractor-types.scala @@ -0,0 +1,30 @@ +package p1 { + object Ex { def unapply(p: Any): Option[_ <: Int] = null } + object Foo { val Ex(_) = null } +} +// a.scala:2: error: error during expansion of this match (this is a scalac bug). +// The underlying error was: type mismatch; +// found : Some[_$1(in value x$1)] where type _$1(in value x$1) +// required: Some[_$1(in method unapply)] +// object Foo { val Ex(_) = null } +// ^ +// one error found + +package p2 { + trait Other { + class Quux + object Baz { def unapply(x: Any): Option[Quux] = None } + } + trait Reifiers { + def f(): Unit = { + val u2: Other = null + (null: Any) match { case u2.Baz(x) => println(x) } //: u2.Quux) } + // The underlying error was: type mismatch; + // found : Other#Quux + // required: u2.Quux + // x match { case u2.Baz(x) => println(x: u2.Quux) } + // ^ + // one error found + } + } +} diff --git a/tests/untried/pos/five-dot-f.flags b/tests/untried/pos/five-dot-f.flags new file mode 100644 index 000000000..112fc720a --- /dev/null +++ b/tests/untried/pos/five-dot-f.flags @@ -0,0 +1 @@ +-Xfuture
\ No newline at end of file diff --git a/tests/untried/pos/five-dot-f.scala b/tests/untried/pos/five-dot-f.scala new file mode 100644 index 000000000..8a7f86e21 --- /dev/null +++ b/tests/untried/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/untried/pos/functions.scala b/tests/untried/pos/functions.scala new file mode 100644 index 000000000..0207523dd --- /dev/null +++ b/tests/untried/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/untried/pos/gadt-gilles.scala b/tests/untried/pos/gadt-gilles.scala new file mode 100644 index 000000000..662be9017 --- /dev/null +++ b/tests/untried/pos/gadt-gilles.scala @@ -0,0 +1,37 @@ +object Test { + trait A[T] + trait B[U, V] extends A[U with V] // indirect constraint + trait C + trait D + + val x: A[C with D] = new B[C, D] {} + val y: A[C with D] = x match { case b: B[u, v] => (new B[u, v] {}): A[u with v] } // OK + + + def f[T, U](p: A[T with U]): A[T with U] = p match { case b: B[u, v] => new A[u with v] {} } // Not OK +} + +object Test1 { + + trait T[U, V <: U] + + def f(r: Any) = r match { + + case t: T[u, v] => new T[u, v]{} + + } + +} +object Test2 { + + trait T[U, V <: U] + + val x: T[Int, Int] = new T[Int, Int]{} + + x match { + + case t: T[u, v] => new T[u, v]{} + + } + +} diff --git a/tests/untried/pos/gadts2.scala b/tests/untried/pos/gadts2.scala new file mode 100644 index 000000000..b67bafb32 --- /dev/null +++ b/tests/untried/pos/gadts2.scala @@ -0,0 +1,25 @@ +object Test { + + abstract class Number + case class MyInt(n: Int) extends Number + case class MyDouble(d: Double) extends Number + + trait Term[a] + case class Cell[a](var x: a) extends Term[a] + final case class NumTerm(val n: Number) extends Term[Number] + + def f[a](t: Term[a], c: Cell[a]): Unit = { + t match { + case NumTerm(n) => c.x = MyDouble(1.0) + } + } + + val x: Term[Number] = NumTerm(MyInt(5)) + + def main(args: Array[String]): Unit = { + val cell = Cell[Number](MyInt(6)) + Console.println(cell) + f[Number](new NumTerm(MyInt(5)), cell) + Console.println(cell) + } +} diff --git a/tests/untried/pos/gen-traversable-methods.scala b/tests/untried/pos/gen-traversable-methods.scala new file mode 100644 index 000000000..b59cd33c7 --- /dev/null +++ b/tests/untried/pos/gen-traversable-methods.scala @@ -0,0 +1,20 @@ + + + +import collection._ + + + +object Test { + + def main(args: Array[String]): Unit = { + val gen: GenTraversable[Int] = List(1, 2, 3) + gen.head + gen.headOption + gen.tail + gen.last + gen.lastOption + gen.init + } + +} diff --git a/tests/untried/pos/generic-sigs.flags b/tests/untried/pos/generic-sigs.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/generic-sigs.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/generic-sigs.scala b/tests/untried/pos/generic-sigs.scala new file mode 100644 index 000000000..98c50b8e8 --- /dev/null +++ b/tests/untried/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 <: 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/untried/pos/getClassType.scala b/tests/untried/pos/getClassType.scala new file mode 100644 index 000000000..7482788a4 --- /dev/null +++ b/tests/untried/pos/getClassType.scala @@ -0,0 +1,16 @@ +trait IdlBase + +class IdlConcrete extends IdlBase + +class A { + // In general, this method should not need an instance to reflect on it, so + // take a Class[] + def reflect(clazz : Class[_ <: IdlBase]) = { + // Get a list of all its methods and build a hash keyed by method name + // for statistics recording. + } + + // But I also really have an IdlConcrete generated by Spring here... + val idl = new IdlConcrete + reflect(idl.getClass) +} diff --git a/tests/untried/pos/gosh.scala b/tests/untried/pos/gosh.scala new file mode 100644 index 000000000..81af14016 --- /dev/null +++ b/tests/untried/pos/gosh.scala @@ -0,0 +1,44 @@ +object ShapeTest extends App { + + class Point(x: Int, y: Int) { + override def toString() = "[" + x + "," + y + "]" + } + + abstract class Shape { + def draw(): Unit + } + + class Line(s: Point, e: Point) extends Shape { + def draw(): Unit = { Console.println("draw line " + s + "," + e) } + } + + abstract class Foo { + type T <: Object + + def show(o: T): Unit + def print(): Unit = { Console.println("in Foo") } + } + + abstract class ShapeFoo extends Foo { + type T <: Shape + def show(o: T): Unit = { o.draw() } + override def print(): Unit = { Console.println("in ShapeFoo") } + } + + class LineFoo extends ShapeFoo { + type T = Line + override def print(): Unit = { Console.println("in LineFoo") } + } + + val p1 = new Point(1,4) + val p2 = new Point(12, 28) + + val l1 = new Line(p1, p2) + + + val l = new ShapeFoo { // ** // + type T = Line // ** // + override def print(): Unit = { Console.println("in LineFoo") } // ** // + } + l.show(l1) // ** // +} diff --git a/tests/untried/pos/gui.scala b/tests/untried/pos/gui.scala new file mode 100644 index 000000000..0504fb435 --- /dev/null +++ b/tests/untried/pos/gui.scala @@ -0,0 +1,101 @@ +object Geom { + trait Shape + case class Point(x: Int, y: Int) extends Shape + case class Rectangle(ll: Point, ur: Point) extends Shape { + def inset(delta: Int) = + Rectangle(Point(ll.x - delta, ll.y - delta), Point(ur.x + delta, ur.y + delta)); + } +} + +object Color { + type Color = Int + val black = 0x000000 + val grey = 0x808080 +} + +trait Screen { + type Color = Int + def drawRect(r: Geom.Rectangle, c: Color): Unit + def fillRect(r: Geom.Rectangle, c: Color): Unit +} + +object DummyScreen extends Screen { + def drawRect(r: Geom.Rectangle, c: Color): Unit = { + Console.println("draw " + r + " with " + c) + } + def fillRect(r: Geom.Rectangle, c: Color): Unit = { + Console.println("fill " + r + " with " + c) + } +} + +object GUI { + + object Controller { + def addMouseCtl(c: MouseCtl) = () + } + + trait Glyph { + def getRect: Geom.Rectangle + def setLoc(p: Geom.Point): Unit + def draw(): Unit = { Console.println("draw " + this) } + } + + class Label(scr: Screen, p: Geom.Point, name: String) extends Glyph { + private var origin = p + def getRect = Geom.Rectangle(origin, origin).inset(10); + def setLoc(p: Geom.Point) = { origin = p } + } + + trait Ctl { + def getGlyph: Glyph + def enable(b: Boolean): this.type + } + + trait MouseCtl extends Ctl { + def mouseDown(p: Geom.Point): Unit + } + + abstract class Button(scr: Screen, p: Geom.Point, name: String) + extends Glyph with MouseCtl { + var enabled: Boolean = false + val label = new Label(scr, p, name) + + /* Glyph methods */ + override def draw(): Unit = { + if (enabled) scr.drawRect(getRect, Color.black) + else scr.fillRect(getRect, Color.grey); + label.draw(); + } + def setLoc(p: Geom.Point) = label.setLoc(p); + def getRect = label.getRect.inset(-2); + + /* Ctl methods */ + def enable(b: Boolean): this.type = { enabled = b; draw(); this } + def getGlyph = label + final def mouseDown(p: Geom.Point): Unit = { + if (enabled) doit() else Console.println("button is disabled"); + } + /* deferred method to be specified by client */ + def doit(): Unit + } +} + +object GUIClient { + + class App { + def quit(): Unit = { Console.println("application exited") } + } + + class QuitButton (scr: Screen, p: Geom.Point, name: String, a: App) + extends GUI.Button(scr, p, name) { + def doit(): Unit = { a.quit() } + } + + def main(args: Array[String]): Unit = { + val b = new QuitButton( + DummyScreen, Geom.Point(1, 1), "quit", new App); + b.draw(); + b.enable(true).mouseDown(Geom.Point(1, 2)); + } +} + diff --git a/tests/untried/pos/hashhash-overloads.scala b/tests/untried/pos/hashhash-overloads.scala new file mode 100644 index 000000000..40519bae0 --- /dev/null +++ b/tests/untried/pos/hashhash-overloads.scala @@ -0,0 +1,6 @@ +object Test { + def f = ().## + def g = 5f.## + def h = ({ 5 ; println("abc") }).## + def f2 = null.## +} diff --git a/tests/untried/pos/hk-infer.scala b/tests/untried/pos/hk-infer.scala new file mode 100644 index 000000000..30e347640 --- /dev/null +++ b/tests/untried/pos/hk-infer.scala @@ -0,0 +1,37 @@ +object Basis { + final case class X[T](t: T) + val x = Seq(X(32)) + val y = Seq(X(true)) + val x1 = Seq(X("asdf")) + val x2 = Seq(X('d')) +} +import Basis._ + +object DoesWork { + // Doesn'tWork + // def f1 = x ++ y ++ x1 ++ x2 + + def f2 = List(x, y, x1, x2).flatten +} + +// Testing the not giving of explicit Booper[M] arguments. +object ShouldWorkHK { + class Booper[M[_]](xs: Seq[M[_]]) extends collection.generic.SeqForwarder[M[_]] { + def underlying = xs + def BOOP(ys: Seq[M[_]]) = new Booper(xs ++ ys) + } + implicit def mkBoop[M[_]](xs: Seq[M[_]]) = new Booper(xs) + + def f1 = x BOOP y BOOP x1 BOOP x2 +} + +object DoesWorkHK { + class Booper[M[_]](xs: Seq[M[_]]) extends collection.generic.SeqForwarder[M[_]] { + def underlying = xs + def BOOP(ys: Seq[M[_]]) = new Booper[M](xs ++ ys) + } + implicit def mkBoop[M[_]](xs: Seq[M[_]]) = new Booper[M](xs) + + def f1 = x BOOP y BOOP x1 BOOP x2 +} + diff --git a/tests/untried/pos/hk-match/a.scala b/tests/untried/pos/hk-match/a.scala new file mode 100644 index 000000000..7144068f3 --- /dev/null +++ b/tests/untried/pos/hk-match/a.scala @@ -0,0 +1,5 @@ +trait A { + type HKAlias[X] = List[X] + + (null: Any) match { case f: Bippy[HKAlias] => f } +} diff --git a/tests/untried/pos/hk-match/b.scala b/tests/untried/pos/hk-match/b.scala new file mode 100644 index 000000000..f7d21f638 --- /dev/null +++ b/tests/untried/pos/hk-match/b.scala @@ -0,0 +1 @@ +trait Bippy[E[X]] diff --git a/tests/untried/pos/hkarray.flags b/tests/untried/pos/hkarray.flags new file mode 100644 index 000000000..e745d8bbe --- /dev/null +++ b/tests/untried/pos/hkarray.flags @@ -0,0 +1 @@ +-Xfatal-warnings -language:higherKinds
\ No newline at end of file diff --git a/tests/untried/pos/hkarray.scala b/tests/untried/pos/hkarray.scala new file mode 100644 index 000000000..a9a4ab3e3 --- /dev/null +++ b/tests/untried/pos/hkarray.scala @@ -0,0 +1,5 @@ +trait Foo[CC[_]] { } + +class Bip { + val x = new Foo[Array] { } +} diff --git a/tests/untried/pos/hklub0.scala b/tests/untried/pos/hklub0.scala new file mode 100644 index 000000000..36cd46332 --- /dev/null +++ b/tests/untried/pos/hklub0.scala @@ -0,0 +1,5 @@ +object Test { + val a : scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq] = null + val b : scala.collection.generic.GenericCompanion[scala.collection.mutable.Seq] = null + List(a, b) // immutable.this.List.apply[scala.collection.generic.GenericCompanion[Seq]](Test.this.a, Test.this.b) +} diff --git a/tests/untried/pos/hkrange.scala b/tests/untried/pos/hkrange.scala new file mode 100644 index 000000000..a6803230e --- /dev/null +++ b/tests/untried/pos/hkrange.scala @@ -0,0 +1,5 @@ +class A { + def f[CC[X] <: Traversable[X]](x: CC[Int]) = () + + f(1 to 5) +} diff --git a/tests/untried/pos/homonym.scala b/tests/untried/pos/homonym.scala new file mode 100644 index 000000000..0836f7d6f --- /dev/null +++ b/tests/untried/pos/homonym.scala @@ -0,0 +1,6 @@ +// bug #502 +class Foo(x: Int) { + def this() = this(0); +} +object Foo { +} diff --git a/tests/untried/pos/ilya/J.java b/tests/untried/pos/ilya/J.java new file mode 100644 index 000000000..b469623f3 --- /dev/null +++ b/tests/untried/pos/ilya/J.java @@ -0,0 +1,14 @@ +package test; + +class Foo { +} + +class Boo<T extends Foo>{} + +class Bar<BooT extends Boo<FooT>, FooT extends Foo>{ + private final int myInt; + + public Bar(int i) { + myInt = i; + } +} diff --git a/tests/untried/pos/ilya/S.scala b/tests/untried/pos/ilya/S.scala new file mode 100644 index 000000000..952c004cc --- /dev/null +++ b/tests/untried/pos/ilya/S.scala @@ -0,0 +1,5 @@ +package test + +class ScBar[BooT <: Boo[FooT], FooT <: Foo](i: Int) extends Bar[BooT, FooT](i) { + +} diff --git a/tests/untried/pos/ilya2/A.scala b/tests/untried/pos/ilya2/A.scala new file mode 100644 index 000000000..923b50f04 --- /dev/null +++ b/tests/untried/pos/ilya2/A.scala @@ -0,0 +1,3 @@ +class A { + def foo = new B().bar(null) +} diff --git a/tests/untried/pos/ilya2/B.java b/tests/untried/pos/ilya2/B.java new file mode 100644 index 000000000..4771493fd --- /dev/null +++ b/tests/untried/pos/ilya2/B.java @@ -0,0 +1,6 @@ +public class B { + public int bar(@Nullable final Object o) { + return 42; + } + +} diff --git a/tests/untried/pos/ilya2/Nullable.java b/tests/untried/pos/ilya2/Nullable.java new file mode 100644 index 000000000..ebbb013d7 --- /dev/null +++ b/tests/untried/pos/ilya2/Nullable.java @@ -0,0 +1,7 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) +public @interface Nullable { + String value() default ""; +} diff --git a/tests/untried/pos/imp2-pos.scala b/tests/untried/pos/imp2-pos.scala new file mode 100644 index 000000000..5460c6001 --- /dev/null +++ b/tests/untried/pos/imp2-pos.scala @@ -0,0 +1,5 @@ +object Test { + import collection.mutable._ + import collection.mutable._ + val x = new HashMap +} diff --git a/tests/untried/pos/implicit-anyval-2.10.flags b/tests/untried/pos/implicit-anyval-2.10.flags new file mode 100644 index 000000000..94c805674 --- /dev/null +++ b/tests/untried/pos/implicit-anyval-2.10.flags @@ -0,0 +1 @@ +-Xsource:2.10 diff --git a/tests/untried/pos/implicit-anyval-2.10.scala b/tests/untried/pos/implicit-anyval-2.10.scala new file mode 100644 index 000000000..aa6665f19 --- /dev/null +++ b/tests/untried/pos/implicit-anyval-2.10.scala @@ -0,0 +1,3 @@ +object Test { + "": AnyVal // newly prohibited in 2.11, allowed under -Xsourse:2.10 +} diff --git a/tests/untried/pos/implicit-infix-ops.scala b/tests/untried/pos/implicit-infix-ops.scala new file mode 100644 index 000000000..918289353 --- /dev/null +++ b/tests/untried/pos/implicit-infix-ops.scala @@ -0,0 +1,23 @@ +object Test { + import Ordering.Implicits._ + import Numeric.Implicits._ + + def f1[T: Numeric](x: T, y: T, z: T) = x + y + z + def f2[T: Ordering](x: T, y: T, z: T) = if (x < y) (z > y) else (x < z) +} + +object Int { + import Ordering.Implicits._ + import math.Integral.Implicits._ + + def f1[T: Integral](x: T, y: T, z: T) = (x + y + z) / z + def f2[T: Ordering](x: T, y: T, z: T) = if (x < y) (z > y) else (x < z) +} + +object Frac { + import Ordering.Implicits._ + import math.Fractional.Implicits._ + + def f1[T: Fractional](x: T, y: T, z: T) = (x + y + z) / z + def f2[T: Ordering](x: T, y: T, z: T) = if (x < y) (z > y) else (x < z) +} diff --git a/tests/untried/pos/implicit-unwrap-tc.scala b/tests/untried/pos/implicit-unwrap-tc.scala new file mode 100644 index 000000000..1afde2661 --- /dev/null +++ b/tests/untried/pos/implicit-unwrap-tc.scala @@ -0,0 +1,10 @@ +trait NewType[X] + +object Test { + // change return type to Foo and it compiles. + implicit def Unwrap[X](n: NewType[X]): X = sys.error("") + class Foo(val a: Int) + def test(f: NewType[Foo]) = f.a +} + + diff --git a/tests/untried/pos/implicits-new.scala b/tests/untried/pos/implicits-new.scala new file mode 100644 index 000000000..d5bf0ecfd --- /dev/null +++ b/tests/untried/pos/implicits-new.scala @@ -0,0 +1,92 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.{ClassTag, classTag} + +// #1435 +object t1435 { + implicit def a(s:String):String = sys.error("") + implicit def a(i:Int):String = sys.error("") + implicit def b(i:Int):String = sys.error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X): Unit = {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ClassTag](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[TypeTag[Class[_]]]) +} diff --git a/tests/untried/pos/implicits-old.scala b/tests/untried/pos/implicits-old.scala new file mode 100644 index 000000000..b0e775086 --- /dev/null +++ b/tests/untried/pos/implicits-old.scala @@ -0,0 +1,89 @@ +// #1435 +object t1435 { + implicit def a(s:String):String = sys.error("") + implicit def a(i:Int):String = sys.error("") + implicit def b(i:Int):String = sys.error("") +} + +class C1435 { + val v:String = { + import t1435.a + 2 + } +} + +// #1492 +class C1492 { + + class X + + def foo(x: X => X): Unit = {} + + foo ( implicit x => implicitly[X] ) + foo { implicit x => implicitly[X] } +} + +// #1579 +object Test1579 { + class Column + class Query[E](val value: E) + class Invoker(q: Any) { val foo = null } + + implicit def unwrap[C](q: Query[C]) = q.value + implicit def invoker(q: Query[Column]) = new Invoker(q) + + val q = new Query(new Column) + q.foo +} +// #1625 +object Test1625 { + + class Wrapped(x:Any) { + def unwrap() = x + } + + implicit def byName[A](x: =>A) = new Wrapped(x) + + implicit def byVal[A](x: A) = x + + def main(args: Array[String]) = { + +// val res:Wrapped = 7 // works + + val res = 7.unwrap() // doesn't work + + println("=> result: " + res) + } +} + +object Test2188 { + implicit def toJavaList[A: ClassManifest](t:collection.Seq[A]):java.util.List[A] = java.util.Arrays.asList(t.toArray:_*) + + val x: java.util.List[String] = List("foo") +} + +object TestNumericWidening { + val y = 1 + val x: java.lang.Long = y +} + +// #2709 +package foo2709 { + class A + class B + + package object bar { + implicit def a2b(a: A): B = new B + } + + package bar { + object test { + new A: B + } + } +} + +// Problem with specs +object specsProblem { + println(implicitly[Manifest[Class[_]]]) +} diff --git a/tests/untried/pos/imports-pos.scala b/tests/untried/pos/imports-pos.scala new file mode 100644 index 000000000..f6a55e5e0 --- /dev/null +++ b/tests/untried/pos/imports-pos.scala @@ -0,0 +1,16 @@ +package test; + +import java.lang.{System => S} + +object test { + import S.out.{print => p, println => print} + + val foo = 1; + + p("hello"); print("world"); S.out.println("!"); + S.out.flush(); +} +object test1 { + import test._; + foo +} diff --git a/tests/untried/pos/infer.scala b/tests/untried/pos/infer.scala new file mode 100644 index 000000000..6aeed4049 --- /dev/null +++ b/tests/untried/pos/infer.scala @@ -0,0 +1,11 @@ +object test { + class List[+a] { + def ::[b >: a](x: b): List[b] = new Cons(x, this) + } + case class Cons[a, b <: a](x: a, xs: List[b]) extends List[a] + case object Nil extends List[Nothing] + def nil[n]: List[n] = Nil + def cons[a](x: a, xs: List[a]): List[a] = null + val x: List[Int] = Nil.::(1) + val y: List[Int] = nil.::(1) +} diff --git a/tests/untried/pos/infer2-pos.scala b/tests/untried/pos/infer2-pos.scala new file mode 100644 index 000000000..2ce88be54 --- /dev/null +++ b/tests/untried/pos/infer2-pos.scala @@ -0,0 +1,7 @@ +package test +class Lst[T] +case class cons[T](x: T, xs: Lst[T]) extends Lst[T] +case class nil[T]() extends Lst[T] +object test { + Console.println(cons(1, nil())) +} diff --git a/tests/untried/pos/inferbroadtype.scala b/tests/untried/pos/inferbroadtype.scala new file mode 100644 index 000000000..de8f7aa18 --- /dev/null +++ b/tests/untried/pos/inferbroadtype.scala @@ -0,0 +1,8 @@ +object Test { + abstract class Base { val changesBaseClasses: Boolean } + class Concrete extends Base { val changesBaseClasses = true } + def getBase : Base = new Concrete + + var c = new Base { val changesBaseClasses = true } + c = getBase +} diff --git a/tests/untried/pos/infersingle.flags b/tests/untried/pos/infersingle.flags new file mode 100644 index 000000000..e1b37447c --- /dev/null +++ b/tests/untried/pos/infersingle.flags @@ -0,0 +1 @@ +-Xexperimental
\ No newline at end of file diff --git a/tests/untried/pos/infersingle.scala b/tests/untried/pos/infersingle.scala new file mode 100644 index 000000000..60f4ff07e --- /dev/null +++ b/tests/untried/pos/infersingle.scala @@ -0,0 +1,52 @@ +object Test1 { + def one[T](x: T): Option[T] = Some(x) + val x = "one" + val y: Option[x.type] = one(x) +} + +object Test2 { + // Has never worked, but seems desirable given the recent changes to + // pattern type inference. + val a = "" + object Id { + def unapply(xxxx: Any): Some[a.type] = Some[a.type](a) + } + val b: a.type = (a: a.type) match { + case Id(x) => x + } +} + +object Test3 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test3.type] = Some[Test3.type](Test3) + } + val b: Test3.type = a match { + case Id(x) => x + } +} + +class Test4 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test4.this.type] = Some[Test4.this.type](Test4.this) + } + val b: Test4.this.type = a match { + case Id(x) => x + } +} + +class Super5 { + final val q = "" + def q1: q.type = q +} + +class Test5 extends Super5 { + val a = "" + object Id { + def unapply(xxxx: Any): Some[Test5.super.q.type] = Some[Test5.super.q.type](q1) + } + val b: Test5.super.q.type = a match { + case Id(x) => x + } +} diff --git a/tests/untried/pos/init.scala b/tests/untried/pos/init.scala new file mode 100644 index 000000000..fdea0e06f --- /dev/null +++ b/tests/untried/pos/init.scala @@ -0,0 +1,14 @@ +class Foo { + + var cnt = 0 + + class Bar { + cnt = cnt + 1 + val id = cnt + } +} + +object Test extends App { + val foo = new Foo + Console.println((new foo.Bar).id) +} diff --git a/tests/untried/pos/inline-access-levels.flags b/tests/untried/pos/inline-access-levels.flags new file mode 100644 index 000000000..882f40f05 --- /dev/null +++ b/tests/untried/pos/inline-access-levels.flags @@ -0,0 +1 @@ +-optimise -Xfatal-warnings -Yinline-warnings diff --git a/tests/untried/pos/inline-access-levels/A_1.scala b/tests/untried/pos/inline-access-levels/A_1.scala new file mode 100644 index 000000000..479fe0fc7 --- /dev/null +++ b/tests/untried/pos/inline-access-levels/A_1.scala @@ -0,0 +1,10 @@ +package test + +object A { + + private var x: Int = 0 + + @inline def actOnX(f: Int => Int) = { + x = f(x) + } +} diff --git a/tests/untried/pos/inline-access-levels/Test_2.scala b/tests/untried/pos/inline-access-levels/Test_2.scala new file mode 100644 index 000000000..639109eb1 --- /dev/null +++ b/tests/untried/pos/inline-access-levels/Test_2.scala @@ -0,0 +1,11 @@ +package test + +object Test { + + def main(args: Array[String]): Unit = { + + A.actOnX(_ + 1) + + } + +} diff --git a/tests/untried/pos/inliner2.flags b/tests/untried/pos/inliner2.flags new file mode 100644 index 000000000..ea03113c6 --- /dev/null +++ b/tests/untried/pos/inliner2.flags @@ -0,0 +1 @@ +-optimise -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/inliner2.scala b/tests/untried/pos/inliner2.scala new file mode 100644 index 000000000..bc83e0431 --- /dev/null +++ b/tests/untried/pos/inliner2.scala @@ -0,0 +1,57 @@ +// This isn't actually testing much, because no warning is emitted in versions +// before the fix which comes with this because the method isn't even considered +// for inlining due to the bug. +class A { + private var debug = false + @inline private def ifelse[T](cond: => Boolean, ifPart: => T, elsePart: => T): T = + if (cond) ifPart else elsePart + + final def bob1() = ifelse(debug, 1, 2) + final def bob2() = if (debug) 1 else 2 +} +// Cool: +// +// % ls -1 /tmp/2901/ +// A$$anonfun$bob1$1.class +// A$$anonfun$bob1$2.class +// A$$anonfun$bob1$3.class +// A.class +// % ls -1 /tmp/trunk +// A.class +// +// Observations: +// +// (1) The inlined version accesses the field: the explicit one calls the accessor. +// (2) The inlined version fails to eliminate boxing. With reference types it emits +// an unneeded checkcast. +// (3) The private var debug is mangled to A$$debug, but after inlining it is never accessed +// from outside of the class and doesn't need mangling. +// (4) We could forego emitting bytecode for ifelse entirely if it has been +// inlined at all sites. +// +// Generated bytecode for the above: +// +// public final int bob1(); +// Code: +// Stack=1, Locals=1, Args_size=1 +// 0: aload_0 +// 1: getfield #11; //Field A$$debug:Z +// 4: ifeq 14 +// 7: iconst_1 +// 8: invokestatic #41; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; +// 11: goto 18 +// 14: iconst_2 +// 15: invokestatic #41; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; +// 18: invokestatic #45; //Method scala/runtime/BoxesRunTime.unboxToInt:(Ljava/lang/Object;)I +// 21: ireturn +// +// public final int bob2(); +// Code: +// Stack=1, Locals=1, Args_size=1 +// 0: aload_0 +// 1: invokevirtual #48; //Method A$$debug:()Z +// 4: ifeq 11 +// 7: iconst_1 +// 8: goto 12 +// 11: iconst_2 +// 12: ireturn diff --git a/tests/untried/pos/irrefutable.scala b/tests/untried/pos/irrefutable.scala new file mode 100644 index 000000000..0a792b644 --- /dev/null +++ b/tests/untried/pos/irrefutable.scala @@ -0,0 +1,22 @@ +// The test which this should perform but does not +// is that f1 is recognized as irrefutable and f2 is not +// This can be recognized via the generated classes: +// +// A$$anonfun$f1$1.class +// A$$anonfun$f2$1.class +// A$$anonfun$f2$2.class +// +// The extra one in $f2$ is the filter. +// +// !!! Marking with exclamation points so maybe someday +// this test will be finished. +class A { + case class Foo[T](x: T) + + def f1(xs: List[Foo[Int]]) = { + for (Foo(x: Int) <- xs) yield x + } + def f2(xs: List[Foo[Any]]) = { + for (Foo(x: Int) <- xs) yield x + } +} diff --git a/tests/untried/pos/isApplicableSafe.scala b/tests/untried/pos/isApplicableSafe.scala new file mode 100644 index 000000000..b4cacbf28 --- /dev/null +++ b/tests/untried/pos/isApplicableSafe.scala @@ -0,0 +1,8 @@ +class A { + // Any of Array[List[Symbol]], List[Array[Symbol]], or List[List[Symbol]] compile. + var xs: Array[Array[Symbol]] = _ + var ys: Array[Map[Symbol, Set[Symbol]]] = _ + + xs = Array(Array()) + ys = Array(Map(), Map()) +} diff --git a/tests/untried/pos/itay.scala b/tests/untried/pos/itay.scala new file mode 100644 index 000000000..9a97ded98 --- /dev/null +++ b/tests/untried/pos/itay.scala @@ -0,0 +1,4 @@ +abstract class Message[+A] + +trait InPort [+T <: Message[V], +V] + diff --git a/tests/untried/pos/iterator-traversable-mix.scala b/tests/untried/pos/iterator-traversable-mix.scala new file mode 100644 index 000000000..2d6bf44c7 --- /dev/null +++ b/tests/untried/pos/iterator-traversable-mix.scala @@ -0,0 +1,8 @@ +object Test { + for { + x1 <- List(1, 2) + x2 <- Iterator(3, 4) + x3 <- Seq(5, 6).iterator + x4 <- Stream(7, 8) + } yield x1+x2+x3+x4 +} diff --git a/tests/untried/pos/java-access-pos/J.java b/tests/untried/pos/java-access-pos/J.java new file mode 100644 index 000000000..b6bc3363a --- /dev/null +++ b/tests/untried/pos/java-access-pos/J.java @@ -0,0 +1,15 @@ +package a.b; + +public abstract class J { + public J() { } + J(int x1) { } + protected J(int x1, int x2) { } + + abstract void packageAbstract(); + protected abstract void protectedAbstract(); + public abstract void publicAbstract(); + + void packageConcrete() { return; } + protected void protectedConcrete() { return; } + public void publicConcrete() { return; } +} diff --git a/tests/untried/pos/java-access-pos/S1.scala b/tests/untried/pos/java-access-pos/S1.scala new file mode 100644 index 000000000..9e6ae4a3b --- /dev/null +++ b/tests/untried/pos/java-access-pos/S1.scala @@ -0,0 +1,67 @@ +package a.b + +/** Declaring "override" all the time. + */ +class S1 extends J { + override private[b] def packageAbstract() = () + override protected[b] def protectedAbstract() = () + override def publicAbstract() = () + + override private[b] def packageConcrete() = () + override protected[b] def protectedConcrete() = () + override def publicConcrete() = () +} + +/** Implementing abstracts. + */ +class S2 extends J { + private[b] def packageAbstract() = () + protected[b] def protectedAbstract() = () + def publicAbstract() = () +} + +/** Widening access. + */ +class S3 extends J { + protected[b] def packageAbstract() = () + protected[b] def protectedAbstract() = () + def publicAbstract() = () + + override protected[b] def packageConcrete() = () + override protected[b] def protectedConcrete() = () + override def publicConcrete() = () +} +/** More widening. + */ +class S4 extends J { + private[a] def packageAbstract() = () + protected[a] def protectedAbstract() = () + def publicAbstract() = () + + override private[a] def packageConcrete() = () + override protected[a] def protectedConcrete() = () + override def publicConcrete() = () +} +/** Yet more widening. + */ +class S5 extends J { + def packageAbstract() = () + def protectedAbstract() = () + def publicAbstract() = () + + override def packageConcrete() = () + override def protectedConcrete() = () + override def publicConcrete() = () +} +/** Constructors. + */ +class S6 extends J(1) { + def packageAbstract() = () + def protectedAbstract() = () + def publicAbstract() = () +} +class S7 extends J(1, 2) { + def packageAbstract() = () + def protectedAbstract() = () + def publicAbstract() = () +} diff --git a/tests/untried/pos/javaConversions-2.10-ambiguity.scala b/tests/untried/pos/javaConversions-2.10-ambiguity.scala new file mode 100644 index 000000000..c4aad6cbf --- /dev/null +++ b/tests/untried/pos/javaConversions-2.10-ambiguity.scala @@ -0,0 +1,10 @@ +import collection.{JavaConversions, mutable, concurrent} +import JavaConversions._ +import java.util.concurrent.{ConcurrentHashMap => CHM} + +object Bar { + def assertType[T](t: T) = t + val a = new CHM[String, String]() += (("", "")) + assertType[concurrent.Map[String, String]](a) +} +// vim: set et: diff --git a/tests/untried/pos/javaConversions-2.10-regression.scala b/tests/untried/pos/javaConversions-2.10-regression.scala new file mode 100644 index 000000000..7c7ff03b5 --- /dev/null +++ b/tests/untried/pos/javaConversions-2.10-regression.scala @@ -0,0 +1,17 @@ +import collection.{JavaConversions, mutable, concurrent} +import JavaConversions._ +import java.util.concurrent.{ConcurrentHashMap => CHM} + +object Foo { + def buildCache2_9_simple[K <: AnyRef, V <: AnyRef]: concurrent.Map[K, V] = + mapAsScalaConcurrentMap(new CHM()) + + def buildCache2_9_implicit[K <: AnyRef, V <: AnyRef]: concurrent.Map[K, V] = + new CHM[K, V]() +} + +object Bar { + def assertType[T](t: T) = t + val a = new CHM[String, String]() += (("", "")) + assertType[concurrent.Map[String, String]](a) +} diff --git a/tests/untried/pos/javaReadsSigs/fromjava.java b/tests/untried/pos/javaReadsSigs/fromjava.java new file mode 100644 index 000000000..92441b0c6 --- /dev/null +++ b/tests/untried/pos/javaReadsSigs/fromjava.java @@ -0,0 +1,75 @@ +import scala.*; +import scala.math.Ordering; +import scala.math.Numeric; +import scala.collection.Seq; +import scala.collection.Traversable; +import scala.collection.Traversable$; +import scala.collection.immutable.Set; +import scala.collection.immutable.HashSet; +import scala.collection.immutable.Map; +import scala.collection.immutable.Map$; +import scala.collection.immutable.HashMap; +import scala.collection.immutable.Vector; +import scala.collection.immutable.List; +import scala.collection.generic.CanBuildFrom; + +class A { }; +class B { }; + +// This one compiles but it would be better if it didn't. +// Checking in under pos anyway in the interests of making sure +// we are informed if the status changes. +class Contra { + // Not an Ordering<Character>. + static Ordering<Object> charOrd = scala.math.Ordering.Char$.MODULE$; + + public boolean useCharOrd() { + return charOrd.compare(new Object(), new Object()) == 0; + } + + static Numeric<?> intNum = scala.math.Numeric.IntIsIntegral$.MODULE$; +} + +public class fromjava { + public static Function1<A, B> f1 = new scala.runtime.AbstractFunction1<A, B>() { + public B apply(A a) { + return null; + } + }; + + public static Function1<Tuple2<? extends Object, B>, B> f2 = new scala.runtime.AbstractFunction1<Tuple2<? extends Object, B>, B>() { + public B apply(Tuple2<? extends Object, B> tup) { + return tup._2(); + } + }; + + public static String vector(Vector<String> x) { + Vector<String> y = x.take(2); + return y.head(); + } + public static String list(List<String> x) { + List<String> y = x.drop(2); + return y.head(); + } + public static Tuple2<String, Integer> map(Map<String, Integer> x) { + Traversable<Tuple2<String, Integer>> y = x.drop(2); + return y.head(); + } + public static <T> Object sum(Traversable<T> x) { + return x.sum(Contra.intNum); + } + // Looks like sum as given below fails under java5, so disabled. + // + // [partest] testing: [...]/files/pos/javaReadsSigs [FAILED] + // [partest] files/pos/javaReadsSigs/fromjava.java:62: name clash: sum(scala.collection.Traversable<A>) and <T>sum(scala.collection.Traversable<T>) have the same erasure + // [partest] public static B sum(Traversable<A> x) { + // [partest] ^ + // + // + // can't make this work with an actual CanBuildFrom: see #4389. + // public static B sum(Traversable<A> x) { + // // have to cast it unfortunately: map in TraversableLike returns + // // "That" and such types seem to be signature poison. + // return ((Traversable<B>)x.map(f1, null)).head(); + // } +}
\ No newline at end of file diff --git a/tests/untried/pos/kinds.scala b/tests/untried/pos/kinds.scala new file mode 100644 index 000000000..6d6da0c8b --- /dev/null +++ b/tests/untried/pos/kinds.scala @@ -0,0 +1,13 @@ +trait IllKind1 { + def g(s: String): String = s + def f: String = ??? + def f[C](c: C): String = g(f) +} + +trait IllKind2 { + def b1: Char = ??? + def b2: Byte = ??? + + def f1 = "abc" contains b1 + def f2 = "abc" contains b2 +} diff --git a/tests/untried/pos/kinzer.scala b/tests/untried/pos/kinzer.scala new file mode 100644 index 000000000..a80bd425c --- /dev/null +++ b/tests/untried/pos/kinzer.scala @@ -0,0 +1,8 @@ +// ScalaMenuTest.scala +object ScalaMenuTest { + def main(args: Array[String]): Unit = { + val v = new javax.swing.JMenu() + v.add(new javax.swing.JMenuItem()) + //v.add(new java.awt.PopupMenu()); + } +} diff --git a/tests/untried/pos/ksbug1.scala b/tests/untried/pos/ksbug1.scala new file mode 100644 index 000000000..ee6ab9b49 --- /dev/null +++ b/tests/untried/pos/ksbug1.scala @@ -0,0 +1,4 @@ +object test { + type z[a, b] = a => b + def f : z[Int, Int] = (i => i + 1) +} diff --git a/tests/untried/pos/lambda.scala b/tests/untried/pos/lambda.scala new file mode 100644 index 000000000..c9094992e --- /dev/null +++ b/tests/untried/pos/lambda.scala @@ -0,0 +1,9 @@ +object test { + + def apply[a,b](f: a => b): a => b = { x: a => f(x) } + + def twice[a](f: a => a): a => a = { x: a => f(f(x)) } + + def main = apply[Int,Int](twice[Int]{x: Int => x})(1); +} + diff --git a/tests/untried/pos/lambdalift.scala b/tests/untried/pos/lambdalift.scala new file mode 100644 index 000000000..bc997d6f8 --- /dev/null +++ b/tests/untried/pos/lambdalift.scala @@ -0,0 +1,15 @@ +import scala._; + +object test { + + def f(x: Int) = { + def g() = h(); + def h() = x; + g(); + class inner() { + def g() = h(); + def h() = x; + } + g() + new inner().g(); + } +} diff --git a/tests/untried/pos/lambdalift1.scala b/tests/untried/pos/lambdalift1.scala new file mode 100644 index 000000000..01b224c3b --- /dev/null +++ b/tests/untried/pos/lambdalift1.scala @@ -0,0 +1,17 @@ +import scala._; + +object test { + + def f[a <: java.lang.Object](x: a) = { + def print() = java.lang.System.out.println(x); + class A() { + def g() = { + class B() { + def h() = print() + } + new B().h() + } + } + new A().g() + } +} diff --git a/tests/untried/pos/largecasetest.scala b/tests/untried/pos/largecasetest.scala new file mode 100644 index 000000000..1f580b5b4 --- /dev/null +++ b/tests/untried/pos/largecasetest.scala @@ -0,0 +1,6 @@ +object Test{ +def foo(x : Int) = x match { + case 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 => 128 + case _ => -1 + } +} diff --git a/tests/untried/pos/lexical.scala b/tests/untried/pos/lexical.scala new file mode 100755 index 000000000..8c29513bb --- /dev/null +++ b/tests/untried/pos/lexical.scala @@ -0,0 +1,9 @@ +// #2081 +class RichInt(n: Int) { + def days = 1000*60*60*24*n +} + +object Test extends App { + implicit def RichInt(n: Int): RichInt = new RichInt(n) + println(10.days) +} diff --git a/tests/untried/pos/liftcode_polymorphic.scala b/tests/untried/pos/liftcode_polymorphic.scala new file mode 100644 index 000000000..249f5a056 --- /dev/null +++ b/tests/untried/pos/liftcode_polymorphic.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ + +object Append extends App { + + def append[A](l1: List[A], l2: List[A]):List[A] = + l1 match { + case Nil => l2 + case x::xs => x :: append(xs, l2) + } + + println(reify(append _).tree) +} diff --git a/tests/untried/pos/list-extractor.scala b/tests/untried/pos/list-extractor.scala new file mode 100644 index 000000000..79c622bca --- /dev/null +++ b/tests/untried/pos/list-extractor.scala @@ -0,0 +1,8 @@ +// This was fixed in r25277 but is enough different +// from the case I was knowingly fixing, I'm throwing it +// in there. +object HasArgs { + def boop(params: List[List[_]]) = params match { + case List(List()) => 2 + } +} diff --git a/tests/untried/pos/list-optim-check.flags b/tests/untried/pos/list-optim-check.flags new file mode 100644 index 000000000..49d036a88 --- /dev/null +++ b/tests/untried/pos/list-optim-check.flags @@ -0,0 +1 @@ +-optimize diff --git a/tests/untried/pos/list-optim-check.scala b/tests/untried/pos/list-optim-check.scala new file mode 100644 index 000000000..f6e6ddec7 --- /dev/null +++ b/tests/untried/pos/list-optim-check.scala @@ -0,0 +1,21 @@ +// Tests a map known to crash in optimizer with faster List map in SI-8240. +// Equivalent tests for collect and flatmap do not crash, but are provided +// anyway. +// See ticket SI-8334 for optimizer bug. +// TODO - Remove this test once SI-8334 is fixed and has its own test. +class A { + def f: Boolean = { + val xs = Nil map (_ => return false) + true + } + + def g: Boolean = { + val xs = Nil collect { case _ => return false } + true + } + + def h: Boolean = { + val xs = Nil flatMap { _ => return false } + true + } +} diff --git a/tests/untried/pos/listpattern.scala b/tests/untried/pos/listpattern.scala new file mode 100644 index 000000000..47145bf03 --- /dev/null +++ b/tests/untried/pos/listpattern.scala @@ -0,0 +1,8 @@ +trait Value {} +case class FloatValue(x: Double) extends Value +object Test { + def applyNumeric(op: (Double, Double) => Double): + PartialFunction[List[Value], Value] = { + case List(FloatValue(x), FloatValue(y)) => FloatValue(op(x, y)) + } +} diff --git a/tests/untried/pos/local-objects.scala b/tests/untried/pos/local-objects.scala new file mode 100644 index 000000000..ed7c50ead --- /dev/null +++ b/tests/untried/pos/local-objects.scala @@ -0,0 +1,9 @@ + + +object Main { + val x = { + object Boo + Boo + } +} + diff --git a/tests/untried/pos/localmodules.scala b/tests/untried/pos/localmodules.scala new file mode 100644 index 000000000..3e1600842 --- /dev/null +++ b/tests/untried/pos/localmodules.scala @@ -0,0 +1,22 @@ +package test; + +object main { + + class a { + + object b { + + trait c {} + def foo(x: c): c = { Console.println("foo(" + x + ")"); x } + + } + + def bar(x: b.c): a.this.b.c = { b.foo(x); x } + } + + def main(args: Array[String]) = { + val aa = new a; + val xx: aa.b.c = null; + Console.println(aa.bar(xx)); + } +} diff --git a/tests/untried/pos/lookupswitch.scala b/tests/untried/pos/lookupswitch.scala new file mode 100644 index 000000000..5d4825124 --- /dev/null +++ b/tests/untried/pos/lookupswitch.scala @@ -0,0 +1,36 @@ +// There's not a real test here, but on compilation the +// switch should have the cases arranged in order from 1-30. +class A { + def f(x: Int) = x match { + case 6 => "6" + case 18 => "18" + case 7 => "7" + case 2 => "2" + case 13 => "13" + case 11 => "11" + case 26 => "26" + case 27 => "27" + case 29 => "29" + case 25 => "25" + case 9 => "9" + case 17 => "17" + case 16 => "16" + case 1 => "1" + case 30 => "30" + case 15 => "15" + case 22 => "22" + case 19 => "19" + case 23 => "23" + case 8 => "8" + case 28 => "28" + case 5 => "5" + case 12 => "12" + case 10 => "10" + case 21 => "21" + case 24 => "24" + case 4 => "4" + case 14 => "14" + case 3 => "3" + case 20 => "20" + } +} diff --git a/tests/untried/pos/looping-jsig.scala b/tests/untried/pos/looping-jsig.scala new file mode 100644 index 000000000..6e3313c46 --- /dev/null +++ b/tests/untried/pos/looping-jsig.scala @@ -0,0 +1,18 @@ +import scala.collection.mutable._ + +trait BugTrack { + trait B[+T] + val cache : HashMap[A[_], B[_]] = HashMap.empty + + def A[T](f: Int => B[T]): A[T] + = new A[T]{def apply(in: Int) = f(in)} + + abstract class A[+T] extends (Int => B[T]) { + def giveMeSame = this + } + + def amethod[T](p: =>A[T]): A[T] = A(in => cache.get(p) match { + case Some(res) => res + case None => p(in) + }).giveMeSame.asInstanceOf[A[T]] +} diff --git a/tests/untried/pos/lub-dealias-widen.scala b/tests/untried/pos/lub-dealias-widen.scala new file mode 100644 index 000000000..d09a3abf8 --- /dev/null +++ b/tests/untried/pos/lub-dealias-widen.scala @@ -0,0 +1,34 @@ +import scala.language.higherKinds + +sealed trait Path { + type EncodeFunc + type Route[R] = List[String] => R + + def >>(f: Route[Int]): Sitelet[EncodeFunc] = ??? +} + +case object PAny extends Path { + type EncodeFunc = List[String] => String +} + +case class PLit[Next <: Path]() extends Path { + type EncodeFunc = Next#EncodeFunc +} + +trait Sitelet[EncodeFunc] { self => + def &[G <: H, H >: EncodeFunc](that: Sitelet[G]): Sitelet[H] = ??? +} + +object Test { + val r: Sitelet[Int => (Int => String)] = ??? + + val p2: PLit[PAny.type] = ??? + val r2 /*: Sitelet[List[String] => String] */ // annotate type and it compiles with 2.10.0 + = p2 >> { (xs: List[String]) => 0 } + + // This works after https://github.com/scala/scala/commit/a06d31f6a + // Before: error: inferred type arguments [List[String] => String,List[String] => String] + // do not conform to method &'s type parameter bounds + // [G <: H,H >: Int => (Int => String)] + val s = r & r2 +} diff --git a/tests/untried/pos/lubs.scala b/tests/untried/pos/lubs.scala new file mode 100644 index 000000000..d7651f86b --- /dev/null +++ b/tests/untried/pos/lubs.scala @@ -0,0 +1,3 @@ +object Test { + List(new { def f = 1; def g = 1}, new { def f = 2}).map(_.f) +} diff --git a/tests/untried/pos/macro-bundle-disambiguate-bundle.check b/tests/untried/pos/macro-bundle-disambiguate-bundle.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/macro-bundle-disambiguate-bundle.check diff --git a/tests/untried/pos/macro-bundle-disambiguate-bundle.scala b/tests/untried/pos/macro-bundle-disambiguate-bundle.scala new file mode 100644 index 000000000..40d965b0e --- /dev/null +++ b/tests/untried/pos/macro-bundle-disambiguate-bundle.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(val c: Context) { + def impl = ??? +} + +object Macros { + def impl(c: Context)(x: c.Tree) = ??? +} + +object Test extends App { + def foo: Unit = macro Macros.impl +} diff --git a/tests/untried/pos/macro-bundle-disambiguate-nonbundle.check b/tests/untried/pos/macro-bundle-disambiguate-nonbundle.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/macro-bundle-disambiguate-nonbundle.check diff --git a/tests/untried/pos/macro-bundle-disambiguate-nonbundle.scala b/tests/untried/pos/macro-bundle-disambiguate-nonbundle.scala new file mode 100644 index 000000000..185177607 --- /dev/null +++ b/tests/untried/pos/macro-bundle-disambiguate-nonbundle.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(val c: Context) { + def impl(x: c.Tree) = ??? +} + +object Macros { + def impl(c: Context) = ??? +} + +object Test extends App { + def foo: Unit = macro Macros.impl +} diff --git a/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.flags b/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.scala b/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.scala new file mode 100644 index 000000000..8eb5a0238 --- /dev/null +++ b/tests/untried/pos/macro-deprecate-dont-touch-backquotedidents.scala @@ -0,0 +1,56 @@ +object Test1 { + val `macro` = ??? +} + +object Test2 { + var `macro` = ??? +} + +object Test3 { + type `macro` = Int +} + +package test4 { + class `macro` +} + +object Test5 { + class `macro` +} + +package test6 { + object `macro` +} + +object Test7 { + object `macro` +} + +package test8 { + trait `macro` +} + +object Test9 { + trait `macro` +} + +package `macro` { + package `macro`.bar { + } +} + +package foo { + package `macro`.foo { + } +} + +//object Test12 { +// val Some(`macro`) = Some(42) +// `macro` match { +// case `macro` => println(`macro`) +// } +//} + +object Test13 { + def `macro` = 2 +} diff --git a/tests/untried/pos/macro-implicit-invalidate-on-error.check b/tests/untried/pos/macro-implicit-invalidate-on-error.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/macro-implicit-invalidate-on-error.check diff --git a/tests/untried/pos/macro-implicit-invalidate-on-error.scala b/tests/untried/pos/macro-implicit-invalidate-on-error.scala new file mode 100644 index 000000000..bb83e3cc3 --- /dev/null +++ b/tests/untried/pos/macro-implicit-invalidate-on-error.scala @@ -0,0 +1,25 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +trait LegacyLiftable[T] { + def apply(universe: scala.reflect.api.Universe, value: T): universe.Tree +} + +object LegacyLiftable { + implicit def liftCaseClass[T <: Product]: LegacyLiftable[T] = macro liftCaseClassImpl[T] + + def liftCaseClassImpl[T: c.WeakTypeTag](c: Context): c.Expr[LegacyLiftable[T]] = { + import c.universe._ + val tpe = weakTypeOf[T] + if (!tpe.typeSymbol.asClass.isCaseClass) c.abort(c.enclosingPosition, "denied") + val p = List(q"Literal(Constant(1))") + c.Expr[LegacyLiftable[T]] { q""" + new LegacyLiftable[$tpe] { + def apply(universe: scala.reflect.api.Universe, value: $tpe): universe.Tree = { + import universe._ + Apply(Select(Ident(TermName("C")), TermName("apply")), List(..$p)) + } + } + """ } + } +} diff --git a/tests/untried/pos/macro-qmarkqmarkqmark.scala b/tests/untried/pos/macro-qmarkqmarkqmark.scala new file mode 100644 index 000000000..de94d69d5 --- /dev/null +++ b/tests/untried/pos/macro-qmarkqmarkqmark.scala @@ -0,0 +1,7 @@ +import language.experimental.macros + +object Macros { + def foo1 = macro ??? + def foo2(x: Int) = macro ??? + def foo3[T] = macro ??? +} diff --git a/tests/untried/pos/manifest1-new.scala b/tests/untried/pos/manifest1-new.scala new file mode 100644 index 000000000..3a957bf0d --- /dev/null +++ b/tests/untried/pos/manifest1-new.scala @@ -0,0 +1,21 @@ +import scala.reflect.runtime.universe._ + +object Test { + def foo[T](x: T)(implicit m: TypeTag[T]): Unit = { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: TypeTag[T]; val x: T } + val stringm = implicitly[TypeTag[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/tests/untried/pos/manifest1-old.scala b/tests/untried/pos/manifest1-old.scala new file mode 100644 index 000000000..b24311bd3 --- /dev/null +++ b/tests/untried/pos/manifest1-old.scala @@ -0,0 +1,21 @@ +import scala.reflect.Manifest + +object Test { + def foo[T](x: T)(implicit m: Manifest[T]): Unit = { + foo(List(x)) + } + foo(1) + foo("abc") + foo(List(1, 2, 3)) + val x: List[Int] with Ordered[List[Int]] = null + foo(x) + foo[x.type](x) + abstract class C { type T = String; val x: T } + val c = new C { val x = "abc" } + foo(c.x) + abstract class D { type T; implicit val m: Manifest[T]; val x: T } + val stringm = implicitly[Manifest[String]] + val d: D = new D { type T = String; val m = stringm; val x = "x" } + import d.m + foo(d.x) +} diff --git a/tests/untried/pos/matthias1.scala b/tests/untried/pos/matthias1.scala new file mode 100644 index 000000000..a923a529f --- /dev/null +++ b/tests/untried/pos/matthias1.scala @@ -0,0 +1,15 @@ +class A() { + class B() { + def foo(x: B) = 0 + } +} +object test { + def main = { + val a = new A(); + val b = new a.B(); + val c = new a.B(); + val d = b.foo(c); + () + } +} + diff --git a/tests/untried/pos/matthias3.scala b/tests/untried/pos/matthias3.scala new file mode 100644 index 000000000..6e86afeca --- /dev/null +++ b/tests/untried/pos/matthias3.scala @@ -0,0 +1,13 @@ + +abstract class A() { + val y: A; +} +class B() extends A() { + val x = this; + val y: x.type = x; +} +abstract class C() { + val b: B = new B(); + val a: A { val y: b.type }; +} + diff --git a/tests/untried/pos/matthias4.scala b/tests/untried/pos/matthias4.scala new file mode 100644 index 000000000..18599ae71 --- /dev/null +++ b/tests/untried/pos/matthias4.scala @@ -0,0 +1,84 @@ +/* +object A requires B { + B.X getX() { + return B.getX(); + } + void setX(B.X x) {} +} +object B { + class X {} + X getX() { + return new X(); + } + void setX(X x) {} +} +object C requires B { + object A; + void test() { + A.setX(B.getX()); + } +} +*/ + +trait _a extends AnyRef with _b { + val a: _a; + val A: A; + type A <: a.AObject; + trait AObject { + def getX(): B.X; + def setX(x: B.X): Unit; + } +} +trait a123 extends AnyRef with _a with _b { + val a: this.type = this; + val A: A = new A(); + class A() extends AObject { + def getX(): B.X = B.getX(); + def setX(x: B.X) = B.setX(x); + } +} + +trait _b { + val b: _b; + val B: B; + type B <: b.BObject; + trait BObject { + type X; + def getX(): X; + def setX(x: X): Unit; + } +} +abstract class b() extends AnyRef with _b { + val b: this.type = this; + val B: B = new B(); + class B() extends BObject { + class X() {} + def getX(): X = new X(); + def setX(x: X) = (); + } +} + +trait _m { + val m: _m; + val M: M; + type M <: m.MObject; + trait MObject {} +} +abstract class m() extends AnyRef with _m with _b { + val m: this.type = this; + val M: M = new M(); + class M() extends MObject with a123 with Linker { + def test() = { + val x: B.X = B.getX(); + A.setX(x); + } + } + trait Linker { + val b: m.this.b.type = m.this.b; + val B: m.this.B.type = m.this.B; + type B = m.this.B; + val m: m.this.m.type = m.this.m; + val M: m.this.M.type = m.this.M; + type M = m.this.M; + } +} diff --git a/tests/untried/pos/matthias5.scala b/tests/untried/pos/matthias5.scala new file mode 100644 index 000000000..0dcb7f833 --- /dev/null +++ b/tests/untried/pos/matthias5.scala @@ -0,0 +1,12 @@ +abstract class A() { + val y: A; +} +class B() extends A() { + val x = this; + val y: x.type = x; +} +abstract class C() { + val b: B = new B(); + val a: A { val y: b.type }; +} + diff --git a/tests/untried/pos/maxim1.scala b/tests/untried/pos/maxim1.scala new file mode 100644 index 000000000..58916beb8 --- /dev/null +++ b/tests/untried/pos/maxim1.scala @@ -0,0 +1,5 @@ +object test { + def f(x: Int)(y: Int) = x + y; + def y: Int => Int = f(2); + def main = y(1); +} diff --git a/tests/untried/pos/michel1.scala b/tests/untried/pos/michel1.scala new file mode 100644 index 000000000..f930a682e --- /dev/null +++ b/tests/untried/pos/michel1.scala @@ -0,0 +1,9 @@ +class A[Ta] (a : Ta) { + def f = 1 +} + +trait C {} + +class B[Tb] (b : Tb) extends A[Tb] (b) with C { + def g = 2 +} diff --git a/tests/untried/pos/michel2.scala b/tests/untried/pos/michel2.scala new file mode 100644 index 000000000..914c1b27a --- /dev/null +++ b/tests/untried/pos/michel2.scala @@ -0,0 +1,16 @@ +object Test { + + trait A extends AnyRef { + def f : Int = 1 + } + + class B extends AnyRef with A { + override def f : Int = super[A].f + } + + def main(args: Array[String]) = + Console.println(new B().f); +} + + + diff --git a/tests/untried/pos/michel3.scala b/tests/untried/pos/michel3.scala new file mode 100644 index 000000000..348a66a10 --- /dev/null +++ b/tests/untried/pos/michel3.scala @@ -0,0 +1,3 @@ +abstract class A() { + val v : Int +} diff --git a/tests/untried/pos/michel4.scala b/tests/untried/pos/michel4.scala new file mode 100644 index 000000000..ce9de29a2 --- /dev/null +++ b/tests/untried/pos/michel4.scala @@ -0,0 +1,7 @@ +class A() { + def f : Int = 2 +} + +class B() extends A() { + override val f : Int = super.f +} diff --git a/tests/untried/pos/michel5.scala b/tests/untried/pos/michel5.scala new file mode 100644 index 000000000..34832c00c --- /dev/null +++ b/tests/untried/pos/michel5.scala @@ -0,0 +1,5 @@ +trait A[Ta] { } + +class B() extends AnyRef with A[Int] { + val x : Int = 2 +} diff --git a/tests/untried/pos/michel6.scala b/tests/untried/pos/michel6.scala new file mode 100644 index 000000000..b32e8bed7 --- /dev/null +++ b/tests/untried/pos/michel6.scala @@ -0,0 +1,6 @@ +object M { + def f(x: Int): Unit = {} + + def g(): Int => Unit = + if (0 == 0) f else g() + } diff --git a/tests/untried/pos/misc-unapply_pos.scala b/tests/untried/pos/misc-unapply_pos.scala new file mode 100644 index 000000000..6651e6436 --- /dev/null +++ b/tests/untried/pos/misc-unapply_pos.scala @@ -0,0 +1,27 @@ +object Test { + val xs = List(1) + val f: Int = { + xs match { + case List(x) => x + } + } +} + +// the following comes from ticket #230 +trait Foo { + def name: String + def unapply(x: String): Option[Unit] = { + if (x == name) Some(()) else None + } +} +object Bar extends Foo { def name = "bar" } +object Baz extends Foo { def name = "baz" } + +object Test_ { + def matcher(s: String) = s match { + case Bar(x) => println("bar") + case Baz(x) => println("baz") +// ^ +// error: unreachable code + } + } diff --git a/tests/untried/pos/mixins.scala b/tests/untried/pos/mixins.scala new file mode 100644 index 000000000..846d6a41b --- /dev/null +++ b/tests/untried/pos/mixins.scala @@ -0,0 +1,22 @@ +package mixins +abstract class Super { + def foo: Int +} +trait Mixin extends Super { + abstract override def foo = super.foo +} +trait MixinSub extends Super with Mixin { + abstract override def foo: Int = super.foo +} +trait MixinSubSub extends MixinSub { + abstract override def foo = super.foo +} +class Sub extends Super { + def foo: Int = 1 +} +class Base extends Sub with MixinSubSub { + override def foo = super.foo +} +trait Mixin1 extends Sub with MixinSubSub {} +class Base1 extends Mixin1 {} + diff --git a/tests/untried/pos/modules.scala b/tests/untried/pos/modules.scala new file mode 100644 index 000000000..8168a42d3 --- /dev/null +++ b/tests/untried/pos/modules.scala @@ -0,0 +1,14 @@ +package scala { + + object a { + + object b { + + trait c {} + def foo(x: c): c = bar(x) + + } + + def bar(x: b.c): b.c = x + } +} diff --git a/tests/untried/pos/modules1.scala b/tests/untried/pos/modules1.scala new file mode 100644 index 000000000..3da14af4f --- /dev/null +++ b/tests/untried/pos/modules1.scala @@ -0,0 +1,14 @@ +package scala { + + object a { + + object b { + + trait c {} + def foo(x: c): c = bar(x) + + } + + def bar(x: b.c): a.b.c = { b.foo(x); x } + } +} diff --git a/tests/untried/pos/moduletrans.scala b/tests/untried/pos/moduletrans.scala new file mode 100644 index 000000000..51538417e --- /dev/null +++ b/tests/untried/pos/moduletrans.scala @@ -0,0 +1,8 @@ +object m1 { + + class m() { + def f() = 5 + } + final val m: m = new m() + +} diff --git a/tests/untried/pos/native-warning.flags b/tests/untried/pos/native-warning.flags new file mode 100644 index 000000000..65faf5357 --- /dev/null +++ b/tests/untried/pos/native-warning.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation
\ No newline at end of file diff --git a/tests/untried/pos/native-warning.scala b/tests/untried/pos/native-warning.scala new file mode 100644 index 000000000..f721a57e8 --- /dev/null +++ b/tests/untried/pos/native-warning.scala @@ -0,0 +1,3 @@ +class A { + @native def setup(): Unit +} diff --git a/tests/untried/pos/needstypeearly.scala b/tests/untried/pos/needstypeearly.scala new file mode 100644 index 000000000..a90c2575f --- /dev/null +++ b/tests/untried/pos/needstypeearly.scala @@ -0,0 +1,4 @@ +abstract class NeedsXEarly { + val x: Int +} +class Foo extends { val x = 1 } with NeedsXEarly diff --git a/tests/untried/pos/nested.scala b/tests/untried/pos/nested.scala new file mode 100644 index 000000000..b038fce39 --- /dev/null +++ b/tests/untried/pos/nested.scala @@ -0,0 +1,29 @@ +// A non-trivial example of nested classes (mostly to test +// ExplicitOuterClasses). + +class A(pa : Int) { + def a1 = pa; + class B(pb : Int) { + def b1 = pa+pb+a1; + class C(pc : Int) extends A(b1) { + def c1 = pc+pb+pa + } + val c1 = new C(66) + } +} + +trait M { + val x : Int; + def m1 = x +} + +class A1(x0 : Int) extends A(x0) with M { + val x = x0; + class D() extends B(42) { + val c2 = new C(66); + class E() extends C(5) { + def e1 = c1+b1+a1; + def e2 = new D(); + } + } +} diff --git a/tests/untried/pos/nested2.scala b/tests/untried/pos/nested2.scala new file mode 100644 index 000000000..421ea6fac --- /dev/null +++ b/tests/untried/pos/nested2.scala @@ -0,0 +1,9 @@ +class C[A] { + class D[B] { + } +} + +object Test { + val x = new C[String] + val y: C[String]#D[Int] = new x.D[Int] +} diff --git a/tests/untried/pos/nonlocal-unchecked.flags b/tests/untried/pos/nonlocal-unchecked.flags new file mode 100644 index 000000000..144ddac9d --- /dev/null +++ b/tests/untried/pos/nonlocal-unchecked.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings diff --git a/tests/untried/pos/nonlocal-unchecked.scala b/tests/untried/pos/nonlocal-unchecked.scala new file mode 100644 index 000000000..6bd3dc479 --- /dev/null +++ b/tests/untried/pos/nonlocal-unchecked.scala @@ -0,0 +1,6 @@ +class A { + def f: Boolean = { + val xs = Nil map (_ => return false) + true + } +} diff --git a/tests/untried/pos/nothing_manifest_disambig-new.scala b/tests/untried/pos/nothing_manifest_disambig-new.scala new file mode 100644 index 000000000..64afdee60 --- /dev/null +++ b/tests/untried/pos/nothing_manifest_disambig-new.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ + +object Test { + def mani[T: TypeTag](xs: T) = xs + mani(List()) + + def listElMani[T: TypeTag](xs: List[T]) = xs + listElMani(List()) + + def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: TypeTag[A]): (C, A, TypeTag[A]) = (m, m.head, mani) + foo(List(1,2,3)) +} diff --git a/tests/untried/pos/nothing_manifest_disambig-old.scala b/tests/untried/pos/nothing_manifest_disambig-old.scala new file mode 100644 index 000000000..f282cb914 --- /dev/null +++ b/tests/untried/pos/nothing_manifest_disambig-old.scala @@ -0,0 +1,10 @@ +object Test { + def mani[T: Manifest](xs: T) = xs + mani(List()) + + def listElMani[T: Manifest](xs: List[T]) = xs + listElMani(List()) + + def foo[A, C](m : C)(implicit ev: C <:< Traversable[A], mani: Manifest[A]): (C, A, Manifest[A]) = (m, m.head, mani) + foo(List(1,2,3)) +} diff --git a/tests/untried/pos/null.scala b/tests/untried/pos/null.scala new file mode 100644 index 000000000..1c68e29f0 --- /dev/null +++ b/tests/untried/pos/null.scala @@ -0,0 +1,3 @@ +object M { + val x: Boolean = null == null; +} diff --git a/tests/untried/pos/nullary.scala b/tests/untried/pos/nullary.scala new file mode 100644 index 000000000..614fcdf48 --- /dev/null +++ b/tests/untried/pos/nullary.scala @@ -0,0 +1,20 @@ +abstract class NullaryTest[T, m[s]] { + def nullary: String = "a" + val x = nullary + + def nullary2: T + val x2 = nullary2 + + def nullary3: m[T] + val x3 = nullary3 +} + +class Concrete extends NullaryTest[Int, List] { + def nullary2 = 1 + def nullary3 = List(1,2,3) +} + +object test { + (new Concrete).nullary2 + (new Concrete).nullary3 +} diff --git a/tests/untried/pos/nullary_poly.scala b/tests/untried/pos/nullary_poly.scala new file mode 100644 index 000000000..d2e1e127a --- /dev/null +++ b/tests/untried/pos/nullary_poly.scala @@ -0,0 +1,10 @@ +// test polymorphic nullary method calls +class A { + // built-in + synchronized {} + + val x: String = "a".asInstanceOf[String] + + // user-defined: + def polyNullary[T]: List[T] = Nil +} diff --git a/tests/untried/pos/optmatch.scala b/tests/untried/pos/optmatch.scala new file mode 100644 index 000000000..354be65da --- /dev/null +++ b/tests/untried/pos/optmatch.scala @@ -0,0 +1,33 @@ +// final case class NonZeroLong(value: Long) extends AnyVal { +// def get: Long = value +// def isEmpty: Boolean = get == 0l +// } + +class NonZeroLong(val value: Long) extends AnyVal { + def get: Long = value + def isEmpty: Boolean = get == 0l +} +object NonZeroLong { + def unapply(value: Long): NonZeroLong = new NonZeroLong(value) +} + + +object Foo { + def unapply(x: Int): NonZeroLong = new NonZeroLong(1L << x) + // public long unapply(int); + // 0: lconst_1 + // 1: iload_1 + // 2: lshl + // 3: lreturn +} + +object Test { + def f(x: Int): Int = x match { + case Foo(1024l) => 1 + case _ => 2 + } + def main(args: Array[String]): Unit = { + println(f(10)) + println(f(11)) + } +} diff --git a/tests/untried/pos/overloaded-unapply.scala b/tests/untried/pos/overloaded-unapply.scala new file mode 100644 index 000000000..4105a25f1 --- /dev/null +++ b/tests/untried/pos/overloaded-unapply.scala @@ -0,0 +1,8 @@ +trait Baz { + type Type >: Null + + case class HoleType(a: String, b: String, c: String) + object HoleType { def unapply(tpe: Type): Option[HoleType] = ??? } + + (null: Type) match { case HoleType(holeTpe) => holeTpe } +} diff --git a/tests/untried/pos/overloaded_extractor_and_regular_def.scala b/tests/untried/pos/overloaded_extractor_and_regular_def.scala new file mode 100644 index 000000000..c34dee8fa --- /dev/null +++ b/tests/untried/pos/overloaded_extractor_and_regular_def.scala @@ -0,0 +1,32 @@ +trait TreesBase { + type Tree + + type Apply <: Tree + + val Apply: ApplyExtractor + + abstract class ApplyExtractor { + def apply(x: Int): Apply + def unapply(apply: Apply): Option[Int] + } +} + +trait TreesApi extends TreesBase { + def Apply(x: String) +} + +class Universe extends TreesApi { + abstract class Tree + case class Apply(x: Int) extends Tree + object Apply extends ApplyExtractor + def Apply(x: String) = Apply(x.toInt) +} + +object Test extends App { + def foo(tapi: TreesApi): Unit = { + import tapi._ + def bar(tree: Tree): Unit = { + val Apply(x) = tree + } + } +} diff --git a/tests/untried/pos/override-object-yes.flags b/tests/untried/pos/override-object-yes.flags new file mode 100644 index 000000000..22e9a95c4 --- /dev/null +++ b/tests/untried/pos/override-object-yes.flags @@ -0,0 +1 @@ +-Yoverride-objects
\ No newline at end of file diff --git a/tests/untried/pos/override-object-yes.scala b/tests/untried/pos/override-object-yes.scala new file mode 100644 index 000000000..858f9b21f --- /dev/null +++ b/tests/untried/pos/override-object-yes.scala @@ -0,0 +1,40 @@ +package case1 { + class Bippy { + def f = 1 + } + + trait Foo { + object Bar extends Bippy { + override def f = 2 + } + } + + trait Foo2 extends Foo { + override object Bar extends Bippy { + override def f = 3 + } + } + + trait Foo3 { + object Bar { + def g: Traversable[Int] = Nil + } + } + trait Foo4 extends Foo3 { + override object Bar { + def g: List[Int] = Nil + } + } +} + +package case2 { + class Bar[T] + + class Foo[T] { + object A extends Bar[T] + } + + class Baz[S] extends Foo[S] { + override object A extends Bar[S] + } +} diff --git a/tests/untried/pos/override.scala b/tests/untried/pos/override.scala new file mode 100644 index 000000000..6312564f4 --- /dev/null +++ b/tests/untried/pos/override.scala @@ -0,0 +1,14 @@ +trait A extends AnyRef { + def f = 1; + val x: A; +} + +trait B extends AnyRef { + def f = 2; +} + +trait C extends AnyRef with A with B { + override def f = super[B].f; + val a: A; + val x: a.type = a; +} diff --git a/tests/untried/pos/overzealous-assert-genbcode.scala b/tests/untried/pos/overzealous-assert-genbcode.scala new file mode 100644 index 000000000..82be359d9 --- /dev/null +++ b/tests/untried/pos/overzealous-assert-genbcode.scala @@ -0,0 +1,10 @@ +object Test { + + def main(args: Array[String]): Unit = { + args(0) match { + case a: String => while(a == null) {} + } + } + +} + diff --git a/tests/untried/pos/package-case.scala b/tests/untried/pos/package-case.scala new file mode 100644 index 000000000..906f1eb3f --- /dev/null +++ b/tests/untried/pos/package-case.scala @@ -0,0 +1,4 @@ +// a.scala +// Sat Jul 16 00:34:36 EDT 2011 + +package object io { case class TextReader() } diff --git a/tests/untried/pos/package-implicit/ActorRef.scala b/tests/untried/pos/package-implicit/ActorRef.scala new file mode 100644 index 000000000..de57e61ce --- /dev/null +++ b/tests/untried/pos/package-implicit/ActorRef.scala @@ -0,0 +1,7 @@ +package t1000647.foo + +trait ActorRef { + def stop(): Unit = {} +} + +trait ScalaActorRef { self: ActorRef => } diff --git a/tests/untried/pos/package-implicit/DataFlow.scala b/tests/untried/pos/package-implicit/DataFlow.scala new file mode 100644 index 000000000..d948280d0 --- /dev/null +++ b/tests/untried/pos/package-implicit/DataFlow.scala @@ -0,0 +1,7 @@ +package t1000647.bar + +import t1000647.foo.{ScalaActorRef} + +object DataFlow { + def foo(ref: ScalaActorRef) = ref.stop() +} diff --git a/tests/untried/pos/package-implicit/package.scala b/tests/untried/pos/package-implicit/package.scala new file mode 100644 index 000000000..d0f28b36b --- /dev/null +++ b/tests/untried/pos/package-implicit/package.scala @@ -0,0 +1,6 @@ +package t1000647 + +package object foo { + implicit def scala2ActorRef(ref: ScalaActorRef): ActorRef = + ref.asInstanceOf[ActorRef] +} diff --git a/tests/untried/pos/package-ob-case.flags b/tests/untried/pos/package-ob-case.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/package-ob-case.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/package-ob-case/A_1.scala b/tests/untried/pos/package-ob-case/A_1.scala new file mode 100644 index 000000000..91a1fb7e4 --- /dev/null +++ b/tests/untried/pos/package-ob-case/A_1.scala @@ -0,0 +1,5 @@ +package foo { + package object foo { + case class X(z: Int) { } + } +} diff --git a/tests/untried/pos/package-ob-case/B_2.scala b/tests/untried/pos/package-ob-case/B_2.scala new file mode 100644 index 000000000..91a1fb7e4 --- /dev/null +++ b/tests/untried/pos/package-ob-case/B_2.scala @@ -0,0 +1,5 @@ +package foo { + package object foo { + case class X(z: Int) { } + } +} diff --git a/tests/untried/pos/packageobjs.scala b/tests/untried/pos/packageobjs.scala new file mode 100755 index 000000000..ccab13371 --- /dev/null +++ b/tests/untried/pos/packageobjs.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/tests/untried/pos/partialfun.scala b/tests/untried/pos/partialfun.scala new file mode 100644 index 000000000..9f32a2202 --- /dev/null +++ b/tests/untried/pos/partialfun.scala @@ -0,0 +1,11 @@ +object partialfun { + + def applyPartial[b](f: PartialFunction[Option[String], b])(x: Option[String]) = + if (f.isDefinedAt(x)) f(x) else "<undefined>"; + + applyPartial { + case Some(xxx) => xxx + case None => throw new MatchError(None) + } (None); + +} diff --git a/tests/untried/pos/pat_gilles.scala b/tests/untried/pos/pat_gilles.scala new file mode 100644 index 000000000..704d5b9c0 --- /dev/null +++ b/tests/untried/pos/pat_gilles.scala @@ -0,0 +1,18 @@ +abstract class Table2 { + + + val x: Any => Unit = { zz:Any => + zz match { + case Table2.CellUpdated(row, column) => + val foo = Table2.CellUpdated(2,2) + Console.println("cuckoo") + case Table2.Gaga => + }} + +} + +object Table2 { + + case class CellUpdated(row: Int, column: Int) + case object Gaga +} diff --git a/tests/untried/pos/pat_iuli.scala b/tests/untried/pos/pat_iuli.scala new file mode 100644 index 000000000..46356ff58 --- /dev/null +++ b/tests/untried/pos/pat_iuli.scala @@ -0,0 +1,22 @@ +trait Ops { self: MyCodes => + abstract class Instru + object opcodes { + case class SWITCH(i:Int) extends Instru + case object EmptyInstr extends Instru + } +} + +trait Blox { self: MyCodes => + import opcodes._ + class Basick { + var foo: Instru = null + + def bar = foo match { + case SWITCH(i) => i + case EmptyInstr => 0 + } + } +} + +abstract class MyCodes extends AnyRef with Ops with Blox { +} diff --git a/tests/untried/pos/patmat-extract-tparam.scala b/tests/untried/pos/patmat-extract-tparam.scala new file mode 100644 index 000000000..6417b49c2 --- /dev/null +++ b/tests/untried/pos/patmat-extract-tparam.scala @@ -0,0 +1,13 @@ +trait Bip[T] { def h: T } +trait BoolBip extends Bip[Boolean] + +class A { + def g(x: Boolean): Unit = () + def f(xs: List[Bip[_]]) = xs foreach { case x: BoolBip => g(x.h) } +} + +class B { + def g(x: Boolean): Unit = () + def g(x: Int): Unit = () + def f(xs: List[Bip[_]]) = xs foreach { case x: BoolBip => g(x.h) } +} diff --git a/tests/untried/pos/patmat.scala b/tests/untried/pos/patmat.scala new file mode 100644 index 000000000..53e1c5f1f --- /dev/null +++ b/tests/untried/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/untried/pos/patterns.scala b/tests/untried/pos/patterns.scala new file mode 100644 index 000000000..547d692d8 --- /dev/null +++ b/tests/untried/pos/patterns.scala @@ -0,0 +1,38 @@ +trait Option[+a] {} + +case class Some[a](x: a) extends Option[a] { + override def toString(): String = "Some(" + x + ")" + override def equals(that: Any): Boolean = that match { + case Some(x) => this.x == x + case _ => false + } + override def hashCode(): Int = getClass().hashCode() * 41 + x.hashCode() +} + +case object None extends Option[Nothing] { + override def toString(): String = "None" + override def equals(that: Any) = that match { + case None => true + case _ => false + } + override def hashCode(): Int = getClass().hashCode() +} + +object test { + + def println(str: String): Unit = java.lang.System.out.println(str) + + def print(opt: Option[String]) = opt match { + case Some(x) => println(x) + case None => println("nothing") + } +} + +// if bodies are duplicated, then we would get an error like "double definition" + +trait John[A,B] { + def filter(x:Any) = x match { + case (x::xs, _) => "ga" + case _ => {x:String => "foobar"} + } +} diff --git a/tests/untried/pos/patterns1.scala b/tests/untried/pos/patterns1.scala new file mode 100644 index 000000000..f660ea054 --- /dev/null +++ b/tests/untried/pos/patterns1.scala @@ -0,0 +1,15 @@ +trait Option[+a] + +case class Some[a](x: a) extends Option[a] + +case object None extends Option[Nothing] + +object test { + + def println(str: String): Unit = java.lang.System.out.println(str) + + def print(opt: Option[String]) = opt match { + case Some(x) => println(x) + case None => println("nothing") + } +} diff --git a/tests/untried/pos/patterns1213.scala b/tests/untried/pos/patterns1213.scala new file mode 100644 index 000000000..de1972ca5 --- /dev/null +++ b/tests/untried/pos/patterns1213.scala @@ -0,0 +1,11 @@ +abstract class MapLocation(ID: Int) { + abstract class Message + case class ReceivePlayer(id: Int) extends Message + + def foo(p: Message): Unit = { + p match { + case ReceivePlayer(ID) => + () + } + } +} diff --git a/tests/untried/pos/patterns2.scala b/tests/untried/pos/patterns2.scala new file mode 100644 index 000000000..821fc43c6 --- /dev/null +++ b/tests/untried/pos/patterns2.scala @@ -0,0 +1,16 @@ +trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: java.lang.String) extends Option; +case object None extends Option; + +object test { + + def f(opt: Option) = opt match { + case Choice(Some("one"), Some(x)) => 1; + case Choice(Some("two"), None) => 1; + case Choice(y, Some("two")) => 2; + case Choice(Some(z), a) => 3; + case Some(b) => 4; + case None => 5; + } +} diff --git a/tests/untried/pos/patterns3.scala b/tests/untried/pos/patterns3.scala new file mode 100644 index 000000000..001bd8989 --- /dev/null +++ b/tests/untried/pos/patterns3.scala @@ -0,0 +1,5 @@ +object M { + + val Tuple2(Tuple2(x, y), _) = Tuple2(Tuple2(1, 2), 3); + +} diff --git a/tests/untried/pos/philippe1.scala b/tests/untried/pos/philippe1.scala new file mode 100644 index 000000000..4b4b22ea7 --- /dev/null +++ b/tests/untried/pos/philippe1.scala @@ -0,0 +1,8 @@ +object test { + def id[a](xs: Array[a]): Array[a] = xs; + + def main(args: Array[String]): Unit = { + val res: Array[String] = id(args); + () + } +} diff --git a/tests/untried/pos/philippe2.scala b/tests/untried/pos/philippe2.scala new file mode 100644 index 000000000..55a283ddd --- /dev/null +++ b/tests/untried/pos/philippe2.scala @@ -0,0 +1,6 @@ +import scala._; +class m1() { + def n() = 0; + def foo(i: Int)(j: Int): Unit = (); + val bar: Int => Unit = foo(n()); +} diff --git a/tests/untried/pos/philippe3.scala b/tests/untried/pos/philippe3.scala new file mode 100644 index 000000000..944258399 --- /dev/null +++ b/tests/untried/pos/philippe3.scala @@ -0,0 +1,40 @@ + +class Foo(x: Int) {} +case class Bar(y: Int) extends Foo(y); + + +trait T {} +trait U {} +class C() {} + + +trait T1; +trait T2 {} +trait T5 extends T; +trait T6 extends T {} +trait T7 extends T with U; +trait T8 extends T with U {} + +class C1(); +class C2() {} +class C5() extends C(); +class C6() extends C() {} +class C7() extends C() with U; +class C8() extends C() with U {} + +case class D1(); +case class D2() {} +case class D5() extends C(); +case class D6() extends C() {} +case class D7() extends C() with U; +case class D8() extends C() with U {} + +object M1; +object M2 {} +object M5 extends C(); +object M6 extends C() {} +object M7 extends C() with U; +object M8 extends C() with U {} + + + diff --git a/tests/untried/pos/philippe4.scala b/tests/untried/pos/philippe4.scala new file mode 100644 index 000000000..9ce3691f5 --- /dev/null +++ b/tests/untried/pos/philippe4.scala @@ -0,0 +1,3 @@ +trait Foo[t <: Foo[t]] { self: t => + def foo(that: t): Boolean; +} diff --git a/tests/untried/pos/pmbug.scala b/tests/untried/pos/pmbug.scala new file mode 100644 index 000000000..7d94e7a8b --- /dev/null +++ b/tests/untried/pos/pmbug.scala @@ -0,0 +1,8 @@ +object Test { + + def flatten[a](l: List[List[a]]): List[a] = l match { + case Nil => Nil + case head :: tail => head ::: flatten(tail) + } + +} diff --git a/tests/untried/pos/polymorphic-case-class.flags b/tests/untried/pos/polymorphic-case-class.flags new file mode 100644 index 000000000..464cc20ea --- /dev/null +++ b/tests/untried/pos/polymorphic-case-class.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked
\ No newline at end of file diff --git a/tests/untried/pos/polymorphic-case-class.scala b/tests/untried/pos/polymorphic-case-class.scala new file mode 100644 index 000000000..5ed5eeddc --- /dev/null +++ b/tests/untried/pos/polymorphic-case-class.scala @@ -0,0 +1,2 @@ +// no unchecked warnings +case class Bippy[T, -U, +V](x: T, z: V) { } diff --git a/tests/untried/pos/pos-bug1210.scala b/tests/untried/pos/pos-bug1210.scala new file mode 100644 index 000000000..eb163a956 --- /dev/null +++ b/tests/untried/pos/pos-bug1210.scala @@ -0,0 +1,28 @@ +object Test +{ + def f[T](recurse: T => List[T]): List[T] = + { + Nil + } + + abstract class M + { self => + type Settings + type selfType = M {type Settings = self.Settings} + + val v: List[selfType] = f[selfType]((x: selfType) => x.v) + } + + abstract class M2 + { self => + type Settings + type selfType = M2 {type Settings = self.Settings} + + def g: List[selfType] = Nil + + { + f[selfType](_.g) + } + } +} + diff --git a/tests/untried/pos/pos-bug1241.scala b/tests/untried/pos/pos-bug1241.scala new file mode 100644 index 000000000..be8615d32 --- /dev/null +++ b/tests/untried/pos/pos-bug1241.scala @@ -0,0 +1,8 @@ +object test extends App { + // more.. + type T = { def hello() } + //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/untried/pos/presuperContext.scala b/tests/untried/pos/presuperContext.scala new file mode 100644 index 000000000..cc3426307 --- /dev/null +++ b/tests/untried/pos/presuperContext.scala @@ -0,0 +1,13 @@ +class A { + class C extends { val x: A = this } with AnyRef +} + +class B(x: Int) + +class D { + class C(x: Int) extends B({val test: D = this; x}) { + def this() { + this({val test: D = this; 1}) + } + } +} diff --git a/tests/untried/pos/private-types-after-typer.scala b/tests/untried/pos/private-types-after-typer.scala new file mode 100644 index 000000000..5c20cac2a --- /dev/null +++ b/tests/untried/pos/private-types-after-typer.scala @@ -0,0 +1,9 @@ +// Testing that the type of the outer accessor in O2 +// doesn't crash the compiler over private type escaping scope. +trait T { + class C { + private object O1 { + object O2 + } + } +} diff --git a/tests/untried/pos/proj-rec-test.flags b/tests/untried/pos/proj-rec-test.flags new file mode 100644 index 000000000..ad928f52a --- /dev/null +++ b/tests/untried/pos/proj-rec-test.flags @@ -0,0 +1 @@ +-Yrecursion 1 diff --git a/tests/untried/pos/proj-rec-test.scala b/tests/untried/pos/proj-rec-test.scala new file mode 100644 index 000000000..b7efcf3e8 --- /dev/null +++ b/tests/untried/pos/proj-rec-test.scala @@ -0,0 +1,13 @@ +object ProjTest { + trait MInt { type Type } + trait _0 extends MInt { type Type = Boolean } + trait Succ[Pre <: MInt] extends MInt { type Type = Pre#Type } + + type _1 = Succ[_0] + type _2 = Succ[_1] + + type X1 = _0#Type // Ok + type X2 = _1#Type // Ok + type X3 = _2#Type // Compiler error, illegal cyclic reference involving type Type +} + diff --git a/tests/untried/pos/propagate.scala b/tests/untried/pos/propagate.scala new file mode 100644 index 000000000..588192079 --- /dev/null +++ b/tests/untried/pos/propagate.scala @@ -0,0 +1,16 @@ +class C { + + def f[a](x: a): a = { + + class D() { + def g(x: a) = f(x): a; + } + + new D().g(x); + + } + +} + + + diff --git a/tests/untried/pos/protected-static/J.java b/tests/untried/pos/protected-static/J.java new file mode 100644 index 000000000..502dc2c17 --- /dev/null +++ b/tests/untried/pos/protected-static/J.java @@ -0,0 +1,7 @@ +package bippy; + +public class J { + protected static String f() { + return "hi mom"; + } +}
\ No newline at end of file diff --git a/tests/untried/pos/protected-static/JavaClass.java b/tests/untried/pos/protected-static/JavaClass.java new file mode 100644 index 000000000..cd45a279c --- /dev/null +++ b/tests/untried/pos/protected-static/JavaClass.java @@ -0,0 +1,6 @@ +package bippy; + +public abstract class JavaClass { + protected static class Inner {} + protected abstract Inner getInner(); +} diff --git a/tests/untried/pos/protected-static/S.scala b/tests/untried/pos/protected-static/S.scala new file mode 100644 index 000000000..644633546 --- /dev/null +++ b/tests/untried/pos/protected-static/S.scala @@ -0,0 +1,7 @@ +package bippy + +object Test extends J { + def main(args: Array[String]): Unit = { + bippy.J.f() + } +} diff --git a/tests/untried/pos/protected-static/ScalaClass.scala b/tests/untried/pos/protected-static/ScalaClass.scala new file mode 100644 index 000000000..11108b890 --- /dev/null +++ b/tests/untried/pos/protected-static/ScalaClass.scala @@ -0,0 +1,6 @@ +import bippy.JavaClass + +class Implementor extends JavaClass { + import JavaClass.Inner + def getInner: Inner = null +} diff --git a/tests/untried/pos/protected-t1010.scala b/tests/untried/pos/protected-t1010.scala new file mode 100644 index 000000000..8575ddaaf --- /dev/null +++ b/tests/untried/pos/protected-t1010.scala @@ -0,0 +1,27 @@ +/** Check protected accessors involving polymorphic methods. */ + +package pkg2 { + +trait PresentationsX extends pkg1.Presentations { + trait ProjectImpl extends super.ProjectImpl { + trait FileImpl extends super.FileImpl { + lockTyper(Console.println) + } + } +} + +} // pkg2 + +package pkg1 { + +trait Presentations { + trait ProjectImpl { + trait FileImpl + protected def lockTyper[T](f : => T) = { + if (this == null) None + else Some(f) + } + } +} + +} // pkg1 diff --git a/tests/untried/pos/rangepos-anonapply.flags b/tests/untried/pos/rangepos-anonapply.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/rangepos-anonapply.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/rangepos-anonapply.scala b/tests/untried/pos/rangepos-anonapply.scala new file mode 100644 index 000000000..0fd04855e --- /dev/null +++ b/tests/untried/pos/rangepos-anonapply.scala @@ -0,0 +1,9 @@ +class Test { + trait PropTraverser { + def apply(x: Int): Unit = {} + } + + def gather(x: Int): Unit = { + (new PropTraverser {})(x) + } +} diff --git a/tests/untried/pos/rangepos-patmat.flags b/tests/untried/pos/rangepos-patmat.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/rangepos-patmat.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/rangepos-patmat.scala b/tests/untried/pos/rangepos-patmat.scala new file mode 100644 index 000000000..98c842aaf --- /dev/null +++ b/tests/untried/pos/rangepos-patmat.scala @@ -0,0 +1,4 @@ +class Foo { + def test: PartialFunction[Any, String] = { case _ => "ok" } + +} diff --git a/tests/untried/pos/rangepos.flags b/tests/untried/pos/rangepos.flags new file mode 100644 index 000000000..fcf951d90 --- /dev/null +++ b/tests/untried/pos/rangepos.flags @@ -0,0 +1 @@ +-Yrangepos
\ No newline at end of file diff --git a/tests/untried/pos/rangepos.scala b/tests/untried/pos/rangepos.scala new file mode 100644 index 000000000..623b096ac --- /dev/null +++ b/tests/untried/pos/rangepos.scala @@ -0,0 +1,5 @@ +class Foo(val x: Double) extends AnyVal { } + +object Pretty { + def f(s1: String) = new { def bar = 5 } +} diff --git a/tests/untried/pos/raw-map/J_1.java b/tests/untried/pos/raw-map/J_1.java new file mode 100644 index 000000000..bd43bcac8 --- /dev/null +++ b/tests/untried/pos/raw-map/J_1.java @@ -0,0 +1,4 @@ +public class J_1 { + public void setRawType(java.util.Map x) { + } +} diff --git a/tests/untried/pos/raw-map/S_2.scala b/tests/untried/pos/raw-map/S_2.scala new file mode 100644 index 000000000..d2886fdce --- /dev/null +++ b/tests/untried/pos/raw-map/S_2.scala @@ -0,0 +1,6 @@ +class Foo { + def foo: Unit = { + val x: J_1 = null + x.setRawType(new java.util.HashMap) + } +} diff --git a/tests/untried/pos/rebind.scala b/tests/untried/pos/rebind.scala new file mode 100644 index 000000000..faedcc9bc --- /dev/null +++ b/tests/untried/pos/rebind.scala @@ -0,0 +1,13 @@ +abstract class Foo { + class Inner { + def inner: Int = 1 + } + def foo: Inner +} +trait Bar { + type Inner + def foo: Inner = foo +} +class Test extends Foo with Bar { + println(foo.inner) +} diff --git a/tests/untried/pos/reflection-compat-api-universe.check b/tests/untried/pos/reflection-compat-api-universe.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/reflection-compat-api-universe.check diff --git a/tests/untried/pos/reflection-compat-api-universe.scala b/tests/untried/pos/reflection-compat-api-universe.scala new file mode 100644 index 000000000..0add9704c --- /dev/null +++ b/tests/untried/pos/reflection-compat-api-universe.scala @@ -0,0 +1,136 @@ +object Test extends App { + val u: scala.reflect.api.Universe = ??? + import u._ + import scala.reflect.ClassTag + import compat._ + + val tree: Tree = ??? + val ttree: TypeTree = ??? + val stree: SymTree = ??? + val trees: List[Tree] = ??? + val mods: Modifiers = ??? + val impl: Template = ??? + val vparamss: List[List[ValDef]] = ??? + val rhs: Tree = ??? + val sym: Symbol = ??? + val tsym: TypeSymbol = ??? + val syms: List[Symbol] = ??? + val params: List[Symbol] = ??? + val tparams: List[Symbol] = ??? + val tpe: Type = ??? + val tpes: List[Type] = ??? + val manifest: Manifest[Int] = ??? + val tag: TypeTag[Int] = ??? + val mirror: Mirror = ??? + val decls: Scope = ??? + val pos: Position = ??? + val ann: Annotation = ??? + val anns: List[Annotation] = ??? + val const: Constant = ??? + val name: Name = ??? + val tyname: TypeName = ??? + val tename: TermName = ??? + val flags: FlagSet = ??? + val str: String = ??? + val i: Int = ??? + val b: Boolean = ??? + + // abstract class BuildApi + // abstract class ReferenceToBoxedExtractor + // abstract trait AttachableApi + // abstract trait FreeTermSymbolApi + // abstract trait FreeTypeSymbolApi + // abstract trait IdentContextApi + // abstract trait ReferenceToBoxedApi + // abstract trait SymTreeContextApi + // abstract trait SymbolContextApi + // abstract trait TreeContextApi + // abstract trait TypeTreeContextApi + locally(ClassDef(sym, impl): ClassDef) + locally(DefDef(sym, mods, vparamss, rhs): DefDef) + locally(DefDef(sym, vparamss, rhs): DefDef) + locally(DefDef(sym, mods, rhs): DefDef) + locally(DefDef(sym, rhs): DefDef) + locally(DefDef(sym, (??? : List[List[Symbol]] => Tree)): DefDef) + locally(LabelDef(sym, params, rhs): LabelDef) + locally(ModuleDef(sym, impl): ModuleDef) + locally(TypeDef(sym, rhs): TypeDef) + locally(TypeDef(sym): TypeDef) + locally(ValDef(sym, rhs): ValDef) + locally(ValDef(sym): ValDef) + locally(AnnotatedType(anns, tpe): AnnotatedType) + locally(BoundedWildcardType(??? : TypeBounds): BoundedWildcardType) + locally(TypeBounds(tpe, tpe): TypeBounds) + locally(MethodType(params, tpe): MethodType) + locally(RefinedType(tpes, decls): RefinedType) + locally(RefinedType(tpes, decls, sym): RefinedType) + locally(ClassInfoType(tpes, decls, sym): ClassInfoType) + locally(SingleType(tpe, sym): Type) + locally(TypeRef(tpe, sym, tpes): Type) + locally(ExistentialType(syms, tpe): ExistentialType) + locally(NullaryMethodType(tpe): NullaryMethodType) + locally(ThisType(sym): Type) + locally(SuperType(tpe, tpe): Type) + locally(PolyType(syms, tpe): PolyType) + locally(ConstantType(const): ConstantType) + locally(sym.asFreeTerm: FreeTermSymbol) + locally(sym.asFreeType: FreeTypeSymbol) + locally(existentialAbstraction(tparams, tpe): Type) + locally(tree.freeTerms: List[FreeTermSymbol]) + locally(tree.freeTypes: List[FreeTypeSymbol]) + locally(intersectionType(tpes): Type) + locally(intersectionType(tpes, sym): Type) + locally(sym.isErroneous: Boolean) + locally(sym.isFreeTerm: Boolean) + locally(sym.isFreeType: Boolean) + locally(sym.isLocal: Boolean) + locally(sym.isOverride: Boolean) + locally(tsym.isSkolem: Boolean) + locally(manifestToTypeTag(mirror, manifest): scala.reflect.api.Universe#TypeTag[Int]) + locally(mkImporter(scala.reflect.runtime.universe): Importer{val from: scala.reflect.runtime.universe.type}) + locally(sym.newClassSymbol(tyname, pos, flags): ClassSymbol) + locally(sym.newMethodSymbol(tename, pos, flags): MethodSymbol) + locally(sym.newModuleAndClassSymbol(name, pos, flags): (ModuleSymbol, ClassSymbol)) + locally(newScopeWith(sym, sym, sym): Scope) + locally(sym.newTermSymbol(tename, pos, flags): TermSymbol) + locally(sym.newTypeSymbol(tyname, pos, flags): TypeSymbol) + locally(polyType(tparams, tpe): Type) + locally(sym.pos: Position) + locally(refinedType(tpes, sym): Type) + locally(refinedType(tpes, sym, decls, pos): Type) + locally(singleType(tpe, sym): Type) + locally(tree.substituteSymbols(syms, syms): Tree) + locally(tree.substituteThis(sym, tree): Tree) + locally(tree.substituteTypes(syms, tpes): Tree) + locally(typeRef(tpe, sym, tpes): Type) + locally(typeTagToManifest(mirror, tag): Manifest[Int]) + locally(FreeTermSymbolTag: ClassTag[FreeTermSymbol]) + locally((??? : FreeTermSymbol).origin) + locally((??? : FreeTermSymbol).value) + locally(FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]) + locally((??? : FreeTypeSymbol).origin) + locally(ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]) + locally(build: BuildApi) + locally(ReferenceToBoxed(??? : Ident): ReferenceToBoxed) + locally((??? : ReferenceToBoxed).ident: Tree) + locally(ReferenceToBoxed.unapply(???): Option[Ident]) + locally(build.selectType(sym, str): TypeSymbol) + locally(build.selectTerm(sym, str): TermSymbol) + locally(build.selectOverloadedMethod(sym, str, i): MethodSymbol) + locally(build.newNestedSymbol(sym, name, pos, flags, b): Symbol) + locally(build.newFreeTerm(str, i): FreeTermSymbol) + locally(build.newFreeTerm(str, i, flags, str): FreeTermSymbol) + locally(build.newFreeType(str): FreeTypeSymbol) + locally(build.newFreeType(str, flags, str): FreeTypeSymbol) + locally(build.setTypeSignature(sym, tpe): Symbol) + locally(build.setAnnotations(sym, anns): Symbol) + locally(build.flagsFromBits(??? : Long): FlagSet) + locally(build.emptyValDef: ValDef) + locally(build.This(sym): Tree) + locally(build.Select(tree, sym): Select) + locally(build.Ident(sym): Ident) + locally(build.TypeTree(tpe): TypeTree) + locally(build.thisPrefix(sym): Type) + locally(build.setType(tree, tpe): Tree) + locally(build.setSymbol(tree, sym): Tree) +} diff --git a/tests/untried/pos/reflection-compat-c.check b/tests/untried/pos/reflection-compat-c.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/reflection-compat-c.check diff --git a/tests/untried/pos/reflection-compat-c.scala b/tests/untried/pos/reflection-compat-c.scala new file mode 100644 index 000000000..f5e3b0129 --- /dev/null +++ b/tests/untried/pos/reflection-compat-c.scala @@ -0,0 +1,139 @@ +import scala.reflect.macros.Context + +object Test extends App { + def impl(c: Context) = { + import c.universe._ + import scala.reflect.ClassTag + import compat._ + + val tree: Tree = ??? + val ttree: TypeTree = ??? + val stree: SymTree = ??? + val trees: List[Tree] = ??? + val mods: Modifiers = ??? + val impl: Template = ??? + val vparamss: List[List[ValDef]] = ??? + val rhs: Tree = ??? + val sym: Symbol = ??? + val tsym: TypeSymbol = ??? + val syms: List[Symbol] = ??? + val params: List[Symbol] = ??? + val tparams: List[Symbol] = ??? + val tpe: Type = ??? + val tpes: List[Type] = ??? + val manifest: Manifest[Int] = ??? + val tag: TypeTag[Int] = ??? + val mirror: Mirror = ??? + val decls: Scope = ??? + val pos: Position = ??? + val ann: Annotation = ??? + val anns: List[Annotation] = ??? + val const: Constant = ??? + val name: Name = ??? + val tyname: TypeName = ??? + val tename: TermName = ??? + val flags: FlagSet = ??? + val str: String = ??? + val i: Int = ??? + val b: Boolean = ??? + + // abstract class BuildApi + // abstract class ReferenceToBoxedExtractor + // abstract trait AttachableApi + // abstract trait FreeTermSymbolApi + // abstract trait FreeTypeSymbolApi + // abstract trait IdentContextApi + // abstract trait ReferenceToBoxedApi + // abstract trait SymTreeContextApi + // abstract trait SymbolContextApi + // abstract trait TreeContextApi + // abstract trait TypeTreeContextApi + locally(ClassDef(sym, impl): ClassDef) + locally(DefDef(sym, mods, vparamss, rhs): DefDef) + locally(DefDef(sym, vparamss, rhs): DefDef) + locally(DefDef(sym, mods, rhs): DefDef) + locally(DefDef(sym, rhs): DefDef) + locally(DefDef(sym, (??? : List[List[Symbol]] => Tree)): DefDef) + locally(LabelDef(sym, params, rhs): LabelDef) + locally(ModuleDef(sym, impl): ModuleDef) + locally(TypeDef(sym, rhs): TypeDef) + locally(TypeDef(sym): TypeDef) + locally(ValDef(sym, rhs): ValDef) + locally(ValDef(sym): ValDef) + locally(AnnotatedType(anns, tpe): AnnotatedType) + locally(BoundedWildcardType(??? : TypeBounds): BoundedWildcardType) + locally(TypeBounds(tpe, tpe): TypeBounds) + locally(MethodType(params, tpe): MethodType) + locally(RefinedType(tpes, decls): RefinedType) + locally(RefinedType(tpes, decls, sym): RefinedType) + locally(ClassInfoType(tpes, decls, sym): ClassInfoType) + locally(SingleType(tpe, sym): Type) + locally(TypeRef(tpe, sym, tpes): Type) + locally(ExistentialType(syms, tpe): ExistentialType) + locally(NullaryMethodType(tpe): NullaryMethodType) + locally(ThisType(sym): Type) + locally(SuperType(tpe, tpe): Type) + locally(PolyType(syms, tpe): PolyType) + locally(ConstantType(const): ConstantType) + locally(sym.asFreeTerm: FreeTermSymbol) + locally(sym.asFreeType: FreeTypeSymbol) + locally(existentialAbstraction(tparams, tpe): Type) + locally(tree.freeTerms: List[FreeTermSymbol]) + locally(tree.freeTypes: List[FreeTypeSymbol]) + locally(intersectionType(tpes): Type) + locally(intersectionType(tpes, sym): Type) + locally(sym.isErroneous: Boolean) + locally(sym.isFreeTerm: Boolean) + locally(sym.isFreeType: Boolean) + locally(sym.isLocal: Boolean) + locally(sym.isOverride: Boolean) + locally(tsym.isSkolem: Boolean) + locally(manifestToTypeTag(mirror, manifest): scala.reflect.api.Universe#TypeTag[Int]) + locally(mkImporter(scala.reflect.runtime.universe): Importer{val from: scala.reflect.runtime.universe.type}) + locally(sym.newClassSymbol(tyname, pos, flags): ClassSymbol) + locally(sym.newMethodSymbol(tename, pos, flags): MethodSymbol) + locally(sym.newModuleAndClassSymbol(name, pos, flags): (ModuleSymbol, ClassSymbol)) + locally(newScopeWith(sym, sym, sym): Scope) + locally(sym.newTermSymbol(tename, pos, flags): TermSymbol) + locally(sym.newTypeSymbol(tyname, pos, flags): TypeSymbol) + locally(polyType(tparams, tpe): Type) + locally(sym.pos: Position) + locally(refinedType(tpes, sym): Type) + locally(refinedType(tpes, sym, decls, pos): Type) + locally(singleType(tpe, sym): Type) + locally(tree.substituteSymbols(syms, syms): Tree) + locally(tree.substituteThis(sym, tree): Tree) + locally(tree.substituteTypes(syms, tpes): Tree) + locally(typeRef(tpe, sym, tpes): Type) + locally(typeTagToManifest(mirror, tag): Manifest[Int]) + locally(FreeTermSymbolTag: ClassTag[FreeTermSymbol]) + locally((??? : FreeTermSymbol).origin) + locally((??? : FreeTermSymbol).value) + locally(FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]) + locally((??? : FreeTypeSymbol).origin) + locally(ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]) + locally(build: BuildApi) + locally(ReferenceToBoxed(??? : Ident): ReferenceToBoxed) + locally((??? : ReferenceToBoxed).ident: Tree) + locally(ReferenceToBoxed.unapply(???): Option[Ident]) + locally(build.selectType(sym, str): TypeSymbol) + locally(build.selectTerm(sym, str): TermSymbol) + locally(build.selectOverloadedMethod(sym, str, i): MethodSymbol) + locally(build.newNestedSymbol(sym, name, pos, flags, b): Symbol) + locally(build.newFreeTerm(str, i): FreeTermSymbol) + locally(build.newFreeTerm(str, i, flags, str): FreeTermSymbol) + locally(build.newFreeType(str): FreeTypeSymbol) + locally(build.newFreeType(str, flags, str): FreeTypeSymbol) + locally(build.setTypeSignature(sym, tpe): Symbol) + locally(build.setAnnotations(sym, anns): Symbol) + locally(build.flagsFromBits(??? : Long): FlagSet) + locally(build.emptyValDef: ValDef) + locally(build.This(sym): Tree) + locally(build.Select(tree, sym): Select) + locally(build.Ident(sym): Ident) + locally(build.TypeTree(tpe): TypeTree) + locally(build.thisPrefix(sym): Type) + locally(build.setType(tree, tpe): Tree) + locally(build.setSymbol(tree, sym): Tree) + } +} diff --git a/tests/untried/pos/reflection-compat-macro-universe.check b/tests/untried/pos/reflection-compat-macro-universe.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/reflection-compat-macro-universe.check diff --git a/tests/untried/pos/reflection-compat-macro-universe.scala b/tests/untried/pos/reflection-compat-macro-universe.scala new file mode 100644 index 000000000..028d8b129 --- /dev/null +++ b/tests/untried/pos/reflection-compat-macro-universe.scala @@ -0,0 +1,177 @@ +object Test extends App { + val u: scala.reflect.macros.Universe = ??? + import u._ + import scala.reflect.macros.Attachments + import scala.reflect.ClassTag + import compat._ + + val tree: Tree = ??? + val ttree: TypeTree = ??? + val stree: SymTree = ??? + val trees: List[Tree] = ??? + val mods: Modifiers = ??? + val impl: Template = ??? + val vparamss: List[List[ValDef]] = ??? + val rhs: Tree = ??? + val sym: Symbol = ??? + val tsym: TypeSymbol = ??? + val syms: List[Symbol] = ??? + val params: List[Symbol] = ??? + val tparams: List[Symbol] = ??? + val tpe: Type = ??? + val tpes: List[Type] = ??? + val manifest: Manifest[Int] = ??? + val tag: TypeTag[Int] = ??? + val mirror: Mirror = ??? + val decls: Scope = ??? + val pos: Position = ??? + val ann: Annotation = ??? + val anns: List[Annotation] = ??? + val const: Constant = ??? + val name: Name = ??? + val tyname: TypeName = ??? + val tename: TermName = ??? + val flags: FlagSet = ??? + val str: String = ??? + val i: Int = ??? + val b: Boolean = ??? + + // abstract class BuildApi + // abstract class ReferenceToBoxedExtractor + // abstract trait AttachableApi + // abstract trait FreeTermSymbolApi + // abstract trait FreeTypeSymbolApi + // abstract trait IdentContextApi + // abstract trait ReferenceToBoxedApi + // abstract trait SymTreeContextApi + // abstract trait SymbolContextApi + // abstract trait TreeContextApi + // abstract trait TypeTreeContextApi + locally(ClassDef(sym, impl): ClassDef) + locally(DefDef(sym, mods, vparamss, rhs): DefDef) + locally(DefDef(sym, vparamss, rhs): DefDef) + locally(DefDef(sym, mods, rhs): DefDef) + locally(DefDef(sym, rhs): DefDef) + locally(DefDef(sym, (??? : List[List[Symbol]] => Tree)): DefDef) + locally(LabelDef(sym, params, rhs): LabelDef) + locally(ModuleDef(sym, impl): ModuleDef) + locally(TypeDef(sym, rhs): TypeDef) + locally(TypeDef(sym): TypeDef) + locally(ValDef(sym, rhs): ValDef) + locally(ValDef(sym): ValDef) + locally(AnnotatedType(anns, tpe): AnnotatedType) + locally(BoundedWildcardType(??? : TypeBounds): BoundedWildcardType) + locally(TypeBounds(tpe, tpe): TypeBounds) + locally(MethodType(params, tpe): MethodType) + locally(RefinedType(tpes, decls): RefinedType) + locally(RefinedType(tpes, decls, sym): RefinedType) + locally(ClassInfoType(tpes, decls, sym): ClassInfoType) + locally(SingleType(tpe, sym): Type) + locally(TypeRef(tpe, sym, tpes): Type) + locally(ExistentialType(syms, tpe): ExistentialType) + locally(NullaryMethodType(tpe): NullaryMethodType) + locally(ThisType(sym): Type) + locally(SuperType(tpe, tpe): Type) + locally(PolyType(syms, tpe): PolyType) + locally(ConstantType(const): ConstantType) + locally(sym.asFreeTerm: FreeTermSymbol) + locally(sym.asFreeType: FreeTypeSymbol) + locally(sym.attachments: Attachments { type Pos = Position }) + locally(tree.attachments: Attachments { type Pos = Position }) + locally(captureVariable(sym): Unit) + locally(capturedVariableType(sym): Type) + locally(sym.deSkolemize: Symbol) + locally(tree.defineType(tpe): Tree) + locally(existentialAbstraction(tparams, tpe): Type) + locally(tree.freeTerms: List[FreeTermSymbol]) + locally(tree.freeTypes: List[FreeTypeSymbol]) + locally(intersectionType(tpes): Type) + locally(intersectionType(tpes, sym): Type) + locally(sym.isErroneous: Boolean) + locally(sym.isFreeTerm: Boolean) + locally(sym.isFreeType: Boolean) + locally(sym.isLocal: Boolean) + locally(sym.isOverride: Boolean) + locally(tsym.isSkolem: Boolean) + locally(manifestToTypeTag(mirror, manifest): scala.reflect.api.Universe#TypeTag[Int]) + locally(treeBuild.mkAttributedIdent(sym): RefTree) + locally(treeBuild.mkAttributedQualifier(tpe): Tree) + locally(treeBuild.mkAttributedQualifier(tpe, sym): Tree) + locally(treeBuild.mkAttributedRef(tpe, sym): RefTree) + locally(treeBuild.mkAttributedRef(sym): RefTree) + locally(treeBuild.mkAttributedSelect(tree, sym): RefTree) + locally(treeBuild.mkAttributedThis(sym): This) + locally(mkImporter(scala.reflect.runtime.universe): Importer{val from: scala.reflect.runtime.universe.type}) + locally(treeBuild.mkMethodCall(sym, trees): Tree) + locally(treeBuild.mkMethodCall(sym, tpes, trees): Tree) + locally(treeBuild.mkMethodCall(sym, name, trees): Tree) + locally(treeBuild.mkMethodCall(sym, name, tpes, trees): Tree) + locally(treeBuild.mkMethodCall(tree, sym, tpes, trees): Tree) + locally(treeBuild.mkMethodCall(tree, trees): Tree) + locally(treeBuild.mkMethodCall(tree, tpes, trees): Tree) + locally(treeBuild.mkNullaryCall(sym, tpes): Tree) + locally(treeBuild.mkRuntimeUniverseRef: Tree) + locally(treeBuild.mkUnattributedRef(name): RefTree) + locally(treeBuild.mkUnattributedRef(sym): RefTree) + locally(sym.newClassSymbol(tyname, pos, flags): ClassSymbol) + locally(sym.newMethodSymbol(tename, pos, flags): MethodSymbol) + locally(sym.newModuleAndClassSymbol(name, pos, flags): (ModuleSymbol, ClassSymbol)) + locally(newScopeWith(sym, sym, sym): Scope) + locally(sym.newTermSymbol(tename, pos, flags): TermSymbol) + locally(sym.newTypeSymbol(tyname, pos, flags): TypeSymbol) + locally(polyType(tparams, tpe): Type) + locally(sym.pos: Position) + locally((tree.pos = pos): Unit) + locally(referenceCapturedVariable(sym): Tree) + locally(refinedType(tpes, sym): Type) + locally(refinedType(tpes, sym, decls, pos): Type) + locally(sym.removeAttachment[Int]: Symbol) + locally(tree.removeAttachment[Int]: Tree) + locally(sym.setAnnotations(ann, ann, ann): Symbol) + locally(sym.setName(name): Symbol) + locally(ttree.setOriginal(tree): TypeTree) + locally(tree.setPos(pos): Tree) + locally(sym.setPrivateWithin(sym): Symbol) + locally(tree.setSymbol(sym): Tree) + locally(tree.setType(tpe): Tree) + locally(sym.setTypeSignature(tpe): Symbol) + locally(singleType(tpe, sym): Type) + locally(tree.substituteSymbols(syms, syms): Tree) + locally(tree.substituteThis(sym, tree): Tree) + locally(tree.substituteTypes(syms, tpes): Tree) + locally((tree.symbol = sym): Unit) + locally((tree.tpe = tpe): Unit) + locally(typeRef(tpe, sym, tpes): Type) + locally(typeTagToManifest(mirror, tag): Manifest[Int]) + locally(sym.updateAttachment(42): Symbol) + locally(tree.updateAttachment(42): Tree) + locally(FreeTermSymbolTag: ClassTag[FreeTermSymbol]) + locally((??? : FreeTermSymbol).origin) + locally((??? : FreeTermSymbol).value) + locally(FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]) + locally((??? : FreeTypeSymbol).origin) + locally(ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]) + locally(build: BuildApi) + locally(ReferenceToBoxed(??? : Ident): ReferenceToBoxed) + locally((??? : ReferenceToBoxed).ident: Tree) + locally(ReferenceToBoxed.unapply(???): Option[Ident]) + locally(build.selectType(sym, str): TypeSymbol) + locally(build.selectTerm(sym, str): TermSymbol) + locally(build.selectOverloadedMethod(sym, str, i): MethodSymbol) + locally(build.newNestedSymbol(sym, name, pos, flags, b): Symbol) + locally(build.newFreeTerm(str, i): FreeTermSymbol) + locally(build.newFreeTerm(str, i, flags, str): FreeTermSymbol) + locally(build.newFreeType(str): FreeTypeSymbol) + locally(build.newFreeType(str, flags, str): FreeTypeSymbol) + locally(build.setTypeSignature(sym, tpe): Symbol) + locally(build.setAnnotations(sym, anns): Symbol) + locally(build.flagsFromBits(??? : Long): FlagSet) + locally(build.emptyValDef: ValDef) + locally(build.This(sym): Tree) + locally(build.Select(tree, sym): Select) + locally(build.Ident(sym): Ident) + locally(build.TypeTree(tpe): TypeTree) + locally(build.thisPrefix(sym): Type) + locally(build.setType(tree, tpe): Tree) + locally(build.setSymbol(tree, sym): Tree) +} diff --git a/tests/untried/pos/reflection-compat-ru.check b/tests/untried/pos/reflection-compat-ru.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/reflection-compat-ru.check diff --git a/tests/untried/pos/reflection-compat-ru.scala b/tests/untried/pos/reflection-compat-ru.scala new file mode 100644 index 000000000..f3f493fba --- /dev/null +++ b/tests/untried/pos/reflection-compat-ru.scala @@ -0,0 +1,135 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + import scala.reflect.ClassTag + import compat._ + + val tree: Tree = ??? + val ttree: TypeTree = ??? + val stree: SymTree = ??? + val trees: List[Tree] = ??? + val mods: Modifiers = ??? + val impl: Template = ??? + val vparamss: List[List[ValDef]] = ??? + val rhs: Tree = ??? + val sym: Symbol = ??? + val tsym: TypeSymbol = ??? + val syms: List[Symbol] = ??? + val params: List[Symbol] = ??? + val tparams: List[Symbol] = ??? + val tpe: Type = ??? + val tpes: List[Type] = ??? + val manifest: Manifest[Int] = ??? + val tag: TypeTag[Int] = ??? + val mirror: Mirror = ??? + val decls: Scope = ??? + val pos: Position = ??? + val ann: Annotation = ??? + val anns: List[Annotation] = ??? + val const: Constant = ??? + val name: Name = ??? + val tyname: TypeName = ??? + val tename: TermName = ??? + val flags: FlagSet = ??? + val str: String = ??? + val i: Int = ??? + val b: Boolean = ??? + + // abstract class BuildApi + // abstract class ReferenceToBoxedExtractor + // abstract trait AttachableApi + // abstract trait FreeTermSymbolApi + // abstract trait FreeTypeSymbolApi + // abstract trait IdentContextApi + // abstract trait ReferenceToBoxedApi + // abstract trait SymTreeContextApi + // abstract trait SymbolContextApi + // abstract trait TreeContextApi + // abstract trait TypeTreeContextApi + locally(ClassDef(sym, impl): ClassDef) + locally(DefDef(sym, mods, vparamss, rhs): DefDef) + locally(DefDef(sym, vparamss, rhs): DefDef) + locally(DefDef(sym, mods, rhs): DefDef) + locally(DefDef(sym, rhs): DefDef) + locally(DefDef(sym, (??? : List[List[Symbol]] => Tree)): DefDef) + locally(LabelDef(sym, params, rhs): LabelDef) + locally(ModuleDef(sym, impl): ModuleDef) + locally(TypeDef(sym, rhs): TypeDef) + locally(TypeDef(sym): TypeDef) + locally(ValDef(sym, rhs): ValDef) + locally(ValDef(sym): ValDef) + locally(AnnotatedType(anns, tpe): AnnotatedType) + locally(BoundedWildcardType(??? : TypeBounds): BoundedWildcardType) + locally(TypeBounds(tpe, tpe): TypeBounds) + locally(MethodType(params, tpe): MethodType) + locally(RefinedType(tpes, decls): RefinedType) + locally(RefinedType(tpes, decls, sym): RefinedType) + locally(ClassInfoType(tpes, decls, sym): ClassInfoType) + locally(SingleType(tpe, sym): Type) + locally(TypeRef(tpe, sym, tpes): Type) + locally(ExistentialType(syms, tpe): ExistentialType) + locally(NullaryMethodType(tpe): NullaryMethodType) + locally(ThisType(sym): Type) + locally(SuperType(tpe, tpe): Type) + locally(PolyType(syms, tpe): PolyType) + locally(ConstantType(const): ConstantType) + locally(sym.asFreeTerm: FreeTermSymbol) + locally(sym.asFreeType: FreeTypeSymbol) + locally(existentialAbstraction(tparams, tpe): Type) + locally(tree.freeTerms: List[FreeTermSymbol]) + locally(tree.freeTypes: List[FreeTypeSymbol]) + locally(intersectionType(tpes): Type) + locally(intersectionType(tpes, sym): Type) + locally(sym.isErroneous: Boolean) + locally(sym.isFreeTerm: Boolean) + locally(sym.isFreeType: Boolean) + locally(sym.isLocal: Boolean) + locally(sym.isOverride: Boolean) + locally(tsym.isSkolem: Boolean) + locally(manifestToTypeTag(mirror, manifest): scala.reflect.api.Universe#TypeTag[Int]) + locally(mkImporter(scala.reflect.runtime.universe): Importer{val from: scala.reflect.runtime.universe.type}) + locally(sym.newClassSymbol(tyname, pos, flags): ClassSymbol) + locally(sym.newMethodSymbol(tename, pos, flags): MethodSymbol) + locally(sym.newModuleAndClassSymbol(name, pos, flags): (ModuleSymbol, ClassSymbol)) + locally(newScopeWith(sym, sym, sym): Scope) + locally(sym.newTermSymbol(tename, pos, flags): TermSymbol) + locally(sym.newTypeSymbol(tyname, pos, flags): TypeSymbol) + locally(polyType(tparams, tpe): Type) + locally(sym.pos: Position) + locally(refinedType(tpes, sym): Type) + locally(refinedType(tpes, sym, decls, pos): Type) + locally(singleType(tpe, sym): Type) + locally(tree.substituteSymbols(syms, syms): Tree) + locally(tree.substituteThis(sym, tree): Tree) + locally(tree.substituteTypes(syms, tpes): Tree) + locally(typeRef(tpe, sym, tpes): Type) + locally(typeTagToManifest(mirror, tag): Manifest[Int]) + locally(FreeTermSymbolTag: ClassTag[FreeTermSymbol]) + locally((??? : FreeTermSymbol).origin) + locally((??? : FreeTermSymbol).value) + locally(FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]) + locally((??? : FreeTypeSymbol).origin) + locally(ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]) + locally(build: BuildApi) + locally(ReferenceToBoxed(??? : Ident): ReferenceToBoxed) + locally((??? : ReferenceToBoxed).ident: Tree) + locally(ReferenceToBoxed.unapply(???): Option[Ident]) + locally(build.selectType(sym, str): TypeSymbol) + locally(build.selectTerm(sym, str): TermSymbol) + locally(build.selectOverloadedMethod(sym, str, i): MethodSymbol) + locally(build.newNestedSymbol(sym, name, pos, flags, b): Symbol) + locally(build.newFreeTerm(str, i): FreeTermSymbol) + locally(build.newFreeTerm(str, i, flags, str): FreeTermSymbol) + locally(build.newFreeType(str): FreeTypeSymbol) + locally(build.newFreeType(str, flags, str): FreeTypeSymbol) + locally(build.setTypeSignature(sym, tpe): Symbol) + locally(build.setAnnotations(sym, anns): Symbol) + locally(build.flagsFromBits(??? : Long): FlagSet) + locally(build.emptyValDef: ValDef) + locally(build.This(sym): Tree) + locally(build.Select(tree, sym): Select) + locally(build.Ident(sym): Ident) + locally(build.TypeTree(tpe): TypeTree) + locally(build.thisPrefix(sym): Type) + locally(build.setType(tree, tpe): Tree) + locally(build.setSymbol(tree, sym): Tree) +} diff --git a/tests/untried/pos/relax_implicit_divergence.scala b/tests/untried/pos/relax_implicit_divergence.scala new file mode 100644 index 000000000..f17d0239d --- /dev/null +++ b/tests/untried/pos/relax_implicit_divergence.scala @@ -0,0 +1,7 @@ +class A(val options: Seq[String]) + +object Test { + implicit def ss: Equiv[Seq[String]] = sys.error("dummy") + implicit def equivA(implicit seqEq: Equiv[Seq[String]]): Equiv[A] = sys.error("dummy") + implicitly[Equiv[A]] +} diff --git a/tests/untried/pos/return_thistype.scala b/tests/untried/pos/return_thistype.scala new file mode 100644 index 000000000..c0736c0ad --- /dev/null +++ b/tests/untried/pos/return_thistype.scala @@ -0,0 +1,8 @@ +// tests transformation of return type in typedTypeApply (see also tcpoly_gm.scala) +class As { + class A { + def foo: A.this.type = bar.asInstanceOf[A.this.type] + def foo2: this.type = bar.asInstanceOf[this.type] + def bar: A = null + } +} diff --git a/tests/untried/pos/sammy_poly.flags b/tests/untried/pos/sammy_poly.flags new file mode 100644 index 000000000..48fd86716 --- /dev/null +++ b/tests/untried/pos/sammy_poly.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/pos/sammy_poly.scala b/tests/untried/pos/sammy_poly.scala new file mode 100644 index 000000000..f43fa292c --- /dev/null +++ b/tests/untried/pos/sammy_poly.scala @@ -0,0 +1,7 @@ +// test synthesizeSAMFunction where the sam type is not fully defined +class T { + trait F[T, U] { def apply(x: T): U } + // NOTE: the f(x) desugaring for now assumes the single abstract method is called 'apply' + def app[T, U](x: T)(f: F[T, U]): U = f(x) + app(1)(x => List(x)) +} diff --git a/tests/untried/pos/sammy_scope.flags b/tests/untried/pos/sammy_scope.flags new file mode 100644 index 000000000..48fd86716 --- /dev/null +++ b/tests/untried/pos/sammy_scope.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/pos/sammy_scope.scala b/tests/untried/pos/sammy_scope.scala new file mode 100644 index 000000000..79b85f3b0 --- /dev/null +++ b/tests/untried/pos/sammy_scope.scala @@ -0,0 +1,8 @@ +// test synthesizeSAMFunction: scope hygiene +abstract class SamFun[T1, R] { self => + def apply(v1: T1): R + + // this should type check, as the apply ref is equivalent to self.apply + // it shouldn't resolve to the sam's apply that's synthesized (that wouldn't type check, hence the pos test) + def compose[A](g: SamFun[A, T1]): SamFun[A, R] = { x => apply(g(x)) } +} diff --git a/tests/untried/pos/sammy_single.flags b/tests/untried/pos/sammy_single.flags new file mode 100644 index 000000000..48fd86716 --- /dev/null +++ b/tests/untried/pos/sammy_single.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/pos/sammy_single.scala b/tests/untried/pos/sammy_single.scala new file mode 100644 index 000000000..c64e9c2b0 --- /dev/null +++ b/tests/untried/pos/sammy_single.scala @@ -0,0 +1,9 @@ +// test that dependent types work +// TODO: def apply(x: String): x.type does NOT work yet +object Test { + val s: String = "" + + trait T { def apply(x: s.type): s.type } + + val preservedResult: s.type = ((x => x): T)(s) +} diff --git a/tests/untried/pos/sammy_twice.flags b/tests/untried/pos/sammy_twice.flags new file mode 100644 index 000000000..48fd86716 --- /dev/null +++ b/tests/untried/pos/sammy_twice.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/pos/sammy_twice.scala b/tests/untried/pos/sammy_twice.scala new file mode 100644 index 000000000..088106e9c --- /dev/null +++ b/tests/untried/pos/sammy_twice.scala @@ -0,0 +1,9 @@ +// test repeated synthesizeSAMFunction where the sam type is not fully defined +// the naive implementation would enter the same apply$body in the same scope twice +trait F[T, U] { def apply(x: T): U } + +class C { + def app[T, U](x: T)(f: F[T, U]): U = f(x) + app(1)(x => List(x)) + app(2)(x => List(x)) +} diff --git a/tests/untried/pos/scala-singleton.scala b/tests/untried/pos/scala-singleton.scala new file mode 100644 index 000000000..08038db93 --- /dev/null +++ b/tests/untried/pos/scala-singleton.scala @@ -0,0 +1,55 @@ +// A bunch of ridiculous seeming tests until you realize much +// of this didn't work until the commit which accompanies this. +object Test { + def f1(x: AnyRef with Singleton): AnyRef with Singleton = x + def f2[T <: AnyRef with Singleton](x: T): T = x + + val x1: AnyRef with Singleton = "abc" + val x2 = "def" + final val x3 = "ghi" + val x4: String = "jkl" + + // compiles... + def narrow1(x: AnyRef): AnyRef with Singleton = x + + // compiles, still doesn't help. + def narrow2(x: AnyRef): AnyRef with Singleton = x.asInstanceOf[x.type] + + // fails, wait, what? This fails and narrow1 compiles? + def narrow3(x: AnyRef): AnyRef with Singleton = x.asInstanceOf[AnyRef with Singleton] + + // ok + def narrow4[T <: AnyRef](x: T): AnyRef with Singleton = x + + object imp { + implicit def narrow4[T <: AnyRef](x: T): AnyRef with Singleton = x + val x5: String = "mno" + def imp1 = f1(x5) + + // f2(x5) // doesn't work but I think it should + def imp2 = f2(narrow4(x5)) + } + + def main(args: Array[String]): Unit = { + // compiles + f1(x1) + f1(x2) + f1(x3) + f1(x4) + + f2(x1) + // f2(x2) + // f2(x3) // maybe this one should work + // f2(x4) + + f1(narrow1(x4)) + f1(narrow2(x4)) + f1(narrow3(x4)) + f1(narrow4(x4)) + f2(narrow1(x4)) + f2(narrow2(x4)) + f2(narrow3(x4)) + f2(narrow4(x4)) + } +} + diff --git a/tests/untried/pos/scoping1.scala b/tests/untried/pos/scoping1.scala new file mode 100644 index 000000000..9fe1b5f3e --- /dev/null +++ b/tests/untried/pos/scoping1.scala @@ -0,0 +1,12 @@ +object This extends App { + trait A { + def foo(): Unit + } + class C { self: A => + def bar() = this.foo() + } + class D extends C with A { + def foo() = () + } + val c: C = new D +} diff --git a/tests/untried/pos/scoping2.scala b/tests/untried/pos/scoping2.scala new file mode 100644 index 000000000..39f3ef5f0 --- /dev/null +++ b/tests/untried/pos/scoping2.scala @@ -0,0 +1,14 @@ +object That { + trait A { + type T <: I; + trait I {} + } + trait B { + type T <: J; + trait J {} + } + trait C extends A with B { + type T <: I with J; + } +} + diff --git a/tests/untried/pos/scoping3.scala b/tests/untried/pos/scoping3.scala new file mode 100644 index 000000000..55fd32d3b --- /dev/null +++ b/tests/untried/pos/scoping3.scala @@ -0,0 +1,21 @@ +object CI { + trait TreeDisplay { + type TreeNode <: ITreeNode + trait ITreeNode { + def display(): Unit + } + } + + trait TreeDisplayExp { + def getRoot(): TreeNode + type TreeNode <: ITreeNodeExp + trait ITreeNodeExp {} + } + + trait TreeDisplayFinal extends TreeDisplay with TreeDisplayExp { + type TreeNode <: ITreeNode with ITreeNodeExp + } + abstract class SimpleTreeDisplay extends TreeDisplay { self: TreeDisplayFinal => + def display(): Unit = { this.getRoot().display() } + } +} diff --git a/tests/untried/pos/sealed-final.flags b/tests/untried/pos/sealed-final.flags new file mode 100644 index 000000000..cfabf7a5b --- /dev/null +++ b/tests/untried/pos/sealed-final.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Yinline-warnings -optimise
\ No newline at end of file diff --git a/tests/untried/pos/sealed-final.scala b/tests/untried/pos/sealed-final.scala new file mode 100644 index 000000000..bdedb5c1f --- /dev/null +++ b/tests/untried/pos/sealed-final.scala @@ -0,0 +1,14 @@ +sealed abstract class Foo { + @inline def bar(x: Int) = x + 1 +} +object Foo { + def mkFoo(): Foo = new Baz2 +} + +object Baz1 extends Foo +final class Baz2 extends Foo + +object Test { + // bar should be inlined now + def f = Foo.mkFoo() bar 10 +} diff --git a/tests/untried/pos/self-type-override.scala b/tests/untried/pos/self-type-override.scala new file mode 100644 index 000000000..7c40ef37e --- /dev/null +++ b/tests/untried/pos/self-type-override.scala @@ -0,0 +1,13 @@ +trait TCommon { + def f: String +} + +class C1 extends TCommon { + def f = "in C1" +} + +trait TOverrider { this: TCommon => + override def f = "in TOverrider" // The overridden self-type member... +} + +class C2 extends C1 with TOverrider // ... fails to override, here. diff --git a/tests/untried/pos/selftails.scala b/tests/untried/pos/selftails.scala new file mode 100644 index 000000000..a4253b80c --- /dev/null +++ b/tests/untried/pos/selftails.scala @@ -0,0 +1,23 @@ +package net.liftweb.util + +/** +* This trait adds functionality to Scala standard types +*/ +trait BasicTypesHelpers { self: StringHelpers with ControlHelpers => + + /** + * Compare two arrays of Byte for byte equality. + * @return true if two Byte arrays contain the same bytes + */ + def isEq(a: Array[Byte], b: Array[Byte]) = { + def eq(a: Array[Byte], b: Array[Byte], pos: Int, len: Int): Boolean = { + if (pos == len) true + else if (a(pos) != b(pos)) false + else eq(a , b, pos + 1, len) + } + a.length == b.length && eq(a, b, 0, a.length) + } +} + +trait StringHelpers +trait ControlHelpers diff --git a/tests/untried/pos/seq-ordering.scala b/tests/untried/pos/seq-ordering.scala new file mode 100644 index 000000000..517d8ae8a --- /dev/null +++ b/tests/untried/pos/seq-ordering.scala @@ -0,0 +1,9 @@ +import Ordering.Implicits._ + +class A { + import Predef.{ implicitly => ? } + + ?[Ordering[List[Int]]] + ?[Ordering[IndexedSeq[(Int, String)]]] + ?[Ordering[Seq[Seq[Int]]]] +} diff --git a/tests/untried/pos/seqtest2.scala b/tests/untried/pos/seqtest2.scala new file mode 100644 index 000000000..239b1b581 --- /dev/null +++ b/tests/untried/pos/seqtest2.scala @@ -0,0 +1,13 @@ +object test { + + val b = List(1, 2, 3); + + def main(args: Array[String]) = + Console.println( + b match { + case List(1, 2, 3) => true; + case _ => false; + } + ) + +} diff --git a/tests/untried/pos/setter-not-implicit.flags b/tests/untried/pos/setter-not-implicit.flags new file mode 100644 index 000000000..792c40565 --- /dev/null +++ b/tests/untried/pos/setter-not-implicit.flags @@ -0,0 +1 @@ +-feature -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/setter-not-implicit.scala b/tests/untried/pos/setter-not-implicit.scala new file mode 100644 index 000000000..9bfffc2ce --- /dev/null +++ b/tests/untried/pos/setter-not-implicit.scala @@ -0,0 +1,3 @@ +object O { + implicit var x: Int = 0 +} diff --git a/tests/untried/pos/signatures/Test.java b/tests/untried/pos/signatures/Test.java new file mode 100644 index 000000000..3d1e3756a --- /dev/null +++ b/tests/untried/pos/signatures/Test.java @@ -0,0 +1,11 @@ +import scala.collection.mutable.IndexedSeq; +import test.Outer; + +/* Test correct generation of java signatures. The Outer class should not + * have a Java signature attribute for the inner method definition. Trait + * Mutable should have one, even though it is also a nested definition. + * (but for classes there is a way to tell about nesting to the JVM). + */ +class Test { + Outer o = new Outer(); +} diff --git a/tests/untried/pos/signatures/sig.scala b/tests/untried/pos/signatures/sig.scala new file mode 100644 index 000000000..4236f27be --- /dev/null +++ b/tests/untried/pos/signatures/sig.scala @@ -0,0 +1,12 @@ +package test + +/* Tests correct generation of Java signatures. The local method 'bar' should + * not get a generic signature, as it may refer to type parameters of the enclosing + * method, and the JVM does not know about nested methods. + */ +class Outer { + def foo[A, B](x: A, y: B) = { + def bar[X](x1: A, y1: B, z1: X) = z1 + bar(x, y, 10) + } +} diff --git a/tests/untried/pos/simple-exceptions.scala b/tests/untried/pos/simple-exceptions.scala new file mode 100644 index 000000000..a9f16bf90 --- /dev/null +++ b/tests/untried/pos/simple-exceptions.scala @@ -0,0 +1,20 @@ +import java.io.IOException; + +object Test { + + //def error[a](x: String):a = new java.lang.RuntimeException(x) throw; + + def main(args: Array[String]): Unit = { + try { + try { + Console.println("hi!") + sys.error("xx") + } + finally Console.println("ho!") + } + catch { + case ex: IOException => Console.println("io exception!"); + case ex => Console.println(ex); + } + } +} diff --git a/tests/untried/pos/simplelists.scala b/tests/untried/pos/simplelists.scala new file mode 100644 index 000000000..ed3d5d2c3 --- /dev/null +++ b/tests/untried/pos/simplelists.scala @@ -0,0 +1,16 @@ +abstract class List[+a] { + def head: a + def tail: List[a] + def cons[b >: a](x: b): List[b] = new Cons[b, a](x, this) +} + +object Nil extends List[Nothing] { + def error(msg: String): Nothing = throw new java.lang.Error(msg) + def head: Nothing = error("Nil.head") + def tail: List[Nothing] = error("Nil.tail") +} + +class Cons[c, d <: c](x: c, xs: List[d]) extends List[c] { + def head: c = x + def tail: List[c] = xs +} diff --git a/tests/untried/pos/spec-Function1.scala b/tests/untried/pos/spec-Function1.scala new file mode 100644 index 000000000..5a115501d --- /dev/null +++ b/tests/untried/pos/spec-Function1.scala @@ -0,0 +1,47 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// generated by genprod on Wed Apr 23 10:06:16 CEST 2008 (with fancy comment) (with extra methods) + +package scalabip + + +/** <p> + * Function with 1 parameters. + * </p> + * <p> + In the following example the definition of + * <code>succ</code> is a shorthand for the anonymous class definition + * <code>anonfun1</code>: + * </p> + * <pre> + * <b>object</b> Main <b>extends</b> App { + * + * <b>val</b> succ = (x: Int) => x + 1 + * + * <b>val</b> anonfun1 = <b>new</b> Function1[Int, Int] { + * <b>def</b> apply(x: Int): Int = x + 1 + * } + * + * println(succ(0)) + * println(anonfun1(0)) + * }</pre> + */ +trait Function1[@specialized -T1, @specialized +R] extends AnyRef { self => + def apply(v1:T1): R + override def toString() = "<function>" + + /** (f compose g)(x) == f(g(x)) + */ + def compose[A](g: A => T1): A => R = { x => apply(g(x)) } + + /** (f andThen g)(x) == g(f(x)) + */ + def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) } + +} diff --git a/tests/untried/pos/spec-annotations.scala b/tests/untried/pos/spec-annotations.scala new file mode 100644 index 000000000..b23abf48e --- /dev/null +++ b/tests/untried/pos/spec-annotations.scala @@ -0,0 +1,35 @@ +class ann(i: Int) extends scala.annotation.Annotation + +// annotations on abstract types +abstract class C1[@annotation.elidable(0) +T, U, V[_]] +abstract class C2[@deprecated + @ann(1) T <: Number, + V] +abstract class C3 { + @ann(2) type X <: Number +} + +object Test { + + // bug #1028 + val x = 1 + @ann(x) val a = () + @ann({val y = 2; y}) val b = () + + def c: Int @ann(x) = 1 + def d: String @ann({val z = 0; z - 1}) = "2" + def e[@deprecated T, U](x: T) = x + + //bug #1214 + val y = new (Integer @ann(0))(2) + + import scala.beans.BeanProperty + + // bug #637 + trait S { def getField(): Int } + class O extends S { @BeanProperty val field = 0 } + + // bug #1070 + trait T { @BeanProperty var field = 1 } +} + diff --git a/tests/untried/pos/spec-arrays.scala b/tests/untried/pos/spec-arrays.scala new file mode 100644 index 000000000..8c039764f --- /dev/null +++ b/tests/untried/pos/spec-arrays.scala @@ -0,0 +1,187 @@ +abstract class AbsArray[T] { + def apply(idx: Int): T + def update(idx: Int, elem: T) + def length: Int + def applyByte(idx: Int): Byte = apply(idx).asInstanceOf[Byte] + def updateByte(idx: Int, elem: Byte) = update(idx, elem.asInstanceOf[T]) + def applyChar(idx: Int): Char = apply(idx).asInstanceOf[Char] + def updateChar(idx: Int, elem: Char) = update(idx, elem.asInstanceOf[T]) + def applyShort(idx: Int): Short = apply(idx).asInstanceOf[Short] + def updateShort(idx: Int, elem: Short) = update(idx, elem.asInstanceOf[T]) + def applyInt(idx: Int): Int = apply(idx).asInstanceOf[Int] + def updateInt(idx: Int, elem: Int) = update(idx, elem.asInstanceOf[T]) + def applyLong(idx: Int): Long = apply(idx).asInstanceOf[Long] + def updateLong(idx: Int, elem: Long) = update(idx, elem.asInstanceOf[T]) + def applyFloat(idx: Int): Float = apply(idx).asInstanceOf[Float] + def updateFloat(idx: Int, elem: Float) = update(idx, elem.asInstanceOf[T]) + def applyDouble(idx: Int): Double = apply(idx).asInstanceOf[Double] + def updateDouble(idx: Int, elem: Double) = update(idx, elem.asInstanceOf[T]) + def applyBoolean(idx: Int): Boolean = apply(idx).asInstanceOf[Boolean] + def updateBoolean(idx: Int, elem: Boolean) = update(idx, elem.asInstanceOf[T]) + def applyObject(idx: Int): Object = apply(idx).asInstanceOf[Object] + def updateObject(idx: Int, elem: Object) = update(idx, elem.asInstanceOf[T]) +} + +final class IntArray(arr: Array[Int]) extends AbsArray[Int] { + def apply(idx: Int): Int = applyInt(idx) + def update(idx: Int, elem: Int) = updateInt(idx, elem) + override def applyInt(idx: Int): Int = arr(idx) + override def updateInt(idx: Int, elem: Int) = arr(idx) = elem + def length: Int = arr.length +} + +final class ArraySeq[T](arr: Array[T]) extends AbsArray[T] { + def apply(idx: Int): T = arr(idx) + def update(idx: Int, elem: T) = arr(idx) = elem + def length: Int = arr.length +} + +class SpecArray[@specialized T](arr: Array[T]) extends AbsArray[T] { + def apply(idx: Int): T = arr(idx) + def update(idx: Int, elem: T) = arr(idx) = elem + def length: Int = arr.length +} + +abstract class Test { + def sum(): Int + def modify(i: Int) + def run(): Unit = { + var s = 0 + for (i <- 1 to 1000000) { + s += sum() + modify(i) + } + println(s) + } +} + +class ScalaSpecTest extends Test { + val arr = new IntArray(new Array[Int](1000)) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr.applyInt(i); i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr.updateInt(i + base, arr.applyInt(i + base) + 1) + i += 1 + } + } +} + +class ScalaSpec2Test extends Test { + val arr: AbsArray[Int] = new IntArray(new Array[Int](1000)) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr.applyInt(i); i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr.updateInt(i + base, arr.applyInt(i + base) + 1) + i += 1 + } + } +} + +class ScalaWrapTest extends Test { + val arr: AbsArray[Int] = new ArraySeq(new Array[Int](1000)) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr.applyInt(i); i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr.updateInt(i + base, arr.applyInt(i + base) + 1) + i += 1 + } + } +} + +class ScalaGenTest extends Test { + val arr: AbsArray[Integer] = new ArraySeq(new Array[Integer](1000)) + for (i <- 0 until arr.length) arr(i) = new Integer(0) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr.apply(i).intValue; i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr.update(i + base, new Integer(arr.apply(i + base).intValue + 1)) + i += 1 + } + } +} + +class JavaTest extends Test { + val arr = new Array[Int](1000) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr(i); i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr(i + base) += 1 + i += 1 + } + } +} + +/** Specialized array test. */ +class ScalaSpec3Test extends Test { + val arr: SpecArray[Int] = new SpecArray(new Array[Int](1000)) + + def sum(): Int = { + var acc = 0 + var i = 0 + while (i < arr.length) { acc = acc + arr(i); i += 1 } + acc + } + + def modify(j: Int) = { + val base = j * 100 % 1000 + var i = 0 + while (i < 100) { + arr(i + base) = arr(i + base) + 1 + i += 1 + } + } +} + +object TestRunner { + (new JavaTest).run() + (new ScalaSpecTest).run() + (new ScalaSpec2Test).run() + (new ScalaGenTest).run() + (new ScalaWrapTest).run() + (new ScalaSpec3Test).run() +} diff --git a/tests/untried/pos/spec-asseenfrom.scala b/tests/untried/pos/spec-asseenfrom.scala new file mode 100644 index 000000000..ede579170 --- /dev/null +++ b/tests/untried/pos/spec-asseenfrom.scala @@ -0,0 +1,29 @@ +class Automaton[@specialized(Double) W,State] { + + def finalWeight(s: State): W = sys.error("todo"); + + def allStates: Set[State] = sys.error("toodo"); + + /** + * Returns a map from states to its final weight. may expand all nodes. + */ + def finalStateWeights = Map.empty ++ allStates.map { s => (s,finalWeight(s)) } + + // This works fine: + /* + def finalStateWeights() = { + val it = allStates.iterator; + while(it.hasNext) { + finalWeight(it.next); + } + } + */ + +} + +abstract class Automaton2[@specialized T1, T2] { + def finalWeight(s: T2): T1 + def allStates: Set[T2] + + def f = allStates map finalWeight +} diff --git a/tests/untried/pos/spec-constr-new.scala b/tests/untried/pos/spec-constr-new.scala new file mode 100644 index 000000000..c6acc862a --- /dev/null +++ b/tests/untried/pos/spec-constr-new.scala @@ -0,0 +1,9 @@ +import scala.reflect.{ClassTag, classTag} + +class SparseArray2[@specialized(Int) T:ClassTag](val maxSize: Int, initialLength:Int = 3) { + private var data = new Array[T](initialLength); + private var index = new Array[Int](initialLength); + + // comment out to compile correctly + data.length + 3; +} diff --git a/tests/untried/pos/spec-constr-old.scala b/tests/untried/pos/spec-constr-old.scala new file mode 100644 index 000000000..e908b65a4 --- /dev/null +++ b/tests/untried/pos/spec-constr-old.scala @@ -0,0 +1,7 @@ +class SparseArray2[@specialized(Int) T:ClassManifest](val maxSize: Int, initialLength:Int = 3) { + private var data = new Array[T](initialLength); + private var index = new Array[Int](initialLength); + + // comment out to compile correctly + data.length + 3; +} diff --git a/tests/untried/pos/spec-cyclic.scala b/tests/untried/pos/spec-cyclic.scala new file mode 100644 index 000000000..6cd768537 --- /dev/null +++ b/tests/untried/pos/spec-cyclic.scala @@ -0,0 +1,33 @@ +trait AbsFun[@specialized -A, @specialized +B] { + def apply(x: A): B +} + +trait MyPartialFunction[-A, +B] extends AnyRef with AbsFun[A, B] + +trait ColMap[A, +B] extends MyPartialFunction[A, B] /*with Collection[(A, B)] */ + +trait ColSorted[K,+A] extends ColRanged[K,A] + +trait ColSortedMap[K,+E] extends ColMap[K,E] with ColSorted[K,Tuple2[K,E]] + +trait MutMap[A, B] extends AnyRef + with ColMap[A, B] + +trait ColRanged[K, +A] //extends Iterable[A] + +trait JclRanged[K,A] extends ColRanged[K,A] //with MutableIterable[A] { + +trait JclMap[K,E] extends /*collection.jcl.MutableIterable[Tuple2[K,E]] with*/ MutMap[K,E] + +trait JclSorted[K,A] extends ColSorted[K,A] with JclRanged[K,A] + +trait JclSortedMap[K,E] extends ColSortedMap[K,E] with JclMap[K,E] with JclSorted[K,Tuple2[K,E]] + +class Foo[A, B] extends JclSortedMap[A, B] { + def apply(x: A): B = sys.error("NYI") +} + +class Bar { + val x: Foo[Int, Int] = new Foo[Int, Int] + x.apply(0) +} diff --git a/tests/untried/pos/spec-doubledef-new.scala b/tests/untried/pos/spec-doubledef-new.scala new file mode 100644 index 000000000..de438d6e9 --- /dev/null +++ b/tests/untried/pos/spec-doubledef-new.scala @@ -0,0 +1,30 @@ +import scala.reflect.runtime.universe._ + +object Test { + def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = + null.asInstanceOf[T] +} + +trait A[@specialized(Int) T] { + var value: T + def getWith[@specialized(Int) Z](f: T => Z) = f(value) +} + +class C extends A[Int] { + var value = 10 + override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) +} + +abstract class B[T, @specialized(scala.Int) U : TypeTag, @specialized(scala.Int) V <% Ordered[V]] { + val u: U + val v: V + + def f(t: T, v2: V): Tuple2[U, V] = { + val m: Array[U] = null + if (m.isEmpty) { + (u, v) + } else { + (u, v2) + } + } +} diff --git a/tests/untried/pos/spec-doubledef-old.scala b/tests/untried/pos/spec-doubledef-old.scala new file mode 100644 index 000000000..bde259e4f --- /dev/null +++ b/tests/untried/pos/spec-doubledef-old.scala @@ -0,0 +1,28 @@ +object Test { + def fn[@specialized T, @specialized U](t : T => Int, u : U => Int) : T = + null.asInstanceOf[T] +} + +trait A[@specialized(Int) T] { + var value: T + def getWith[@specialized(Int) Z](f: T => Z) = f(value) +} + +class C extends A[Int] { + var value = 10 + override def getWith[@specialized(Int) Z](f: Int => Z) = f(value) +} + +abstract class B[T, @specialized(scala.Int) U : Manifest, @specialized(scala.Int) V <% Ordered[V]] { + val u: U + val v: V + + def f(t: T, v2: V): Tuple2[U, V] = { + val m: Array[U] = null + if (m.isEmpty) { + (u, v) + } else { + (u, v2) + } + } +} diff --git a/tests/untried/pos/spec-example1.scala b/tests/untried/pos/spec-example1.scala new file mode 100644 index 000000000..870c0ed9b --- /dev/null +++ b/tests/untried/pos/spec-example1.scala @@ -0,0 +1,17 @@ +abstract class C[@specialized T](_f: T) { + def m(x: T): T + def n(x: T): T = x + + val f: T = _f +/* + class Inner[@specialized B] { + def foo(x: T): T = x + } + + new Inner +*/ +} + +class D extends C[Int](0) { + def m(x: Int): Int = x * x +} diff --git a/tests/untried/pos/spec-fields-new.scala b/tests/untried/pos/spec-fields-new.scala new file mode 100644 index 000000000..2163e654e --- /dev/null +++ b/tests/untried/pos/spec-fields-new.scala @@ -0,0 +1,12 @@ +import scala.reflect.{ClassTag, classTag} + +abstract class Foo[@specialized T: ClassTag, U <: Ordered[U]](x: T, size: Int) { + var y: T + var z: T = x + + def initialSize = 16 + val array = new Array[T](initialSize + size) + + def getZ = z + def setZ(zz: T) = z = zz +} diff --git a/tests/untried/pos/spec-fields-old.scala b/tests/untried/pos/spec-fields-old.scala new file mode 100644 index 000000000..26a8c4ffb --- /dev/null +++ b/tests/untried/pos/spec-fields-old.scala @@ -0,0 +1,10 @@ +abstract class Foo[@specialized T: ClassManifest, U <: Ordered[U]](x: T, size: Int) { + var y: T + var z: T = x + + def initialSize = 16 + val array = new Array[T](initialSize + size) + + def getZ = z + def setZ(zz: T) = z = zz +} diff --git a/tests/untried/pos/spec-foo.scala b/tests/untried/pos/spec-foo.scala new file mode 100644 index 000000000..aabe0d51e --- /dev/null +++ b/tests/untried/pos/spec-foo.scala @@ -0,0 +1,4 @@ +class Foo { + val xs = List(1, 2) + 1 :: xs +} diff --git a/tests/untried/pos/spec-funs.scala b/tests/untried/pos/spec-funs.scala new file mode 100644 index 000000000..a742d81aa --- /dev/null +++ b/tests/untried/pos/spec-funs.scala @@ -0,0 +1,60 @@ +trait AbsFunction1[@specialized -T, @specialized +U] { + def apply(x: T): U +} + +final class IntTest { + + val niters = 10000 + + def transF(xs: Array[Int], f: AbsFunction1[Int, Int]) = { + var i = 0 + var s = 0 + while (i < xs.length) { + xs(i) = f(xs(i)) + 1 + i += 1 + } + } + + def run(): Unit = { + val xs = new Array[Int](10000) + val f = new AbsFunction1[Int, Int] { + def apply(x: Int): Int = x * x + } + for (j <- 0 until niters) { + transF(xs, f) + } + var acc = 0 + for (i <- 0 until xs.length) acc += xs(i) + println(acc) + } +} + +final class ClosureTest { + + val niters = 10000 + + def transF(xs: Array[Int], f: Int => Int) = { + var i = 0 + var s = 0 + while (i < xs.length) { + xs(i) = f.apply(xs(i)) + 1 + i += 1 + } + } + + def run(): Unit = { + val xs = new Array[Int](10000) +// val f = (x: Int) => x * x + for (j <- 0 until niters) { + transF(xs, x => x * x) + } + var acc = 0 + for (i <- 0 until xs.length) acc += xs(i) + println(acc) + } +} + +object TestRunner { + (new IntTest).run() + (new ClosureTest).run() +} diff --git a/tests/untried/pos/spec-groups.scala b/tests/untried/pos/spec-groups.scala new file mode 100644 index 000000000..9b6359a98 --- /dev/null +++ b/tests/untried/pos/spec-groups.scala @@ -0,0 +1,65 @@ +import Specializable._ + +class A[@specialized(Primitives) T](x: T) { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class B[@specialized(Everything) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class C[@specialized(Bits32AndUp) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class D[@specialized(Integral) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class E[@specialized(AllNumeric) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class F[@specialized(BestOfBreed) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} +class G[@specialized(Byte, Double, AnyRef) T] { + def f1[@specialized(Primitives) U](x: T, y: U) = ((x, y)) + def f2[@specialized(Everything) U](x: T, y: U) = ((x, y)) + def f3[@specialized(Bits32AndUp) U](x: T, y: U) = ((x, y)) + def f4[@specialized(Integral) U](x: T, y: U) = ((x, y)) + def f5[@specialized(AllNumeric) U](x: T, y: U) = ((x, y)) + def f6[@specialized(BestOfBreed) U](x: T, y: U) = ((x, y)) + def f7[@specialized(Byte, Double, AnyRef) U](x: T, y: U) = ((x, y)) +} diff --git a/tests/untried/pos/spec-lists.scala b/tests/untried/pos/spec-lists.scala new file mode 100644 index 000000000..46e164e9c --- /dev/null +++ b/tests/untried/pos/spec-lists.scala @@ -0,0 +1,6 @@ +object Main extends App { + + val xs = 1 :: 2 :: 3 :: 4 :: 5 :: Nil + + println(xs) +} diff --git a/tests/untried/pos/spec-localdefs.scala b/tests/untried/pos/spec-localdefs.scala new file mode 100644 index 000000000..2df500e20 --- /dev/null +++ b/tests/untried/pos/spec-localdefs.scala @@ -0,0 +1,7 @@ +class Foo[@specialized T] { + def foo(x: T) = { + class Bar + x.asInstanceOf[List[Bar]] + x.asInstanceOf[Bar] + } +} diff --git a/tests/untried/pos/spec-maps.scala b/tests/untried/pos/spec-maps.scala new file mode 100644 index 000000000..d961110cd --- /dev/null +++ b/tests/untried/pos/spec-maps.scala @@ -0,0 +1,10 @@ +trait Fun1[@specialized +R, @specialized -T] { + def apply(x: T): R +} + +object Main { + def mapA[@specialized B](xs: Array[B], f: Fun1[B, B]): Unit = { + for (i <- 0 until xs.length) + xs(i) = f(xs(i)) + } +} diff --git a/tests/untried/pos/spec-multiplectors.scala b/tests/untried/pos/spec-multiplectors.scala new file mode 100644 index 000000000..8434a1393 --- /dev/null +++ b/tests/untried/pos/spec-multiplectors.scala @@ -0,0 +1,3 @@ +class Spec[@specialized(Int) A]() { + def this(n: Int) = this() +} diff --git a/tests/untried/pos/spec-params-new.scala b/tests/untried/pos/spec-params-new.scala new file mode 100644 index 000000000..959ce1591 --- /dev/null +++ b/tests/untried/pos/spec-params-new.scala @@ -0,0 +1,34 @@ +import scala.reflect.{ClassTag, classTag} + +class Foo[@specialized A: ClassTag] { + + // conflicting in bounds, expect a normalized member calling m + // and bridge + implementation in specialized subclasses + // and overloads here according to specialization on A + def m1[@specialized B <: A](x: B, y: A) = + goal(x) + + // conflicting, unsolvable, expect a warning + def m2[@specialized B <: String](x: B) = x.concat("a") + + // conflicting in bounds, no mention of other spec members + // expect an overload here plus implementation in + // compatible specialized subclasses + def m3[@specialized B >: A](x: B) = () + + // non-conflicting, expect a normalized overload implementation here + def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () + + // non-conflicting, expect a normalized overload implementation here + def m5[@specialized B](x: B) = x + + // non-conflicting, expect a normalized implementation here + // and specialized implementations for all expansions in specialized subclasses + def m6[@specialized B](x: B, y: A) = + goal(y) + + def goal(x: A) = { + val xs = new Array[A](1) + xs(0) = x + } +} diff --git a/tests/untried/pos/spec-params-old.scala b/tests/untried/pos/spec-params-old.scala new file mode 100644 index 000000000..33a252120 --- /dev/null +++ b/tests/untried/pos/spec-params-old.scala @@ -0,0 +1,32 @@ +class Foo[@specialized A: ClassManifest] { + + // conflicting in bounds, expect a normalized member calling m + // and bridge + implementation in specialized subclasses + // and overloads here according to specialization on A + def m1[@specialized B <: A](x: B, y: A) = + goal(x) + + // conflicting, unsolvable, expect a warning + def m2[@specialized B <: String](x: B) = x.concat("a") + + // conflicting in bounds, no mention of other spec members + // expect an overload here plus implementation in + // compatible specialized subclasses + def m3[@specialized B >: A](x: B) = () + + // non-conflicting, expect a normalized overload implementation here + def m4[@specialized T, U <: Ordered[T]](x: T, y: U) = () + + // non-conflicting, expect a normalized overload implementation here + def m5[@specialized B](x: B) = x + + // non-conflicting, expect a normalized implementation here + // and specialized implementations for all expansions in specialized subclasses + def m6[@specialized B](x: B, y: A) = + goal(y) + + def goal(x: A) = { + val xs = new Array[A](1) + xs(0) = x + } +} diff --git a/tests/untried/pos/spec-partially.scala b/tests/untried/pos/spec-partially.scala new file mode 100644 index 000000000..90778e42a --- /dev/null +++ b/tests/untried/pos/spec-partially.scala @@ -0,0 +1,5 @@ +/** Test case for partially specialized classes. see #2880. */ + +class Arc[State, @specialized T](label: T, to: State) + + diff --git a/tests/untried/pos/spec-partialmap.scala b/tests/untried/pos/spec-partialmap.scala new file mode 100644 index 000000000..09684e024 --- /dev/null +++ b/tests/untried/pos/spec-partialmap.scala @@ -0,0 +1,17 @@ + +// ticket #3378, overloaded specialized variants +import scala.collection.{Traversable,TraversableLike}; +import scala.collection.generic.CanBuildFrom; + +trait PartialMap[@specialized A,@specialized B] +extends PartialFunction[A,B] with Iterable[(A,B)] { + + // commenting out this declaration gives a different exception. + /** Getter for all values for which the given key function returns true. */ + def apply(f : (A => Boolean)) : Iterator[B] = + for ((k,v) <- iterator; if f(k)) yield v; + + // if this is commented, it compiles fine: + def apply[This <: Traversable[A], That](keys : TraversableLike[A,This]) + (implicit bf: CanBuildFrom[This, B, That]) : That = keys.map(apply); +} diff --git a/tests/untried/pos/spec-polymeth.scala b/tests/untried/pos/spec-polymeth.scala new file mode 100644 index 000000000..df2f460fd --- /dev/null +++ b/tests/untried/pos/spec-polymeth.scala @@ -0,0 +1,8 @@ +abstract class AbsFun[@specialized R] { +// def andThen[B](x: B): B + + def compose[A](x: A, y: R): A = { + val y: A = x + x + } +} diff --git a/tests/untried/pos/spec-private.scala b/tests/untried/pos/spec-private.scala new file mode 100644 index 000000000..cd79170eb --- /dev/null +++ b/tests/untried/pos/spec-private.scala @@ -0,0 +1,10 @@ +class Foo { + + def foo[@specialized(Int) T](x: T) = new Object { + private final val myEdges = List(1, 2 , 3) + + def boo: Unit = { + myEdges + } + } +} diff --git a/tests/untried/pos/spec-sealed.scala b/tests/untried/pos/spec-sealed.scala new file mode 100644 index 000000000..d7ecfaaab --- /dev/null +++ b/tests/untried/pos/spec-sealed.scala @@ -0,0 +1,32 @@ +sealed abstract class MyList[@specialized +A] { + def head: A + def tail: MyList[A] + + def ::[@specialized B >: A](x: B): MyList[B] = + new Cons[B](x, this) +} + +case object MyNil extends MyList[Nothing] { + def head = sys.error("nil") + def tail = sys.error("nil") +} + +case class Cons[@specialized a](private val hd: a, tl: MyList[a]) extends MyList[a] { + def head = hd + def tail = tl +} + +abstract class IntList extends MyList[Int] + +object Main extends App { + val xs = 1 :: 2 :: 3 :: MyNil + println(xs) +} + +/* +final class ConsI(hd1: Int, tl1: MyList[Int]) extends Cons[Int](hd1, tl1) { + override val hd = hd1 + override val tl = tl1 +} +*/ +//class IntCons(_hd: Int, _tl: MyList[Int]) extends Cons[Int](_hd, _tl) diff --git a/tests/untried/pos/spec-short.scala b/tests/untried/pos/spec-short.scala new file mode 100644 index 000000000..71e56a485 --- /dev/null +++ b/tests/untried/pos/spec-short.scala @@ -0,0 +1,26 @@ +abstract class AbsFun[@specialized T, @specialized U] { + // abstract function, fully specialized + def apply(x: T): U + + // abstract function, specialized + def sum(xs: List[T]): Int + + def prod(xs: List[T], mul: (Int, T) => Int): Int = + (1 /: xs)(mul) + + // concrete function, not specialized + def bar(m: String): String = m + + // abstract function, not specialized + def abs(m: Int): Int +} + +class Square extends AbsFun[Int, Int] { + def apply(x: Int): Int = x * x + + def sum(xs: List[Int]): Int = + (0 /: xs) (_ + _) + + def abs(m: Int): Int = + sum(List(1, 2, 3)) +} diff --git a/tests/untried/pos/spec-simple.scala b/tests/untried/pos/spec-simple.scala new file mode 100644 index 000000000..19b660688 --- /dev/null +++ b/tests/untried/pos/spec-simple.scala @@ -0,0 +1,51 @@ +class Foo[@specialized T] { + var v: T = _ + + def foo(x: T): T = x + + println("abc") + + class Bar[@specialized U] { + def bar(x: U): T = v +// def barInt(x: Int): T = bar(x.asInstanceOf[U]) + } +} + +class Test { + def test: Unit = { + val a = new Foo[Int] + val b = new a.Bar[Int] + a.foo(10) + b.bar(11) + } +} + +/* +abstract class Foo[@specialized T] { + def foo(x: T): T + def foo$Int(x: Int): Int + + abstract class Bar[@specialized U] { + def bar(x: U): T + def bar$Int(x: Int): T + } + abstract class Bar$Int extends Bar[Int] { + def bar(x: Int): T = bar$Int(x) + def bar$Int(x: Int): T + } +} + +abstract class Foo$Int extends Foo[Int] { + def foo(x: Int): Int = foo$Int(x) + def foo$Int(x: Int): Int + + abstract class Bar[@specialized U] { + def bar(x: U): Int + def bar$Int(x: Int): Int + } + abstract class Bar$Int extends Bar[Int] { + def bar(x: Int): Int = bar$Int(x) + def bar$Int(x: Int): Int + } +} +*/ diff --git a/tests/untried/pos/spec-sparsearray-new.scala b/tests/untried/pos/spec-sparsearray-new.scala new file mode 100644 index 000000000..df31089fe --- /dev/null +++ b/tests/untried/pos/spec-sparsearray-new.scala @@ -0,0 +1,25 @@ +import scala.reflect.{ClassTag, classTag} +import scala.collection.mutable.MapLike + +class SparseArray[@specialized(Int) T:ClassTag] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { + override def get(x: Int) = { + val ind = findOffset(x) + if(ind < 0) None else Some(sys.error("ignore")) + } + + /** + * Returns the offset into index and data for the requested vector + * index. If the requested index is not found, the return value is + * negative and can be converted into an insertion point with -(rv+1). + */ + private def findOffset(i : Int) : Int = { + sys.error("impl doesn't matter") + } + + override def apply(i : Int) : T = { sys.error("ignore") } + override def update(i : Int, value : T) = sys.error("ignore") + override def empty = new SparseArray[T] + def -=(ind: Int) = sys.error("ignore") + def +=(kv: (Int,T)) = sys.error("ignore") + override final def iterator = sys.error("ignore") +} diff --git a/tests/untried/pos/spec-sparsearray-old.scala b/tests/untried/pos/spec-sparsearray-old.scala new file mode 100644 index 000000000..e10dabd54 --- /dev/null +++ b/tests/untried/pos/spec-sparsearray-old.scala @@ -0,0 +1,24 @@ +import scala.collection.mutable.MapLike + +class SparseArray[@specialized(Int) T:ClassManifest] extends collection.mutable.Map[Int,T] with collection.mutable.MapLike[Int,T,SparseArray[T]] { + override def get(x: Int) = { + val ind = findOffset(x) + if(ind < 0) None else Some(sys.error("ignore")) + } + + /** + * Returns the offset into index and data for the requested vector + * index. If the requested index is not found, the return value is + * negative and can be converted into an insertion point with -(rv+1). + */ + private def findOffset(i : Int) : Int = { + sys.error("impl doesn't matter") + } + + override def apply(i : Int) : T = { sys.error("ignore") } + override def update(i : Int, value : T) = sys.error("ignore") + override def empty = new SparseArray[T] + def -=(ind: Int) = sys.error("ignore") + def +=(kv: (Int,T)) = sys.error("ignore") + override final def iterator = sys.error("ignore") +} diff --git a/tests/untried/pos/spec-super.scala b/tests/untried/pos/spec-super.scala new file mode 100644 index 000000000..67179e023 --- /dev/null +++ b/tests/untried/pos/spec-super.scala @@ -0,0 +1,20 @@ +import scala.collection.immutable._ +import scala.collection.mutable.ListBuffer +import scala.collection.generic._ + +trait Base[+A] extends Traversable[A] { + def add[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Base[A], B, That]): That = { + val b = bf(this) + b ++= this + b ++= that + b.result + } + +} + +abstract class Derived[@specialized +A] extends Base[A] { + override def add[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Base[A], B, That]): That = { + val b = bf(this) + super.add[B, That](that) + } +} diff --git a/tests/untried/pos/spec-t3497.scala b/tests/untried/pos/spec-t3497.scala new file mode 100644 index 000000000..ff054aa7d --- /dev/null +++ b/tests/untried/pos/spec-t3497.scala @@ -0,0 +1,16 @@ +abstract class A[T, @specialized U] { + def score(state: T): U +} + +object B extends A[ Array[Byte], Int ] { + def score(state: Array[Byte]): Int = { + var index = 0 + while (index < state.length) { // (index < 2) leads to the #2755 NullPointerException + if (state(index) == 0) { + return -1 + } + } + + return 0 + } +} diff --git a/tests/untried/pos/spec-t6286.scala b/tests/untried/pos/spec-t6286.scala new file mode 100755 index 000000000..4d87998ec --- /dev/null +++ b/tests/untried/pos/spec-t6286.scala @@ -0,0 +1,10 @@ +trait Foo[@specialized(Int) A] { + def fun[@specialized(Int) B](init: B)(f: (B, A) => B): B +} + +class Bar(values: Array[Int]) extends Foo[Int] { + def fun[@specialized(Int) C](init: C)(f: (C, Int) => C): C = { + val arr = values + f(init, arr(0)) + } +} diff --git a/tests/untried/pos/spec-tailcall.scala b/tests/untried/pos/spec-tailcall.scala new file mode 100644 index 000000000..703ec011a --- /dev/null +++ b/tests/untried/pos/spec-tailcall.scala @@ -0,0 +1,17 @@ +class TailCall[@specialized T] { + final def dropLeft(n: Int, xs: List[T]): List[T] = + if (n == 0) xs + else dropLeft(n - 1, xs.tail) +/* + def filter(pf: PartialFunction[Option[String], Boolean]) = null + + def crash(o: Option[String]) = filter { + case None if { + def dropLeft[T](n: Int, xs: List[T]): List[T] = + if (n == 0) xs + else dropLeft(n - 1, xs.tail) + dropLeft(2, List(1, 2, 3)).isEmpty + } => true + } +*/ +} diff --git a/tests/untried/pos/spec-thistype.scala b/tests/untried/pos/spec-thistype.scala new file mode 100644 index 000000000..52b2bf34b --- /dev/null +++ b/tests/untried/pos/spec-thistype.scala @@ -0,0 +1,3 @@ +class Foo[@specialized A] { + def bar(xs: List[A]): this.type = this +} diff --git a/tests/untried/pos/spec-traits.scala b/tests/untried/pos/spec-traits.scala new file mode 100644 index 000000000..c8c8000d8 --- /dev/null +++ b/tests/untried/pos/spec-traits.scala @@ -0,0 +1,64 @@ +trait A[@specialized(Int) T] { def foo: T } +class B extends A[Int] { val foo = 10 } +class C extends B + +// issue 3309 +class Lazy { + def test[U](block: => U): Unit = { block } + + test { lazy val x = 1 } +} + +// issue 3307 +class Bug3307 { + def f[Z](block: String => Z): Unit = { + block("abc") + } + + ({ () => + f { implicit x => println(x) } })() +} + +// issue 3301 + trait T[X] + +class Bug3301 { + def t[A]: T[A] = sys.error("stub") + + () => { + type X = Int + + def foo[X] = t[X] + () + } +} +// issue 3299 +object Failure { + def thunk(): Unit = { + for (i <- 1 to 2) { + val Array(a, b) = Array(1,2) + () + } + } +} + +// issue 3296 + +object AA +{ + def f(block: => Unit): Unit = {} + + object BB + { + f { + object CC + + () + } + } + + def foo[T](x: T) = { object A; false } +} + +// issue 3325 +object O { def f[@specialized T]: Unit = { for(k <- Nil: List[T]) { } } } diff --git a/tests/untried/pos/spec-vector.scala b/tests/untried/pos/spec-vector.scala new file mode 100644 index 000000000..392949c66 --- /dev/null +++ b/tests/untried/pos/spec-vector.scala @@ -0,0 +1,4 @@ +// ticket #3379, abstract overrides +trait Vector extends (Int=>Double) { + override def apply(i: Int): Double +} diff --git a/tests/untried/pos/spec.scala b/tests/untried/pos/spec.scala new file mode 100644 index 000000000..f548e156f --- /dev/null +++ b/tests/untried/pos/spec.scala @@ -0,0 +1,64 @@ + + + + +class Bar[@specialized(Int, AnyRef) A](a: A) { + val memb = a +} + + +class WithInner[@specialized(Int, AnyRef) A](a: A) { + class Inner { + def meth = a + } +} + + +class Baz[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B] { + def ab(a: A, b: B) = (a, b) +} + + +trait Base[@specialized(Int, AnyRef) A] +class Concrete[@specialized(Int, AnyRef) A] extends Base[A] + + +class WithAnon[@specialized(Int, AnyRef) A](a: A) { + new AnyRef { + def foo = a + } +} + + +class Norm { + def id[@specialized(Int, AnyRef) A](a: A) = a +} + + +class Qux[@specialized(AnyRef) A] { + def memb[@specialized(AnyRef) B](a: A, b: B) = (a, b) +} + + +class Foo[@specialized(Int, AnyRef) A](val a: Array[A]) { + a(0) + + def id(elem: A) = a(0) = elem +} + + +// instantiation and selection +object Test { + def main(arg: Array[String]): Unit = { + val f = new Foo(new Array[String](5)) + f.id("") + + val z = new Baz[Int, Double] + z.ab(1, 1.0) + + testspec(new Array[String](5)) + testspec(new Array[Int](5)) + } + + def testspec[@specialized(Int, AnyRef) T](arr: Array[T]) = arr(0) +} diff --git a/tests/untried/pos/specialize10.scala b/tests/untried/pos/specialize10.scala new file mode 100644 index 000000000..bbe197cda --- /dev/null +++ b/tests/untried/pos/specialize10.scala @@ -0,0 +1,7 @@ +trait Bippy[@specialized( + scala.Char, scala.Boolean, scala.Byte, + scala.Short, scala.Int, scala.Long, + scala.Float, scala.Double, scala.Unit, + scala.AnyRef) T] { } + +trait Bippy2[@specialized(Char, Boolean, Byte, Short, Int, Long, Float, Double, Unit, AnyRef) T] { } diff --git a/tests/untried/pos/specializes-sym-crash.scala b/tests/untried/pos/specializes-sym-crash.scala new file mode 100644 index 000000000..7778ba277 --- /dev/null +++ b/tests/untried/pos/specializes-sym-crash.scala @@ -0,0 +1,26 @@ +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 Transformed[+B] extends SeqView[B, Coll] with super.Transformed[B] { + def length: Int + def apply(idx: Int): B + override def toString = viewToString + } + trait Reversed extends Transformed[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/untried/pos/spurious-overload.scala b/tests/untried/pos/spurious-overload.scala new file mode 100644 index 000000000..aae4c9632 --- /dev/null +++ b/tests/untried/pos/spurious-overload.scala @@ -0,0 +1,32 @@ +object Test extends App { + def foo(bar: Any) = bar + + val code = foo{ + object lazyLib { + + def delay[A](value: => A): Susp[A] = new SuspImpl[A](value) + + implicit def force[A](s: Susp[A]): A = s() + + abstract class Susp[+A] extends Function0[A] + + class SuspImpl[A](lazyValue: => A) extends Susp[A] { + private var maybeValue: Option[A] = None + + override def apply() = maybeValue match { + case None => + val value = lazyValue + maybeValue = Some(value) + value + case Some(value) => + value + } + } + } + + import lazyLib._ + + val s: Susp[Int] = delay { println("evaluating..."); 3 } + println("2 + s = " + (2 + s)) // implicit call to force() + } +} diff --git a/tests/untried/pos/stable.scala b/tests/untried/pos/stable.scala new file mode 100644 index 000000000..267a36fe5 --- /dev/null +++ b/tests/untried/pos/stable.scala @@ -0,0 +1,11 @@ +trait Base { + val x: Int; + val y: Int; + var z: Int; +} + +class Sub() extends Base { + val x: Int = 1; + val y: Int = 2; + var z: Int = 3; +} diff --git a/tests/untried/pos/strings.scala b/tests/untried/pos/strings.scala new file mode 100644 index 000000000..9fe8cfd94 --- /dev/null +++ b/tests/untried/pos/strings.scala @@ -0,0 +1,10 @@ +// martin 1-3-2002: it seems there is a problem with the way Serializable is loaded. +object test { + + def f() = "hello".concat("world"); + +} +// #1000 +object A { + println("""This a "raw" string ending with a "double quote"""") +} diff --git a/tests/untried/pos/strip-tvars-for-lubbasetypes.scala b/tests/untried/pos/strip-tvars-for-lubbasetypes.scala new file mode 100644 index 000000000..2be8625ba --- /dev/null +++ b/tests/untried/pos/strip-tvars-for-lubbasetypes.scala @@ -0,0 +1,25 @@ +object Test { + + implicit final class EqualOps[T](val x: T) extends AnyVal { + def ===[T1, Ph >: T <: T1, Ph2 >: Ph <: T1](other: T1): Boolean = x == other + def !!![T1, Ph2 >: Ph <: T1, Ph >: T <: T1](other: T1): Boolean = x == other + } + + class A + class B extends A + class C extends A + + val a = new A + val b = new B + val c = new C + + val x1 = a === b + val x2 = b === a + val x3 = b === c // error, infers Object{} for T1 + val x4 = b.===[A, B, B](c) + + val x5 = b !!! c // always compiled due to the order of Ph2 and Ph + + + +} diff --git a/tests/untried/pos/sudoku.scala b/tests/untried/pos/sudoku.scala new file mode 100644 index 000000000..9435f504d --- /dev/null +++ b/tests/untried/pos/sudoku.scala @@ -0,0 +1,41 @@ +object SudokuSolver extends App { + // The board is represented by an array of strings (arrays of chars), + // held in a global variable m. The program begins by reading 9 lines + // of input to fill the board + var m: Array[Array[Char]] = Array.tabulate(9)((x: Int) => readLine.toArray) + + // For printing m, a method print is defined + def print = { println(""); m map (carr => println(new String(carr))) } + + // The test for validity is performed by looping over i=0..8 and + // testing the row, column and 3x3 square containing the given + // coordinate + def invalid(i: Int, x: Int, y: Int, n: Char): Boolean = + i<9 && (m(y)(i) == n || m(i)(x) == n || + m(y/3*3 + i/3)(x/3*3 + i % 3) == n || invalid(i+1, x, y, n)) + + // Looping over a half-closed range of consecutive integers [l..u) + // is factored out into a higher-order function + def fold(f: (Int, Int) => Int, accu: Int, l: Int, u: Int): Int = + if(l==u) accu else fold(f, f(accu, l), l+1, u) + + // The search function examines each position on the board in turn, + // trying the numbers 1..9 in each unfilled position + // The function is itself a higher-order fold, accumulating the value + // accu by applying the given function f to it whenever a solution m + // is found + def search(x:Int, y:Int, f: (Int) => Int, accu: Int): Int = (x, y) match { + case (9, y) => search(0, y+1, f, accu) // next row + case (0, 9) => f(accu) // found a solution + case (x, y) => if (m(y)(x) != '0') search(x+1, y, f, accu) else + fold((accu: Int, n: Int) => + if (invalid(0, x, y, (n + 48).toChar)) accu else { + m(y)(x) = (n + 48).toChar; + val newaccu = search(x+1, y, f, accu); + m(y)(x) = '0'; + newaccu}, accu, 1, 10)} + + // The main part of the program uses the search function to accumulate + // the total number of solutions + println("\n"+search(0,0,i => {print; i+1},0)+" solution(s)") +} diff --git a/tests/untried/pos/super/Super_1.java b/tests/untried/pos/super/Super_1.java new file mode 100644 index 000000000..9acbba0ec --- /dev/null +++ b/tests/untried/pos/super/Super_1.java @@ -0,0 +1,6 @@ +// A.java +interface Inter<T> { } + +class Super implements Inter<Super.Inner> { + public class Inner { }; +} diff --git a/tests/untried/pos/super/Super_2.scala b/tests/untried/pos/super/Super_2.scala new file mode 100644 index 000000000..486d6b700 --- /dev/null +++ b/tests/untried/pos/super/Super_2.scala @@ -0,0 +1,6 @@ +object Test { + val x: Super = null + + def main(args: Array[String]): Unit = { + } +} diff --git a/tests/untried/pos/switch-small.flags b/tests/untried/pos/switch-small.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/switch-small.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/switch-small.scala b/tests/untried/pos/switch-small.scala new file mode 100644 index 000000000..9de9ca028 --- /dev/null +++ b/tests/untried/pos/switch-small.scala @@ -0,0 +1,8 @@ +import annotation._ + +object Test { + def f(x: Int) = (x: @switch) match { + case 1 => 1 + case _ => 2 + } +} diff --git a/tests/untried/pos/switchUnbox.scala b/tests/untried/pos/switchUnbox.scala new file mode 100644 index 000000000..1d4b742ff --- /dev/null +++ b/tests/untried/pos/switchUnbox.scala @@ -0,0 +1,8 @@ +object Foo { + var xyz: (Int, String) = (1, "abc") + xyz._1 match { + case 1 => Console.println("OK") + case 2 => Console.println("OK") + case _ => Console.println("KO") + } +} diff --git a/tests/untried/pos/t0002.scala b/tests/untried/pos/t0002.scala new file mode 100644 index 000000000..4c58ed3f4 --- /dev/null +++ b/tests/untried/pos/t0002.scala @@ -0,0 +1,6 @@ +object main { + def main(args: Array[String]) = { + val b = true; + while (b == true) { } + } +} diff --git a/tests/untried/pos/t0017.scala b/tests/untried/pos/t0017.scala new file mode 100644 index 000000000..d2bcda08d --- /dev/null +++ b/tests/untried/pos/t0017.scala @@ -0,0 +1,21 @@ +class Quantity { + def getValue = 0; + def connect(c: Constraint) = c.newValue; +} + +abstract class Constraint(q: Quantity) { + def newValue: Unit; + q connect this +} + +class Adder(q: Quantity) extends Constraint(q) { + def newValue = Console.println(q.getValue); +} + +object Main { + def main(args: Array[String]): Unit = { + val x = new Quantity; + new Adder(x); + () + } +} diff --git a/tests/untried/pos/t0020.scala b/tests/untried/pos/t0020.scala new file mode 100644 index 000000000..4f1e5b173 --- /dev/null +++ b/tests/untried/pos/t0020.scala @@ -0,0 +1,8 @@ +object Exceptions { + + class CubeException(s: String) extends RuntimeException(s); + + def main(args: Array[String]) = + Console.println(new CubeException("test")); + +} diff --git a/tests/untried/pos/t0029.scala b/tests/untried/pos/t0029.scala new file mode 100644 index 000000000..937b6d70c --- /dev/null +++ b/tests/untried/pos/t0029.scala @@ -0,0 +1,3 @@ +object Main { + def f[a]: List[List[a]] = for (l1 <- Nil; l2 <- Nil) yield l1 +} diff --git a/tests/untried/pos/t0030.scala b/tests/untried/pos/t0030.scala new file mode 100644 index 000000000..2f23be14d --- /dev/null +++ b/tests/untried/pos/t0030.scala @@ -0,0 +1,9 @@ +trait A { + def f(x: Int): Unit; + def f(x: String): Unit; +} + +class B extends A { + def f(x: Int): Unit = (); + def f(x: String): Unit = (); +} diff --git a/tests/untried/pos/t0031.scala b/tests/untried/pos/t0031.scala new file mode 100644 index 000000000..d4050c818 --- /dev/null +++ b/tests/untried/pos/t0031.scala @@ -0,0 +1,29 @@ +object Main { + + trait Ensure[a] { + def ensure(postcondition: a => Boolean): a + } + + def require[a](precondition: => Boolean)(command: => a): Ensure[a] = + if (precondition) + new Ensure[a] { + def ensure(postcondition: a => Boolean): a = { + val result = command; + if (postcondition(result)) result + else sys.error("Assertion error") + } + } + else + sys.error("Assertion error"); + + def arb[a](s: List[a]) = + require (! s.isEmpty) { + s.head + } ensure (result => s contains result); + + def main(args: Array[String]) = { + val s = List(1, 2); + Console.println(arb(s)) + } + +} diff --git a/tests/untried/pos/t0032.scala b/tests/untried/pos/t0032.scala new file mode 100644 index 000000000..727a7d4e9 --- /dev/null +++ b/tests/untried/pos/t0032.scala @@ -0,0 +1,17 @@ +import java.io.{OutputStream, PrintStream}; + +class PromptStream(s: OutputStream) extends PrintStream(s) { + override def println() = super.println(); +} + +object Main { + + val out = new PromptStream(java.lang.System.out); + + java.lang.System.setOut(out); + + def main(args: Array[String]) = + //out.println("hello world"); + () + +} diff --git a/tests/untried/pos/t0036.scala b/tests/untried/pos/t0036.scala new file mode 100644 index 000000000..3c9a84f8a --- /dev/null +++ b/tests/untried/pos/t0036.scala @@ -0,0 +1,8 @@ +object m { + + val xs: List[Int] = Nil + def f(i: Int) = 0 + val v = xs map f + + def m() = {} +} diff --git a/tests/untried/pos/t0039.scala b/tests/untried/pos/t0039.scala new file mode 100644 index 000000000..652c606b0 --- /dev/null +++ b/tests/untried/pos/t0039.scala @@ -0,0 +1,6 @@ +abstract class Extensible[A, This <: Extensible[A, This]](x: A, xs: This) { self: This => + def mkObj(x: A, xs: This): This; +} +class Fixed[A](x: A, xs: Fixed[A]) extends Extensible[A, Fixed[A]](x, xs) { + def mkObj(x: A, xs: Fixed[A]) = new Fixed(x, xs); +} diff --git a/tests/untried/pos/t0049.scala b/tests/untried/pos/t0049.scala new file mode 100644 index 000000000..dd8664226 --- /dev/null +++ b/tests/untried/pos/t0049.scala @@ -0,0 +1,3 @@ +class C1(x: AnyRef) {}; + +class C2 extends C1({ class A extends AnyRef {}; (new A) : AnyRef }) {}; diff --git a/tests/untried/pos/t0053.scala b/tests/untried/pos/t0053.scala new file mode 100644 index 000000000..44763ef14 --- /dev/null +++ b/tests/untried/pos/t0053.scala @@ -0,0 +1,7 @@ +object bug { + def foobar[c]: Int = { + class Foo { def foo: Bar = new Bar(); } + class Bar { def bar: c = bar; } + 0 + } +} diff --git a/tests/untried/pos/t0054.scala b/tests/untried/pos/t0054.scala new file mode 100644 index 000000000..670160f36 --- /dev/null +++ b/tests/untried/pos/t0054.scala @@ -0,0 +1,4 @@ +class A { + case class B(x: C) extends A { val z: A.this.C = x } + class C {} +} diff --git a/tests/untried/pos/t0055.scala b/tests/untried/pos/t0055.scala new file mode 100644 index 000000000..079629440 --- /dev/null +++ b/tests/untried/pos/t0055.scala @@ -0,0 +1,6 @@ +class X(x : Any) +class W { + new X(new Z() with Y) {} + trait Y { def y = () } +} +class Z(r : Any) { def this() = this(null) } diff --git a/tests/untried/pos/t0061.scala b/tests/untried/pos/t0061.scala new file mode 100644 index 000000000..dd3f94f30 --- /dev/null +++ b/tests/untried/pos/t0061.scala @@ -0,0 +1,10 @@ +object O { + + class testClass ; + + case class testA() extends testClass ; // works if you leave away "extends..." + // or if you write TestA + def ga( x:testClass ) = x match { + case testA() => () + } +} diff --git a/tests/untried/pos/t0064.scala b/tests/untried/pos/t0064.scala new file mode 100644 index 000000000..1eeca8dca --- /dev/null +++ b/tests/untried/pos/t0064.scala @@ -0,0 +1,6 @@ +object B { + def main(Args:Array[String]) = { + val (_,x) = (1,2); + x + 1; + } +} diff --git a/tests/untried/pos/t0066.scala b/tests/untried/pos/t0066.scala new file mode 100644 index 000000000..2153264e7 --- /dev/null +++ b/tests/untried/pos/t0066.scala @@ -0,0 +1,7 @@ +class GBTree[A, B] /*with Map[A, B, GBTree[A,B]]*/ { + abstract class Tree[A,B]; + case class Node[A,B](key:A,value:B,smaller:Node[A,B],bigger:Node[A,B]) + extends Tree[A,B]; + case class Nil[A,B]() extends Tree[A,B]; + +} diff --git a/tests/untried/pos/t0068.scala b/tests/untried/pos/t0068.scala new file mode 100644 index 000000000..beb2c7c0a --- /dev/null +++ b/tests/untried/pos/t0068.scala @@ -0,0 +1,6 @@ +class E { + def f() = { + val (_::l1) = List(1,2,3); + l1.tail; + } +} diff --git a/tests/untried/pos/t0069.scala b/tests/untried/pos/t0069.scala new file mode 100644 index 000000000..e4c242c0e --- /dev/null +++ b/tests/untried/pos/t0069.scala @@ -0,0 +1,10 @@ +object testCQ { + // why does this not work directly + case class Thing( name:String, contains:List[ Thing ] ); + + /* ... but this one does? + abstract class T; + case class Thing2( name:String, contains:List[ T ] ) extends T; + */ + +} diff --git a/tests/untried/pos/t0076.scala b/tests/untried/pos/t0076.scala new file mode 100644 index 000000000..5419cf515 --- /dev/null +++ b/tests/untried/pos/t0076.scala @@ -0,0 +1,9 @@ +// This is extracted from a test file => don't add a new test file. +object bug { + def foo(i: => Int): Int = 0; + + def bar: Int = { + var i: Int = 0; + foo (i); + } +} diff --git a/tests/untried/pos/t0081.scala b/tests/untried/pos/t0081.scala new file mode 100644 index 000000000..20fd60497 --- /dev/null +++ b/tests/untried/pos/t0081.scala @@ -0,0 +1,4 @@ +class A { + val b: A#B = new B; + class B {} +} diff --git a/tests/untried/pos/t0082.scala b/tests/untried/pos/t0082.scala new file mode 100644 index 000000000..2b365ca33 --- /dev/null +++ b/tests/untried/pos/t0082.scala @@ -0,0 +1,18 @@ + +object Main { + + def min0[A](less: (A, A) => Boolean, xs: List[A]): Option[A] = xs match { + case List() => None + case List(x) => Some(x) +// case x :: Nil => Some(x) + case y :: ys => (min0(less, ys): @unchecked) match { + case Some(m) => if (less(y, m)) Some(y) else Some(m) + } + } + + def min(xs: List[Int]) = min0((x: Int, y: Int) => x < y, xs); + + def main(args: Array[String]) = + Console.println(min(List())); + +} diff --git a/tests/untried/pos/t0085.scala b/tests/untried/pos/t0085.scala new file mode 100644 index 000000000..e018afb6e --- /dev/null +++ b/tests/untried/pos/t0085.scala @@ -0,0 +1,8 @@ +object A { + case class B(c: C) { + class C; + } + class C; + val b: B = new B(new C()); + val c: C = b.c; +} diff --git a/tests/untried/pos/t0091.scala b/tests/untried/pos/t0091.scala new file mode 100644 index 000000000..d491b7cfb --- /dev/null +++ b/tests/untried/pos/t0091.scala @@ -0,0 +1,6 @@ +class Bug { + def main(args: Array[String]) = { + var msg: String = null; // no bug if "null" instead of "_" + val f: PartialFunction[Any, Unit] = { case 42 => msg = "coucou" }; + } +} diff --git a/tests/untried/pos/t0093.scala b/tests/untried/pos/t0093.scala new file mode 100644 index 000000000..d648d773b --- /dev/null +++ b/tests/untried/pos/t0093.scala @@ -0,0 +1,4 @@ +object Bug { + def f(cond: => Boolean) = while (cond == false) {}; + // no bug with "false == cond" +} diff --git a/tests/untried/pos/t0095.scala b/tests/untried/pos/t0095.scala new file mode 100644 index 000000000..71386cf5c --- /dev/null +++ b/tests/untried/pos/t0095.scala @@ -0,0 +1,15 @@ +class ParseResult[+T] +case class Success[+T](t: T) extends ParseResult[T] + +abstract class Nonterminal[Output] { + + type SubNonterminal = Nonterminal[T] forSome { type T <: Output } + + def parse: ParseResult[Output] + + def parse1(nts: List[SubNonterminal]): ParseResult[Output] = + nts match { + case nt::nts => nt.parse match { case Success(so) => Success(so) } + case Nil => throw new Error + } +} diff --git a/tests/untried/pos/t0123.scala b/tests/untried/pos/t0123.scala new file mode 100644 index 000000000..79f0c907a --- /dev/null +++ b/tests/untried/pos/t0123.scala @@ -0,0 +1,3 @@ +class M{ + val 1 = 1; +} diff --git a/tests/untried/pos/t0154.scala b/tests/untried/pos/t0154.scala new file mode 100644 index 000000000..9fb943067 --- /dev/null +++ b/tests/untried/pos/t0154.scala @@ -0,0 +1,10 @@ +package test +trait MyMatchers { + val StringMatch = new AnyRef {} + trait Something { + (null : AnyRef) match { + case (StringMatch) => + case _ => + } + } +} diff --git a/tests/untried/pos/t0165.scala b/tests/untried/pos/t0165.scala new file mode 100644 index 000000000..76aef8524 --- /dev/null +++ b/tests/untried/pos/t0165.scala @@ -0,0 +1,14 @@ +package test3 +import scala.collection.mutable.LinkedHashMap + +trait Main { + def asMany : ArrayResult = { + object result extends LinkedHashMap[String,String] with ArrayResult { + def current = result + } + result + } + trait ArrayResult { + def current : scala.collection.Map[String,String] + } +} diff --git a/tests/untried/pos/t0204.scala b/tests/untried/pos/t0204.scala new file mode 100644 index 000000000..23d36523e --- /dev/null +++ b/tests/untried/pos/t0204.scala @@ -0,0 +1,7 @@ +class A { + object B { + def f() = { + class C extends A {}; new C : A + } + } +} diff --git a/tests/untried/pos/t0227.scala b/tests/untried/pos/t0227.scala new file mode 100644 index 000000000..806b20d40 --- /dev/null +++ b/tests/untried/pos/t0227.scala @@ -0,0 +1,31 @@ +final class Settings { + def f[T](a_args: T*): List[T] = Nil +} + +abstract class Factory { + type libraryType <: Base + + final def apply(settings: Settings): libraryType = sys.error("bla") +} + +abstract class Base { + val settings: Settings + + protected val demands: List[Factory] = Nil +} + +class SA(val settings: Settings) extends Base { + override val demands = List( + SD + ) ::: settings.f( + SC + ) +} + +object SC extends Factory { + type libraryType = Base +} + +object SD extends Factory { + type libraryType = SA +} diff --git a/tests/untried/pos/t0231.scala b/tests/untried/pos/t0231.scala new file mode 100644 index 000000000..0850d7a57 --- /dev/null +++ b/tests/untried/pos/t0231.scala @@ -0,0 +1,17 @@ +class Foo { + def aaa: Unit = { + println("a") + } +} + +class Bar extends Foo { + object b { + //println("b: " + a) //OK + println("b: " + Bar.super.aaa) + } +} + +object bug extends App { + new Bar + () +} diff --git a/tests/untried/pos/t0273.scala b/tests/untried/pos/t0273.scala new file mode 100644 index 000000000..ac02b8c15 --- /dev/null +++ b/tests/untried/pos/t0273.scala @@ -0,0 +1,6 @@ +class A + +object Test { +def a = () => () +def a[T] = (p:A) => () +} diff --git a/tests/untried/pos/t0288/Foo.scala b/tests/untried/pos/t0288/Foo.scala new file mode 100644 index 000000000..778ba65f5 --- /dev/null +++ b/tests/untried/pos/t0288/Foo.scala @@ -0,0 +1,9 @@ +package test2; + +import test.Outer; + +class Foo extends Outer{ + + val bar = new Inner(); // Shouldn't this work? + +} diff --git a/tests/untried/pos/t0288/Outer.java b/tests/untried/pos/t0288/Outer.java new file mode 100644 index 000000000..bea3e3f8d --- /dev/null +++ b/tests/untried/pos/t0288/Outer.java @@ -0,0 +1,9 @@ +package test; + +public class Outer{ + + public class Inner{ + + } + +} diff --git a/tests/untried/pos/t0301.scala b/tests/untried/pos/t0301.scala new file mode 100644 index 000000000..24b477601 --- /dev/null +++ b/tests/untried/pos/t0301.scala @@ -0,0 +1,12 @@ +package fos + +abstract class Expr +case class Var() extends Expr + +object Analyzer { + def substitution(expr: Expr, cls: (Var,Var)): Expr = + expr match { + case cls._2 => cls._1 // source of the error + case _ => expr + } +} diff --git a/tests/untried/pos/t0304.scala b/tests/untried/pos/t0304.scala new file mode 100644 index 000000000..607a115db --- /dev/null +++ b/tests/untried/pos/t0304.scala @@ -0,0 +1,5 @@ +object O { + def f1 = -1; + def f2 = 0-1; + def f3 = f1 + f2; +} diff --git a/tests/untried/pos/t0305.scala b/tests/untried/pos/t0305.scala new file mode 100644 index 000000000..4838b1fcf --- /dev/null +++ b/tests/untried/pos/t0305.scala @@ -0,0 +1,7 @@ +object Test extends App { + + def foo(is:Int*) = 1; + def foo(i:Int) = 2; + + assert(foo( List(3):_* ) == 1) +} diff --git a/tests/untried/pos/t0438.scala b/tests/untried/pos/t0438.scala new file mode 100644 index 000000000..fa5b7711f --- /dev/null +++ b/tests/untried/pos/t0438.scala @@ -0,0 +1,12 @@ +class Foo { + implicit def pair2fun2[A, B, C](f: (A, B) => C) = + {p: (A, B) => f(p._1, p._2) } + + def foo(f: ((Int, Int)) => Int) = f + def bar(x: Int, y: Int) = x + y + + foo({ (x: Int, y: Int) => x + y }) // works + foo(pair2fun2(bar _)) // works + foo(bar _) // error + foo(bar) // same error +} diff --git a/tests/untried/pos/t0453.scala b/tests/untried/pos/t0453.scala new file mode 100644 index 000000000..dfacc5eed --- /dev/null +++ b/tests/untried/pos/t0453.scala @@ -0,0 +1,6 @@ +object Test { + val foo = new { + trait Bar + def l () : Bar = { new Bar {} } + } +} diff --git a/tests/untried/pos/t0504.scala b/tests/untried/pos/t0504.scala new file mode 100644 index 000000000..b2b0b85e4 --- /dev/null +++ b/tests/untried/pos/t0504.scala @@ -0,0 +1,9 @@ +package b { + class B +} + +package a.b { + class A { + val x = new _root_.b.B + } +} diff --git a/tests/untried/pos/t0586.scala b/tests/untried/pos/t0586.scala new file mode 100644 index 000000000..540e225a1 --- /dev/null +++ b/tests/untried/pos/t0586.scala @@ -0,0 +1,9 @@ +object RClose { + type ReflectCloseable = { def close(): Unit } + def withReflectCloseable[T <: ReflectCloseable, R](s: T)(action: T => R): R = + try { + action(s) + } finally { + s.close() + } +} diff --git a/tests/untried/pos/t0591.scala b/tests/untried/pos/t0591.scala new file mode 100644 index 000000000..15f2dba08 --- /dev/null +++ b/tests/untried/pos/t0591.scala @@ -0,0 +1,7 @@ +object Test { + def implicitly[T](implicit t : T) = t + implicit def perhaps[T](implicit t : T) : Option[T] = Some(t) + implicit val hello = "Hello" + implicitly[String] + implicitly[Option[String]] +} diff --git a/tests/untried/pos/t0599.scala b/tests/untried/pos/t0599.scala new file mode 100644 index 000000000..885159af6 --- /dev/null +++ b/tests/untried/pos/t0599.scala @@ -0,0 +1,18 @@ +abstract class FooA { + type A <: Ax; + abstract class Ax; + abstract class InnerA { + type B <: A; + def doB : B; + } + } + trait FooB extends FooA { + type A <: Ax; + trait Ax extends super.Ax { def xxx : Int; } + abstract class InnerB extends InnerA { + // type B <: A; + val a : A = doB; + a.xxx; + doB.xxx; + } + } diff --git a/tests/untried/pos/t0612/C.scala b/tests/untried/pos/t0612/C.scala new file mode 100644 index 000000000..1f260a5b0 --- /dev/null +++ b/tests/untried/pos/t0612/C.scala @@ -0,0 +1,6 @@ +package test +package app + +class C { + Ob.f +} diff --git a/tests/untried/pos/t0612/Ob.scala b/tests/untried/pos/t0612/Ob.scala new file mode 100644 index 000000000..d12e64963 --- /dev/null +++ b/tests/untried/pos/t0612/Ob.scala @@ -0,0 +1,5 @@ +package test + +object Ob { + protected[test] def f: Unit = {} +} diff --git a/tests/untried/pos/t0625.scala b/tests/untried/pos/t0625.scala new file mode 100644 index 000000000..561454259 --- /dev/null +++ b/tests/untried/pos/t0625.scala @@ -0,0 +1,8 @@ +object Test { + def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) + + def main(args: Array[String]): Unit = { + idMap(Some(5)) + idMap(Responder.constant(5)) + } +} diff --git a/tests/untried/pos/t0644.scala b/tests/untried/pos/t0644.scala new file mode 100644 index 000000000..e51ec7df5 --- /dev/null +++ b/tests/untried/pos/t0644.scala @@ -0,0 +1,12 @@ +class A { + def apply(): Int = 0 + def update(n: Int): Unit = {} +} + +class B extends A { + this() + this()=1 + // 644 is wontfix so this is what should work. + super.apply() + super.update(1) +} diff --git a/tests/untried/pos/t0654.scala b/tests/untried/pos/t0654.scala new file mode 100644 index 000000000..07b4e7279 --- /dev/null +++ b/tests/untried/pos/t0654.scala @@ -0,0 +1,5 @@ +object Test { + class Foo[T] + type C[T] = Foo[_ <: T] + val a: C[AnyRef] = new Foo[AnyRef] +} diff --git a/tests/untried/pos/t0674.scala b/tests/untried/pos/t0674.scala new file mode 100644 index 000000000..589eeec9f --- /dev/null +++ b/tests/untried/pos/t0674.scala @@ -0,0 +1,48 @@ +object Test extends App { +println( +for(a <- Some(1); + b <- Some(2); + c <- Some(3); + d <- Some(4); + e <- Some(5); + f <- Some(6); + g <- Some(7); + h <- Some(8); + i <- Some(9); + j <- Some(10); + k <- Some(11); + l <- Some(12); + m <- Some(13); + n <- Some(14); + o <- Some(15); + p <- Some(16); + q <- Some(17); + r <- Some(18); + s <- Some(19); + d <- Some(4); + e <- Some(5); + f <- Some(6); + g <- Some(7); + h <- Some(8); + i <- Some(9); + j <- Some(10); + k <- Some(11); + l <- Some(12); + m <- Some(13); + n <- Some(14); + o <- Some(15); + p <- Some(16); + q <- Some(17); + r <- Some(18); + s <- Some(19); + k <- Some(11); + l <- Some(12); + m <- Some(13); + n <- Some(14); + o <- Some(15) +// p <- Some(16); +// q <- Some(17) +// r <- Some(18); +// s <- Some(19) + ) yield a) +} diff --git a/tests/untried/pos/t0695/JavaClass.java b/tests/untried/pos/t0695/JavaClass.java new file mode 100644 index 000000000..a765f7e32 --- /dev/null +++ b/tests/untried/pos/t0695/JavaClass.java @@ -0,0 +1,5 @@ +public class JavaClass<A> { + class InnerClass { + public A method() { return null; } + } +} diff --git a/tests/untried/pos/t0695/Test.scala b/tests/untried/pos/t0695/Test.scala new file mode 100644 index 000000000..7318867bf --- /dev/null +++ b/tests/untried/pos/t0695/Test.scala @@ -0,0 +1,3 @@ +object Test extends JavaClass[AnyRef] { + var field: InnerClass = null +} diff --git a/tests/untried/pos/t0710.scala b/tests/untried/pos/t0710.scala new file mode 100644 index 000000000..d550d63f9 --- /dev/null +++ b/tests/untried/pos/t0710.scala @@ -0,0 +1,10 @@ +object t0710 { + def method: Unit = { + sealed class Parent + case object Child extends Parent + val x: Parent = Child + x match { + case Child => () + } + } +} diff --git a/tests/untried/pos/t0770.scala b/tests/untried/pos/t0770.scala new file mode 100644 index 000000000..7a0a2bf9b --- /dev/null +++ b/tests/untried/pos/t0770.scala @@ -0,0 +1,13 @@ +trait A +{ + private[this] val p = 5 + + def f = (b: Byte) => p +} + +trait B +{ + def failure: Boolean + def success = !failure +} + diff --git a/tests/untried/pos/t0774/deathname.scala b/tests/untried/pos/t0774/deathname.scala new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/untried/pos/t0774/deathname.scala @@ -0,0 +1 @@ + diff --git a/tests/untried/pos/t0774/unrelated.scala b/tests/untried/pos/t0774/unrelated.scala new file mode 100644 index 000000000..1efdb2505 --- /dev/null +++ b/tests/untried/pos/t0774/unrelated.scala @@ -0,0 +1,9 @@ +object Outer { + import Inner._ + + deathname + + object Inner { + def deathname: Int = 1 + } +} diff --git a/tests/untried/pos/t0786.scala b/tests/untried/pos/t0786.scala new file mode 100644 index 000000000..4cd09f4a1 --- /dev/null +++ b/tests/untried/pos/t0786.scala @@ -0,0 +1,29 @@ +object ImplicitProblem { + class M[T] + + def nullval[T] = null.asInstanceOf[T]; + + trait Rep[T] { + def eval: Int + } + + implicit def toRep0(n: Int) = new Rep[Int] { + def eval = 0 + } + + implicit def toRepN[T](n: M[T])(implicit f: T => Rep[T]) = new Rep[M[T]] { + def eval = f(nullval[T]).eval + 1 + } + + def depth[T <% Rep[T]](n: T) = n.eval + + def main(args: Array[String]): Unit = { + println(depth(nullval[M[Int]])) // (1) this works + println(nullval[M[Int]].eval) // (2) this works + + type m = M[Int] + println(depth(nullval[m])) // (3) this doesn't compile on 2.7.RC1 + println(nullval[m].eval) // (4) this works + } + +} diff --git a/tests/untried/pos/t0851.scala b/tests/untried/pos/t0851.scala new file mode 100644 index 000000000..fc7109dcd --- /dev/null +++ b/tests/untried/pos/t0851.scala @@ -0,0 +1,14 @@ +package test + +object test1 { + case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){ + def apply(t : T) = (s:T2) => f(t,s) + def apply(p : (T,T2)) = f(p._1,p._2) + } + implicit def g[T](f : (T,String) => String) = Foo(f) + def main(args : Array[String]) : Unit = { + val f = (x:Int,s:String) => s + x + println(f(1)) + () + } +} diff --git a/tests/untried/pos/t0872.scala b/tests/untried/pos/t0872.scala new file mode 100644 index 000000000..79df8e804 --- /dev/null +++ b/tests/untried/pos/t0872.scala @@ -0,0 +1,8 @@ +object Main { + def main(args : Array[String]): Unit = { + val fn = (a : Int, str : String) => "a: " + a + ", str: " + str + implicit def fx[T](f : (T,String) => String) = (x:T) => f(x,null) + println(fn(1)) + () + } +} diff --git a/tests/untried/pos/t0904.scala b/tests/untried/pos/t0904.scala new file mode 100644 index 000000000..28ad30fc2 --- /dev/null +++ b/tests/untried/pos/t0904.scala @@ -0,0 +1,17 @@ +trait A { + def apply(x: Int): Int + def update(x: Int, y: Int): Unit +} + +trait B extends A + +abstract class Foo { + val a: A = null + val b: B = null + + a(0) = 1 + b(0) = 1 + + a(0) += 1 + b(0) += 1 // this one does not type check. +} diff --git a/tests/untried/pos/t0905.scala b/tests/untried/pos/t0905.scala new file mode 100644 index 000000000..8cd84759c --- /dev/null +++ b/tests/untried/pos/t0905.scala @@ -0,0 +1,6 @@ +object Test { + trait A[T] + def f(implicit p: A[T] forSome { type T } ) = null + implicit val x: A[T] forSome { type T } = null + println(f) +} diff --git a/tests/untried/pos/t1000.scala b/tests/untried/pos/t1000.scala new file mode 100644 index 000000000..613af76b9 --- /dev/null +++ b/tests/untried/pos/t1000.scala @@ -0,0 +1,8 @@ +object A { + println("""This a "raw" string ending with a "double quote"""") +} + +object Test extends App { + val xs = Array(1, 2, 3) + Console.println(xs.filter(_ >= 0).length) +} diff --git a/tests/untried/pos/t1001.scala b/tests/untried/pos/t1001.scala new file mode 100644 index 000000000..7a06bfa0e --- /dev/null +++ b/tests/untried/pos/t1001.scala @@ -0,0 +1,115 @@ +// was t1001.scala +class Foo; + +object Overload{ + val foo = classOf[Foo].getConstructors()(0) + foo.getDeclaringClass +} + +// was t1001.scala + +// I suspect the stack overflow is occurring when the compiler is determining the types for the following line at the end of the file:- +// val data = List(N26,N25) + +abstract class A +{ + // commenting out the following line (only) leads to successful compilation + protected val data: List[A] +} + +trait B[T <: B[T]] extends A { self: T => } + +abstract class C extends A +{ + // commenting out the following line (only) leads to successful compilation + protected val data: List[C] +} + +abstract class D extends C with B[D] {} + +abstract class Ee extends C with B[Ee] +{ +} + + +object N1 extends D +{ + val data = Nil +} + +object N2 extends D +{ + val data = Nil +} + +object N5 extends D +{ + val data = List(N1) +} + +object N6 extends D +{ + val data = List(N1) +} + +object N8 extends D +{ + val data = List(N1) +} + +object N10 extends D +{ + val data = Nil +} + +object N13 extends D +{ + val data = List(N2) +} + +object N14 extends D +{ + val data = List(N5,N10,N8) +} + +object N15 extends D +{ + val data = List(N14) +} + +object N16 extends D +{ + val data = List(N13,N6,N15) +} + +object N17 extends D +{ + val data = List(N16) +} + +object N21 extends D +{ + val data = List(N16) +} + +object N22 extends D +{ + val data = List(N17) +} + +object N25 extends D +{ + val data = List(N22) +} + +object N26 extends Ee +{ + val data = List(N21,N17) +} + +// Commenting out the following object (only) leads to successful compilation +object N31 extends Ee +{ + // If we use List[C](N26,N25), we achieve successful compilation + val data = List[C](N26,N25) +} diff --git a/tests/untried/pos/t1006.scala b/tests/untried/pos/t1006.scala new file mode 100644 index 000000000..2163b2b74 --- /dev/null +++ b/tests/untried/pos/t1006.scala @@ -0,0 +1,15 @@ +object Test extends App { + +def test(): Unit = { + + abstract class A[T] { + def myVal: T + } + + class B[T1](value: T1) extends A[T1] { + def myVal: T1 = value + } + + Console.println(new B[Int](23).myVal) +} +} diff --git a/tests/untried/pos/t1014.scala b/tests/untried/pos/t1014.scala new file mode 100644 index 000000000..6fb7f7ba4 --- /dev/null +++ b/tests/untried/pos/t1014.scala @@ -0,0 +1,16 @@ +class NodeSeq +class Elem extends NodeSeq + +class EO extends App with Moo { + // return type is Flog, inherited from overridden method. + // implicit conversions are applied because expected type `pt` is `Flog` when `computeType(rhs, pt)`. + def cat = (??? : Elem) + + implicit def nodeSeqToFlog(in: Elem): Flog = new Flog(in) +} + +trait Moo { + def cat: Flog +} + +class Flog(val in: NodeSeq) diff --git a/tests/untried/pos/t1027.scala b/tests/untried/pos/t1027.scala new file mode 100644 index 000000000..02ba9a8a3 --- /dev/null +++ b/tests/untried/pos/t1027.scala @@ -0,0 +1,18 @@ +object T1027 extends App { + trait Comparable[T <: Comparable[T]] { this: T => + def < (that: T): Boolean + def <=(that: T): Boolean = this < that || this == that + def > (that: T): Boolean = that < this + def >=(that: T): Boolean = that <= this + } + class A(val x: String) extends Comparable[A]{ + def < (that: A) = this.x < that.x + } + val a = new A("a") + val b = new A("b") + println(a < b) + println(a > b) + println(a <= b) + println(a >= b) + println("Comparable traits : " + (new A("x") > new A("y")).toString) + } diff --git a/tests/untried/pos/t1029/Test_1.scala b/tests/untried/pos/t1029/Test_1.scala new file mode 100644 index 000000000..d268c7142 --- /dev/null +++ b/tests/untried/pos/t1029/Test_1.scala @@ -0,0 +1,7 @@ +class ann(a: Array[Int]) extends annotation.StaticAnnotation + +object Test1 { + // bug #1029 + @ann(Array(10, 2)) def u = () + val v: String @ann(Array(13, 2)) = "-1" +} diff --git a/tests/untried/pos/t1029/Test_2.scala b/tests/untried/pos/t1029/Test_2.scala new file mode 100644 index 000000000..00589052c --- /dev/null +++ b/tests/untried/pos/t1029/Test_2.scala @@ -0,0 +1,3 @@ +object Test { + val t = Test1 +} diff --git a/tests/untried/pos/t1034.scala b/tests/untried/pos/t1034.scala new file mode 100644 index 000000000..9d966334a --- /dev/null +++ b/tests/untried/pos/t1034.scala @@ -0,0 +1,6 @@ +object Terminal { + def apply[a] : a => Unit = { a => () } + val i0 = Terminal.apply[Int] + val i1 = (Terminal)[Int] + val i2 = Terminal[Int] +} diff --git a/tests/untried/pos/t1035.scala b/tests/untried/pos/t1035.scala new file mode 100644 index 000000000..e0a9379c7 --- /dev/null +++ b/tests/untried/pos/t1035.scala @@ -0,0 +1,32 @@ +//A fatal error or Scala compiler +// Scala compiler version 2.7.1-final -- (c) 2002-2011 LAMP/EPFL +// Carlos Loria cloria@artinsoft.com +// 7/10/2008 + +class A { + var name:String = _ + def getName() = name + def this(name:String, age:Int){this();this.name=name} + +} + +class B(name:String) extends A(name,0){ +} + +class D { + + object A { + def unapply(p:A) = Some(p.getName) + } + + object B { + def unapply(p:B) = Some(p.getName) + } + def foo(p:Any) = p match { + case B(n) => println("B") + case A(n) => println("A") + + + } + +} diff --git a/tests/untried/pos/t1048.scala b/tests/untried/pos/t1048.scala new file mode 100644 index 000000000..cd16db5b6 --- /dev/null +++ b/tests/untried/pos/t1048.scala @@ -0,0 +1,14 @@ +trait T[U] { + def x: T[V] forSome { type V <: U } +} + +object T { + def unapply[U](t: T[U]): Option[T[V] forSome { type V <: U }] = Some(t.x) +} + +object Test { + def f[W](t: T[W]) = t match { + case T(T(_)) => () + } +} + diff --git a/tests/untried/pos/t1049.scala b/tests/untried/pos/t1049.scala new file mode 100644 index 000000000..61d99f946 --- /dev/null +++ b/tests/untried/pos/t1049.scala @@ -0,0 +1,7 @@ +package t1049 + +abstract class Test { + type T <: A + class A { self: T => } + class B extends A { self: T => } +} diff --git a/tests/untried/pos/t1050.scala b/tests/untried/pos/t1050.scala new file mode 100644 index 000000000..d34b0cff1 --- /dev/null +++ b/tests/untried/pos/t1050.scala @@ -0,0 +1,10 @@ +package t1050 + +abstract class A { + type T <: scala.AnyRef + class A { this: T => + def b = 3 + def c = b + b + } +} diff --git a/tests/untried/pos/t1053.scala b/tests/untried/pos/t1053.scala new file mode 100644 index 000000000..1d4dfb637 --- /dev/null +++ b/tests/untried/pos/t1053.scala @@ -0,0 +1,6 @@ +trait T[A] { trait U { type W = A; val x = 3 } } + +object Test { + val x : ({ type V = T[this.type] })#V = null + val y = new x.U { } +} diff --git a/tests/untried/pos/t1056.scala b/tests/untried/pos/t1056.scala new file mode 100644 index 000000000..68f1ff273 --- /dev/null +++ b/tests/untried/pos/t1056.scala @@ -0,0 +1,5 @@ +object Test { + type T = PartialFunction[String,String] + def g(h: T) = () + g({case s: String => s}) +} diff --git a/tests/untried/pos/t1070.scala b/tests/untried/pos/t1070.scala new file mode 100644 index 000000000..1622043a8 --- /dev/null +++ b/tests/untried/pos/t1070.scala @@ -0,0 +1,4 @@ +import scala.beans.BeanProperty; +trait beanpropertytrait { + @BeanProperty var myVariable: Long = -1l; +} diff --git a/tests/untried/pos/t1071.scala b/tests/untried/pos/t1071.scala new file mode 100644 index 000000000..59149a021 --- /dev/null +++ b/tests/untried/pos/t1071.scala @@ -0,0 +1,17 @@ +class C { + private val a = 0 + def getA = a +} + +class D(c: C) { + def a = c.getA +} + +object Test { + implicit def c2d(c: C): D = new D(c) + + val c = new C + (c: D).a // works + c.a // error +} + diff --git a/tests/untried/pos/t1075.scala b/tests/untried/pos/t1075.scala new file mode 100644 index 000000000..5f72957da --- /dev/null +++ b/tests/untried/pos/t1075.scala @@ -0,0 +1,17 @@ +class Directory(var dir_ : String) +{ + if (!dir_.startsWith("/")) { + throw new RuntimeException("Invalid directory") + } + dir_ = dir_.replaceAll("/{2,}", "/") + + def this(serialized : Array[Byte]) = { + this(new String(serialized, "UTF-8")) + } + + def dir = dir_ +} + +object Test extends Directory("/bab/dkkd//dkkdkd//kdkdk") with App { + println(dir) +} diff --git a/tests/untried/pos/t1085.scala b/tests/untried/pos/t1085.scala new file mode 100644 index 000000000..c59e657cb --- /dev/null +++ b/tests/untried/pos/t1085.scala @@ -0,0 +1,9 @@ +trait Functor[a] { + type MyType[a] +} + +object Test { + def listFunctor[a]: Functor[a]{type MyType[x]=List[x]} = new Functor[a] { + type MyType[t]=List[t] + } +} diff --git a/tests/untried/pos/t1090.scala b/tests/untried/pos/t1090.scala new file mode 100644 index 000000000..a9bce90b0 --- /dev/null +++ b/tests/untried/pos/t1090.scala @@ -0,0 +1,16 @@ +object Test { + trait Manager { + type Node; + def iterator : Iterator[Node] + } + trait Core { + type Node; + trait NodeImpl + trait Manager extends Test.Manager { + type Node = Core.this.Node + } + def f(manager : Manager) = manager.iterator.foreach{ + case node : NodeImpl => + } + } +} diff --git a/tests/untried/pos/t1101/J.java b/tests/untried/pos/t1101/J.java new file mode 100644 index 000000000..2bc1d53e0 --- /dev/null +++ b/tests/untried/pos/t1101/J.java @@ -0,0 +1 @@ +class J { enum E { E1 } } diff --git a/tests/untried/pos/t1101/S.scala b/tests/untried/pos/t1101/S.scala new file mode 100644 index 000000000..af7a591e5 --- /dev/null +++ b/tests/untried/pos/t1101/S.scala @@ -0,0 +1 @@ +class S { val x: J.E = null; System.out.println(J.E.E1) } diff --git a/tests/untried/pos/t1102/J.java b/tests/untried/pos/t1102/J.java new file mode 100644 index 000000000..530102b91 --- /dev/null +++ b/tests/untried/pos/t1102/J.java @@ -0,0 +1,4 @@ +class J { + enum E { E1 } + void foo(E e) { } +} diff --git a/tests/untried/pos/t1102/S.scala b/tests/untried/pos/t1102/S.scala new file mode 100644 index 000000000..9beee8d90 --- /dev/null +++ b/tests/untried/pos/t1102/S.scala @@ -0,0 +1 @@ +class S(j:J) { j.foo(J.E.E1) } diff --git a/tests/untried/pos/t1107a.scala b/tests/untried/pos/t1107a.scala new file mode 100644 index 000000000..0bf40bb4c --- /dev/null +++ b/tests/untried/pos/t1107a.scala @@ -0,0 +1,10 @@ +object F { + type AnyClass = Class[_] + def tryf[T](ignore: List[AnyClass])(f: => T): Any = { + try { + f + } catch { + case e if ignore == null || ignore.isEmpty => {false} + } + } +} diff --git a/tests/untried/pos/t1107b/O.scala b/tests/untried/pos/t1107b/O.scala new file mode 100644 index 000000000..019886770 --- /dev/null +++ b/tests/untried/pos/t1107b/O.scala @@ -0,0 +1,13 @@ +object O +{ + def d(t: Top) = t match { + case s: Sub => true + case _ => false + } + + def main(args: Array[String]): Unit = { + val c = new AnyRef with C + + c.bob.toString + c.bob2.toString + } +} diff --git a/tests/untried/pos/t1107b/T.scala b/tests/untried/pos/t1107b/T.scala new file mode 100644 index 000000000..0dff0b94f --- /dev/null +++ b/tests/untried/pos/t1107b/T.scala @@ -0,0 +1,7 @@ +sealed trait Top +sealed trait Sub extends Top +trait C { + private object P extends Sub + def bob() = P.getClass + def bob2() = O.d(P) +} diff --git a/tests/untried/pos/t1119.scala b/tests/untried/pos/t1119.scala new file mode 100644 index 000000000..8b36877c4 --- /dev/null +++ b/tests/untried/pos/t1119.scala @@ -0,0 +1,10 @@ +trait B +{ + type T >: this.type <: B + + + // compile-time check: have we achieved our objective? + def test: T = this +} + + diff --git a/tests/untried/pos/t1123.scala b/tests/untried/pos/t1123.scala new file mode 100644 index 000000000..3812fa3eb --- /dev/null +++ b/tests/untried/pos/t1123.scala @@ -0,0 +1,11 @@ + +package test; +object Test { + class Editor { + private object extraListener { + def h : AnyRef = extraListener + } + def f = extraListener.h + } + def main(args : Array[String]) : Unit = (new Editor).f +} diff --git a/tests/untried/pos/t112606A.scala b/tests/untried/pos/t112606A.scala new file mode 100644 index 000000000..5bf532f8d --- /dev/null +++ b/tests/untried/pos/t112606A.scala @@ -0,0 +1,25 @@ +package test; +trait Test { + trait Global { + type Tree; + def get : Tree; + } + trait TreeBuilder { + val global : Global; + def set(tree : global.Tree) = {} + } + val nsc : Global; + trait FileImpl { + object treeBuilder extends TreeBuilder { + val global : nsc.type = nsc; + } + // ok + treeBuilder.set(nsc.get); + } + val file0 : FileImpl; + // ok + file0.treeBuilder.set(nsc.get); + def file : FileImpl; + // type mismatch + file.treeBuilder.set(nsc.get); +} diff --git a/tests/untried/pos/t1131.scala b/tests/untried/pos/t1131.scala new file mode 100644 index 000000000..1b2a90457 --- /dev/null +++ b/tests/untried/pos/t1131.scala @@ -0,0 +1,4 @@ +trait A { self: Any { def p: Any } => + def f(b: => Unit): Unit = {} + f { p } +} diff --git a/tests/untried/pos/t1133.scala b/tests/untried/pos/t1133.scala new file mode 100644 index 000000000..562b528ea --- /dev/null +++ b/tests/untried/pos/t1133.scala @@ -0,0 +1,32 @@ +object Match +{ + def main(args: Array[String]) = { + args(0) match { + case Extractor1(Extractor2(Extractor3("dog", "dog", "dog"), x2, x3), b, c, Extractor3("b", "b", f), e) => println(e) + case Extractor3(Extractor2(Extractor1("a", "aa", "aaa", "aa", "a"), Extractor2("a", "aa", "aaa"), e), y, z) => println(e) + case Extractor2(Extractor3("a", "a", x), Extractor3("b", "b", y), Extractor3("c", "c", z)) => println(z) + case _ => println("fail") + } + } + + object Extractor1 { + def unapply(x: Any) = x match { + case x: String => Some(x, x+x, x+x+x, x+x, x) + case _ => None + } + } + + object Extractor2 { + def unapply(x: Any) = x match { + case x: String => Some(x, x+x, x+x+x) + case _ => None + } + } + + object Extractor3 { + def unapply(x: Any) = x match { + case x: String => Some(x, x, x) + case _ => None + } + } +} diff --git a/tests/untried/pos/t1136.scala b/tests/untried/pos/t1136.scala new file mode 100644 index 000000000..92d603e69 --- /dev/null +++ b/tests/untried/pos/t1136.scala @@ -0,0 +1,8 @@ +object test { + def foo(s: Int*): Unit = { + s.toList match { + case t: List[Int] => foo(t: _*) + //case _ => // unreachable code + } + } +} diff --git a/tests/untried/pos/t1146.scala b/tests/untried/pos/t1146.scala new file mode 100644 index 000000000..7e5adc4f4 --- /dev/null +++ b/tests/untried/pos/t1146.scala @@ -0,0 +1,6 @@ +class Code { + val _ = () => { + val arr = Array[String]() + null + } +} diff --git a/tests/untried/pos/t1147.scala b/tests/untried/pos/t1147.scala new file mode 100644 index 000000000..d4b3967dd --- /dev/null +++ b/tests/untried/pos/t1147.scala @@ -0,0 +1,6 @@ +class App(arg: String) { + @deprecated("..") def this() { + this("foo") + } +} + diff --git a/tests/untried/pos/t115.scala b/tests/untried/pos/t115.scala new file mode 100644 index 000000000..0e6a63c16 --- /dev/null +++ b/tests/untried/pos/t115.scala @@ -0,0 +1,9 @@ +class S[A](f: A => A, x: A) { + Console.println(f(x)); +} +class T[B](f: B => B, y: B) extends S((x: B) => f(x), y) { +} +object Test extends App { + new T[Int](x => x * 2, 1); + val f = new S((x: Int) => x, 1); +} diff --git a/tests/untried/pos/t1150/J.java b/tests/untried/pos/t1150/J.java new file mode 100644 index 000000000..68fa04a17 --- /dev/null +++ b/tests/untried/pos/t1150/J.java @@ -0,0 +1,4 @@ +class J { + static void bbb (Boolean b) { } + static void ddd (Double d) { } +} diff --git a/tests/untried/pos/t1150/S.scala b/tests/untried/pos/t1150/S.scala new file mode 100644 index 000000000..41dd06403 --- /dev/null +++ b/tests/untried/pos/t1150/S.scala @@ -0,0 +1,4 @@ +object S { + J.bbb(new java.lang.Boolean(true)) + J.ddd(new java.lang.Double(0)) +} diff --git a/tests/untried/pos/t1152/J.java b/tests/untried/pos/t1152/J.java new file mode 100644 index 000000000..6e562e573 --- /dev/null +++ b/tests/untried/pos/t1152/J.java @@ -0,0 +1 @@ +class J { java.util.List<String> k = null; } diff --git a/tests/untried/pos/t1152/S.scala b/tests/untried/pos/t1152/S.scala new file mode 100644 index 000000000..7f751c509 --- /dev/null +++ b/tests/untried/pos/t1152/S.scala @@ -0,0 +1,2 @@ +class S2(fn:(J)=>Any) +object S { new S2(_.k) } diff --git a/tests/untried/pos/t1159.scala b/tests/untried/pos/t1159.scala new file mode 100644 index 000000000..7e09418b2 --- /dev/null +++ b/tests/untried/pos/t1159.scala @@ -0,0 +1,13 @@ +object test17 { + def main(args : Array[String]) = { + val value = + if (false) + new java.lang.Float(0) + else if (false) + new java.lang.Long(0) + else + new java.lang.Integer(0) + + println(value) + } +} diff --git a/tests/untried/pos/t116.scala b/tests/untried/pos/t116.scala new file mode 100644 index 000000000..1e31b71bf --- /dev/null +++ b/tests/untried/pos/t116.scala @@ -0,0 +1,6 @@ +class C { + def this(x: Int) = { + this(); + class D extends C; + } +} diff --git a/tests/untried/pos/t1164.scala b/tests/untried/pos/t1164.scala new file mode 100644 index 000000000..ab58c1d6b --- /dev/null +++ b/tests/untried/pos/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 }} + + + // 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/untried/pos/t1168.scala b/tests/untried/pos/t1168.scala new file mode 100644 index 000000000..75638e792 --- /dev/null +++ b/tests/untried/pos/t1168.scala @@ -0,0 +1,16 @@ +object Test extends App { + + trait SpecialException {} + + try { + throw new Exception + } catch { + case e : SpecialException => { + println("matched SpecialException: "+e) + assume(e.isInstanceOf[SpecialException]) + } + case e : Exception => { + assume(e.isInstanceOf[Exception]) + } + } +} diff --git a/tests/untried/pos/t1176/J.java b/tests/untried/pos/t1176/J.java new file mode 100644 index 000000000..0d82c75fc --- /dev/null +++ b/tests/untried/pos/t1176/J.java @@ -0,0 +1,4 @@ +class J { + J() { } + J( java.util.Collection<?> collection ) { } +} diff --git a/tests/untried/pos/t1176/S.scala b/tests/untried/pos/t1176/S.scala new file mode 100644 index 000000000..a7fc3e0ce --- /dev/null +++ b/tests/untried/pos/t1176/S.scala @@ -0,0 +1 @@ +class S { new J } diff --git a/tests/untried/pos/t1185.scala b/tests/untried/pos/t1185.scala new file mode 100644 index 000000000..fa863d158 --- /dev/null +++ b/tests/untried/pos/t1185.scala @@ -0,0 +1,15 @@ +class Test { + private[this] var member = 0; + def foo() = { + (() => member=1)() + } + def look=member +} + +object Main{ + def main(args : Array[String]): Unit = { + val fff=new Test() + fff.foo() + assert(1==fff.look) + } +} diff --git a/tests/untried/pos/t1186/t1186.java b/tests/untried/pos/t1186/t1186.java new file mode 100644 index 000000000..5f2607623 --- /dev/null +++ b/tests/untried/pos/t1186/t1186.java @@ -0,0 +1,8 @@ +import scala.collection.immutable.Map; + +class Test { + + void foo() { + Map<String, String> map = null; + } +} diff --git a/tests/untried/pos/t119.scala b/tests/untried/pos/t119.scala new file mode 100644 index 000000000..44a156675 --- /dev/null +++ b/tests/untried/pos/t119.scala @@ -0,0 +1,7 @@ +class K[E] { + case class A(v: E) {} +} + +class K2 extends K[Int] { + val A(v) = A(42) +} diff --git a/tests/untried/pos/t1196/J.java b/tests/untried/pos/t1196/J.java new file mode 100644 index 000000000..2ec7a711b --- /dev/null +++ b/tests/untried/pos/t1196/J.java @@ -0,0 +1 @@ +class J { static void foo(Class c) { } } diff --git a/tests/untried/pos/t1196/S.scala b/tests/untried/pos/t1196/S.scala new file mode 100644 index 000000000..f17cd249a --- /dev/null +++ b/tests/untried/pos/t1196/S.scala @@ -0,0 +1 @@ +object S { J.foo(null) } diff --git a/tests/untried/pos/t1197/J.java b/tests/untried/pos/t1197/J.java new file mode 100644 index 000000000..b4e0a4255 --- /dev/null +++ b/tests/untried/pos/t1197/J.java @@ -0,0 +1,2 @@ +class J { interface K { } } + diff --git a/tests/untried/pos/t1197/S.scala b/tests/untried/pos/t1197/S.scala new file mode 100644 index 000000000..7c9c15440 --- /dev/null +++ b/tests/untried/pos/t1197/S.scala @@ -0,0 +1,2 @@ +object S extends J.K + diff --git a/tests/untried/pos/t1203a.scala b/tests/untried/pos/t1203a.scala new file mode 100644 index 000000000..cf5ab9fba --- /dev/null +++ b/tests/untried/pos/t1203a.scala @@ -0,0 +1,13 @@ +class Node +object NodeSeq { + implicit def seqToNodeSeq(s: Seq[Node]): NodeSeq = ??? +} +abstract class NodeSeq extends collection.immutable.Seq[Node] + +case class ant(t: String) extends scala.annotation.Annotation +object Test { + def main(args: Array[String]): Unit = { + val a: NodeSeq @ant("12") = Nil + println(a) + } +} diff --git a/tests/untried/pos/t1203b/J.java b/tests/untried/pos/t1203b/J.java new file mode 100644 index 000000000..7fae118e0 --- /dev/null +++ b/tests/untried/pos/t1203b/J.java @@ -0,0 +1 @@ +interface J { int j = 200 ; } diff --git a/tests/untried/pos/t1203b/S.scala b/tests/untried/pos/t1203b/S.scala new file mode 100644 index 000000000..68eac4bf6 --- /dev/null +++ b/tests/untried/pos/t1203b/S.scala @@ -0,0 +1 @@ +object S { J.j } diff --git a/tests/untried/pos/t1208.scala b/tests/untried/pos/t1208.scala new file mode 100644 index 000000000..9ac783d39 --- /dev/null +++ b/tests/untried/pos/t1208.scala @@ -0,0 +1,4 @@ +object Test { + object Foo + val f: Option[Foo.type] = Some(Foo) +} diff --git a/tests/untried/pos/t121.scala b/tests/untried/pos/t121.scala new file mode 100644 index 000000000..78ddc41ee --- /dev/null +++ b/tests/untried/pos/t121.scala @@ -0,0 +1,3 @@ +class Bug121_B(b: Array[Byte]) { + def get(x: Int): Byte = return b(x); +} diff --git a/tests/untried/pos/t1210a.scala b/tests/untried/pos/t1210a.scala new file mode 100644 index 000000000..b3492f96e --- /dev/null +++ b/tests/untried/pos/t1210a.scala @@ -0,0 +1,15 @@ +// both styles of abstraction should behave the same +// related to 1210 because that bug broke the OO version below +trait OO { + abstract class Test { self => + type T + + val v: Test {type T = self.T} = self.v.v + } +} + +trait FP { + abstract class Test[T] { + val v: Test[T] = v.v + } +} diff --git a/tests/untried/pos/t122.scala b/tests/untried/pos/t122.scala new file mode 100644 index 000000000..630e24ce4 --- /dev/null +++ b/tests/untried/pos/t122.scala @@ -0,0 +1,4 @@ +class L { + val List(v:Int, 2) = List(2, v:Int) + val (a:Int, b:Int) = (1, a) +} diff --git a/tests/untried/pos/t1226.scala b/tests/untried/pos/t1226.scala new file mode 100644 index 000000000..0af21cbb6 --- /dev/null +++ b/tests/untried/pos/t1226.scala @@ -0,0 +1,8 @@ +package graphs; + +abstract class Graph (private[graphs] val mappings : Any){ +} + +class Nodes (mappings : Any) extends Graph(mappings) { + mappings.toString; +} diff --git a/tests/untried/pos/t1230/J.java b/tests/untried/pos/t1230/J.java new file mode 100644 index 000000000..35aefd250 --- /dev/null +++ b/tests/untried/pos/t1230/J.java @@ -0,0 +1 @@ +class J { public int foo ; } diff --git a/tests/untried/pos/t1230/S.scala b/tests/untried/pos/t1230/S.scala new file mode 100644 index 000000000..530dd4b85 --- /dev/null +++ b/tests/untried/pos/t1230/S.scala @@ -0,0 +1 @@ +object S extends App { (new J).foo = 5 } diff --git a/tests/untried/pos/t1231/J.java b/tests/untried/pos/t1231/J.java new file mode 100644 index 000000000..6b24205e5 --- /dev/null +++ b/tests/untried/pos/t1231/J.java @@ -0,0 +1 @@ +enum J { j1 } diff --git a/tests/untried/pos/t1231/S.scala b/tests/untried/pos/t1231/S.scala new file mode 100644 index 000000000..f14aa2561 --- /dev/null +++ b/tests/untried/pos/t1231/S.scala @@ -0,0 +1 @@ +object S extends App { println(J.j1) } diff --git a/tests/untried/pos/t1232/J.java b/tests/untried/pos/t1232/J.java new file mode 100644 index 000000000..2d9e3bbd5 --- /dev/null +++ b/tests/untried/pos/t1232/J.java @@ -0,0 +1,2 @@ +package j; +public class J { public enum E { e1 } } diff --git a/tests/untried/pos/t1232/J2.java b/tests/untried/pos/t1232/J2.java new file mode 100644 index 000000000..29237780a --- /dev/null +++ b/tests/untried/pos/t1232/J2.java @@ -0,0 +1,2 @@ +import s.S; +class J2 { } diff --git a/tests/untried/pos/t1232/S.scala b/tests/untried/pos/t1232/S.scala new file mode 100644 index 000000000..1b6bca732 --- /dev/null +++ b/tests/untried/pos/t1232/S.scala @@ -0,0 +1,2 @@ +package s +class S { j.J.E.e1 } diff --git a/tests/untried/pos/t1235/Test.java b/tests/untried/pos/t1235/Test.java new file mode 100644 index 000000000..7bb83a849 --- /dev/null +++ b/tests/untried/pos/t1235/Test.java @@ -0,0 +1,9 @@ +import scala.collection.immutable.HashMap; + +public class Test { + + void foo() { + new HashMap<String, String>(); + } +} + diff --git a/tests/untried/pos/t1236.scala b/tests/untried/pos/t1236.scala new file mode 100644 index 000000000..75a1befd2 --- /dev/null +++ b/tests/untried/pos/t1236.scala @@ -0,0 +1,14 @@ +trait Empty[E[_]] { + def e[A]: E[A] +} + +object T { + val ListEmpty = new Empty[List] { + def e[A] = Nil + } + + def foo[F[_]](q:(String,String)) = "hello" + def foo[F[_]](e: Empty[F]) = "world" + + val x = foo[List](ListEmpty) +} diff --git a/tests/untried/pos/t1237.scala b/tests/untried/pos/t1237.scala new file mode 100644 index 000000000..31ba2966a --- /dev/null +++ b/tests/untried/pos/t1237.scala @@ -0,0 +1,14 @@ +class HelloWorld { + def main(args: Array[String]): Unit = { + + object TypeBool; + + trait Fct { + def g(x : Int) = TypeBool // breaks. + + // def g(x : Int) = 3 // fine. + } + + () + } +} diff --git a/tests/untried/pos/t124.scala b/tests/untried/pos/t124.scala new file mode 100644 index 000000000..9aed6786f --- /dev/null +++ b/tests/untried/pos/t124.scala @@ -0,0 +1,5 @@ +class N{ + val F: Any => Any = (x:Any) => F(x); + val f:(Any => Any) = (x:Any) => f(x); + val g: Any => Any = (x:Any) => g(x); +} diff --git a/tests/untried/pos/t1254/t1254.java b/tests/untried/pos/t1254/t1254.java new file mode 100644 index 000000000..17e1c60bf --- /dev/null +++ b/tests/untried/pos/t1254/t1254.java @@ -0,0 +1,28 @@ +/* Taken from ticket #1254. Tests Java signatures in mirror classes and that + Nothing is translated to Nothing$. +*/ + +import scala.None; + +// This compiles with javac but fails with Eclipse java compiler: +// 'The type scala.Nothing cannot be resolved. It is indirectly referenced from required .class files' +class NothingBug3 { + public NothingBug3() { + scala.Option<?> o = scala.None$.MODULE$; + + test(o); + None.toLeft(new scala.runtime.AbstractFunction0<Integer>() { + public Integer apply() { return 0; } + }); + } + + public <T>void test(scala.Option<T> f) {} +} + +// This compiles with javac but fails with Eclipse java compiler: +// 'The type scala.Nothing cannot be resolved. It is indirectly referenced from required .class files' +class NothingBug4 { + public NothingBug4() { + scala.Option o = scala.None$.MODULE$; + } +} diff --git a/tests/untried/pos/t1260.scala b/tests/untried/pos/t1260.scala new file mode 100644 index 000000000..02f9e7e6b --- /dev/null +++ b/tests/untried/pos/t1260.scala @@ -0,0 +1,18 @@ +case class Foo(a: String, b: String) + +object Bar { + def unapply(s: String): Option[Long] = + try { Some(s.toLong) } catch { case _ => None } +} + +object Test { + def main(args: Array[String]): Unit = { + val f = Foo("1", "2") + f match { + case Foo(Bar(1), Bar(2)) => 1 + case Foo(Bar(i), Bar(j)) if i >= 0 => 2 + case _ => 3 + } + } +} + diff --git a/tests/untried/pos/t1263/Test.java b/tests/untried/pos/t1263/Test.java new file mode 100644 index 000000000..1718a9909 --- /dev/null +++ b/tests/untried/pos/t1263/Test.java @@ -0,0 +1,17 @@ +package test; + +import java.rmi.RemoteException; + +import test.Map; + +@SuppressWarnings("unchecked") +public class Test implements Map<String, String> { + public Map.MapTo plus(String o) { + return null; + } + + public int $tag() throws RemoteException { + return 0; + } +} + diff --git a/tests/untried/pos/t1263/test.scala b/tests/untried/pos/t1263/test.scala new file mode 100644 index 000000000..92d8c1cdf --- /dev/null +++ b/tests/untried/pos/t1263/test.scala @@ -0,0 +1,10 @@ +package test + +trait Map[A, +B] { + def plus(key: A): MapTo = new MapTo(key) + + class MapTo(key: A) { + def arrow [B1 >: B](value: B1) = null + } +} + diff --git a/tests/untried/pos/t1272.scala b/tests/untried/pos/t1272.scala new file mode 100644 index 000000000..916b783bb --- /dev/null +++ b/tests/untried/pos/t1272.scala @@ -0,0 +1,9 @@ +object ImplicitTest { + implicit val i : Int = 10 + implicit def a(implicit i : Int) : Array[Byte] = null + implicit def b[T](implicit i : Int) : Array[T] = null + + def fn[T](implicit x : T) = 0 + + val x = fn[Array[Byte]] +} diff --git a/tests/untried/pos/t1279a.scala b/tests/untried/pos/t1279a.scala new file mode 100644 index 000000000..18b1e53f4 --- /dev/null +++ b/tests/untried/pos/t1279a.scala @@ -0,0 +1,39 @@ +// covariant linked list +abstract class M { + self => + + type T + final type selfType = M {type T <: self.T} + type actualSelfType >: self.type <: 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/untried/pos/t1280.scala b/tests/untried/pos/t1280.scala new file mode 100644 index 000000000..39406b2e3 --- /dev/null +++ b/tests/untried/pos/t1280.scala @@ -0,0 +1 @@ +trait X { x => type T >: Null; new X { type T = Any with x.T } } diff --git a/tests/untried/pos/t1292.scala b/tests/untried/pos/t1292.scala new file mode 100644 index 000000000..83a996d53 --- /dev/null +++ b/tests/untried/pos/t1292.scala @@ -0,0 +1,33 @@ +trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] { + type StV = Enum#Value + type Meta = MegaFoo[T, Enum] + + type Slog <: Enumeration + + def getSingleton: Meta +} + +trait MegaFoo[T <: Foo[T, Enum], Enum <: Enumeration] extends Foo[T, Enum] { + def doSomething(what: T, misc: StV, dog: Meta#Event) = None + abstract class Event + object Event + + def stateEnumeration: Slog + def se2: Enum +} + +object E extends Enumeration { + val A = Value + val B = Value +} + +class RFoo extends Foo[RFoo, E.type] { + def getSingleton = MegaRFoo + + type Slog = E.type +} + +object MegaRFoo extends RFoo with MegaFoo[RFoo, E.type] { + def stateEnumeration = E + def se2 = E +} diff --git a/tests/untried/pos/t1318.scala b/tests/untried/pos/t1318.scala new file mode 100644 index 000000000..34e2bc8dd --- /dev/null +++ b/tests/untried/pos/t1318.scala @@ -0,0 +1,31 @@ +abstract class F { + type mType <: M +} + +abstract class M { self => + + type mType <: M + + type fType = F {type mType >: self.mType } + def fs: List[fType] +} + +abstract class A0 extends M { + type mType = A0 + def fs: List[fType] = Nil +} + +object A extends A0 {} + +abstract class B0 extends M { + type mType = B0 + def fs: List[fType] = Nil +} + +object B extends B0 {} + +object C { + def ab = List(A) ::: List(B) + // the following compiles successfully: + // def ab = List(A) ::: List[M](B) +} diff --git a/tests/untried/pos/t1357.scala b/tests/untried/pos/t1357.scala new file mode 100644 index 000000000..05f8d20ed --- /dev/null +++ b/tests/untried/pos/t1357.scala @@ -0,0 +1,21 @@ +object NonEmptyCons { + def unapply[H, T](c: (H, T)): Option[(H, T)] = Some(c) +} + + +object Main { + + type BT[+H, +T <: Tuple2[Tuple2[H, T], Tuple2[H, T]]] = Tuple2[H, T] + + // type T = Tuple2[String,String] + type BinaryTree[+E] = BT[E, T forSome { type T <: Tuple2[BT[E, T], BT[E, T]] }] + + def foo[E](tree: BinaryTree[E]): Unit = tree match { + case NonEmptyCons(_, tail) => { + tail match { + case NonEmptyCons(_, _) => { + } + } + } + } +} diff --git a/tests/untried/pos/t1381-new.scala b/tests/untried/pos/t1381-new.scala new file mode 100644 index 000000000..b0b300c6f --- /dev/null +++ b/tests/untried/pos/t1381-new.scala @@ -0,0 +1,31 @@ +import scala.reflect.runtime.universe._ + +class D[V <: Variable] + +class ID[V<:IV] extends D[V] { + type E = V#ValueType + def index(value:E) : Int = 0 + // Comment this out to eliminate crash. Or see below + def index(values:E*) : Iterable[Int] = null +} + +abstract class Variable { + type VT <: Variable + def d : D[VT] = null +} + +abstract class PV[T](initval:T) extends Variable { + type VT <: PV[T] + type ValueType = T +} + +trait IV extends Variable { + type ValueType +} + +abstract class EV[T](initval:T) extends PV[T](initval) with IV { + type VT <: EV[T] + override def d : ID[VT] = null + // Comment this out to eliminate crash + protected var indx = d.index(initval) +} diff --git a/tests/untried/pos/t1381-old.scala b/tests/untried/pos/t1381-old.scala new file mode 100644 index 000000000..076289189 --- /dev/null +++ b/tests/untried/pos/t1381-old.scala @@ -0,0 +1,31 @@ +import scala.reflect.Manifest + +class D[V <: Variable] + +class ID[V<:IV] extends D[V] { + type E = V#ValueType + def index(value:E) : Int = 0 + // Comment this out to eliminate crash. Or see below + def index(values:E*) : Iterable[Int] = null +} + +abstract class Variable { + type VT <: Variable + def d : D[VT] = null +} + +abstract class PV[T](initval:T) extends Variable { + type VT <: PV[T] + type ValueType = T +} + +trait IV extends Variable { + type ValueType +} + +abstract class EV[T](initval:T) extends PV[T](initval) with IV { + type VT <: EV[T] + override def d : ID[VT] = null + // Comment this out to eliminate crash + protected var indx = d.index(initval) +} diff --git a/tests/untried/pos/t1385.scala b/tests/untried/pos/t1385.scala new file mode 100644 index 000000000..aefd9c35b --- /dev/null +++ b/tests/untried/pos/t1385.scala @@ -0,0 +1,3 @@ +object Test extends Serializable { + private def readResolve: AnyRef = this +} diff --git a/tests/untried/pos/t1391.scala b/tests/untried/pos/t1391.scala new file mode 100644 index 000000000..5178ba987 --- /dev/null +++ b/tests/untried/pos/t1391.scala @@ -0,0 +1,43 @@ +package sandbox + + class hierarOverload { + + /* + * Template structure - using abstract types. + */ + trait AB { + type TA <: A + type TB <: B + + protected trait A { + val entities : List[TB] + } + + protected trait B { + var group : TA + } + } + + /* + * Template instantiation in an object to ease use and globally define + abstract types + */ + object NAnB extends AB { + type TB = nB + type TA = nA + + class nA extends A { + val entities = List[nB]() + } + + class nB extends B { + var group = new nA + } + } + + def foo (): Unit = { + val t = new NAnB.nA + println(t) + } + + } diff --git a/tests/untried/pos/t1409/AbstractImpl.java b/tests/untried/pos/t1409/AbstractImpl.java new file mode 100644 index 000000000..b22a94fa1 --- /dev/null +++ b/tests/untried/pos/t1409/AbstractImpl.java @@ -0,0 +1,3 @@ +public abstract class AbstractImpl implements OuterInterface { + public abstract InnerInterface create(); + } diff --git a/tests/untried/pos/t1409/ConcreteImpl.scala b/tests/untried/pos/t1409/ConcreteImpl.scala new file mode 100644 index 000000000..d427e957e --- /dev/null +++ b/tests/untried/pos/t1409/ConcreteImpl.scala @@ -0,0 +1,3 @@ +class ConcreteImpl extends AbstractImpl { + def create : OuterInterface.InnerInterface = null + } diff --git a/tests/untried/pos/t1409/OuterInterface.java b/tests/untried/pos/t1409/OuterInterface.java new file mode 100644 index 000000000..dd288ceea --- /dev/null +++ b/tests/untried/pos/t1409/OuterInterface.java @@ -0,0 +1,5 @@ +public interface OuterInterface { + public interface InnerInterface { + public void foo(); + } + } diff --git a/tests/untried/pos/t1422_pos.scala b/tests/untried/pos/t1422_pos.scala new file mode 100644 index 000000000..658f5c730 --- /dev/null +++ b/tests/untried/pos/t1422_pos.scala @@ -0,0 +1,2 @@ +case class A(private val foo:String) +case class B(protected[this] val foo:String) diff --git a/tests/untried/pos/t1438.scala b/tests/untried/pos/t1438.scala new file mode 100644 index 000000000..221c3439d --- /dev/null +++ b/tests/untried/pos/t1438.scala @@ -0,0 +1,10 @@ +class C[A] { + type CC[B] <: C[B] + def aio[T]: T = aio[T] +} +class D[A] extends C[A] { + protected def nv[B](elems: Iterator[B]): CC[B] = { + val x = new D[B] + x.aio[CC[B]] + } +} diff --git a/tests/untried/pos/t1439.flags b/tests/untried/pos/t1439.flags new file mode 100644 index 000000000..bca57e478 --- /dev/null +++ b/tests/untried/pos/t1439.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings -language:higherKinds diff --git a/tests/untried/pos/t1439.scala b/tests/untried/pos/t1439.scala new file mode 100644 index 000000000..0efcc74b6 --- /dev/null +++ b/tests/untried/pos/t1439.scala @@ -0,0 +1,8 @@ +// no unchecked warnings +class View[C[A]] { } + +object Test { + (null: Any) match { + case v: View[_] => + } +} diff --git a/tests/untried/pos/t1459/AbstractBase.java b/tests/untried/pos/t1459/AbstractBase.java new file mode 100755 index 000000000..492419416 --- /dev/null +++ b/tests/untried/pos/t1459/AbstractBase.java @@ -0,0 +1,5 @@ +package base; + +public abstract class AbstractBase { + public abstract void doStuff(String... params); // !!! was Object.. +}
\ No newline at end of file diff --git a/tests/untried/pos/t1459/App.scala b/tests/untried/pos/t1459/App.scala new file mode 100755 index 000000000..36e5022e9 --- /dev/null +++ b/tests/untried/pos/t1459/App.scala @@ -0,0 +1,18 @@ +package foo +import base._ + +object App extends scala.App { + class Concrete extends AbstractBase { + override def doStuff(params:java.lang.String*): Unit = println("doStuff invoked") + } + + val impl = new Concrete + + //succeeds + impl.doStuff(null) + + val caller = new Caller + + // fails with AbstractMethodError + caller.callDoStuff(impl) +} diff --git a/tests/untried/pos/t1459/Caller.java b/tests/untried/pos/t1459/Caller.java new file mode 100755 index 000000000..4ae51d8c5 --- /dev/null +++ b/tests/untried/pos/t1459/Caller.java @@ -0,0 +1,7 @@ +package base; + +public class Caller { + public void callDoStuff(AbstractBase impl) { + impl.doStuff("abc"); // was new Object()); + } +}
\ No newline at end of file diff --git a/tests/untried/pos/t1480.scala b/tests/untried/pos/t1480.scala new file mode 100644 index 000000000..1d9f94d2e --- /dev/null +++ b/tests/untried/pos/t1480.scala @@ -0,0 +1,6 @@ +class Foo{ + def compare(newP : Any, oldP : Any) : Boolean = (newP,oldP) match { + case (newP : AnyRef, oldP : AnyRef) if newP == oldP => newP == oldP + case (newS : Symbol, oldS: Symbol) if newS == oldS => newS == oldS + } +} diff --git a/tests/untried/pos/t151.scala b/tests/untried/pos/t151.scala new file mode 100644 index 000000000..86667b49f --- /dev/null +++ b/tests/untried/pos/t151.scala @@ -0,0 +1,6 @@ +abstract class Foo { + type T; + def foo(a: T): Int = 0; + val foo: Foo = null; + def a: foo.T = a; +} diff --git a/tests/untried/pos/t1560.scala b/tests/untried/pos/t1560.scala new file mode 100644 index 000000000..2af299af8 --- /dev/null +++ b/tests/untried/pos/t1560.scala @@ -0,0 +1,13 @@ +object Test extends App { + + trait C[T] { + def t: T + } + + def b: Option[C[x] forSome { type x }] = null + + def c = b match { + case Some(b) => b.t + } + +} diff --git a/tests/untried/pos/t1565.scala b/tests/untried/pos/t1565.scala new file mode 100644 index 000000000..df333151d --- /dev/null +++ b/tests/untried/pos/t1565.scala @@ -0,0 +1,18 @@ +object Bug1565 { + object X0 { 0; (a : Int, b : Int, c : Int) => println(List(a, b)) } + def x() = { 0; (a : Int, b : Int) => println(List(a, b)) ; 0 } + + (a : Int, b : Int) => println(List(a, b)) + + // various function syntaxes to exercise the parser + val xs = List(1,2,3) + xs.filter(x => x < 2) + xs.filter((x) => x < 2) + xs.filter { x => x < 2 } + xs.filter { _ < 2 } + xs.filter (_ < 2) + xs.foreach { e => + val buf0 = e + 1 + buf0 + } +} diff --git a/tests/untried/pos/t1569.scala b/tests/untried/pos/t1569.scala new file mode 100644 index 000000000..a7200a6d1 --- /dev/null +++ b/tests/untried/pos/t1569.scala @@ -0,0 +1,5 @@ +object Bug { + class C { type T } + def foo(x: Int)(y: C)(z: y.T): Unit = {} + foo(3)(new C { type T = String })("hello") +} diff --git a/tests/untried/pos/t159.scala b/tests/untried/pos/t159.scala new file mode 100644 index 000000000..4d67f8aff --- /dev/null +++ b/tests/untried/pos/t159.scala @@ -0,0 +1,22 @@ +object foo { + // the problem seems to appear only + // if "val _" is in the body of a case + def cooked(ckd: StringBuilder): Unit = { + 'a' match { + case '-' => + val _ = ckd.append( '_' ); + case 'v' => + val _ = ckd.append( '_' ); + } + } +} + +object foo1 { + def f(): Unit = { + 1 match { + case 2 => val _ = 1; + case 3 => val _ = 2; + case 4 => val _ = 2; + } + } +} diff --git a/tests/untried/pos/t1591_pos.scala b/tests/untried/pos/t1591_pos.scala new file mode 100644 index 000000000..4f55d7ce1 --- /dev/null +++ b/tests/untried/pos/t1591_pos.scala @@ -0,0 +1,7 @@ +trait A + +object Test { + lazy val a = new A { + object Zenek + } +} diff --git a/tests/untried/pos/t1591b.scala b/tests/untried/pos/t1591b.scala new file mode 100644 index 000000000..c671ad647 --- /dev/null +++ b/tests/untried/pos/t1591b.scala @@ -0,0 +1,13 @@ +import scala.tools.nsc._ + +class SemanticTokens(val compiler: Global) { + import compiler._ + + def build() = ErrorType + + class Process { + def f() = analyzer + // or to crash the compiler instead of a nice message, + // def f() = analyzer underlying _ + } +} diff --git a/tests/untried/pos/t160.scala b/tests/untried/pos/t160.scala new file mode 100644 index 000000000..91ac2ba84 --- /dev/null +++ b/tests/untried/pos/t160.scala @@ -0,0 +1,3 @@ +class Foo(s:String) { + def this() = { this("DEFAULT") } +} diff --git a/tests/untried/pos/t1614/bar.scala b/tests/untried/pos/t1614/bar.scala new file mode 100644 index 000000000..be994c3af --- /dev/null +++ b/tests/untried/pos/t1614/bar.scala @@ -0,0 +1,4 @@ +// bar.scala +object Bar { + val a = new FooImpl with AbstractOverrideFoo +} diff --git a/tests/untried/pos/t1614/foo.scala b/tests/untried/pos/t1614/foo.scala new file mode 100644 index 000000000..5db548ac7 --- /dev/null +++ b/tests/untried/pos/t1614/foo.scala @@ -0,0 +1,12 @@ +// foo.scala +trait Foo { + def foo(arg: List[_]) +} +trait FooImpl extends Foo { + def foo(arg: List[_]): Unit = {} +} +trait AbstractOverrideFoo extends Foo { + abstract override def foo(arg: List[_]): Unit = { + super.foo(arg) + } +} diff --git a/tests/untried/pos/t1642/JavaCallingScalaHashMap.java b/tests/untried/pos/t1642/JavaCallingScalaHashMap.java new file mode 100644 index 000000000..976e465ff --- /dev/null +++ b/tests/untried/pos/t1642/JavaCallingScalaHashMap.java @@ -0,0 +1,8 @@ +import scala.collection.immutable.HashMap; +import scala.collection.immutable.Map; + +public class JavaCallingScalaHashMap { + public static void main( String[] args ) { + Map<String, Integer> hashMap = new HashMap<String, Integer>(); + } +} diff --git a/tests/untried/pos/t1642b.scala b/tests/untried/pos/t1642b.scala new file mode 100644 index 000000000..72e53b0c9 --- /dev/null +++ b/tests/untried/pos/t1642b.scala @@ -0,0 +1,6 @@ +package x +abstract class H[A] { + type P <: R[P] + def a: P +} +class R[F] diff --git a/tests/untried/pos/t1659.scala b/tests/untried/pos/t1659.scala new file mode 100644 index 000000000..10470d66f --- /dev/null +++ b/tests/untried/pos/t1659.scala @@ -0,0 +1,4 @@ +trait Y { type X } +trait W { def u[A](v : Y { type X = A }) : Unit } +class Z extends W { def u[A](v : Y { type X = A }) = null } + diff --git a/tests/untried/pos/t1672.scala b/tests/untried/pos/t1672.scala new file mode 100644 index 000000000..5ee6bb175 --- /dev/null +++ b/tests/untried/pos/t1672.scala @@ -0,0 +1,10 @@ +object Test { + @annotation.tailrec + def bar : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => bar + } + } +} diff --git a/tests/untried/pos/t1675.scala b/tests/untried/pos/t1675.scala new file mode 100644 index 000000000..8630890ee --- /dev/null +++ b/tests/untried/pos/t1675.scala @@ -0,0 +1,11 @@ +package a +object Foo extends pack.Bar { + for(i <- 0 to 10) { + test("") + } +} +package pack { + class Bar { + protected def test(s: String*): Unit = {} + } +} diff --git a/tests/untried/pos/t1693.scala b/tests/untried/pos/t1693.scala new file mode 100644 index 000000000..881bf89a0 --- /dev/null +++ b/tests/untried/pos/t1693.scala @@ -0,0 +1,9 @@ +object Test { + class Foo + class SomeOps(x : Foo) { def foo(x: String) = 1 } + class OtherOps(x : Foo) { def foo(x: Int) = 1 } + implicit def mkSomeOps(x: Foo) : SomeOps = new SomeOps(x) + implicit def mkOtherOps(x: Foo) : OtherOps = new OtherOps(x) + + (new Foo).foo(1) +} diff --git a/tests/untried/pos/t1711/Seq.scala b/tests/untried/pos/t1711/Seq.scala new file mode 100644 index 000000000..c18f05cd7 --- /dev/null +++ b/tests/untried/pos/t1711/Seq.scala @@ -0,0 +1,12 @@ +package com + +object Sequence { + + def filteringFunction[V](filter: V => Boolean): List[V] => List[V] = { + def include(v: V) = + filter(v) + (l: List[V]) => l.filter(include) + } + +} + diff --git a/tests/untried/pos/t1711/Test.java b/tests/untried/pos/t1711/Test.java new file mode 100644 index 000000000..5ec0f2297 --- /dev/null +++ b/tests/untried/pos/t1711/Test.java @@ -0,0 +1,6 @@ +import com.Sequence; + +public class Test { + void foo() { + } +} diff --git a/tests/untried/pos/t1722-A.scala b/tests/untried/pos/t1722-A.scala new file mode 100644 index 000000000..d059bf22f --- /dev/null +++ b/tests/untried/pos/t1722-A.scala @@ -0,0 +1,10 @@ +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +*/ diff --git a/tests/untried/pos/t1722/Test.scala b/tests/untried/pos/t1722/Test.scala new file mode 100755 index 000000000..f236d3fdc --- /dev/null +++ b/tests/untried/pos/t1722/Test.scala @@ -0,0 +1,5 @@ +package t1722 + +object Test { + val x = new AnyRef with C +} diff --git a/tests/untried/pos/t1722/Top.scala b/tests/untried/pos/t1722/Top.scala new file mode 100755 index 000000000..4ac52412a --- /dev/null +++ b/tests/untried/pos/t1722/Top.scala @@ -0,0 +1,13 @@ +package t1722 + +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +Martin: I think this has to do with children property. +*/ diff --git a/tests/untried/pos/t1745/J.java b/tests/untried/pos/t1745/J.java new file mode 100644 index 000000000..8444eabb2 --- /dev/null +++ b/tests/untried/pos/t1745/J.java @@ -0,0 +1,10 @@ +class J { + S1 s1; + S2 s2; + + String s = bar(S3.foo(), S3.bar("def")); + + private String bar(String s1, String s2) { + return s1 + s2; + } +} diff --git a/tests/untried/pos/t1745/S.scala b/tests/untried/pos/t1745/S.scala new file mode 100644 index 000000000..84c437133 --- /dev/null +++ b/tests/untried/pos/t1745/S.scala @@ -0,0 +1,7 @@ +case class S1(n: Int) { } +case class S2(n: Int, p: Int) { } +class S3 { } +object S3 { + def foo() = "abc" + def bar[T](x: T): T = x +} diff --git a/tests/untried/pos/t175.scala b/tests/untried/pos/t175.scala new file mode 100644 index 000000000..4c0eb28ba --- /dev/null +++ b/tests/untried/pos/t175.scala @@ -0,0 +1,3 @@ +abstract class C { + def this(x: Unit) = { this() } +} diff --git a/tests/untried/pos/t1751/A1_2.scala b/tests/untried/pos/t1751/A1_2.scala new file mode 100644 index 000000000..354d5eecd --- /dev/null +++ b/tests/untried/pos/t1751/A1_2.scala @@ -0,0 +1,2 @@ +@SuiteClasses(Array(classOf[A2])) +class A1 diff --git a/tests/untried/pos/t1751/A2_1.scala b/tests/untried/pos/t1751/A2_1.scala new file mode 100644 index 000000000..c768062e4 --- /dev/null +++ b/tests/untried/pos/t1751/A2_1.scala @@ -0,0 +1,2 @@ +@SuiteClasses(Array()) +class A2 diff --git a/tests/untried/pos/t1751/SuiteClasses.java b/tests/untried/pos/t1751/SuiteClasses.java new file mode 100644 index 000000000..a415e4f57 --- /dev/null +++ b/tests/untried/pos/t1751/SuiteClasses.java @@ -0,0 +1,3 @@ +public @interface SuiteClasses { + public Class<?>[] value(); +} diff --git a/tests/untried/pos/t1756.scala b/tests/untried/pos/t1756.scala new file mode 100755 index 000000000..1d067c3b0 --- /dev/null +++ b/tests/untried/pos/t1756.scala @@ -0,0 +1,54 @@ + +/** +This is a tricky issue which has to do with the fact that too much conflicting +type information is propagated into a single implicit search, where the intended +solution applies two implicit searches. + +Roughly, in x + x * y, the first x is first typed as Poly[A]. That +means the x * y is then typed as Poly[A]. Then the second x is typed +as Poly[A], then y is typed as Poly[Poly[A]]. The application x * y +fails, so the coef2poly implicit conversion is applied to x. That +means we look for an implicit conversion from type Poly[A] to type +?{val *(x$1: ?>: Poly[Poly[A]] <: Any): Poly[A]}. Note that the result +type Poly[A] is propagated into the implicit search. Poly[A] comes as +expected type from x+, because the lhs x is still typed as a Poly[A]. +This means that the argument of the implicit conversion is typechecked +with expected type A with Poly[A]. And no solution is found. + +To solve this, I added a fallback scheme similar to implicit arguments: +When an implicit view that adds a method matching given arguments and result +type fails, try again without the result type. +*/ +trait Ring[T <: Ring[T]] { + def +(that: T): T + def *(that: T): T +} + +class A extends Ring[A] { + def +(that: A) = new A + def *(that: A) = new A +} + +class Poly[C <: Ring[C]](val c: C) extends Ring[Poly[C]] { + def +(that: Poly[C]) = new Poly(this.c+that.c) + def *(that: Poly[C]) = new Poly(this.c*that.c) +} + +object Test extends App { + + implicit def coef2poly[C <: Ring[C]](c: C): Poly[C] = new Poly(c) + + val a = new A + val x = new Poly(new A) + + println(x+a) // works + println(a+x) // works + + val y = new Poly(new Poly(new A)) + + println(x+y*x) // works + println(x*y+x) // works + println(y*x+x) // works + + println(x+x*y) // failed before +} diff --git a/tests/untried/pos/t177.scala b/tests/untried/pos/t177.scala new file mode 100644 index 000000000..33b4de926 --- /dev/null +++ b/tests/untried/pos/t177.scala @@ -0,0 +1,8 @@ +class A { + def foo = { + object Y { + def bar = 1; + } + Y.bar + } +} diff --git a/tests/untried/pos/t1782/Ann.java b/tests/untried/pos/t1782/Ann.java new file mode 100644 index 000000000..0dcfbd2ed --- /dev/null +++ b/tests/untried/pos/t1782/Ann.java @@ -0,0 +1,3 @@ +public @interface Ann { + public Days value(); +} diff --git a/tests/untried/pos/t1782/Days.java b/tests/untried/pos/t1782/Days.java new file mode 100644 index 000000000..203a87b1c --- /dev/null +++ b/tests/untried/pos/t1782/Days.java @@ -0,0 +1,3 @@ +public enum Days { + Friday, Sunday +} diff --git a/tests/untried/pos/t1782/ImplementedBy.java b/tests/untried/pos/t1782/ImplementedBy.java new file mode 100644 index 000000000..6aa8b4fa9 --- /dev/null +++ b/tests/untried/pos/t1782/ImplementedBy.java @@ -0,0 +1,3 @@ +public @interface ImplementedBy { + public Class<?> value(); +} diff --git a/tests/untried/pos/t1782/Test_1.scala b/tests/untried/pos/t1782/Test_1.scala new file mode 100644 index 000000000..6467a74c2 --- /dev/null +++ b/tests/untried/pos/t1782/Test_1.scala @@ -0,0 +1,16 @@ +@ImplementedBy(classOf[Provider]) +trait Service { + def someMethod() +} + +class Provider + extends Service +{ + // test enumeration java annotations + @Ann(Days.Friday) def someMethod() = () + + // #2103 + @scala.beans.BeanProperty + @Ann(value = Days.Sunday) + val t2103 = "test" +} diff --git a/tests/untried/pos/t1785.scala b/tests/untried/pos/t1785.scala new file mode 100644 index 000000000..0b1fafb27 --- /dev/null +++ b/tests/untried/pos/t1785.scala @@ -0,0 +1,7 @@ +class t1785 { + def apply[T](x: Int) = 1 +} + +object test { + (new t1785)[Int](1) +} diff --git a/tests/untried/pos/t1786-counter.scala b/tests/untried/pos/t1786-counter.scala new file mode 100644 index 000000000..a2431343d --- /dev/null +++ b/tests/untried/pos/t1786-counter.scala @@ -0,0 +1,38 @@ +trait ShapeLevel + +object Fail { + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } + + trait ShapeLevel +} + +object Ok { + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } +} + +// This is why we reverted the fix for SI-1786 -- see SI-6169 for a potential alternative that could be extended to cover this. +// both objects type check on 2.10.3, but only Ok was accepted by 2.11 after the original fix to SI-1786. +// Fail results in: +/* +t1786-counter.scala:10: error: class TupleShape needs to be abstract, since method copy in class ProductNodeShape of type (shapes: Seq[Fail.Shape[_, _, _, _]])Fail.Shape[Level, _, _, _] is not defined +(Note that Seq[Fail.Shape[_, _, _, _]] does not match Seq[Fail.Shape[_ <: Fail.ShapeLevel, _, _, _]]: their type parameters differ) + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + ^ +one error found +*/ diff --git a/tests/untried/pos/t1786-cycle.scala b/tests/untried/pos/t1786-cycle.scala new file mode 100644 index 000000000..9de149fbc --- /dev/null +++ b/tests/untried/pos/t1786-cycle.scala @@ -0,0 +1,57 @@ +trait GenTraversableLike[+A, +Repr] extends Any + +object O { + (null: Any) match { + case _: LongTraversableLike[_] => + } +} + +trait LongTraversable extends LongTraversableLike[LongTraversable] + +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + +/* +% scalac-hash v2.11.0-M8 test/files/pos/t1786-cycle.scala +[warn] v2.11.0-M8 failed, using closest available +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + ^ +one error found + +Okay again after SI-1786 was reverted. + + +|-- object O BYVALmode-EXPRmode (site: package <empty>) +| |-- super EXPRmode-POLYmode-QUALmode (silent: <init> in O) +| | |-- this EXPRmode (silent: <init> in O) +| | | \-> O.type +| | \-> O.type +| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ <em... BYVALmode-EXPRmode (site: value <local O> in O) +| | |-- (null: Any) BYVALmode-EXPRmode (site: value <local O> in O) +| | | |-- Any TYPEmode (site: value <local O> in O) +| | | | \-> Any +| | | |-- null : pt=Any EXPRmode (site: value <local O> in O) +| | | | \-> Null(null) +| | | \-> Any +| | |-- (_: LongTraversableLike[(_ @ <empty>)]) : pt=Any PATTERNmode (site: value <local O> in O) enrichment only +| | | |-- LongTraversableLike[(_ @ <empty>)] TYPEPATmode-TYPEmode (site: value <local O> in O) enrichment only +| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in <empty>) +| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in <empty>) +| | | | | | |-- Repr NOmode (site: type Repr in <empty>) +| | | | | | | \-> Repr +| | | | | | \-> LongTraversableLike[Repr] +| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) +| | | | | \-> <: LongTraversableLike[Repr] +| | | | |-- (_ @ <empty>) TYPEPATmode-TYPEmode (site: value <local O> in O) enrichment only +| | | | | \-> _ +| | | | |-- GenTraversableLike FUNmode-TYPEmode (site: trait LongTraversableLike) +| | | | | \-> GenTraversableLike +| | | | |-- GenTraversableLike[Any, Repr] TYPEmode (site: trait LongTraversableLike) +| | | | | |-- Any TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Any +| | | | | |-- Repr TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Repr +| | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving trait LongTraversableLike: while typing GenTraversableLike[Any, Repr] +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenT +*/ diff --git a/tests/untried/pos/t1789.scala b/tests/untried/pos/t1789.scala new file mode 100644 index 000000000..1a37d48d0 --- /dev/null +++ b/tests/untried/pos/t1789.scala @@ -0,0 +1,5 @@ +object S { + try { } + catch { case _ => } + finally { while(true) { } } +} diff --git a/tests/untried/pos/t1798.scala b/tests/untried/pos/t1798.scala new file mode 100644 index 000000000..1624e3025 --- /dev/null +++ b/tests/untried/pos/t1798.scala @@ -0,0 +1,10 @@ +object Foo { private def bar(): Int = 55 } +class Foo(x: Int) { def this() = this(Foo.bar()) } + +/* + * scalac28 a.scala +a.scala:2: error: method bar cannot be accessed in object Foo +class Foo(x: Int) { def this() = this(Foo.bar()) } + ^ +one error found +*/ diff --git a/tests/untried/pos/t1803.flags b/tests/untried/pos/t1803.flags new file mode 100644 index 000000000..d1a824416 --- /dev/null +++ b/tests/untried/pos/t1803.flags @@ -0,0 +1 @@ +-Yinfer-argument-types
\ No newline at end of file diff --git a/tests/untried/pos/t1803.scala b/tests/untried/pos/t1803.scala new file mode 100644 index 000000000..42f4e784a --- /dev/null +++ b/tests/untried/pos/t1803.scala @@ -0,0 +1,2 @@ +class A { def foo[A](a: A) = a } +class B extends A { override def foo[A](b) = b } diff --git a/tests/untried/pos/t183.scala b/tests/untried/pos/t183.scala new file mode 100644 index 000000000..d7ed27f73 --- /dev/null +++ b/tests/untried/pos/t183.scala @@ -0,0 +1,4 @@ +object Test { + new Foo(0); + class Foo(x: Int); +} diff --git a/tests/untried/pos/t1832.scala b/tests/untried/pos/t1832.scala new file mode 100644 index 000000000..7e435d70b --- /dev/null +++ b/tests/untried/pos/t1832.scala @@ -0,0 +1,8 @@ +trait Cloning { + trait Foo + def fn(g: Any => Unit): Foo + + implicit def mkStar(i: Int) = new { def *(a: Foo): Foo = null } + + val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } +} diff --git a/tests/untried/pos/t1836/J.java b/tests/untried/pos/t1836/J.java new file mode 100644 index 000000000..a009a59e2 --- /dev/null +++ b/tests/untried/pos/t1836/J.java @@ -0,0 +1 @@ +public abstract class J<T> { protected J(T id) { } } diff --git a/tests/untried/pos/t1836/S.scala b/tests/untried/pos/t1836/S.scala new file mode 100644 index 000000000..88ce1063e --- /dev/null +++ b/tests/untried/pos/t1836/S.scala @@ -0,0 +1 @@ +class S extends J("") diff --git a/tests/untried/pos/t1840/J.java b/tests/untried/pos/t1840/J.java new file mode 100644 index 000000000..fd98b6c4a --- /dev/null +++ b/tests/untried/pos/t1840/J.java @@ -0,0 +1,4 @@ +package p; +class J { + J() {} +} diff --git a/tests/untried/pos/t1840/S.scala b/tests/untried/pos/t1840/S.scala new file mode 100644 index 000000000..ff513d2c1 --- /dev/null +++ b/tests/untried/pos/t1840/S.scala @@ -0,0 +1,2 @@ +package p +class S { new J } diff --git a/tests/untried/pos/t1843.scala b/tests/untried/pos/t1843.scala new file mode 100644 index 000000000..8504bf342 --- /dev/null +++ b/tests/untried/pos/t1843.scala @@ -0,0 +1,25 @@ +/** +* Scala Compiler Will Crash On this File +* ... Or Will It? +* +*/ + +object Crash { + trait UpdateType[A] + case class StateUpdate[A](updateType : UpdateType[A], value : A) + case object IntegerUpdateType extends UpdateType[Integer] + + //However this method will cause a crash + def crash(updates: List[StateUpdate[_]]): Unit = { + updates match { + case Nil => + case u::us => + u match { + //Line below seems to be the crashing line + case StateUpdate(key, newValue) if (key == IntegerUpdateType) => + println("Requires a statement to induce the crash") + case _ => + } + } + } +} diff --git a/tests/untried/pos/t1858.scala b/tests/untried/pos/t1858.scala new file mode 100644 index 000000000..c06e73e7e --- /dev/null +++ b/tests/untried/pos/t1858.scala @@ -0,0 +1,13 @@ +import scala.collection.immutable.Stack + +object Test { + + def test = { + val s = new Stack[Int] + s.push(1) + s.push(1, 2) + s.push(1, 2, 3) + s.push(1, 2, 3, 4) + } + +} diff --git a/tests/untried/pos/t1896/D0.scala b/tests/untried/pos/t1896/D0.scala new file mode 100644 index 000000000..6b3150d96 --- /dev/null +++ b/tests/untried/pos/t1896/D0.scala @@ -0,0 +1,11 @@ +package p + +class X[T] + +trait A { + def m(s:X[_]): Unit = {} +} + +trait B extends A { + def f: Unit = { super.m(null) } +} diff --git a/tests/untried/pos/t1896/D1.scala b/tests/untried/pos/t1896/D1.scala new file mode 100644 index 000000000..e1ab50679 --- /dev/null +++ b/tests/untried/pos/t1896/D1.scala @@ -0,0 +1,2 @@ +package p +class C extends B diff --git a/tests/untried/pos/t1937/NumberGenerator.java b/tests/untried/pos/t1937/NumberGenerator.java new file mode 100644 index 000000000..59d604733 --- /dev/null +++ b/tests/untried/pos/t1937/NumberGenerator.java @@ -0,0 +1,7 @@ +package br.com.caelum.caelumweb2.money; + +public class NumberGenerator { + public String generate() { + return null; + } +} diff --git a/tests/untried/pos/t1942/A_1.scala b/tests/untried/pos/t1942/A_1.scala new file mode 100644 index 000000000..4915b54a6 --- /dev/null +++ b/tests/untried/pos/t1942/A_1.scala @@ -0,0 +1,11 @@ +class A { + def foo(x: Int) = 0 + def foo(x: String) = 1 +} + +class ann(x: Int) extends annotation.StaticAnnotation + +class t { + val a = new A + @ann(a.foo(1)) def bar = 1 +} diff --git a/tests/untried/pos/t1942/Test_2.scala b/tests/untried/pos/t1942/Test_2.scala new file mode 100644 index 000000000..6c045bbce --- /dev/null +++ b/tests/untried/pos/t1942/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + println(new t) +} diff --git a/tests/untried/pos/t1957.scala b/tests/untried/pos/t1957.scala new file mode 100644 index 000000000..711ce17de --- /dev/null +++ b/tests/untried/pos/t1957.scala @@ -0,0 +1,38 @@ +object Test { + abstract class Settings {} + + abstract class Grist + { self => + type settingsType <: Settings + type moduleType <: Module {type settingsType = self.settingsType} + val module: moduleType + } + + abstract class Tool + { self => + type settingsType <: Settings + type moduleType = Module { type settingsType = self.settingsType } + type gristType = Grist { type moduleType <: self.moduleType; type settingsType <: self.settingsType } + + def inputGrist: List[gristType] + } + + abstract class Module + { self => + type settingsType <: Settings + final type commonModuleType = Module {type settingsType = self.settingsType} + type selfType >: self.type <: commonModuleType + + // BTW: if we use the commented out type decls, the code compiles successfully + // type gristType = Grist {type settingsType <: self.settingsType; type moduleType <: commonModuleType } + + val tools: List[Tool {type settingsType = self.settingsType}] + + protected def f: List[commonModuleType] = + { + val inputGrists = tools.flatMap(_.inputGrist) // val inputGrists: List[gristType] = + inputGrists.map(_.module) + } + + } +} diff --git a/tests/untried/pos/t1974.scala b/tests/untried/pos/t1974.scala new file mode 100644 index 000000000..3f4d41e7f --- /dev/null +++ b/tests/untried/pos/t1974.scala @@ -0,0 +1,20 @@ +object Broken { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += (c -> s) + def fetch(c : Class[_]) = map(c) +} + +object Works { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c, s)) + def fetch(c : Class[_]) = map(c) +} + +object Works2 { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c : Class[_]) -> s) + def fetch(c : Class[_]) = map(c) +} diff --git a/tests/untried/pos/t1987a.scala b/tests/untried/pos/t1987a.scala new file mode 100644 index 000000000..ccab13371 --- /dev/null +++ b/tests/untried/pos/t1987a.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/tests/untried/pos/t1987b/a.scala b/tests/untried/pos/t1987b/a.scala new file mode 100644 index 000000000..ff27044b6 --- /dev/null +++ b/tests/untried/pos/t1987b/a.scala @@ -0,0 +1,7 @@ +package bug + +// goes with t1987b.scala +package object packageb { + def func(a: Int) = () + def func(a: String) = () +} diff --git a/tests/untried/pos/t1987b/b.scala b/tests/untried/pos/t1987b/b.scala new file mode 100644 index 000000000..a469ca6ea --- /dev/null +++ b/tests/untried/pos/t1987b/b.scala @@ -0,0 +1,10 @@ +// compile with t1987a.scala + +package bug.packageb +// Note that the overloading works if instead of being in the package we import it: +// replace the above line with import bug.packageb._ + +class Client { + val x = func(1) // doesn't compile: type mismatch; found: Int(1) required: String + val y = func("1") // compiles +} diff --git a/tests/untried/pos/t1996.scala b/tests/untried/pos/t1996.scala new file mode 100644 index 000000000..273012819 --- /dev/null +++ b/tests/untried/pos/t1996.scala @@ -0,0 +1,19 @@ +object forbug { + val l1 = List(List(ValDef(new A)), List(ValDef(new A))) + for ((e1s, e2s) <- l1.zip(l1); + (e1, e2) <- e1s.zip(e2s)) { + e1.a.doSome(20) +// () + } +} + + +class A { + def doSome(a: Int): this.type = { + println(a) + this + } +} + +case class ValDef(a: A) + diff --git a/tests/untried/pos/t201.scala b/tests/untried/pos/t201.scala new file mode 100644 index 000000000..b0c6b8da4 --- /dev/null +++ b/tests/untried/pos/t201.scala @@ -0,0 +1,7 @@ +class C[a] { def f: a = f; } +class D[b] { class E extends C[b]; } +object Test { + val d = new D[Int]; + def e = new d.E; + e.f; +} diff --git a/tests/untried/pos/t2018.scala b/tests/untried/pos/t2018.scala new file mode 100644 index 000000000..198b4be42 --- /dev/null +++ b/tests/untried/pos/t2018.scala @@ -0,0 +1,15 @@ +class A { + val b = new B + + def getChildren = List(new A).iterator + + class B { + private def check = true + + private def getAncestor(p: A): A = { + val c = (p.getChildren.find(_.b.check)) match {case Some(d) => d case None => p} + + if (c == p) p else c.b.getAncestor(c) + } + } +} diff --git a/tests/untried/pos/t2023.scala b/tests/untried/pos/t2023.scala new file mode 100644 index 000000000..21c6fc96a --- /dev/null +++ b/tests/untried/pos/t2023.scala @@ -0,0 +1,16 @@ +trait C[A] + +object C { + implicit def ipl[A](implicit from: A => Ordered[A]): C[A] = null +} + +object P { + def foo[A](i: A, j: A)(implicit c: C[A]): Unit = () +} + +class ImplicitChainTest { + def testTrivial: Unit = { + P.foo('0', '9') + P.foo('0', '9') + } +} diff --git a/tests/untried/pos/t2038.scala b/tests/untried/pos/t2038.scala new file mode 100644 index 000000000..8c8ca44da --- /dev/null +++ b/tests/untried/pos/t2038.scala @@ -0,0 +1,5 @@ +class Test { + List(Some(classOf[java.lang.Integer]), Some(classOf[Int])).map { + case Some(f: Class[_]) => f.cast(???) + } +} diff --git a/tests/untried/pos/t2060.scala b/tests/untried/pos/t2060.scala new file mode 100755 index 000000000..2c701150e --- /dev/null +++ b/tests/untried/pos/t2060.scala @@ -0,0 +1,44 @@ +/* The problem here is that we cannot insert an implicit to + * add a polymorphic method which is then instantiated to the + * right type. When searching for the implicit in the `fails to compile + * line': + * + * val failure = 1.0 + new Op[Int] + * + * we reduce the problem to finding a function from Double to + * {+: _ >: Op[Int] <: Any}, that is, a method which takes + * an argument which is an Op[Int] or a supertype thereof. + * Class Rich is not a subtype of this structural record, because + * polymorphic method instantiation is not contained in subtyping. + * That is: The method type [I](op : Op[I]): Op[I] is not a subtype + * of (Op[Int]): Op[Int]. + * At present it is unclear whether this problem can be solved. + */ +object Test { + class Op[I]; + class IntOp extends Op[Int]; + + class Rich(x : Double) { + def + (op : IntOp): IntOp = op; + def + [I](op : Op[I]): Op[I] = op; + def plus [I](op : Op[I]): Op[I] = op; + } + + implicit def iToRich(x : Double) = + new Rich(x); + + // fails to compile + val x = 1.0 + new Op[Int] + + // works as expected -- + // problem isn't in adding new "+" + val a = 1.0 + new IntOp; + + // works as expected -- + // problem isn't in binding type variable I + val b = 1.0 plus new Op[Int]; + + // works as expected -- + // problem isn't in using Rich.+[I](op : Op[I]) + val c = iToRich(1.0) + new Op[Int]; +} diff --git a/tests/untried/pos/t2066-2.10-compat.flags b/tests/untried/pos/t2066-2.10-compat.flags new file mode 100644 index 000000000..94c805674 --- /dev/null +++ b/tests/untried/pos/t2066-2.10-compat.flags @@ -0,0 +1 @@ +-Xsource:2.10 diff --git a/tests/untried/pos/t2066-2.10-compat.scala b/tests/untried/pos/t2066-2.10-compat.scala new file mode 100644 index 000000000..fb8103e4a --- /dev/null +++ b/tests/untried/pos/t2066-2.10-compat.scala @@ -0,0 +1,71 @@ +import language._ +trait A1 { + def f[T[_]] = () +} + +trait B1 extends A1 { + override def f[T[+_]] = () +} + +trait C1 extends A1 { + override def f[T[-_]] = () +} + + +trait A2 { + def f[T[+_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () // okay +} + +trait C2 extends A2 { + override def f[T[-_]] = () +} + + +trait A3 { + def f[T[-_]] = () +} + +trait B3 extends A3 { + override def f[T[_]] = () // okay +} + +trait C3 extends A3 { + override def f[T[-_]] = () +} + + +trait A4 { + def f[T[X[+_]]] = () +} + +trait B4 extends A4 { + override def f[T[X[_]]] = () +} + +trait A5 { + def f[T[X[-_]]] = () +} + +trait B5 extends A5 { + override def f[T[X[_]]] = () +} + + + +trait A6 { + def f[T[X[_]]] = () +} + +trait B6 extends A6 { + override def f[T[X[+_]]] = () // okay +} +trait C6 extends A6 { + override def f[T[X[_]]] = () // okay +} +trait D6 extends A6 { + override def f[T[X[-_]]] = () +} diff --git a/tests/untried/pos/t2066.scala b/tests/untried/pos/t2066.scala new file mode 100644 index 000000000..30cb99d45 --- /dev/null +++ b/tests/untried/pos/t2066.scala @@ -0,0 +1,25 @@ +trait A1 { + def f[T[+_]] = () +} + +trait B1 extends A1 { + override def f[T[_]] = () +} + + +trait A2 { + def f[T[-_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () +} + + +trait A3 { + def f[T[X[_]]] = () +} + +trait B3 extends A3 { + override def f[T[X[+_]]] = () +} diff --git a/tests/untried/pos/t2081.scala b/tests/untried/pos/t2081.scala new file mode 100644 index 000000000..395134f71 --- /dev/null +++ b/tests/untried/pos/t2081.scala @@ -0,0 +1,11 @@ +object ScalaForRubyists { + class RichInt(n: Int) { + def days = 1000*60*60*24*n + } + + implicit def RichInt(n: Int): RichInt = new RichInt(n) + + val x = 10.days + // a couple parser corner cases I wanted not to break + val y = 5.0e0 + 5e7 +} diff --git a/tests/untried/pos/t2082.scala b/tests/untried/pos/t2082.scala new file mode 100755 index 000000000..a7ee3789b --- /dev/null +++ b/tests/untried/pos/t2082.scala @@ -0,0 +1,39 @@ + +trait Mapper[T <: Mapper[T]] + +trait KeyedMapper[KeyType, T <: KeyedMapper[KeyType, T]] extends Mapper[T] + + +trait KeyedMetaMapper[KeyType, T <: KeyedMapper[KeyType, T]] + +trait MappedForeignKey[KeyType, Owner <: Mapper[Owner], Other <: KeyedMapper[KeyType, Other]] + +trait IdPK + +class TestSubject extends KeyedMapper[Long, TestSubject] with IdPK + +class TestRun extends KeyedMapper[Long, TestRun] with IdPK { + object testSubject extends MappedForeignKey[Long, TestRun, TestSubject] +} + +object TestRun extends TestRun with KeyedMetaMapper[Long, TestRun] + +class MetaTestSubject extends TestSubject with KeyedMetaMapper[Long, TestSubject] +object TestSubject extends MetaTestSubject + +object Main { + + def oneToOneJoin[PType <: KeyedMapper[Long, PType] with IdPK, + CType <: KeyedMapper[Long, CType] with IdPK, + CMetaType <: CType with KeyedMetaMapper[Long, CType], + FKType <: MappedForeignKey[Long, PType, CType]] + (parents: List[PType], metaMapper: CMetaType, keyGetter: (PType) => FKType ): + Map[Long, CType] = Map.empty + + def callIt: Unit = { + oneToOneJoin[TestRun, TestSubject, MetaTestSubject, + MappedForeignKey[Long, TestRun, TestSubject]]( + List(), TestSubject, (tr: TestRun) => tr.testSubject) + } + +} diff --git a/tests/untried/pos/t2094.scala b/tests/untried/pos/t2094.scala new file mode 100644 index 000000000..6b6c4f077 --- /dev/null +++ b/tests/untried/pos/t2094.scala @@ -0,0 +1,31 @@ +object Test extends App { + // compiles: + Map[Int, Value]( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // does not compile: + Map( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // Experiment.scala:10: error: type mismatch; + // found : (Int, KnownType) + // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 + // 0 -> KnownType(classOf[Object]), + // ^ + // one error found +} +sealed trait Value { + def getType: Option[Class[_]] +} + +case class UnknownValue() extends Value { + def getType = None + // compiles if changed to: + // def getType: Option[Class[_]] = None +} + +case class KnownType(typ: Class[_]) extends Value { + def getType = Some(typ) +} diff --git a/tests/untried/pos/t210.scala b/tests/untried/pos/t210.scala new file mode 100644 index 000000000..f0b907aa5 --- /dev/null +++ b/tests/untried/pos/t210.scala @@ -0,0 +1,17 @@ +trait Lang1 { + trait Exp; + trait Visitor { def f(left: Exp): Unit } + class Eval1 extends Visitor { self: Visitor => + def f(left: Exp) = () + } +} + +trait Lang2 extends Lang1 { + class Eval2 extends Eval1 { self: Visitor => } +} +/* +object Main with App { + val lang2 = new Lang2 {} + val eval = new lang2.Eval2 +} +*/ diff --git a/tests/untried/pos/t211.scala b/tests/untried/pos/t211.scala new file mode 100644 index 000000000..d51c9706d --- /dev/null +++ b/tests/untried/pos/t211.scala @@ -0,0 +1,8 @@ +trait A; +trait B; +class Foo extends A with B { self: A with B => } +object Test extends App { + new Foo(); + Console.println("t211 completed"); +} + diff --git a/tests/untried/pos/t2119.scala b/tests/untried/pos/t2119.scala new file mode 100644 index 000000000..b9cb4d9c6 --- /dev/null +++ b/tests/untried/pos/t2119.scala @@ -0,0 +1,4 @@ +class A { + val orig = new java.util.ArrayList[String] + val copy = new java.util.ArrayList(orig) +} diff --git a/tests/untried/pos/t2127.scala b/tests/untried/pos/t2127.scala new file mode 100644 index 000000000..88cc9e708 --- /dev/null +++ b/tests/untried/pos/t2127.scala @@ -0,0 +1,5 @@ +class Foo private (val value : Int) + +abstract class Bar(val ctor : (Int) => Foo) + +object Foo extends Bar(new Foo(_)) //<--- ILLEGAL ACCESS diff --git a/tests/untried/pos/t2130-1.scala b/tests/untried/pos/t2130-1.scala new file mode 100644 index 000000000..8dd61c4d3 --- /dev/null +++ b/tests/untried/pos/t2130-1.scala @@ -0,0 +1,5 @@ +package foo + +package object bar { + case class Bippy(x: Int) { } +} diff --git a/tests/untried/pos/t2130-2.scala b/tests/untried/pos/t2130-2.scala new file mode 100644 index 000000000..1d0b33c3e --- /dev/null +++ b/tests/untried/pos/t2130-2.scala @@ -0,0 +1,17 @@ +package foo + +package object bar { + class Bippy(x: Int) { + class Ding + object Ding + case class Dong(x: Float) + } + object Bippy { + class Dingus + object Dingus + case class Dongus(x: Float) + + def apply(xs: Int*) = new Bippy(xs.sum) + def apply() = new Bippy(5) + } +} diff --git a/tests/untried/pos/t2133.scala b/tests/untried/pos/t2133.scala new file mode 100644 index 000000000..c74d0a4bb --- /dev/null +++ b/tests/untried/pos/t2133.scala @@ -0,0 +1,18 @@ +trait Foo { + object bar { + private[this] def fn() = 5 + } +} + +trait Foo2 { + object bip { + def fn() = 10 + } +} + +class Bob extends AnyRef with Foo with Foo2 { + import bip._ + import bar._ + + def go() = fn() +} diff --git a/tests/untried/pos/t2168.scala b/tests/untried/pos/t2168.scala new file mode 100644 index 000000000..21afb239a --- /dev/null +++ b/tests/untried/pos/t2168.scala @@ -0,0 +1,4 @@ +object Test extends App { + def foo1(x: AnyRef) = x match { case x: Function0[_] => x() } + def foo2(x: AnyRef) = x match { case x: Function0[Any] => x() } +} diff --git a/tests/untried/pos/t2171.flags b/tests/untried/pos/t2171.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/untried/pos/t2171.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/untried/pos/t2171.scala b/tests/untried/pos/t2171.scala new file mode 100644 index 000000000..6c754c76a --- /dev/null +++ b/tests/untried/pos/t2171.scala @@ -0,0 +1,7 @@ +final object test { + def logIgnoredException(msg: => String) = + try 0 catch { case ex => println(msg) } + + def main (args: Array[String]): Unit = + while (true) logIgnoredException ("...") +} diff --git a/tests/untried/pos/t2179.scala b/tests/untried/pos/t2179.scala new file mode 100755 index 000000000..89e22b6e2 --- /dev/null +++ b/tests/untried/pos/t2179.scala @@ -0,0 +1,3 @@ +object Test { + (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) +} diff --git a/tests/untried/pos/t2183.scala b/tests/untried/pos/t2183.scala new file mode 100644 index 000000000..1243568b6 --- /dev/null +++ b/tests/untried/pos/t2183.scala @@ -0,0 +1,5 @@ +import scala.collection.mutable._ + +object Test { + val m = new HashSet[String] with SynchronizedSet[String] +} diff --git a/tests/untried/pos/t2187-2.scala b/tests/untried/pos/t2187-2.scala new file mode 100644 index 000000000..506cc496f --- /dev/null +++ b/tests/untried/pos/t2187-2.scala @@ -0,0 +1,7 @@ +class Test { + def test[A](list: List[A]) = list match { + case Seq(x, y) => "xy" + case Seq(x) => "x" + case _ => "something else" + } +} diff --git a/tests/untried/pos/t2187.scala b/tests/untried/pos/t2187.scala new file mode 100644 index 000000000..8a3353154 --- /dev/null +++ b/tests/untried/pos/t2187.scala @@ -0,0 +1,7 @@ +// bug #2187 +object Test extends App { + def foo(xs:List[String]) = xs match { + case Seq(x) => x + case Seq(x,y) => "" + } +} diff --git a/tests/untried/pos/t2194.scala b/tests/untried/pos/t2194.scala new file mode 100644 index 000000000..e87be509d --- /dev/null +++ b/tests/untried/pos/t2194.scala @@ -0,0 +1,8 @@ +// tricky to do differently? +class C + +object Test { + def f = { object o extends C; o} + val y: C = f + val x = f +} diff --git a/tests/untried/pos/t2208_pos.scala b/tests/untried/pos/t2208_pos.scala new file mode 100644 index 000000000..dd6d686ba --- /dev/null +++ b/tests/untried/pos/t2208_pos.scala @@ -0,0 +1,8 @@ +object Test { + class A + + class B[X] + type Alias[X <: A] = B[X] + + val foo: B[A] = new Alias[A] // check that type aliases can be instantiated +} diff --git a/tests/untried/pos/t2234.scala b/tests/untried/pos/t2234.scala new file mode 100644 index 000000000..218e9f5e5 --- /dev/null +++ b/tests/untried/pos/t2234.scala @@ -0,0 +1,4 @@ +object Test extends App { + val res0 = 1 #:: Stream.empty + res0 match { case 1 #:: xs => xs } +} diff --git a/tests/untried/pos/t2260.scala b/tests/untried/pos/t2260.scala new file mode 100644 index 000000000..4e4cc5ab2 --- /dev/null +++ b/tests/untried/pos/t2260.scala @@ -0,0 +1,10 @@ +package top + +class Text(val value: String) extends Ordered[Text] { + def compare(that: Text) = value.compare(that.value) +} + +object Index { + import scala.collection.immutable.TreeMap + val tree = TreeMap.empty[Text, String] +} diff --git a/tests/untried/pos/t2261.scala b/tests/untried/pos/t2261.scala new file mode 100644 index 000000000..06360d500 --- /dev/null +++ b/tests/untried/pos/t2261.scala @@ -0,0 +1,9 @@ +class Bob[T] +object Test { + implicit def foo2bar[T](xs: List[T]): Bob[T] = new Bob[T] + var x: Bob[Int] = null + x = List(1,2,3) + // the problem here was that somehow the type variable that was used to infer the type argument for List.apply + // would accumulate several conflicting constraints + // can't reproduce with +} diff --git a/tests/untried/pos/t229.scala b/tests/untried/pos/t229.scala new file mode 100644 index 000000000..72ddfa74f --- /dev/null +++ b/tests/untried/pos/t229.scala @@ -0,0 +1,3 @@ +class Test extends java.util.ArrayList[Object] { + override def add(index: Int, element: java.lang.Object): Unit = {} +} diff --git a/tests/untried/pos/t2293.scala b/tests/untried/pos/t2293.scala new file mode 100644 index 000000000..536d4ec3d --- /dev/null +++ b/tests/untried/pos/t2293.scala @@ -0,0 +1,5 @@ +import scala.collection.JavaConversions._ + +object Test { + val m: java.util.Map[String,String] = collection.mutable.Map("1"->"2") +} diff --git a/tests/untried/pos/t2305.scala b/tests/untried/pos/t2305.scala new file mode 100644 index 000000000..3338ab911 --- /dev/null +++ b/tests/untried/pos/t2305.scala @@ -0,0 +1,26 @@ +import java.util.ArrayList + +trait Bind[Z[_]] + +class MySerializable[X] extends java.io.Serializable + +object Bind { + implicit val JavaArrayListBind: Bind[ArrayList] = new Bind[ArrayList] {} + implicit val MySerializableBind: Bind[MySerializable] = new Bind[MySerializable] {} +} + +object works { + // this works fine: + def runbind(implicit bind: Bind[MySerializable]): Unit = {} + runbind +} + +object breaks { + def runbind(implicit bind: Bind[ArrayList]): Unit = {} + runbind + /*java.lang.AssertionError: assertion failed: java.io.Serializable + at scala.Predef$.assert(Predef.scala:107) + at scala.tools.nsc.symtab.Types$TypeRef.transform(Types.scala:1417) + at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1559) + */ +} diff --git a/tests/untried/pos/t2310.scala b/tests/untried/pos/t2310.scala new file mode 100644 index 000000000..68912b496 --- /dev/null +++ b/tests/untried/pos/t2310.scala @@ -0,0 +1,38 @@ +import scala.Stream._ + +object consistencyError { + /* this gives an error: + Consistency problem compiling (virtual file)! + Trying to call method body%1(List(scala.collection.immutable.Stream[A])) with arguments (List(tp2, temp6, temp5)) + case (l #:: ls, rs) => None + ^ + scala.tools.nsc.symtab.Types$TypeError: too many arguments for method body%1: (val rs: scala.collection.immutable.Stream[A])None.type + + two errors found + vss(0) = + args = List(tp2, temp6, temp5) + vss(1) = value rs, value ls, value l + args = List(tp2, temp6, temp5) + targets(0) = FinalState(,scala.None) + targets(1) = FinalState(,scala.None) + labels(1) = method body%1 + labels(0) = method body%0 + bx = 1 + label.tpe = (val rs: scala.collection.immutable.Stream[A])None.type + */ + def crash[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + case (Stream.Empty, Stream.Empty) => None + case (l #:: ls, rs) => None + } + + // These work + // def works1[A](lefts: Stream[A]) = lefts match { + // case Stream.Empty => None + // case l #:: ls => None + // } + // + // def works2[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + // case (Stream.Empty, Stream.Empty) => None + // case (ls, rs) => None + // } +} diff --git a/tests/untried/pos/t2331.scala b/tests/untried/pos/t2331.scala new file mode 100644 index 000000000..a7f80ac98 --- /dev/null +++ b/tests/untried/pos/t2331.scala @@ -0,0 +1,11 @@ +trait C { + def m[T]: T +} + +object Test { + val o /*: C --> no crash*/ = new C { + def m[T]: Nothing /*: T --> no crash*/ = sys.error("omitted") + } + + o.m[Nothing] +} diff --git a/tests/untried/pos/t2377/Q.java b/tests/untried/pos/t2377/Q.java new file mode 100644 index 000000000..e3d11c70e --- /dev/null +++ b/tests/untried/pos/t2377/Q.java @@ -0,0 +1,12 @@ +public final class Q { + public static final class Stage { + public static Builder newBuilder() { return new Builder(); } + public static final class Builder { } + public Builder toBuilder() { return newBuilder(); } + } + public static final class WorkUnit { + public static Builder newBuilder() { return new Builder(); } + public static final class Builder { } + public Builder toBuilder() { return newBuilder(); } + } +} diff --git a/tests/untried/pos/t2377/a.scala b/tests/untried/pos/t2377/a.scala new file mode 100644 index 000000000..bda59ce0d --- /dev/null +++ b/tests/untried/pos/t2377/a.scala @@ -0,0 +1,8 @@ +import Q._ + +class Bop(var workUnit: WorkUnit) { + def addStages(stageBuilder: Stage.Builder): Unit = { + val builder = workUnit.toBuilder + () + } +} diff --git a/tests/untried/pos/t2399.scala b/tests/untried/pos/t2399.scala new file mode 100644 index 000000000..a99998a0a --- /dev/null +++ b/tests/untried/pos/t2399.scala @@ -0,0 +1,14 @@ +trait That1[A] +trait That2[A, R <: That2[A, R]] + +trait T[A, This >: Null <: That1[A] with T[A, This]] extends That2[A, This] { + self: This => + + private var next: This = _ + def isEmpty = next eq null + + def length: Int = { + def loop(x: This, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) + loop(self, 0) + } +} diff --git a/tests/untried/pos/t2405.scala b/tests/untried/pos/t2405.scala new file mode 100644 index 000000000..224b2ce83 --- /dev/null +++ b/tests/untried/pos/t2405.scala @@ -0,0 +1,23 @@ +object A { implicit val x: Int = 1 } + +// Problem as stated in the ticket. +object Test1 { + import A.{x => y} + implicitly[Int] +} + +// Testing for the absense of shadowing #1. +object Test2 { + import A.{x => y} + val x = 2 + implicitly[Int] +} + +// Testing for the absense of shadowing #2. +object Test3 { + { + import A.{x => y} + def x: Int = 0 + implicitly[Int] + } +} diff --git a/tests/untried/pos/t2409/J.java b/tests/untried/pos/t2409/J.java new file mode 100644 index 000000000..6b7c45ff6 --- /dev/null +++ b/tests/untried/pos/t2409/J.java @@ -0,0 +1,4 @@ +class J { + static class J2 { } + J(J2 j2) { } +} diff --git a/tests/untried/pos/t2409/t2409.scala b/tests/untried/pos/t2409/t2409.scala new file mode 100644 index 000000000..0412f7d82 --- /dev/null +++ b/tests/untried/pos/t2409/t2409.scala @@ -0,0 +1 @@ +object S { new J(null) } diff --git a/tests/untried/pos/t2413/TestJava.java b/tests/untried/pos/t2413/TestJava.java new file mode 100644 index 000000000..252c01fbc --- /dev/null +++ b/tests/untried/pos/t2413/TestJava.java @@ -0,0 +1,7 @@ +package pack; + +public class TestJava { + protected String repeatParam(String ... items) { + return "nothing"; + } +} diff --git a/tests/untried/pos/t2413/TestScalac.scala b/tests/untried/pos/t2413/TestScalac.scala new file mode 100644 index 000000000..098e852dd --- /dev/null +++ b/tests/untried/pos/t2413/TestScalac.scala @@ -0,0 +1,23 @@ +import pack.TestJava + +class Foo extends TestJava { + + // THIS METHOD YIELDS TO CRASH +/* def foomethod : Option[String] => Unit = { + case None => + val path = repeatParam("s","a","b","c") + () + case Some(error) => + () + } + + // THIS IS OK + def foomethod2 : String = repeatParam("s","a"); + + // THIS IS OK + val aVal = repeatParam("1","2","3") */ + + // THIS YIELDS TO CRASH + for (a <- 1 to 4 ; anotherVal = repeatParam("1","2","3")) + yield anotherVal +} diff --git a/tests/untried/pos/t2421.scala b/tests/untried/pos/t2421.scala new file mode 100644 index 000000000..2544a1cb3 --- /dev/null +++ b/tests/untried/pos/t2421.scala @@ -0,0 +1,14 @@ +object Test { + abstract class <~<[-From, +To] extends (From => To) + implicit def trivial[A]: A <~< A = sys.error("") + + + trait Forcible[T] + implicit val forcibleInt: (Int <~< Forcible[Int]) = sys.error("") + + def headProxy[P <: Forcible[Int]](implicit w: Int <~< P): P = sys.error("") + + headProxy + // trivial[Int] should not be considered a valid implicit, since w would have type Int <~< Int, + // and headProxy's type parameter P cannot be instantiated to Int +} diff --git a/tests/untried/pos/t2421_delitedsl.scala b/tests/untried/pos/t2421_delitedsl.scala new file mode 100644 index 000000000..da60c1ef3 --- /dev/null +++ b/tests/untried/pos/t2421_delitedsl.scala @@ -0,0 +1,37 @@ +trait DeliteDSL { + abstract class <~<[-From, +To] extends (From => To) + implicit def trivial[A]: A <~< A = new (A <~< A) {def apply(x: A) = x} + + trait Forcible[T] + object Forcible { + def factory[T](f: T => Forcible[T]) = new (T <~< Forcible[T]){def apply(x: T) = f(x)} + } + + case class DeliteInt(x: Int) extends Forcible[Int] + implicit val forcibleInt = Forcible.factory(DeliteInt(_: Int)) + + import scala.collection.Traversable + class DeliteCollection[T](val xs: Traversable[T]) { + // must use existential in bound of P, instead of T itself, because we cannot both have: + // Test.x below: DeliteCollection[T=Int] -> P=DeliteInt <: Forcible[T=Int], as T=Int <~< P=DeliteInt + // Test.xAlready below: DeliteCollection[T=DeliteInt] -> P=DeliteInt <: Forcible[T=DeliteInt], as T=DeliteInt <~< P=DeliteInt + // this would required DeliteInt <: Forcible[Int] with Forcible[DeliteInt] + + def headProxy[P <: Forcible[_]](implicit w: T <~< P): P = xs.head + } + // If T is already a proxy (it is forcible), the compiler should use + // forcibleIdentity to deduce that P=T. If T is Int, the compiler + // should use intToForcible to deduce that P=DeliteInt. + // + // Without this feature, the user must write 'xs.proxyOfFirst[DeliteInt]', + // with the feature they can write 'xs.proxyOfFirst', which is shorter and + // avoids exposing internal DELITE types to the world. + + object Test { + val x = new DeliteCollection(List(1,2,3)).headProxy + // inferred: val x: Forcible[Int] = new DeliteCollection[Int](List.apply[Int](1, 2, 3)).headProxy[Forcible[Int]](forcibleInt); + + val xAlready = new DeliteCollection(List(DeliteInt(1),DeliteInt(2),DeliteInt(3))).headProxy + // inferred: val xAlready: DeliteInt = new DeliteCollection[DeliteInt](List.apply[DeliteInt](DeliteInt(1), DeliteInt(2), DeliteInt(3))).headProxy[DeliteInt](trivial[DeliteInt]); + } +} diff --git a/tests/untried/pos/t2421b_pos.scala b/tests/untried/pos/t2421b_pos.scala new file mode 100644 index 000000000..0df346166 --- /dev/null +++ b/tests/untried/pos/t2421b_pos.scala @@ -0,0 +1,19 @@ +object Test { + class A + class B + class C + class F[X] + + def f(implicit aa: F[A]) = println(aa) + + implicit def a : F[A] = new F[A]() + implicit def b[X <: B] = new F[X]() + + f +} +/* bug: +error: ambiguous implicit values: + both method b in object Test1 of type [X <: Test1.B]Test1.F[X] + and method a in object Test1 of type => Test1.F[Test1.A] + match expected type Test1.F[Test1.A] +*/ diff --git a/tests/untried/pos/t2421c.scala b/tests/untried/pos/t2421c.scala new file mode 100644 index 000000000..d212fb903 --- /dev/null +++ b/tests/untried/pos/t2421c.scala @@ -0,0 +1,17 @@ +object Test { + class A + class B + class C + class F[X] + + def f(implicit aa: F[A]) = println(aa) + + implicit def a : F[A] = new F[A]() + + // generalised from t2421b to verify we check enough + class G[X] + implicit def g[X] = new G[X]() + implicit def b[X <: B](implicit mx: G[X]) = new F[X]() + + f +} diff --git a/tests/untried/pos/t2425.scala b/tests/untried/pos/t2425.scala new file mode 100755 index 000000000..477d5467a --- /dev/null +++ b/tests/untried/pos/t2425.scala @@ -0,0 +1,15 @@ +trait B +class D extends B +object Test extends App { + def foo[T](bar: T) = { + bar match { + case _: Array[Array[_]] => println("array 2d") + case _: Array[_] => println("array 1d") + case _ => println("something else") + } + } + foo(Array.fill(10)(2)) + foo(Array.fill(10, 10)(2)) + foo(Array.fill(10, 10, 10)(2)) + foo(List(1, 2, 3)) +} diff --git a/tests/untried/pos/t2429.scala b/tests/untried/pos/t2429.scala new file mode 100755 index 000000000..4cda3bde1 --- /dev/null +++ b/tests/untried/pos/t2429.scala @@ -0,0 +1,25 @@ +object Msg { + trait T + + trait TSeq + + object TSeq { + implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") + } + + def render: Unit = { + val msgs: TSeq = (List[(Any, Any)]().flatMap { + case (a, b) => { + a match { + case _ => b match { + case _ => sys.error("stub") + } + } + } + } /*: Seq[T] Adding this type annotation avoids the compile error.*/) + } +} +object Oops { + implicit def someImplicit(s: Seq[_]): String = sys.error("stub") + def item: String = Nil map { case e: Any => e } +} diff --git a/tests/untried/pos/t2433/A.java b/tests/untried/pos/t2433/A.java new file mode 100755 index 000000000..340690c40 --- /dev/null +++ b/tests/untried/pos/t2433/A.java @@ -0,0 +1,4 @@ +class A223 extends B223.Inner { + static class Inner {} + void foo() {} +}
\ No newline at end of file diff --git a/tests/untried/pos/t2433/B.java b/tests/untried/pos/t2433/B.java new file mode 100755 index 000000000..151dd71ca --- /dev/null +++ b/tests/untried/pos/t2433/B.java @@ -0,0 +1,4 @@ +class B223 { + static class Inner {} + void m(A223.Inner x) {} +}
\ No newline at end of file diff --git a/tests/untried/pos/t2433/Test.scala b/tests/untried/pos/t2433/Test.scala new file mode 100755 index 000000000..02fd89b64 --- /dev/null +++ b/tests/untried/pos/t2433/Test.scala @@ -0,0 +1,3 @@ +object Test { + (new A223).foo() +} diff --git a/tests/untried/pos/t2435.scala b/tests/untried/pos/t2435.scala new file mode 100644 index 000000000..697e9e1f2 --- /dev/null +++ b/tests/untried/pos/t2435.scala @@ -0,0 +1,27 @@ +object Bug { + abstract class FChain { + type T + + def chain(constant:String) = + new FConstant[this.type](constant, this) //removing [this.type], everything compiles + } + + case class FConstant[E <: FChain](constant:String, tail:E) extends FChain { + type T = tail.T + } + + object FNil extends FChain { + type T = Unit + } + +} + +object Test { + import Bug._ + println("Compiles:") + val a1 = FNil.chain("a").chain("a") + val a2 = a1.chain("a") + + println("\nDoesn't compile:") + val a = FNil.chain("a").chain("a").chain("a") +} diff --git a/tests/untried/pos/t2441pos.scala b/tests/untried/pos/t2441pos.scala new file mode 100644 index 000000000..25eb2232c --- /dev/null +++ b/tests/untried/pos/t2441pos.scala @@ -0,0 +1,8 @@ +abstract class A { + private def foo = List(1, 2) +} +trait B extends A { + private def foo = List("a", "b") + // However it compiles correctly if the type is given: + // private def foo: List[String] = List("a", "b") +} diff --git a/tests/untried/pos/t2444.scala b/tests/untried/pos/t2444.scala new file mode 100644 index 000000000..fac1e95d0 --- /dev/null +++ b/tests/untried/pos/t2444.scala @@ -0,0 +1,15 @@ +object Test { + + trait Foo + + class Bar { + object baz extends Foo + } + + def frob[P1, P2<:Foo](f:P1 => P2) = () + + def main(args:Array[String]) : Unit = { + frob((p:Bar) => p.baz) + } + +} diff --git a/tests/untried/pos/t245.scala b/tests/untried/pos/t245.scala new file mode 100644 index 000000000..570ac4178 --- /dev/null +++ b/tests/untried/pos/t245.scala @@ -0,0 +1,18 @@ +class Value {} + +object Test { + + implicit def view(v: Value): Int = 0 + + def foo(i: Int): Int = 0 + + def fun0 : Value = null + def fun0(i: Int ): Value = null + + def fun1(i: Int ): Value = null + def fun1(l: Long): Value = null + + foo(fun0 ); + foo(fun1(new Value)); + +} diff --git a/tests/untried/pos/t2454.scala b/tests/untried/pos/t2454.scala new file mode 100644 index 000000000..00f2e6f67 --- /dev/null +++ b/tests/untried/pos/t2454.scala @@ -0,0 +1,25 @@ +package am; + +trait One[M[_]] { + val x : Int +} + +trait Two[M[_,_]] { + val x : Int +} + +object Test { + // Works. + val x = new Two[Map] { + val x = 5 + } + + val o = new One[java.util.List] { + val x = 1 + } + + // Does not work + val y = new Two[java.util.concurrent.ConcurrentHashMap] { + val x = 3 + } +} diff --git a/tests/untried/pos/t2464/JavaOne.java b/tests/untried/pos/t2464/JavaOne.java new file mode 100644 index 000000000..ff36868a0 --- /dev/null +++ b/tests/untried/pos/t2464/JavaOne.java @@ -0,0 +1,5 @@ +class ClassTwo { + public static class Child { + public void func2() {return ;} + } +} diff --git a/tests/untried/pos/t2464/ScalaOne_1.scala b/tests/untried/pos/t2464/ScalaOne_1.scala new file mode 100644 index 000000000..1caf8ecae --- /dev/null +++ b/tests/untried/pos/t2464/ScalaOne_1.scala @@ -0,0 +1,6 @@ +class ScalaClassOne extends ClassTwo.Child { + def func4() = { + func2 + } +} + diff --git a/tests/untried/pos/t2464/t2464_2.scala b/tests/untried/pos/t2464/t2464_2.scala new file mode 100644 index 000000000..13a52c952 --- /dev/null +++ b/tests/untried/pos/t2464/t2464_2.scala @@ -0,0 +1,3 @@ +object Test { + val c1 = new ScalaClassOne +} diff --git a/tests/untried/pos/t247.scala b/tests/untried/pos/t247.scala new file mode 100644 index 000000000..fdcafeb2c --- /dev/null +++ b/tests/untried/pos/t247.scala @@ -0,0 +1,26 @@ +class Order[t](less:(t,t) => Boolean,equal:(t,t) => Boolean) {} + +trait Map[A, B] extends scala.collection.Map[A, B] { + val factory:MapFactory[A] +} +abstract class MapFactory[A] { + def Empty[B]:Map[A,B]; +} + +class TreeMapFactory[KEY](newOrder:Order[KEY]) extends MapFactory[KEY] { + val order = newOrder; + def Empty[V] = new TreeMap[KEY,V](new TreeMapFactory[KEY](order)); +} + +class Tree[KEY,Entry](order:Order[KEY]) { + def size =0; +} + +class TreeMap[KEY,VALUE](_factory:TreeMapFactory[KEY]) extends Tree[KEY,Tuple2[KEY,VALUE]](_factory.order) with scala.collection.DefaultMap[KEY, VALUE] with Map[KEY, VALUE] { + val factory = _factory + val order = _factory.order; + def this(newOrder:Order[KEY]) = this(new TreeMapFactory[KEY](newOrder)); + def get(key:KEY) = null; + def iterator:Iterator[Tuple2[KEY,VALUE]] = null; + override def size = super[Tree].size +} diff --git a/tests/untried/pos/t2484.scala b/tests/untried/pos/t2484.scala new file mode 100755 index 000000000..15165c247 --- /dev/null +++ b/tests/untried/pos/t2484.scala @@ -0,0 +1,19 @@ +import concurrent.ExecutionContext.Implicits.global + +class Admin extends javax.swing.JApplet { + val jScrollPane = new javax.swing.JScrollPane (null, 0, 0) + def t2484: Unit = { + scala.concurrent.Future {jScrollPane.synchronized { + def someFunction () = {} + //scala.concurrent.ops.spawn {someFunction ()} + jScrollPane.addComponentListener (new java.awt.event.ComponentAdapter {override def componentShown (e: java.awt.event.ComponentEvent) = { + someFunction (); jScrollPane.removeComponentListener (this)}}) + }} + } +} +// t2630.scala +object Test { + def meh(xs: List[Any]): Unit = { + xs map { x => (new AnyRef {}) } + } +} diff --git a/tests/untried/pos/t2486.scala b/tests/untried/pos/t2486.scala new file mode 100644 index 000000000..69fe4c127 --- /dev/null +++ b/tests/untried/pos/t2486.scala @@ -0,0 +1,3 @@ +class A[T] +class B extends A[Int] +class C[T] extends A[T] { def f(t: A[T]) = t match { case x: B => () } } diff --git a/tests/untried/pos/t2500.scala b/tests/untried/pos/t2500.scala new file mode 100644 index 000000000..d0ff99a93 --- /dev/null +++ b/tests/untried/pos/t2500.scala @@ -0,0 +1,6 @@ +object Test { + import scala.collection._ + ((Map(1 -> "a", 2 -> "b"): collection.Map[Int, String]) map identity[(Int, String)]) : scala.collection.Map[Int,String] + ((SortedMap(1 -> "a", 2 -> "b"): collection.SortedMap[Int, String]) map identity[(Int, String)]): scala.collection.SortedMap[Int,String] + ((SortedSet(1, 2): collection.SortedSet[Int]) map identity[Int]): scala.collection.SortedSet[Int] +} diff --git a/tests/untried/pos/t2504.scala b/tests/untried/pos/t2504.scala new file mode 100755 index 000000000..67f822685 --- /dev/null +++ b/tests/untried/pos/t2504.scala @@ -0,0 +1,5 @@ +object Test { + val ys: Iterable[_] = Array("abc") + val xs = Array("abc") + xs sameElements Array("abc") +} diff --git a/tests/untried/pos/t252.scala b/tests/untried/pos/t252.scala new file mode 100644 index 000000000..d51b5511e --- /dev/null +++ b/tests/untried/pos/t252.scala @@ -0,0 +1,17 @@ +abstract class Module {} + +abstract class T { + type moduleType <: Module + val module: moduleType +} + +abstract class Base { + type mType = Module + type tType = T { type moduleType <: mType } +} + +abstract class Derived extends Base { + def f(inputs: List[tType]): Unit = { + for (t <- inputs; m = t.module) { } + } +} diff --git a/tests/untried/pos/t2545.scala b/tests/untried/pos/t2545.scala new file mode 100755 index 000000000..6ad994223 --- /dev/null +++ b/tests/untried/pos/t2545.scala @@ -0,0 +1,10 @@ +trait Frog[T] { + def hello: T + def size: Int + } + + trait OnlyWithFrogs { + self: Frog[_] => + + def sizeStr = size.toString + } diff --git a/tests/untried/pos/t2569/Child.scala b/tests/untried/pos/t2569/Child.scala new file mode 100644 index 000000000..64f4dc172 --- /dev/null +++ b/tests/untried/pos/t2569/Child.scala @@ -0,0 +1,9 @@ +package varargs + + class Child extends Parent { + + override def concatenate(strings: String*): String = + strings map("\"" + _ + "\"") mkString("(", ", ", ")") + + } + diff --git a/tests/untried/pos/t2569/Parent.java b/tests/untried/pos/t2569/Parent.java new file mode 100644 index 000000000..89421becb --- /dev/null +++ b/tests/untried/pos/t2569/Parent.java @@ -0,0 +1,13 @@ +package varargs; + + public class Parent { + + public String concatenate(String... strings) { + StringBuilder builder = new StringBuilder(); + for (String s : strings) { + builder.append(s); + } + return builder.toString(); + } + + } diff --git a/tests/untried/pos/t2591.scala b/tests/untried/pos/t2591.scala new file mode 100644 index 000000000..47ae551bf --- /dev/null +++ b/tests/untried/pos/t2591.scala @@ -0,0 +1,15 @@ +class A +class B + +object Implicits { + implicit def imp(x: A): Int = 41 + implicit def imp(x: B): Int = 41 +} + +object Test { + // should cause imp to be in scope so that the next expression type checks + // `import Implicits._` works + import Implicits.imp + + (new A) : Int +} diff --git a/tests/untried/pos/t2610.scala b/tests/untried/pos/t2610.scala new file mode 100644 index 000000000..8a82b4a72 --- /dev/null +++ b/tests/untried/pos/t2610.scala @@ -0,0 +1,17 @@ +package mada; package defects; package tests + +package object bbb { + def bar = () + aaa.foo // value foo is not a member of package mada.defects.tests.aaa +} + +package object aaa { + def foo = () +} + +/* compiles successfully if placed here.. +package object bbb { + def bar = () + aaa.foo // value foo is not a member of package mada.defects.tests.aaa +} +*/ diff --git a/tests/untried/pos/t2613.scala b/tests/untried/pos/t2613.scala new file mode 100644 index 000000000..3a64dbc28 --- /dev/null +++ b/tests/untried/pos/t2613.scala @@ -0,0 +1,11 @@ +import language.existentials + +object Test { + class Row + + abstract class MyRelation [R <: Row, +Relation <: MyRelation[R, Relation]] + + type M = MyRelation[R, Relation] forSome {type R <: Row; type Relation <: MyRelation[R, Relation]} + + var (x,y): (String, M) = null +} diff --git a/tests/untried/pos/t2619.scala b/tests/untried/pos/t2619.scala new file mode 100644 index 000000000..283d93bf2 --- /dev/null +++ b/tests/untried/pos/t2619.scala @@ -0,0 +1,80 @@ +abstract class F { + final def apply(x: Int): AnyRef = null +} +abstract class AbstractModule { + def as: List[AnyRef] + def ms: List[AbstractModule] + def fs: List[F] = Nil + def rs(x: Int): List[AnyRef] = fs.map(_(x)) +} +abstract class ModuleType1 extends AbstractModule {} +abstract class ModuleType2 extends AbstractModule {} + +object ModuleAE extends ModuleType1 { + def as = Nil + def ms = Nil +} +object ModuleAF extends ModuleType2 { + def as = Nil + def ms = List(ModuleAE) +} +object ModuleAG extends ModuleType1 { + def as = List("") + def ms = Nil +} +object ModuleAI extends ModuleType1 { + def as = Nil + def ms = List(ModuleAE) +} +object ModuleAK extends ModuleType2 { + def as = Nil + def ms = List(ModuleAF) +} +object ModuleAL extends ModuleType1 { + def as = Nil + def ms = List( + ModuleAG, + ModuleAI + ) +} +object ModuleAM extends ModuleType1 { + def as = Nil + def ms = List( + ModuleAL, + ModuleAE + ) ::: List(ModuleAK) +} +object ModuleBE extends ModuleType1 { + def as = Nil + def ms = Nil +} +object ModuleBF extends ModuleType2 { + def as = Nil + def ms = List(ModuleBE) +} +object ModuleBG extends ModuleType1 { + def as = List("") + def ms = Nil +} +object ModuleBI extends ModuleType1 { + def as = Nil + def ms = List(ModuleBE) +} +object ModuleBK extends ModuleType2 { + def as = Nil + def ms = List(ModuleBF) +} +object ModuleBL extends ModuleType1 { + def as = Nil + def ms = List( + ModuleBG, + ModuleBI + ) +} +object ModuleBM extends ModuleType1 { + def as = Nil + def ms = List( + ModuleBL, + ModuleBE + ) ::: List(ModuleBK) +} diff --git a/tests/untried/pos/t262.scala b/tests/untried/pos/t262.scala new file mode 100644 index 000000000..ec6187b36 --- /dev/null +++ b/tests/untried/pos/t262.scala @@ -0,0 +1,14 @@ +object O { + abstract class A { + def f:A; + } + class B extends A { + def f = if(1 == 2) new C else new D; + } + class C extends A { + def f = this; + } + class D extends A { + def f = this; + } +} diff --git a/tests/untried/pos/t2624.scala b/tests/untried/pos/t2624.scala new file mode 100644 index 000000000..76f0e3036 --- /dev/null +++ b/tests/untried/pos/t2624.scala @@ -0,0 +1,4 @@ +object Test { + List(1).map(identity(_)) + List(1).map(identity) // this didn't typecheck before the fix +} diff --git a/tests/untried/pos/t2635.scala b/tests/untried/pos/t2635.scala new file mode 100755 index 000000000..7cd553135 --- /dev/null +++ b/tests/untried/pos/t2635.scala @@ -0,0 +1,16 @@ +abstract class Base + +object Test +{ + def run(c: Class[_ <: Base]): Unit = { + } + + def main(args: Array[String]): Unit = + { + val sc: Option[Class[_ <: Base]] = Some(classOf[Base]) + sc match { + case Some(c) => run(c) + case None => + } + } +} diff --git a/tests/untried/pos/t2660.scala b/tests/untried/pos/t2660.scala new file mode 100644 index 000000000..d42dcc72b --- /dev/null +++ b/tests/untried/pos/t2660.scala @@ -0,0 +1,25 @@ +package hoho + +class G + +class H extends G + +class A[T](x: T) { + + def this(y: G, z: T) = { + this(z) + print(1) + } + + def this(z: H, h: T) = { + this(h) + print(2) + } +} + +object T { + def main(args: Array[String]): Unit = { + implicit def g2h(g: G): H = new H + new A(new H, 23) + } +} diff --git a/tests/untried/pos/t2664.scala b/tests/untried/pos/t2664.scala new file mode 100644 index 000000000..7b667d010 --- /dev/null +++ b/tests/untried/pos/t2664.scala @@ -0,0 +1,9 @@ +package pkg1 { + class C { + private[pkg1] def foo: Int = 1 + } + + trait T extends C { + private[pkg1] abstract override def foo = super.foo + 1 + } +} diff --git a/tests/untried/pos/t2665.scala b/tests/untried/pos/t2665.scala new file mode 100644 index 000000000..e46453534 --- /dev/null +++ b/tests/untried/pos/t2665.scala @@ -0,0 +1,3 @@ +object Test { + val x: Unit = Array("") +} diff --git a/tests/untried/pos/t2667.scala b/tests/untried/pos/t2667.scala new file mode 100644 index 000000000..7f1f36f00 --- /dev/null +++ b/tests/untried/pos/t2667.scala @@ -0,0 +1,6 @@ +object A { + def foo(x: Int, y: Int*): Int = 45 + def foo[T](x: T*): Int = 55 + + val x: Unit = foo(23, 23f) +} diff --git a/tests/untried/pos/t2669.scala b/tests/untried/pos/t2669.scala new file mode 100644 index 000000000..72e931178 --- /dev/null +++ b/tests/untried/pos/t2669.scala @@ -0,0 +1,28 @@ +// #2629, #2639, #2669 +object Test2669 { + + def test[T](l: java.util.ArrayList[_ <: T]) = 1 + test(new java.util.ArrayList[String]()) + +} + +import java.util.ArrayList + +object Test2629 { + def main(args: Array[String]): Unit = { + val l = new ArrayList[String](1) + val m = new ArrayList(l) + + println(l.size) + println(m.size) + } +} + + +import java.util.Vector + +// scalac cannot detect lack of type params, but then throws AssertionError later: +class TVector2639 { + val b = new Vector // this line passed without error detected + val a = new Vector(1) // this line caused throwing AssertionError when scalac +} diff --git a/tests/untried/pos/t267.scala b/tests/untried/pos/t267.scala new file mode 100644 index 000000000..7e5876eae --- /dev/null +++ b/tests/untried/pos/t267.scala @@ -0,0 +1,55 @@ +package expAbstractData + +/** A base class consisting of + * - a root trait (i.e. abstract class) `Exp' with an `eval' function + * - an abstract type `exp' bounded by `Exp' + * - a concrete instance class `Num' of `Exp' for numeric literals + */ +trait Base { + type exp <: Exp + + trait Exp { + def eval: Int + } + class Num(v: Int) extends Exp { self: exp => + val value = v + def eval = value + } +} + +object testBase extends App with Base { + type exp = Exp + val term = new Num(2); + Console.println(term.eval) +} + +/** Data extension: An extension of `Base' with `Plus' expressions + */ +trait BasePlus extends Base { + class Plus(l: exp, r: exp) extends Exp { self: exp => + val left = l + val right = r + def eval = left.eval + right.eval + } +} + +/** Operation extension: An extension of `Base' with 'show' methods. + */ +trait Show extends Base { + type exp <: Exp1 + + trait Exp1 extends Exp { + def show: String + } + class Num1(v: Int) extends Num(v) with Exp1 { self: exp with Num1 => + def show = value.toString() + } +} + +/** Operation extension: An extension of `BasePlus' with 'show' methods. + */ +trait ShowPlus extends BasePlus with Show { + class Plus1(l: exp, r: exp) extends Plus(l, r) with Exp1 { self: exp with Plus1 => + def show = left.show + " + " + right.show + } +} diff --git a/tests/untried/pos/t2683.scala b/tests/untried/pos/t2683.scala new file mode 100755 index 000000000..4ba34b554 --- /dev/null +++ b/tests/untried/pos/t2683.scala @@ -0,0 +1,7 @@ +class A +class B extends A + +object Test { + val c: Class[_ <: A] = Class.forName("B").asSubclass(classOf[A]) + val x: Option[Class[_ <: A]] = Some(3).map { case _ => c } +} diff --git a/tests/untried/pos/t2691.scala b/tests/untried/pos/t2691.scala new file mode 100644 index 000000000..5f0ddd122 --- /dev/null +++ b/tests/untried/pos/t2691.scala @@ -0,0 +1,16 @@ +object Breakdown { + def unapplySeq(x: Int): Some[List[String]] = Some(List("", "there")) +} +object Test { + 42 match { + case Breakdown("") => // needed to trigger bug + case Breakdown("", who) => println ("hello " + who) + } +} +object Test2 { + 42 match { + case Breakdown("") => // needed to trigger bug + case Breakdown("foo") => // needed to trigger bug + case Breakdown("", who) => println ("hello " + who) + } +} diff --git a/tests/untried/pos/t2693.scala b/tests/untried/pos/t2693.scala new file mode 100644 index 000000000..5d4d0380c --- /dev/null +++ b/tests/untried/pos/t2693.scala @@ -0,0 +1,6 @@ +class A { + trait T[A] + def usetHk[T[_], A](ta: T[A]) = 0 + usetHk(new T[Int]{}: T[Int]) + usetHk(new T[Int]{}) // fails with: found: java.lang.Object with T[Int], required: ?T[ ?A ] +} diff --git a/tests/untried/pos/t2698.scala b/tests/untried/pos/t2698.scala new file mode 100644 index 000000000..bce02e48b --- /dev/null +++ b/tests/untried/pos/t2698.scala @@ -0,0 +1,14 @@ +class WordExp { + abstract class Label + type _labelT <: Label +} + +import scala.collection._ + +abstract class S2 { + val lang: WordExp + type __labelT = lang._labelT + + var deltaq: Array[__labelT] = _ + def delta1 = immutable.Map(deltaq.zipWithIndex: _*) +} diff --git a/tests/untried/pos/t2708.scala b/tests/untried/pos/t2708.scala new file mode 100644 index 000000000..19485bf4c --- /dev/null +++ b/tests/untried/pos/t2708.scala @@ -0,0 +1 @@ +class Foo(@volatile var v: Int) diff --git a/tests/untried/pos/t2726/SQLBuilder_1.scala b/tests/untried/pos/t2726/SQLBuilder_1.scala new file mode 100644 index 000000000..8d07a8826 --- /dev/null +++ b/tests/untried/pos/t2726/SQLBuilder_1.scala @@ -0,0 +1,7 @@ +class SQLBuilder extends SQLBuilder.Segment + +object SQLBuilder { + trait Segment +} + + diff --git a/tests/untried/pos/t2726/t2726_2.scala b/tests/untried/pos/t2726/t2726_2.scala new file mode 100644 index 000000000..e738143ae --- /dev/null +++ b/tests/untried/pos/t2726/t2726_2.scala @@ -0,0 +1,3 @@ +object SQuery2Test { + new SQLBuilder +} diff --git a/tests/untried/pos/t2741/2741_1.scala b/tests/untried/pos/t2741/2741_1.scala new file mode 100644 index 000000000..d9d04f7ab --- /dev/null +++ b/tests/untried/pos/t2741/2741_1.scala @@ -0,0 +1,9 @@ +trait Partial { + type Apply[XYZ] = List[XYZ] +} +trait MA[M[_]] +trait MAs { + val a: MA[Partial#Apply] = null // after compilation, the type is pickled as `MA[ [B] List[B] ]` +} + +object Scalaz extends MAs diff --git a/tests/untried/pos/t2741/2741_2.scala b/tests/untried/pos/t2741/2741_2.scala new file mode 100644 index 000000000..a9fd9d7d0 --- /dev/null +++ b/tests/untried/pos/t2741/2741_2.scala @@ -0,0 +1,5 @@ +// object Test compiles jointly, but not separately. +object Test { + import Scalaz._ + Scalaz.a +} diff --git a/tests/untried/pos/t2764/Ann.java b/tests/untried/pos/t2764/Ann.java new file mode 100644 index 000000000..184fc6e86 --- /dev/null +++ b/tests/untried/pos/t2764/Ann.java @@ -0,0 +1,5 @@ +package bippy; + +public @interface Ann { + Enum value(); +} diff --git a/tests/untried/pos/t2764/Enum.java b/tests/untried/pos/t2764/Enum.java new file mode 100644 index 000000000..fe0755953 --- /dev/null +++ b/tests/untried/pos/t2764/Enum.java @@ -0,0 +1,5 @@ +package bippy; + +public enum Enum { + VALUE; +} diff --git a/tests/untried/pos/t2764/Use.scala b/tests/untried/pos/t2764/Use.scala new file mode 100644 index 000000000..b0c108907 --- /dev/null +++ b/tests/untried/pos/t2764/Use.scala @@ -0,0 +1,6 @@ +package bippy + +class Use { + @Ann(Enum.VALUE) + def foo: Unit = {} +} diff --git a/tests/untried/pos/t2782.scala b/tests/untried/pos/t2782.scala new file mode 100644 index 000000000..ab12aaf1f --- /dev/null +++ b/tests/untried/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]]) = new Foo[M[A,B]] {} + implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] // no difference if this line is uncommented + implicit def Tuple2Foo[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/untried/pos/t2794.scala b/tests/untried/pos/t2794.scala new file mode 100644 index 000000000..a17edf8cb --- /dev/null +++ b/tests/untried/pos/t2794.scala @@ -0,0 +1,9 @@ +class Key[T] + +class Entry[T](val k: Key[T], val v: T) + +object Entry { + + def makeDefault[T >: Null <: AnyRef] = new Entry[T](new Key[T], null: T) + +} diff --git a/tests/untried/pos/t2795-new.scala b/tests/untried/pos/t2795-new.scala new file mode 100644 index 000000000..e307133e0 --- /dev/null +++ b/tests/untried/pos/t2795-new.scala @@ -0,0 +1,19 @@ +package t1 + +import scala.reflect.{ClassTag, classTag} + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ClassTag[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/tests/untried/pos/t2795-old.scala b/tests/untried/pos/t2795-old.scala new file mode 100644 index 000000000..935cb1f44 --- /dev/null +++ b/tests/untried/pos/t2795-old.scala @@ -0,0 +1,17 @@ +package t1 + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ClassManifest[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/tests/untried/pos/t2797.scala b/tests/untried/pos/t2797.scala new file mode 100644 index 000000000..cf579d8de --- /dev/null +++ b/tests/untried/pos/t2797.scala @@ -0,0 +1,9 @@ +class MyVector[A] { + def map[B](f: A => B): MyVector[B] = sys.error("") +} + +object Test { + def unzip[B, C](_this: MyVector[(B, C)]): (MyVector[B], MyVector[C]) = { + (_this.map{ bc => bc._1 }, _this.map{ bc => bc._2 }) + } +} diff --git a/tests/untried/pos/t2799.flags b/tests/untried/pos/t2799.flags new file mode 100644 index 000000000..d1b831ea8 --- /dev/null +++ b/tests/untried/pos/t2799.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t2799.scala b/tests/untried/pos/t2799.scala new file mode 100644 index 000000000..7710cce26 --- /dev/null +++ b/tests/untried/pos/t2799.scala @@ -0,0 +1 @@ +@deprecated("hi mom", "") case class Bob () diff --git a/tests/untried/pos/t2809.scala b/tests/untried/pos/t2809.scala new file mode 100644 index 000000000..1f68b0b07 --- /dev/null +++ b/tests/untried/pos/t2809.scala @@ -0,0 +1,20 @@ +package p1 { + abstract class T1 { + protected def bug(p: Int = 1): Int // without 'protected' compiles fine + } +} +package p2 { // all being in the same package compiles fine + import p1._ + abstract class T2 extends T1 { + class A { + bug() + } + } + + abstract class T3 extends T2 { + class A { + bug() + } + } +} + diff --git a/tests/untried/pos/t2810.scala b/tests/untried/pos/t2810.scala new file mode 100644 index 000000000..c85eca164 --- /dev/null +++ b/tests/untried/pos/t2810.scala @@ -0,0 +1,8 @@ + + + + +object Test { + val closeable1: { def close(): Unit } = new scala.io.Source { val iter: Iterator[Char] = "".iterator } + val closeable2: { def close(): Unit } = new java.io.Closeable { def close() = {} } +} diff --git a/tests/untried/pos/t284-pos.scala b/tests/untried/pos/t284-pos.scala new file mode 100644 index 000000000..40277e2db --- /dev/null +++ b/tests/untried/pos/t284-pos.scala @@ -0,0 +1,5 @@ +trait B[T] { + def f1(a: T): Unit { } + def f2(a: T): Unit + def f3(a: T): Unit = { } +} diff --git a/tests/untried/pos/t287.scala b/tests/untried/pos/t287.scala new file mode 100644 index 000000000..8e5e8831c --- /dev/null +++ b/tests/untried/pos/t287.scala @@ -0,0 +1,12 @@ +object testBuf { + class mystream extends java.io.BufferedOutputStream(new java.io.FileOutputStream("/dev/null")) { + def w( x:String ):Unit = { + val foo = new Array[Byte](2); + + // write( byte[] ) is defined in FilterOutputStream, the superclass of BufferedOutputStream + super.write( foo ); // error + + super.write( foo, 0, foo.length ); // this works however + } + } +} diff --git a/tests/untried/pos/t289.scala b/tests/untried/pos/t289.scala new file mode 100644 index 000000000..96c0244df --- /dev/null +++ b/tests/untried/pos/t289.scala @@ -0,0 +1,5 @@ +class A { + object B; +} + +object C extends A; diff --git a/tests/untried/pos/t2910.scala b/tests/untried/pos/t2910.scala new file mode 100644 index 000000000..f9f2c87a9 --- /dev/null +++ b/tests/untried/pos/t2910.scala @@ -0,0 +1,33 @@ +object Test { + def test1: Unit = { + C + object C + } + + def test2: Unit = { + println(s.length) + lazy val s = "abc" + } + + def test3: Unit = { + lazy val lazyBar = bar + object bar { + val foo = 12 + } + lazy val lazyBar2 = bar + } + + def test4: Unit = { + lazy val x = { + x + lazy val x = 12 + 0 + } + } + + def test5: Unit = { + lazy val f: Int = g + Console.println("foo") + lazy val g: Int = f + } +} diff --git a/tests/untried/pos/t2913.scala b/tests/untried/pos/t2913.scala new file mode 100755 index 000000000..6366548c6 --- /dev/null +++ b/tests/untried/pos/t2913.scala @@ -0,0 +1,53 @@ +class A { + def foo(a: Int) = 0 +} + +class RichA { + def foo(a: String) = 0 + def foo(a: String, b: String) = 0 + def foo() = 0 +} + +object Test { + + implicit def AToRichA(a: A) = new RichA + + val a = new A + a.foo() + a.foo(1) + + a.foo("") // Without implicits, a type error regarding invalid argument types is generated at `""`. This is + // the same position as an argument, so the 'second try' typing with an Implicit View is tried, + // and AToRichA(a).foo("") is found. + // + // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should + // not be triggered. + // + // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756 + + a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo(<error>"", "")`. + // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`. + // None of these po +} + +// t0851 is essentially the same: +object test1 { + case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){ + def apply(t : T) = (s:T2) => f(t,s) + def apply(p : (T,T2)) = f(p._1,p._2) + } + implicit def g[T](f : (T,String) => String) = Foo(f) + def main(args : Array[String]) : Unit = { + val f = (x:Int,s:String) => s + x + println(f(1)) + () + } +} +object Main { + def main(args : Array[String]): Unit = { + val fn = (a : Int, str : String) => "a: " + a + ", str: " + str + implicit def fx[T](f : (T,String) => String) = (x:T) => f(x,null) + println(fn(1)) + () + } +} diff --git a/tests/untried/pos/t2939.scala b/tests/untried/pos/t2939.scala new file mode 100644 index 000000000..57dd52024 --- /dev/null +++ b/tests/untried/pos/t2939.scala @@ -0,0 +1,13 @@ +import collection._ + +object Proxies { + class C1 extends MapProxy[Int,Int] { def self = Map[Int,Int]() } + class C2 extends mutable.MapProxy[Int,Int] { def self = mutable.Map[Int,Int]() } + class C3 extends immutable.MapProxy[Int,Int] { def self = immutable.Map[Int,Int]() } + + class C4 extends SetProxy[Int] { def self = Set[Int]() } + class C5 extends mutable.SetProxy[Int] { def self = mutable.Set[Int]() } + class C6 extends immutable.SetProxy[Int] { def self = immutable.Set[Int]() } + + class C7 extends SeqProxy[Int] { def self = Seq[Int]() } +} diff --git a/tests/untried/pos/t294/Ann.java b/tests/untried/pos/t294/Ann.java new file mode 100644 index 000000000..934ca4629 --- /dev/null +++ b/tests/untried/pos/t294/Ann.java @@ -0,0 +1,3 @@ +public @interface Ann { + public Ann2[] nested(); +} diff --git a/tests/untried/pos/t294/Ann2.java b/tests/untried/pos/t294/Ann2.java new file mode 100644 index 000000000..025b79e79 --- /dev/null +++ b/tests/untried/pos/t294/Ann2.java @@ -0,0 +1,3 @@ +public @interface Ann2 { + public int value(); +} diff --git a/tests/untried/pos/t294/Test_1.scala b/tests/untried/pos/t294/Test_1.scala new file mode 100644 index 000000000..ff1f34b10 --- /dev/null +++ b/tests/untried/pos/t294/Test_1.scala @@ -0,0 +1,7 @@ +// also test pickling of java annotations; Test_2.scala will +// read this class file +@Ann(nested = Array(new Ann2(10))) class Test { + @Ann2(100) var ctx: Object = _ + @Ann(nested = Array()) def foo = 10 + @Ann(nested = Array(new Ann2(10), new Ann2(23))) val bam = -3 +} diff --git a/tests/untried/pos/t294/Test_2.scala b/tests/untried/pos/t294/Test_2.scala new file mode 100644 index 000000000..9fb1c6e17 --- /dev/null +++ b/tests/untried/pos/t294/Test_2.scala @@ -0,0 +1 @@ +class Test2 extends Test diff --git a/tests/untried/pos/t2940/Cycle.java b/tests/untried/pos/t2940/Cycle.java new file mode 100644 index 000000000..eef6c23b5 --- /dev/null +++ b/tests/untried/pos/t2940/Cycle.java @@ -0,0 +1,3 @@ +public interface Cycle<T extends Cycle<?>> { + void doStuff(); +}
\ No newline at end of file diff --git a/tests/untried/pos/t2940/Error.scala b/tests/untried/pos/t2940/Error.scala new file mode 100644 index 000000000..92f08f580 --- /dev/null +++ b/tests/untried/pos/t2940/Error.scala @@ -0,0 +1,12 @@ +abstract class Error { + val c: Cycle[_] +} + +object Test { + trait Quux[T] extends Cycle[Quux[T]] + val x = new Quux[Int] { def doStuff(): Unit = { } } + + def main(args: Array[String]): Unit = { + + } +} diff --git a/tests/untried/pos/t2945.scala b/tests/untried/pos/t2945.scala new file mode 100644 index 000000000..0379e9ba1 --- /dev/null +++ b/tests/untried/pos/t2945.scala @@ -0,0 +1,12 @@ +object Foo { + def test(s: String) = { + (s: Seq[Char]) match { + case Seq('f', 'o', 'o', ' ', rest1 @ _*) => + rest1 + case Seq('b', 'a', 'r', ' ', ' ', rest2 @ _*) => + rest2 + case _ => + s + } + } +} diff --git a/tests/untried/pos/t295.scala b/tests/untried/pos/t295.scala new file mode 100644 index 000000000..22c7beff4 --- /dev/null +++ b/tests/untried/pos/t295.scala @@ -0,0 +1,2 @@ +object Test extends java.rmi.server.UnicastRemoteObject { +} diff --git a/tests/untried/pos/t2956/BeanDefinitionVisitor.java b/tests/untried/pos/t2956/BeanDefinitionVisitor.java new file mode 100644 index 000000000..2ff5daa25 --- /dev/null +++ b/tests/untried/pos/t2956/BeanDefinitionVisitor.java @@ -0,0 +1,6 @@ +import java.util.Map; +public class BeanDefinitionVisitor { + @SuppressWarnings("unchecked") + protected void visitMap(Map<?, ?> mapVal) { + } +} diff --git a/tests/untried/pos/t2956/t2956.scala b/tests/untried/pos/t2956/t2956.scala new file mode 100755 index 000000000..33803874b --- /dev/null +++ b/tests/untried/pos/t2956/t2956.scala @@ -0,0 +1,7 @@ +import scala.collection.JavaConversions._ + +class Outer { + protected class Inner extends BeanDefinitionVisitor { + protected def visitMap(mapVal: Map[_, _]): Unit = () + } +} diff --git a/tests/untried/pos/t296.scala b/tests/untried/pos/t296.scala new file mode 100644 index 000000000..0c267a307 --- /dev/null +++ b/tests/untried/pos/t296.scala @@ -0,0 +1,3 @@ +object Bug { + def foo (l: => String) : String = 12 match { case _ => l} +} diff --git a/tests/untried/pos/t2973.scala b/tests/untried/pos/t2973.scala new file mode 100644 index 000000000..f5dde856d --- /dev/null +++ b/tests/untried/pos/t2973.scala @@ -0,0 +1 @@ +package foo {}; package bar {}; package baz {} diff --git a/tests/untried/pos/t2994a.scala b/tests/untried/pos/t2994a.scala new file mode 100644 index 000000000..f1a4a4a12 --- /dev/null +++ b/tests/untried/pos/t2994a.scala @@ -0,0 +1,27 @@ +object Naturals { + trait NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] <: NAT + type v = a[SUCC, ZERO] + } + final class ZERO extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = z + } + final class SUCC[n <: NAT] extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] + } + type _0 = ZERO + type _1 = SUCC[_0] + type _2 = SUCC[_1] + type _3 = SUCC[_2] + type _4 = SUCC[_3] + type _5 = SUCC[_4] + type _6 = SUCC[_5] + + + // crashes scala-2.8.0 beta1 + trait MUL[n <: NAT, m <: NAT] extends NAT { + trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] } + type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] + } + +} diff --git a/tests/untried/pos/t2994b.scala b/tests/untried/pos/t2994b.scala new file mode 100644 index 000000000..8b5eb9692 --- /dev/null +++ b/tests/untried/pos/t2994b.scala @@ -0,0 +1,7 @@ +object Test { + trait Bar[X[_]] + trait Baz[S[_] <: Bar[S]] { + type Apply[T] + } + trait Foo[V[_] <: Bar[V]] extends Bar[Baz[V]#Apply] +} diff --git a/tests/untried/pos/t3020.scala b/tests/untried/pos/t3020.scala new file mode 100644 index 000000000..016563e27 --- /dev/null +++ b/tests/untried/pos/t3020.scala @@ -0,0 +1,9 @@ +object Test { + def main(args: Array[String]): Unit = { + var x = true + + ( { if (x) new scala.util.Random() } .asInstanceOf[Runnable] ) + } +} + + diff --git a/tests/untried/pos/t3037.scala b/tests/untried/pos/t3037.scala new file mode 100644 index 000000000..b71ffe041 --- /dev/null +++ b/tests/untried/pos/t3037.scala @@ -0,0 +1,13 @@ +package test + +object A { + println(("a" match { + case "a" => 1 + case _ => "a" + }).asInstanceOf[Object]) + def foo[T](x: T) = x + var x: Int = 1 + var y: Long = 1L + x = foo(x) + y = foo(y) +} diff --git a/tests/untried/pos/t304.scala b/tests/untried/pos/t304.scala new file mode 100644 index 000000000..76da44157 --- /dev/null +++ b/tests/untried/pos/t304.scala @@ -0,0 +1,5 @@ +object O { + def f1 = -1; + def f2 = 0-1; + def f3 = -f1; +} diff --git a/tests/untried/pos/t3048.scala b/tests/untried/pos/t3048.scala new file mode 100644 index 000000000..dc056ecba --- /dev/null +++ b/tests/untried/pos/t3048.scala @@ -0,0 +1,8 @@ +class B +object C extends B + +class F[T <: B](cons: => T) +class F2[T <: B](cons: => T) extends F(cons) + +object D extends F2(C) // works +object E extends F2(new B {}) diff --git a/tests/untried/pos/t3071.scala b/tests/untried/pos/t3071.scala new file mode 100644 index 000000000..7e1443294 --- /dev/null +++ b/tests/untried/pos/t3071.scala @@ -0,0 +1,7 @@ +class A (val i: Int) { + def copy (i: Int = this.i): A = new A(i) +} + +class B (val j: Int) extends A(1) { + override def copy (j: Int = this.j): B = new B(j) +} diff --git a/tests/untried/pos/t3076/C2.scala b/tests/untried/pos/t3076/C2.scala new file mode 100644 index 000000000..c8a6ea9e3 --- /dev/null +++ b/tests/untried/pos/t3076/C2.scala @@ -0,0 +1,4 @@ +class C2 { + def m1(): Unit = { new T { } } + def m2(): Unit = { new T { } } +} diff --git a/tests/untried/pos/t3076/T.scala b/tests/untried/pos/t3076/T.scala new file mode 100644 index 000000000..b710a2934 --- /dev/null +++ b/tests/untried/pos/t3076/T.scala @@ -0,0 +1,2 @@ +trait T { private val z = new C1 } +private class C1 diff --git a/tests/untried/pos/t3079.scala b/tests/untried/pos/t3079.scala new file mode 100644 index 000000000..b7bd63190 --- /dev/null +++ b/tests/untried/pos/t3079.scala @@ -0,0 +1,17 @@ +sealed trait Identity[A] { + val value: A +} + +trait Coerce[A, B] { + def unwrap: (A => B) +} + +object Coerce { + def IdentityCoerce[B] = new Coerce[Identity[B], B] { + // java.lang.Error: A in trait Identity cannot be instantiated from ?x$1.type + def unwrap = _.value + + // Providing the type of _ works around the problem. + //def unwrap = (_: Identity[B]).value + } +} diff --git a/tests/untried/pos/t3106.scala b/tests/untried/pos/t3106.scala new file mode 100644 index 000000000..a9591d0aa --- /dev/null +++ b/tests/untried/pos/t3106.scala @@ -0,0 +1,7 @@ +class Sample[A] (val d0: ((A,A)) => A) {} + +object Sample { + implicit def apply[A] (x:A): Sample[A] = { + new Sample(p => p._1) + } +} diff --git a/tests/untried/pos/t3120/J1.java b/tests/untried/pos/t3120/J1.java new file mode 100644 index 000000000..12b23c1c9 --- /dev/null +++ b/tests/untried/pos/t3120/J1.java @@ -0,0 +1,4 @@ +class J1 { + public class Inner1 { } + public static class Inner2 { } +} diff --git a/tests/untried/pos/t3120/J2.java b/tests/untried/pos/t3120/J2.java new file mode 100644 index 000000000..db6e85902 --- /dev/null +++ b/tests/untried/pos/t3120/J2.java @@ -0,0 +1,4 @@ +public class J2 { + public void f1(J1.Inner1 p) { } + public void f2(J1.Inner2 p) { } +} diff --git a/tests/untried/pos/t3120/Q.java b/tests/untried/pos/t3120/Q.java new file mode 100644 index 000000000..fe2269308 --- /dev/null +++ b/tests/untried/pos/t3120/Q.java @@ -0,0 +1,3 @@ +public class Q { + public static void passInner(J1.Inner1 myInner) {} +} diff --git a/tests/untried/pos/t3120/Test.scala b/tests/untried/pos/t3120/Test.scala new file mode 100644 index 000000000..c02146fba --- /dev/null +++ b/tests/untried/pos/t3120/Test.scala @@ -0,0 +1,3 @@ +object Test { + Q.passInner(null) +} diff --git a/tests/untried/pos/t3136.scala b/tests/untried/pos/t3136.scala new file mode 100644 index 000000000..33d42c2f3 --- /dev/null +++ b/tests/untried/pos/t3136.scala @@ -0,0 +1,19 @@ +class Type +class Symbol +case class PolyType(tps: List[Symbol], res: Type) extends Type +class OtherType extends Type + +// case class NullaryMethodType(tp: Type) extends Type + +object NullaryMethodType { + def apply(resTpe: Type): Type = PolyType(List(), resTpe) + def unapply(tp: Type): Option[(Type)] = None +} + +object Test { + def TEST(tp: Type): String = + tp match { + case PolyType(ps1, PolyType(ps2, res @ PolyType(a, b))) => "1"+tp // couldn't find a simpler version that still crashes + case NullaryMethodType(meh) => "2"+meh + } +} diff --git a/tests/untried/pos/t3137.scala b/tests/untried/pos/t3137.scala new file mode 100644 index 000000000..cb7317af0 --- /dev/null +++ b/tests/untried/pos/t3137.scala @@ -0,0 +1,17 @@ +trait A { + val C: Any +} + +class B extends A { + class C + object C +} + +trait AA { + type C + def C: Int => C +} + +class BB extends AA { + case class C(v: Int) +} diff --git a/tests/untried/pos/t3152.scala b/tests/untried/pos/t3152.scala new file mode 100644 index 000000000..3d1dcbd6f --- /dev/null +++ b/tests/untried/pos/t3152.scala @@ -0,0 +1,20 @@ +trait Applicative[M[_]] + +sealed trait MA[M[_], A] { + def sequence[N[_], B](implicit a: A <:< N[B], n: Applicative[N]): N[M[B]] = sys.error("stub") + // def sequence3[N[_], B]()(implicit a: A <:< N[B], n: Applicative[N]): N[M[B]] = sys.error("stub") +} + +object test { + implicit def ListMA[A](l: List[A]): MA[List, A] = sys.error("stub") + implicit val ao: Applicative[Option] = sys.error("stub") + + /* This compiles OK: + (Nil: List[Option[Int]]).sequence3(): Option[List[Int]] + */ + + // BUG: error: immutable is not an enclosing class + // !!! No line number is reported with the error + (Nil: List[Option[Int]]).sequence: Option[List[Int]] + (List[Option[Int]]()).sequence: Option[List[Int]] +} diff --git a/tests/untried/pos/t3160.scala b/tests/untried/pos/t3160.scala new file mode 100644 index 000000000..cc007dc01 --- /dev/null +++ b/tests/untried/pos/t3160.scala @@ -0,0 +1,6 @@ +import scala.collection.mutable._ +class Node + +class A { + def f(x: Node): Node = ??? +} diff --git a/tests/untried/pos/t3174.scala b/tests/untried/pos/t3174.scala new file mode 100755 index 000000000..8d9b2578d --- /dev/null +++ b/tests/untried/pos/t3174.scala @@ -0,0 +1,14 @@ +object test { + def method(): Unit = { + class Foo extends AnyRef { + object Color { + object Blue + } + + class Board { + val grid = Color.Blue + } + } + new Foo + } + } diff --git a/tests/untried/pos/t3174b.scala b/tests/untried/pos/t3174b.scala new file mode 100755 index 000000000..4df1bfe83 --- /dev/null +++ b/tests/untried/pos/t3174b.scala @@ -0,0 +1,12 @@ +trait Foo[X] { def foo : Map[String,Foo[X]] } + +object Test { + def f[T]() : Foo[T] = { + class Anon extends Foo[T] { + var foo: Map[String, Foo[T]] = Map[String,Foo[T]]() + //def foo = Map[String,Foo[T]]() + //def foo_=(x: Map[String,Foo[T]]) {} + } + new Anon + } +} diff --git a/tests/untried/pos/t3175-pos.scala b/tests/untried/pos/t3175-pos.scala new file mode 100644 index 000000000..89bbf8b5f --- /dev/null +++ b/tests/untried/pos/t3175-pos.scala @@ -0,0 +1,7 @@ +object Test { + def f(g:{val update:Unit}) = g.update + + def main(args: Array[String]): Unit = { + + } +} diff --git a/tests/untried/pos/t3177.scala b/tests/untried/pos/t3177.scala new file mode 100644 index 000000000..9b850966d --- /dev/null +++ b/tests/untried/pos/t3177.scala @@ -0,0 +1,39 @@ +trait InvariantFunctor[F[_]] { + def xmap[A, B](ma: F[A], f: A => B, g: B => A): F[B] +} + +object InvariantFunctor { + import Endo._ + + implicit val EndoInvariantFunctor = new InvariantFunctor[Endo] { + def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b))) + } + + // The definition about fails with: + // anon-type.scala:9: error: not found: value b + // def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b))) + // ^ + // anon-type.scala:8: error: not found: type $anon + // implicit val EndoInvariantFunctor = new InvariantFunctor[Endo] { + // ^ + + + // These both work: + // implicit val EndoInvariantFunctorAscribed: InvariantFunctor[Endo] = new InvariantFunctor[Endo] { + // def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = (b: B) => f(ma(g(b))) + // } + // + // implicit val EndoInvariantFunctorStubbed = new InvariantFunctor[Endo] { + // def xmap[A, B](ma: Endo[A], f: A => B, g: B => A): Endo[B] = error("stub") + // } +} + +trait Endo[X] + +object Endo { + implicit def EndoTo[A](f: A => A): Endo[A] = new Endo[A] { + def apply(a: A) = f(a) + } + + implicit def EndoFrom[A](e: Endo[A]): A => A = e.apply(_) +} diff --git a/tests/untried/pos/t318.scala b/tests/untried/pos/t318.scala new file mode 100644 index 000000000..dbe0e0528 --- /dev/null +++ b/tests/untried/pos/t318.scala @@ -0,0 +1,9 @@ +object Test { + def fun: Int = { + object o { + def a: Int = 1; + class C { def b: Int = a; } + } + 0 + } +} diff --git a/tests/untried/pos/t319.scala b/tests/untried/pos/t319.scala new file mode 100644 index 000000000..eed25eb84 --- /dev/null +++ b/tests/untried/pos/t319.scala @@ -0,0 +1,21 @@ +object test { + + trait A { type T; } + + trait B { type T; } + + /** def functor(x: A): B { type T = x.T } */ + abstract class functor() { + val arg: A; + val res: B { type T = arg.T } = + new B { type T = arg.T; }; + } + + val a = new A { type T = String }; + /** val b: B { type T = String } = functor(a) */ + val b: B { type T = String } = { + val tmp = new functor() { val arg = a }; + tmp.res + } + +} diff --git a/tests/untried/pos/t3249/Test.java b/tests/untried/pos/t3249/Test.java new file mode 100644 index 000000000..4cc7cb2ab --- /dev/null +++ b/tests/untried/pos/t3249/Test.java @@ -0,0 +1,5 @@ +public class Test { + public static void meh() { + new A<Integer>().f(); + } +}
\ No newline at end of file diff --git a/tests/untried/pos/t3249/a.scala b/tests/untried/pos/t3249/a.scala new file mode 100644 index 000000000..fad6f8da6 --- /dev/null +++ b/tests/untried/pos/t3249/a.scala @@ -0,0 +1,11 @@ +class A[U] { def f[T] = { class X extends A[T] } } + + +/* +$ scalac a.scala +$ javac -cp .:$SCALA_HOME/lib/scala-library.jar -Xprint 'A$X$1' + + public class X$1 extends A<java.lang.Object> implements scala.ScalaObject { + public X$1(A<U> null); + } +*/ diff --git a/tests/untried/pos/t3252.flags b/tests/untried/pos/t3252.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/untried/pos/t3252.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/untried/pos/t3252.scala b/tests/untried/pos/t3252.scala new file mode 100644 index 000000000..3ecc1e7ce --- /dev/null +++ b/tests/untried/pos/t3252.scala @@ -0,0 +1,15 @@ +class A { + def f(x : Boolean) : Thread = { + g { + x match { + case false => + B.h { } + } + } + } + + private def g[T](block : => T) = sys.error("") +} +object B { + def h(block : => Unit) : Nothing = sys.error("") +} diff --git a/tests/untried/pos/t3272.scala b/tests/untried/pos/t3272.scala new file mode 100644 index 000000000..cf54d6a84 --- /dev/null +++ b/tests/untried/pos/t3272.scala @@ -0,0 +1,8 @@ +trait A { + trait C[+T] { + protected[this] def f(t: T): Unit = {} + } + trait D[T] extends C[T] { + def g(t: T): Unit = { f(t) } + } +} diff --git a/tests/untried/pos/t3274.scala b/tests/untried/pos/t3274.scala new file mode 100644 index 000000000..bd8b080c9 --- /dev/null +++ b/tests/untried/pos/t3274.scala @@ -0,0 +1,9 @@ +trait A { this: B => + trait X { + class Y1 extends Y + } +} + +trait B extends A { + trait Y { def f: Unit = {} } +} diff --git a/tests/untried/pos/t3278.scala b/tests/untried/pos/t3278.scala new file mode 100644 index 000000000..458070c5e --- /dev/null +++ b/tests/untried/pos/t3278.scala @@ -0,0 +1,15 @@ +class Foo +class Test { + def update[B](x : B, b : Int): Unit = {} + def apply[B](x : B) = 1 +} + +object Test { + def main(a : Array[String]): Unit = { + val a = new Test + val f = new Foo + a(f) = 1 //works + a(f) = a(f) + 1 //works + a(f) += 1 //error: reassignment to val + } +} diff --git a/tests/untried/pos/t3312.scala b/tests/untried/pos/t3312.scala new file mode 100644 index 000000000..aef965d2e --- /dev/null +++ b/tests/untried/pos/t3312.scala @@ -0,0 +1,17 @@ +trait Root { + def say: String +} + +trait A extends Root { + override def say: String = "bow" +} + +trait B extends Root { + override def say: String = "hi" +} + +object Foo extends A with B { + override def say: String = foo(super[A].say) + + def foo(p: => String): String = p +} diff --git a/tests/untried/pos/t3343.scala b/tests/untried/pos/t3343.scala new file mode 100644 index 000000000..9d1bc9355 --- /dev/null +++ b/tests/untried/pos/t3343.scala @@ -0,0 +1,15 @@ +import scala.collection.mutable.{ Builder, ListBuffer } + +object Test { + class Converter[T] + object SimpleIntConverter extends Converter[Int] + + class TraversableConverter[T, Coll[X] <: Traversable[X]](converter: Converter[T], builder: Builder[T, Coll[T]]) extends Converter[Coll[T]] { + def convert(x: T): List[T] = List(x) + } + val tc: Converter[List[Int]] = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int]) + val tc2 = new TraversableConverter(SimpleIntConverter, new ListBuffer[Int]) + + def main(args: Array[String]): Unit = { + } +} diff --git a/tests/untried/pos/t3349/AbstractTupleSet.java b/tests/untried/pos/t3349/AbstractTupleSet.java new file mode 100644 index 000000000..38e4743ef --- /dev/null +++ b/tests/untried/pos/t3349/AbstractTupleSet.java @@ -0,0 +1,9 @@ +public abstract class AbstractTupleSet implements TupleSet { + public void addColumn(String name, Class type) { + throw new UnsupportedOperationException(); + } + + public void addColumn(String name, String expr) { + throw new UnsupportedOperationException(); + } +} diff --git a/tests/untried/pos/t3349/Table.java b/tests/untried/pos/t3349/Table.java new file mode 100644 index 000000000..160936762 --- /dev/null +++ b/tests/untried/pos/t3349/Table.java @@ -0,0 +1,9 @@ +public class Table extends AbstractTupleSet { + public void addColumn(String name, Class type) { + throw new UnsupportedOperationException(); + } + + public void addColumn(String name, String expr) { + throw new UnsupportedOperationException(); + } +}
\ No newline at end of file diff --git a/tests/untried/pos/t3349/Test.scala b/tests/untried/pos/t3349/Test.scala new file mode 100644 index 000000000..595beadc2 --- /dev/null +++ b/tests/untried/pos/t3349/Test.scala @@ -0,0 +1,5 @@ +object Test { + val label = "name" + val table: Table = sys.error("") + table.addColumn( label, label.getClass ) +} diff --git a/tests/untried/pos/t3349/TupleSet.java b/tests/untried/pos/t3349/TupleSet.java new file mode 100644 index 000000000..14a073a95 --- /dev/null +++ b/tests/untried/pos/t3349/TupleSet.java @@ -0,0 +1,4 @@ +public interface TupleSet { + public void addColumn(String name, Class type); + public void addColumn(String name, String expr); +}
\ No newline at end of file diff --git a/tests/untried/pos/t3363-new.scala b/tests/untried/pos/t3363-new.scala new file mode 100644 index 000000000..d4d431984 --- /dev/null +++ b/tests/untried/pos/t3363-new.scala @@ -0,0 +1,20 @@ +import scala.reflect.runtime.universe._ + +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: TypeTag[T] = sys.error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]): Unit = { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/tests/untried/pos/t3363-old.scala b/tests/untried/pos/t3363-old.scala new file mode 100644 index 000000000..36d4cd933 --- /dev/null +++ b/tests/untried/pos/t3363-old.scala @@ -0,0 +1,18 @@ +object TestCase { + + //now matter if you put (abstract) class or trait it will fail in all cases + trait MapOps[T] + + //if fs was reduced to List (generic type with one parameter) then the code compiles + //if you inherit from MapOps[T] instead of MapOps[F] then code compiles fine + implicit def map2ops[T,F](fs: Map[T,F]) = new MapOps[F] { + //if you remove this line, then code compiles + lazy val m: Manifest[T] = sys.error("just something to make it compile") + def is(xs: List[T]) = List(xs) + } + + def main(args: Array[String]): Unit = { + println(Map(1 -> "2") is List(2)) + } + + } diff --git a/tests/untried/pos/t3371.scala b/tests/untried/pos/t3371.scala new file mode 100644 index 000000000..897cd9de4 --- /dev/null +++ b/tests/untried/pos/t3371.scala @@ -0,0 +1,9 @@ +// that compiles +class Test(myValue:String) { println(myValue) } + +// that compiles too +trait Other { val otherValue = "" } +class Test2(myValue:String) { self:Other => println(otherValue) } + +// that does not compile saying that myValue is not found +class Test3(myValue:String) { self:Other => println(myValue) } diff --git a/tests/untried/pos/t3373.scala b/tests/untried/pos/t3373.scala new file mode 100644 index 000000000..91768e201 --- /dev/null +++ b/tests/untried/pos/t3373.scala @@ -0,0 +1,11 @@ +class Entry(time: Long) { + def getTime: Long = time +} + +object Test { + def extractTime(e: Entry) = e.getTime + + implicit val orderEntries = new Ordering[Entry] { + def compare(first: Entry, second: Entry) = extractTime(first) compare extractTime(second) + } +} diff --git a/tests/untried/pos/t3374.scala b/tests/untried/pos/t3374.scala new file mode 100644 index 000000000..c9bedcf69 --- /dev/null +++ b/tests/untried/pos/t3374.scala @@ -0,0 +1,6 @@ +trait Parent { + type Test[A, H[B <: A]] +} +trait Sub extends Parent { + type Test[AS, HS[B <: AS]] = AS +} diff --git a/tests/untried/pos/t3384.scala b/tests/untried/pos/t3384.scala new file mode 100644 index 000000000..4d4a81d69 --- /dev/null +++ b/tests/untried/pos/t3384.scala @@ -0,0 +1,14 @@ +package test + +package p { + class A(a: String = "") +} + +package object po { + type A = p.A +} + +import po._ +class C { + val a = new A() //p.A.init$default$1) +} diff --git a/tests/untried/pos/t3404/Base.java b/tests/untried/pos/t3404/Base.java new file mode 100644 index 000000000..c5df18cc9 --- /dev/null +++ b/tests/untried/pos/t3404/Base.java @@ -0,0 +1,3 @@ +abstract class Base { + abstract Class foo(Object o); +}
\ No newline at end of file diff --git a/tests/untried/pos/t3404/Derived.scala b/tests/untried/pos/t3404/Derived.scala new file mode 100644 index 000000000..b1a6c6b19 --- /dev/null +++ b/tests/untried/pos/t3404/Derived.scala @@ -0,0 +1,3 @@ +class Derived extends Base { + def foo(a: AnyRef) = classOf[String] +} diff --git a/tests/untried/pos/t3411.scala b/tests/untried/pos/t3411.scala new file mode 100644 index 000000000..6d46be4e4 --- /dev/null +++ b/tests/untried/pos/t3411.scala @@ -0,0 +1,8 @@ +object A { + def g(c: PartialFunction[Any,Unit]): Unit = {} + + def f: Unit = { + lazy val x = 0 + g { case `x` => } + } +} diff --git a/tests/untried/pos/t3419/B_1.scala b/tests/untried/pos/t3419/B_1.scala new file mode 100644 index 000000000..f11701a86 --- /dev/null +++ b/tests/untried/pos/t3419/B_1.scala @@ -0,0 +1,3 @@ +trait T[A,B] { + type X[a <: A, b <: B] <: B +} diff --git a/tests/untried/pos/t3419/C_2.scala b/tests/untried/pos/t3419/C_2.scala new file mode 100644 index 000000000..880c2838c --- /dev/null +++ b/tests/untried/pos/t3419/C_2.scala @@ -0,0 +1,3 @@ +object F { + type S = T[Any,Int] {type X[N <: Int, Acc <: Int] = Acc} +} diff --git a/tests/untried/pos/t3420.flags b/tests/untried/pos/t3420.flags new file mode 100644 index 000000000..ea03113c6 --- /dev/null +++ b/tests/untried/pos/t3420.flags @@ -0,0 +1 @@ +-optimise -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t3420.scala b/tests/untried/pos/t3420.scala new file mode 100644 index 000000000..0fc56ed67 --- /dev/null +++ b/tests/untried/pos/t3420.scala @@ -0,0 +1,5 @@ +class C { + val cv = Map[Int, Int](1 -> 2) + lazy val cl = Map[Int, Int](1 -> 2) + def cd = Map[Int, Int](1 -> 2) +} diff --git a/tests/untried/pos/t3429/A.scala b/tests/untried/pos/t3429/A.scala new file mode 100644 index 000000000..ea89af168 --- /dev/null +++ b/tests/untried/pos/t3429/A.scala @@ -0,0 +1,12 @@ +class A { + @Test(exc = classOf[Exception]) + def myTestMethod = 0 +} +// rytz@chara:~/scala/trunk/sandbox$ javac Test.java +// rytz@chara:~/scala/trunk/sandbox$ ../build/pack/bin/scalac A.scala +// A.scala:2: error: type mismatch; +// found : java.lang.Class[Exception](classOf[java.lang.Exception]) +// required: java.lang.Class +// @Test(exc = classOf[Exception]) +// ^ +// one error found diff --git a/tests/untried/pos/t3429/Test.java b/tests/untried/pos/t3429/Test.java new file mode 100644 index 000000000..e7c57c90c --- /dev/null +++ b/tests/untried/pos/t3429/Test.java @@ -0,0 +1,3 @@ +public @interface Test { + public Class exc() default Exception.class; +}
\ No newline at end of file diff --git a/tests/untried/pos/t3430.flags b/tests/untried/pos/t3430.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/untried/pos/t3430.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/untried/pos/t3430.scala b/tests/untried/pos/t3430.scala new file mode 100644 index 000000000..f86d776bd --- /dev/null +++ b/tests/untried/pos/t3430.scala @@ -0,0 +1,13 @@ +// package com.example + +object A { + def f1(f: String => Boolean) = f("a") + + def f2(): Boolean = + f1 { s1 => + f1 { s2 => + while (true) { } + true + } + } +} diff --git a/tests/untried/pos/t344.scala b/tests/untried/pos/t344.scala new file mode 100644 index 000000000..449a763af --- /dev/null +++ b/tests/untried/pos/t344.scala @@ -0,0 +1,12 @@ +object Bug { + class A; + case class A1() extends A; + case class A2() extends A; + def f: A = + if (true) + A1() + else { + val a = if (true) A1() else A2(); + a + }; +} diff --git a/tests/untried/pos/t3440.scala b/tests/untried/pos/t3440.scala new file mode 100644 index 000000000..0e7ca6b70 --- /dev/null +++ b/tests/untried/pos/t3440.scala @@ -0,0 +1,18 @@ +object test { + abstract class SampleFormat1 { + def readerFactory: Any + } + + case object Int8 extends SampleFormat1 { + def readerFactory = sys.error("") + } + case object Int16 extends SampleFormat1 { + def readerFactory = sys.error("") + } + + (new {}: Any) match { + case 8 => Int8 + case 16 => Int16 + case _ => sys.error("") + } +} diff --git a/tests/untried/pos/t3452f.scala b/tests/untried/pos/t3452f.scala new file mode 100644 index 000000000..efe25a62f --- /dev/null +++ b/tests/untried/pos/t3452f.scala @@ -0,0 +1,10 @@ +class Base[Coll] { + trait Transformed[S] { + lazy val underlying: Coll = ??? + } +} + +class Derived extends Base[String] { + class C extends Transformed[Any] +} + diff --git a/tests/untried/pos/t3477.scala b/tests/untried/pos/t3477.scala new file mode 100644 index 000000000..6a94baa6c --- /dev/null +++ b/tests/untried/pos/t3477.scala @@ -0,0 +1,7 @@ +class J3 { + def f[K, K1 >: K, V](x: Map[K1, V]): Map[K, V] = sys.error("") +} + +object Test { + (new J3).f(Map[Int, Int]()) +} diff --git a/tests/untried/pos/t3480.scala b/tests/untried/pos/t3480.scala new file mode 100644 index 000000000..830365170 --- /dev/null +++ b/tests/untried/pos/t3480.scala @@ -0,0 +1,4 @@ +object Test { + val List(_*) = List(1) + val Array( who, what @ _* ) = "Eclipse plugin cannot not handle this" split (" ") +} diff --git a/tests/untried/pos/t3486/JTest.java b/tests/untried/pos/t3486/JTest.java new file mode 100644 index 000000000..0bf388b72 --- /dev/null +++ b/tests/untried/pos/t3486/JTest.java @@ -0,0 +1,3 @@ +public class JTest<A> extends T2<A> { + public A m( A a ) { return a; } +}
\ No newline at end of file diff --git a/tests/untried/pos/t3486/test.scala b/tests/untried/pos/t3486/test.scala new file mode 100644 index 000000000..d4534e29f --- /dev/null +++ b/tests/untried/pos/t3486/test.scala @@ -0,0 +1,6 @@ +trait Test[A] { + def m( a: A ): A + def specified(a:A):A = a +} + +abstract class T2[A] extends Test[A] diff --git a/tests/untried/pos/t348plus.scala b/tests/untried/pos/t348plus.scala new file mode 100644 index 000000000..e61f7346f --- /dev/null +++ b/tests/untried/pos/t348plus.scala @@ -0,0 +1,24 @@ +// bug #348 + +trait Foo { + type bar <: Bar; + abstract class Bar; + case class Baz(r:bar) extends Bar; + case object NoBar extends Bar; +} +object Test extends App { + object ConcreteFooBar extends Foo { // if moved to toplevel, it works + type bar = Bar; + } + def foo = { + import ConcreteFooBar._ ; + Baz( NoBar ) + } +} + +// bug #367 + +object Bla { + def foo(): Unit = (return null).equals(null); +} + diff --git a/tests/untried/pos/t3494.scala b/tests/untried/pos/t3494.scala new file mode 100644 index 000000000..dd54b0f82 --- /dev/null +++ b/tests/untried/pos/t3494.scala @@ -0,0 +1,7 @@ +object Test { + def f[T](xs: T*) = () + + val x = "abc" + + f[x.type](x) +} diff --git a/tests/untried/pos/t3495.flags b/tests/untried/pos/t3495.flags new file mode 100644 index 000000000..08de722af --- /dev/null +++ b/tests/untried/pos/t3495.flags @@ -0,0 +1 @@ +-Dsoot.class.path=bin:. diff --git a/tests/untried/pos/t3495.scala b/tests/untried/pos/t3495.scala new file mode 100644 index 000000000..8d5dff430 --- /dev/null +++ b/tests/untried/pos/t3495.scala @@ -0,0 +1,2 @@ +class Foo { } + diff --git a/tests/untried/pos/t3498-new.scala b/tests/untried/pos/t3498-new.scala new file mode 100644 index 000000000..ccf2af9de --- /dev/null +++ b/tests/untried/pos/t3498-new.scala @@ -0,0 +1,17 @@ +import scala.reflect.{ClassTag, classTag} + +abstract class A[T, @specialized(scala.Int) U : ClassTag] { + def f(state: T): Array[U] +} + +abstract class B extends A[ Array[Byte], Int ] { + type T = Array[Byte] + type U = Int + + val N = 0 + + def f(state: T): Array[U] = + { + new Array[U](N + state(N)) + } +} diff --git a/tests/untried/pos/t3498-old.scala b/tests/untried/pos/t3498-old.scala new file mode 100644 index 000000000..118a8d849 --- /dev/null +++ b/tests/untried/pos/t3498-old.scala @@ -0,0 +1,15 @@ +abstract class A[T, @specialized(scala.Int) U : Manifest] { + def f(state: T): Array[U] +} + +abstract class B extends A[ Array[Byte], Int ] { + type T = Array[Byte] + type U = Int + + val N = 0 + + def f(state: T): Array[U] = + { + new Array[U](N + state(N)) + } +} diff --git a/tests/untried/pos/t3521/DoubleValue.java b/tests/untried/pos/t3521/DoubleValue.java new file mode 100644 index 000000000..e8c093890 --- /dev/null +++ b/tests/untried/pos/t3521/DoubleValue.java @@ -0,0 +1,7 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface DoubleValue { + double value(); +}
\ No newline at end of file diff --git a/tests/untried/pos/t3521/a.scala b/tests/untried/pos/t3521/a.scala new file mode 100644 index 000000000..e9619b76e --- /dev/null +++ b/tests/untried/pos/t3521/a.scala @@ -0,0 +1,4 @@ +class Test { + @DoubleValue(-0.05) + var a = 0 +} diff --git a/tests/untried/pos/t3528.scala b/tests/untried/pos/t3528.scala new file mode 100644 index 000000000..ff49b3e92 --- /dev/null +++ b/tests/untried/pos/t3528.scala @@ -0,0 +1,8 @@ +class A { + // 3528 - not fixed + // def f1 = List(List(1), Stream(1)) + // 3528 comments + def f2 = List(Set(1,2,3), List(1,2,3)) + // 2322 + def f3 = List(null: Range, null: List[Int]) +} diff --git a/tests/untried/pos/t3534.scala b/tests/untried/pos/t3534.scala new file mode 100644 index 000000000..44d3aafb6 --- /dev/null +++ b/tests/untried/pos/t3534.scala @@ -0,0 +1,6 @@ +object Test { + List[Option[Int]]() match { + case None :: bb :: cc => () + case x => throw new Exception(x.filter(_.isDefined).mkString) + } + } diff --git a/tests/untried/pos/t3560.scala b/tests/untried/pos/t3560.scala new file mode 100644 index 000000000..3cde9710d --- /dev/null +++ b/tests/untried/pos/t3560.scala @@ -0,0 +1,2 @@ +trait Foo[X] { def foo : Map[String,Foo[X]] } +object T3560 { def f[T]() : Foo[T] = new Foo[T] { var foo = Map[String,Foo[T]]() } } diff --git a/tests/untried/pos/t3567/Foo.scala b/tests/untried/pos/t3567/Foo.scala new file mode 100644 index 000000000..4f83ba9f4 --- /dev/null +++ b/tests/untried/pos/t3567/Foo.scala @@ -0,0 +1,3 @@ +class Foo { + val foo = Outer.f() +} diff --git a/tests/untried/pos/t3567/Outer.java b/tests/untried/pos/t3567/Outer.java new file mode 100644 index 000000000..f1f124b80 --- /dev/null +++ b/tests/untried/pos/t3567/Outer.java @@ -0,0 +1,7 @@ +class Outer<T> { + class Inner { + } + static Outer<Integer>.Inner f() { + return null; + } +} diff --git a/tests/untried/pos/t3568.scala b/tests/untried/pos/t3568.scala new file mode 100755 index 000000000..50f0cdb2e --- /dev/null +++ b/tests/untried/pos/t3568.scala @@ -0,0 +1,46 @@ +import scala.annotation._ +import scala.annotation.unchecked._ +import scala.collection._ + + +package object buffer { + val broken = new ArrayVec2() // commenting out this line causes the file to compile. + + val works = Class.forName("buffer.ArrayVec2").newInstance().asInstanceOf[ArrayVec2] +} + +package buffer { + object Main { + // ArrayVec2 can be compiled, instantiated and used. + def main(args: Array[String]): Unit = { println(works) } + } + + trait ElemType { type Element; type Component <: ElemType } + trait Float1 extends ElemType { type Element = Float; type Component = Float1} + class Vec2 extends ElemType { type Element = Vec2; type Component = Float1 } + + abstract class BaseSeq[T <: ElemType, E] + extends IndexedSeq[E] with IndexedSeqOptimized[E, IndexedSeq[E]] { + def length = 1 + def apply(i: Int) :E + } + + abstract class GenericSeq[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataArray[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataView[T <: ElemType] extends BaseSeq[T, T#Element] + abstract class BaseFloat1 extends BaseSeq[Float1, Float] + + class ArrayFloat1 extends BaseFloat1 with DataArray[Float1] { + def apply(i: Int) :Float = 0f + } + + class ViewFloat1 extends BaseFloat1 with DataView[Float1] { + def apply(i: Int) :Float = 0f + } + + class ArrayVec2(val backingSeq: ArrayFloat1) + extends GenericSeq[Vec2] with DataArray[Vec2] { + def this() = this(new ArrayFloat1) + def apply(i: Int) :Vec2 = null + } +} diff --git a/tests/untried/pos/t3570.scala b/tests/untried/pos/t3570.scala new file mode 100644 index 000000000..0e20905af --- /dev/null +++ b/tests/untried/pos/t3570.scala @@ -0,0 +1,7 @@ +class test { + object Break extends Throwable + def break = throw Break + def block(x: => Unit): Unit = { + try { x } catch { case e: Break.type => } + } +} diff --git a/tests/untried/pos/t3577.scala b/tests/untried/pos/t3577.scala new file mode 100644 index 000000000..80a280f67 --- /dev/null +++ b/tests/untried/pos/t3577.scala @@ -0,0 +1,29 @@ +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 @ _*) => { + 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/untried/pos/t3578.scala b/tests/untried/pos/t3578.scala new file mode 100644 index 000000000..d98411820 --- /dev/null +++ b/tests/untried/pos/t3578.scala @@ -0,0 +1,30 @@ +object Test { + sealed abstract class JValue { + def ++(other: JValue) = { + def append(value1: JValue, value2: JValue): JValue = (value1, value2) match { + case (JNothing, x) => x + case (x, JNothing) => x + case (JObject(xs), x: JField) => JObject(xs ::: List(x)) + case (x: JField, JObject(xs)) => JObject(x :: xs) + case (JArray(xs), JArray(ys)) => JArray(xs ::: ys) + case (JArray(xs), v: JValue) => JArray(xs ::: List(v)) + case (v: JValue, JArray(xs)) => JArray(v :: xs) + case (f1: JField, f2: JField) => JObject(f1 :: f2 :: Nil) + case (JField(n, v1), v2: JValue) => JField(n, append(v1, v2)) + case (x, y) => JArray(x :: y :: Nil) + } + append(this, other) + } + } + + case object JNothing extends JValue + case object JNull extends JValue + case class JString(s: String) extends JValue + case class JDouble(num: Double) extends JValue + case class JInt(num: BigInt) extends JValue + case class JBool(value: Boolean) extends JValue + case class JField(name: String, value: JValue) extends JValue + case class JObject(obj: List[JField]) extends JValue + case class JArray(arr: List[JValue]) extends JValue +} + diff --git a/tests/untried/pos/t3582.scala b/tests/untried/pos/t3582.scala new file mode 100644 index 000000000..d13d69775 --- /dev/null +++ b/tests/untried/pos/t3582.scala @@ -0,0 +1,12 @@ +trait C[A] +object Test { + def ImplicitParamCA[CC[A], A](implicit ev: C[A]): Unit = {implicitly[C[A]]} // must use this exact syntax... + // error: could not find implicit value for parameter e: C[A] +} +// [[syntax trees at end of typer]] +// abstract trait C#5[A#9116 >: Nothing#5832 <: Any#52] extends scala#33.AnyRef#2780; +// final object Test#15 extends java.lang.Object#2485 with ScalaObject#1913 { +// def ImplicitParamCA#9123[CC#9124[A#10858 >: Nothing#5832 <: Any#52] >: [A#10858]Nothing#5832 <: [A#10858]Any#52, +// A#9125 >: Nothing#5832 <: Any#52](implicit ev#10856: C#5[A#9127]): Unit#3818 +// = scala#34.this.Predef#1683.implicitly#8816[C#5[A#10858]]() +// } diff --git a/tests/untried/pos/t3582b.scala b/tests/untried/pos/t3582b.scala new file mode 100644 index 000000000..f7778148e --- /dev/null +++ b/tests/untried/pos/t3582b.scala @@ -0,0 +1,5 @@ +object ParamScoping { + // scoping worked fine in the result type, but was wrong in body + // reason: typedTypeDef needs new context, which was set up by typed1 but not by typedDefDef and typedClassDef + def noOverlapFOwithHO[T, G[T]]: G[T] = null.asInstanceOf[G[T]] +} diff --git a/tests/untried/pos/t359.scala b/tests/untried/pos/t359.scala new file mode 100644 index 000000000..11233c3ba --- /dev/null +++ b/tests/untried/pos/t359.scala @@ -0,0 +1,28 @@ +object Bug359 { + class C; + def f1(xs: List[C]): C = { + g { + xs => + if (false) { + f1(xs) + } else { + val a: C = null; + val b: C = null; + if (xs.isEmpty) a else b + } + } + } + def f2(xs: List[C]): C = { + g { + xs => + if (false) { + val a: C = null; + val b: C = null; + if (xs.isEmpty) a else b + } else { + f2(xs); + } + } + } + private def g(op: List[C] => C): C = null; +} diff --git a/tests/untried/pos/t360.scala b/tests/untried/pos/t360.scala new file mode 100644 index 000000000..f3716d4f9 --- /dev/null +++ b/tests/untried/pos/t360.scala @@ -0,0 +1,9 @@ +abstract class Bug360A { self: Bug360C => + def f: String = "hello"; +} +trait Bug360B { self: Bug360C => + object d { + Console.println(f); + } +} +abstract class Bug360C extends Bug360A with Bug360B; diff --git a/tests/untried/pos/t361.scala b/tests/untried/pos/t361.scala new file mode 100644 index 000000000..1d19ecb52 --- /dev/null +++ b/tests/untried/pos/t361.scala @@ -0,0 +1,16 @@ +class Bug361Global extends Bug361Trees + +abstract class Bug361Trees { self: Bug361Global => + + abstract class Tree { + var pos: Int = 0 + } + + object posAssigner { + def atPos[T <: Tree](pos: Int, tree: T): T = { + tree.pos = pos; tree + } + } + + def atPos[T <: Tree](pos: Int)(tree: T): T = posAssigner.atPos(pos, tree) +} diff --git a/tests/untried/pos/t3612.scala b/tests/untried/pos/t3612.scala new file mode 100644 index 000000000..a9d063998 --- /dev/null +++ b/tests/untried/pos/t3612.scala @@ -0,0 +1,6 @@ +trait C + +class Outer { + object O0 extends C {} + object O extends C { self => } +} diff --git a/tests/untried/pos/t3622/AsyncTask.java b/tests/untried/pos/t3622/AsyncTask.java new file mode 100644 index 000000000..cfcea3fe1 --- /dev/null +++ b/tests/untried/pos/t3622/AsyncTask.java @@ -0,0 +1,5 @@ +package test; + +public abstract class AsyncTask<Params, Progress, Result> { + protected abstract Result doInBackground(Params... args); +}
\ No newline at end of file diff --git a/tests/untried/pos/t3622/MyAsyncTask.java b/tests/untried/pos/t3622/MyAsyncTask.java new file mode 100644 index 000000000..9ef494705 --- /dev/null +++ b/tests/untried/pos/t3622/MyAsyncTask.java @@ -0,0 +1,9 @@ +package test; + +public abstract class MyAsyncTask extends AsyncTask<String, String, String> { + protected abstract String doInBackground1(String[] args); + @Override + protected String doInBackground(String... args) { + return doInBackground1(new String[]{"dummy"}); + } +}
\ No newline at end of file diff --git a/tests/untried/pos/t3622/Test.scala b/tests/untried/pos/t3622/Test.scala new file mode 100644 index 000000000..d18953bba --- /dev/null +++ b/tests/untried/pos/t3622/Test.scala @@ -0,0 +1,5 @@ +package test + +class Test extends MyAsyncTask { + protected[test] def doInBackground1(args: Array[String]): String = "" +} diff --git a/tests/untried/pos/t3631.scala b/tests/untried/pos/t3631.scala new file mode 100644 index 000000000..e72374130 --- /dev/null +++ b/tests/untried/pos/t3631.scala @@ -0,0 +1,3 @@ +case class X22(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) { } + +case class X23(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int) { } diff --git a/tests/untried/pos/t3636.scala b/tests/untried/pos/t3636.scala new file mode 100644 index 000000000..cd224a32f --- /dev/null +++ b/tests/untried/pos/t3636.scala @@ -0,0 +1,49 @@ +class CTxnLocal[ T ] { + def set( x: T )( implicit t: Txn ): Unit = {} + def get( implicit t: Txn ) : T = null.asInstanceOf[ T ] + def initialValue( t: Txn ) : T = null.asInstanceOf[ T ] +} + +trait Txn + +trait ProcTxn { + def ccstm: Txn +} + +trait TxnLocal[ @specialized T ] { + def apply()( implicit tx: ProcTxn ) : T + def set( v: T )( implicit tx: ProcTxn ) : Unit + def swap( v: T )( implicit tx: ProcTxn ) : T + def transform( f: T => T )( implicit tx: ProcTxn ) : Unit +} + +object TxnLocal { + def apply[ @specialized T ] : TxnLocal[ T ] = new Impl( new CTxnLocal[ T ]) + def apply[ @specialized T ]( initValue: => T ) : TxnLocal[ T ] = new Impl( new CTxnLocal[ T ] { + override def initialValue( tx: Txn ): T = initValue + }) + + private class Impl[ T ]( c: CTxnLocal[ T ]) extends TxnLocal[ T ] { + def apply()( implicit tx: ProcTxn ) : T = c.get( tx.ccstm ) + def set( v: T )( implicit tx: ProcTxn ) : Unit = c.set( v )( tx.ccstm ) + def swap( v: T )( implicit tx: ProcTxn ) : T = { + // currently not implemented in CTxnLocal + val oldV = apply + set( v ) + oldV + } + def transform( f: T => T )( implicit tx: ProcTxn ): Unit = { + set( f( apply )) + } + } +} + + +object Transition { + private val currentRef = TxnLocal[ Transition ]( Instant ) + def current( implicit tx: ProcTxn ) : Transition = currentRef() +} + +sealed abstract class Transition +case object Instant extends Transition + diff --git a/tests/untried/pos/t3642/Tuppel_1.java b/tests/untried/pos/t3642/Tuppel_1.java new file mode 100644 index 000000000..07c715ee9 --- /dev/null +++ b/tests/untried/pos/t3642/Tuppel_1.java @@ -0,0 +1,7 @@ +public class Tuppel_1<T> { + private Tuppel_1(){} + + public static <A> Tuppel_1<A> get() { + return new Tuppel_1<A>() {}; + } +}
\ No newline at end of file diff --git a/tests/untried/pos/t3642/t3642_2.scala b/tests/untried/pos/t3642/t3642_2.scala new file mode 100644 index 000000000..954795fe2 --- /dev/null +++ b/tests/untried/pos/t3642/t3642_2.scala @@ -0,0 +1,3 @@ +object T { + Tuppel_1.get +} diff --git a/tests/untried/pos/t3670.scala b/tests/untried/pos/t3670.scala new file mode 100644 index 000000000..ec4fbe5b4 --- /dev/null +++ b/tests/untried/pos/t3670.scala @@ -0,0 +1,43 @@ +class A { + val n = { + val z = { + lazy val bb = 1 + bb + } + val a = { + lazy val cc = 2 + cc + } + lazy val b = { + lazy val dd = 3 + dd + } + z + } +} + +class B { + locally { + lazy val ms = "as" + ms + } +} + +class C { + val things = List("things") + if(things.size < 100) { + lazy val msg = "foo" + msg + } +} + +class D { + val things = List("things") + if(things.size < 100) { + if (things.size > 10) { + lazy val msg = "foo" + msg + } + } +} + diff --git a/tests/untried/pos/t3671.scala b/tests/untried/pos/t3671.scala new file mode 100644 index 000000000..afb3a539d --- /dev/null +++ b/tests/untried/pos/t3671.scala @@ -0,0 +1,7 @@ +object Crash { + def crash(value: Int): Unit = + value match { + case java.lang.Integer.MAX_VALUE => println("MAX_VALUE") + case java.lang.Integer.MIN_VALUE => println("MIN_VALUE") + } +} diff --git a/tests/untried/pos/t3672.scala b/tests/untried/pos/t3672.scala new file mode 100644 index 000000000..b2752ce21 --- /dev/null +++ b/tests/untried/pos/t3672.scala @@ -0,0 +1,4 @@ +object Test { + def foo(f: Int => Int) = () ; foo { implicit x : Int => x + 1 } + def bar(f: Int => Int) = () ; foo { x : Int => x + 1 } +} diff --git a/tests/untried/pos/t3676.scala b/tests/untried/pos/t3676.scala new file mode 100644 index 000000000..60c0ceaec --- /dev/null +++ b/tests/untried/pos/t3676.scala @@ -0,0 +1,5 @@ +trait SeqLike[+Repr] +trait Seq extends SeqLike[Seq] + +trait MySeq extends Seq with SeqLike[MySub] +trait MySub extends MySeq diff --git a/tests/untried/pos/t3688.scala b/tests/untried/pos/t3688.scala new file mode 100644 index 000000000..bf7983081 --- /dev/null +++ b/tests/untried/pos/t3688.scala @@ -0,0 +1,14 @@ +import collection.mutable +import collection.JavaConversions._ +import java.{util => ju} + +object Test { + + implicitly[mutable.Map[Int, String] => ju.Dictionary[Int, String]] + +} + +object Test2 { + def m[P <% ju.List[Int]](l: P) = 1 + m(List(1)) // bug: should compile +} diff --git a/tests/untried/pos/t372.scala b/tests/untried/pos/t372.scala new file mode 100644 index 000000000..9ce5b9ab7 --- /dev/null +++ b/tests/untried/pos/t372.scala @@ -0,0 +1,2 @@ +class Bug372Names; +class Bug372Symbols { self: Bug372Symbols with Bug372Names => } diff --git a/tests/untried/pos/t3731.scala b/tests/untried/pos/t3731.scala new file mode 100644 index 000000000..7a3cbec0f --- /dev/null +++ b/tests/untried/pos/t3731.scala @@ -0,0 +1,13 @@ +object Test{ + trait ZW[S]{type T} + def ZipWith[S, M <: ZW[S]]: M#T = sys.error("ZW") + + // meh must be parameterised to force an asSeenFrom that + // duplicates the refinement in the TR's pre without updating its sym + def meh[A] = ZipWith[A, ZW[A]{type T=Stream[A]}] + + meh[Int]: Stream[Int] +} +// debugging output in coevolveSym should say: +// coevolved type T#11029 : Stream#3234[A#9228] to type T#11277 : Stream#3234[A#9227] +// with Test.ZW#9219[A#9228]{type T#11029 = Stream#3234[A#9228]} -> Test.ZW#9219[A#9227]{type T#11277 = Stream#3234[A#9227]} diff --git a/tests/untried/pos/t374.scala b/tests/untried/pos/t374.scala new file mode 100644 index 000000000..fb9c0b402 --- /dev/null +++ b/tests/untried/pos/t374.scala @@ -0,0 +1,21 @@ +object tokens extends Enumeration { + type Token = Value; + val BAD = Value("<bad>"); + val IDENT = Value("ident"); + val NAME = Value("name"); +} + +object test extends AnyRef with App { + import tokens._; + + val reserved = new scala.collection.mutable.HashMap[String, Token](); + + if (true) { + reserved.get("a") match { + case None => IDENT + case Some(tk) => tk + } + } + else + BAD +} diff --git a/tests/untried/pos/t3774.scala b/tests/untried/pos/t3774.scala new file mode 100644 index 000000000..2869925b0 --- /dev/null +++ b/tests/untried/pos/t3774.scala @@ -0,0 +1,5 @@ +// This used to hang the lub process. Now it rejects the file. This is still not correct, +// but we can solve this only after a redesign of lub a la dot. +object Hang { + Map[(Int,Int),List[Int]]() ++ (for(x <- 0 to 1 ; y <- 0 to 1) yield {(x,y)-> (0 to 1)}) +} diff --git a/tests/untried/pos/t3777.scala b/tests/untried/pos/t3777.scala new file mode 100644 index 000000000..165eeebfd --- /dev/null +++ b/tests/untried/pos/t3777.scala @@ -0,0 +1,7 @@ +object Test { + type Point = Map[Symbol, String] + type Points = IndexedSeq[Point] + + def makePoints2: Points = IndexedSeq[Point]() + val spoints2 = util.Random.shuffle(makePoints2) +} diff --git a/tests/untried/pos/t3792.scala b/tests/untried/pos/t3792.scala new file mode 100644 index 000000000..364d46317 --- /dev/null +++ b/tests/untried/pos/t3792.scala @@ -0,0 +1,4 @@ +object Test { + type Hui = Nil.type + val n: Hui = Nil +} diff --git a/tests/untried/pos/t3800.scala b/tests/untried/pos/t3800.scala new file mode 100644 index 000000000..096502174 --- /dev/null +++ b/tests/untried/pos/t3800.scala @@ -0,0 +1,6 @@ +class meh extends annotation.StaticAnnotation + +class ALike[C] +abstract class AFactory[CC[x] <: ALike[CC[x]]] { + def aCompanion : AFactory[CC @meh] +} diff --git a/tests/untried/pos/t3808.scala b/tests/untried/pos/t3808.scala new file mode 100644 index 000000000..8162fce72 --- /dev/null +++ b/tests/untried/pos/t3808.scala @@ -0,0 +1,11 @@ +object Test { + def meh: Unit = { + trait TC[I] + implicit val tci = new TC[Int]{} + + def baz[J : TC] : String = "meh" + + baz + // () // commenting or uncommenting this line should not affect compilation (visibly) + } +} diff --git a/tests/untried/pos/t3833.scala b/tests/untried/pos/t3833.scala new file mode 100644 index 000000000..2df658df1 --- /dev/null +++ b/tests/untried/pos/t3833.scala @@ -0,0 +1,26 @@ +object Main { + def mkArray[T <: A](atype: Int) :T#AType = { + (atype match { + case 1 => + new Array[Int](10) + // Decompiled code: return (Object[])new int[10]; + case 2 => + new Array[Float](10) + }).asInstanceOf[T#AType] + } + + def main(args: Array[String]): Unit = { + println(mkArray[I](1)) + //java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object; + } +} + +trait A { + type AType <: AnyRef +} +trait I extends A { + type AType = Array[Int] +} +trait F extends A { + type AType = Array[Float] +} diff --git a/tests/untried/pos/t3836.scala b/tests/untried/pos/t3836.scala new file mode 100644 index 000000000..840f17116 --- /dev/null +++ b/tests/untried/pos/t3836.scala @@ -0,0 +1,14 @@ +package foo + +package object bar { + type IOException = java.io.IOException +} + +package baz { + import java.io._ + import foo.bar._ + + object Test { + def f = new IOException + } +} diff --git a/tests/untried/pos/t3837.scala b/tests/untried/pos/t3837.scala new file mode 100644 index 000000000..bcaf63cc8 --- /dev/null +++ b/tests/untried/pos/t3837.scala @@ -0,0 +1,10 @@ +class BipClass { } +trait BipTrait { + self: BipClass => + + private[this] def foo() = 5 + def bar() = this.foo() +} +// error: value foo is not a member of BipTrait with BipClass +// def bar() = this.foo() +// ^ diff --git a/tests/untried/pos/t3856.scala b/tests/untried/pos/t3856.scala new file mode 100644 index 000000000..132c95c5e --- /dev/null +++ b/tests/untried/pos/t3856.scala @@ -0,0 +1,9 @@ +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 } + println(x) +} diff --git a/tests/untried/pos/t3859.scala b/tests/untried/pos/t3859.scala new file mode 100644 index 000000000..992207301 --- /dev/null +++ b/tests/untried/pos/t3859.scala @@ -0,0 +1,4 @@ +class Test { + def foo: Unit = bar(Array(): _*) + def bar(values: AnyRef*): Unit = () +} diff --git a/tests/untried/pos/t3861.scala b/tests/untried/pos/t3861.scala new file mode 100644 index 000000000..5ebe02520 --- /dev/null +++ b/tests/untried/pos/t3861.scala @@ -0,0 +1,2 @@ +trait Y +abstract class X(x: Int) { self: Y => x } diff --git a/tests/untried/pos/t3862.scala b/tests/untried/pos/t3862.scala new file mode 100644 index 000000000..8ca4a0586 --- /dev/null +++ b/tests/untried/pos/t3862.scala @@ -0,0 +1,8 @@ +object OverloadingShapeType { + // comment out this, and the other alternative is chosen. + def blerg(f: String): Unit = {} + + def blerg[M[X], T](l: M[T]): Unit = {} + + blerg(List(1)) // error: type mismatch; found : List[Int] required: String +} diff --git a/tests/untried/pos/t3864/scalaz_2.scala b/tests/untried/pos/t3864/scalaz_2.scala new file mode 100644 index 000000000..a7a50de2c --- /dev/null +++ b/tests/untried/pos/t3864/scalaz_2.scala @@ -0,0 +1 @@ +object Scalaz extends Tuples diff --git a/tests/untried/pos/t3864/tuples_1.scala b/tests/untried/pos/t3864/tuples_1.scala new file mode 100644 index 000000000..5e97f8452 --- /dev/null +++ b/tests/untried/pos/t3864/tuples_1.scala @@ -0,0 +1,78 @@ +trait EnrichedType[X] { + val value: X +} + +trait Tuples { + + +trait Tuple15W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] extends EnrichedType[Tuple15[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple15[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15)) +} + +implicit def ToTuple15W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)): Tuple15W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] = new { val value = t } with Tuple15W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] + + +trait Tuple16W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] extends EnrichedType[Tuple16[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple16[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16)) +} + +implicit def ToTuple16W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)): Tuple16W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] = new { val value = t } with Tuple16W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] + + +trait Tuple17W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] extends EnrichedType[Tuple17[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple17[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17)) +} + +implicit def ToTuple17W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)): Tuple17W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] = new { val value = t } with Tuple17W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] + + +trait Tuple18W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] extends EnrichedType[Tuple18[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple18[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _, _18: (R => RR) = identity[R] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17), _18(value._18)) +} + +implicit def ToTuple18W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)): Tuple18W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] = new { val value = t } with Tuple18W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] + + +trait Tuple19W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] extends EnrichedType[Tuple19[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple19[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _, _18: (R => RR) = identity[R] _, _19: (S => SS) = identity[S] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17), _18(value._18), _19(value._19)) +} + +implicit def ToTuple19W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)): Tuple19W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] = new { val value = t } with Tuple19W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] + + +trait Tuple20W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] extends EnrichedType[Tuple20[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple20[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _, _18: (R => RR) = identity[R] _, _19: (S => SS) = identity[S] _, _20: (T => TT) = identity[T] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17), _18(value._18), _19(value._19), _20(value._20)) +} + +implicit def ToTuple20W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)): Tuple20W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] = new { val value = t } with Tuple20W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] + + +trait Tuple21W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] extends EnrichedType[Tuple21[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple21[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT, UU](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _, _18: (R => RR) = identity[R] _, _19: (S => SS) = identity[S] _, _20: (T => TT) = identity[T] _, _21: (U => UU) = identity[U] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT, UU) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17), _18(value._18), _19(value._19), _20(value._20), _21(value._21)) +} + +implicit def ToTuple21W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)): Tuple21W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] = new { val value = t } with Tuple21W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] + + +trait Tuple22W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] extends EnrichedType[Tuple22[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V]] { + def fold[Z](f: => (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V) => Z): Z = {import value._; f(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22)} + def toIndexedSeq[Z](implicit ev: value.type <:< Tuple22[Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z, Z]): IndexedSeq[Z] = {val zs = ev(value); import zs._; IndexedSeq(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22)} + def mapElements[AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT, UU, VV](_1: (A => AA) = identity[A] _, _2: (B => BB) = identity[B] _, _3: (C => CC) = identity[C] _, _4: (D => DD) = identity[D] _, _5: (E => EE) = identity[E] _, _6: (F => FF) = identity[F] _, _7: (G => GG) = identity[G] _, _8: (H => HH) = identity[H] _, _9: (I => II) = identity[I] _, _10: (J => JJ) = identity[J] _, _11: (K => KK) = identity[K] _, _12: (L => LL) = identity[L] _, _13: (M => MM) = identity[M] _, _14: (N => NN) = identity[N] _, _15: (O => OO) = identity[O] _, _16: (P => PP) = identity[P] _, _17: (Q => QQ) = identity[Q] _, _18: (R => RR) = identity[R] _, _19: (S => SS) = identity[S] _, _20: (T => TT) = identity[T] _, _21: (U => UU) = identity[U] _, _22: (V => VV) = identity[V] _): (AA, BB, CC, DD, EE, FF, GG, HH, II, JJ, KK, LL, MM, NN, OO, PP, QQ, RR, SS, TT, UU, VV) = (_1(value._1), _2(value._2), _3(value._3), _4(value._4), _5(value._5), _6(value._6), _7(value._7), _8(value._8), _9(value._9), _10(value._10), _11(value._11), _12(value._12), _13(value._13), _14(value._14), _15(value._15), _16(value._16), _17(value._17), _18(value._18), _19(value._19), _20(value._20), _21(value._21), _22(value._22)) +} + +implicit def ToTuple22W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V](t: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)): Tuple22W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] = new { val value = t } with Tuple22W[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] +} diff --git a/tests/untried/pos/t3866.scala b/tests/untried/pos/t3866.scala new file mode 100644 index 000000000..140732499 --- /dev/null +++ b/tests/untried/pos/t3866.scala @@ -0,0 +1,17 @@ +abstract class ImplicitRepeated { + trait T[+A, +B] + trait X + + def f[N, R <: List[_]](elems: T[N, R]*) // alternative a) + def f[N, R <: List[_]](props: String, elems: T[N, R]*) // alternative b) + + // the following implicit causes "cannot be applied" errors + implicit def xToRight(r: X): T[Nothing, X] = null + implicit def anyToN[N](x: N): T[N, Nothing] = null + + + f("A", 1, 2) // should be implicitly resolved to alternative b) + f( 1, 2 ) // should be implicitly resolved to alternative a) + // ImplicitRepeated.this.f[Int, Nothing]("A", ImplicitRepeated.this.anyToN[Int](1), ImplicitRepeated.this.anyToN[Int](2)); + // ImplicitRepeated.this.f[Int, Nothing](ImplicitRepeated.this.anyToN[Int](1), ImplicitRepeated.this.anyToN[Int](2)) +} diff --git a/tests/untried/pos/t3869.scala b/tests/untried/pos/t3869.scala new file mode 100644 index 000000000..581c11c81 --- /dev/null +++ b/tests/untried/pos/t3869.scala @@ -0,0 +1,10 @@ + +// see ticket #3869 +object Test { + def f: Unit = + try return finally while(true) () + + def main(args: Array[String]): Unit = { + f + } +} diff --git a/tests/untried/pos/t3880.scala b/tests/untried/pos/t3880.scala new file mode 100644 index 000000000..f778eb71a --- /dev/null +++ b/tests/untried/pos/t3880.scala @@ -0,0 +1,16 @@ +abstract class Bar[+B] { +} +abstract class C1[+B] extends Bar[B] { + private[this] def g(x: C1[B]): Unit = () + + // this method is fine: notice that it allows the call to g, + // which requires C1[B], even though we matched on C1[_]. + // (That is good news.) + private[this] def f1(x: Bar[B]): Unit = x match { + case x: C1[_] => g(x) + } + // this one crashes. + private[this] def f2(x: Bar[B]): Unit = x match { + case x: C1[_] => f2(x) + } +} diff --git a/tests/untried/pos/t3883.scala b/tests/untried/pos/t3883.scala new file mode 100644 index 000000000..1b62c0c6d --- /dev/null +++ b/tests/untried/pos/t3883.scala @@ -0,0 +1,15 @@ +// need to test both orders +object A1 { + implicit def i: Equiv[Boolean] = sys.error("") + implicit def div[T, A](implicit f: T => A, eq: Equiv[A]): Equiv[T] = sys.error("") + + implicitly[Equiv[Boolean]] +} + +object A2 { + implicit def div[T, A](implicit f: T => A, eq: Equiv[A]): Equiv[T] = sys.error("") + implicit def i: Equiv[Boolean] = sys.error("") + + implicitly[Equiv[Boolean]] +} + diff --git a/tests/untried/pos/t389.scala b/tests/untried/pos/t389.scala new file mode 100644 index 000000000..535bd4de8 --- /dev/null +++ b/tests/untried/pos/t389.scala @@ -0,0 +1,7 @@ +object Test { + def a = 'a + def b = 'B + def c = '+ + //def d = '`\n` //error: unclosed character literal + def e = '\u0041 +} diff --git a/tests/untried/pos/t3890.scala b/tests/untried/pos/t3890.scala new file mode 100644 index 000000000..0c5f5dfe6 --- /dev/null +++ b/tests/untried/pos/t3890.scala @@ -0,0 +1,4 @@ +object Test { + def g[S, T <: S](s: S)(t: T): Unit = println("") + g("a")("a") // error: inferred type arguments [java.lang.String] do not conform to method g's type parameter bounds [T <: S] +} diff --git a/tests/untried/pos/t3898.scala b/tests/untried/pos/t3898.scala new file mode 100644 index 000000000..ab47bbd87 --- /dev/null +++ b/tests/untried/pos/t3898.scala @@ -0,0 +1,6 @@ +trait Atomic[@specialized(Boolean) T] { + def x: T + + def f(fn: T => T): Boolean = f(fn(x), true) + def f[R](a: T, b: R): R = b +} diff --git a/tests/untried/pos/t3924.scala b/tests/untried/pos/t3924.scala new file mode 100644 index 000000000..b11b67c56 --- /dev/null +++ b/tests/untried/pos/t3924.scala @@ -0,0 +1,6 @@ +object Test { + class Hoe extends Serializable { + def add(a: java.io.Serializable): Unit = println(a) + def someMethod(): Unit = { add(this) } + } +} diff --git a/tests/untried/pos/t3927.scala b/tests/untried/pos/t3927.scala new file mode 100644 index 000000000..5e0d581d4 --- /dev/null +++ b/tests/untried/pos/t3927.scala @@ -0,0 +1,6 @@ +object A { + def x: Unit = { + implicit lazy val e: Equiv[Int] = sys.error("") + implicitly[Equiv[Int]] + } +} diff --git a/tests/untried/pos/t3936/BlockingQueue.java b/tests/untried/pos/t3936/BlockingQueue.java new file mode 100644 index 000000000..b902d4528 --- /dev/null +++ b/tests/untried/pos/t3936/BlockingQueue.java @@ -0,0 +1,3 @@ +package pack; +import java.util.Queue; +public interface BlockingQueue<E> extends Queue<E> { } diff --git a/tests/untried/pos/t3936/Queue.java b/tests/untried/pos/t3936/Queue.java new file mode 100644 index 000000000..25c908760 --- /dev/null +++ b/tests/untried/pos/t3936/Queue.java @@ -0,0 +1,2 @@ +package pack; +public interface Queue { } diff --git a/tests/untried/pos/t3936/Test.scala b/tests/untried/pos/t3936/Test.scala new file mode 100644 index 000000000..c867a05ec --- /dev/null +++ b/tests/untried/pos/t3936/Test.scala @@ -0,0 +1,4 @@ +package pack +trait Test { + val b: BlockingQueue[Nothing] +} diff --git a/tests/untried/pos/t3938/Parent.java b/tests/untried/pos/t3938/Parent.java new file mode 100644 index 000000000..08fae330b --- /dev/null +++ b/tests/untried/pos/t3938/Parent.java @@ -0,0 +1,9 @@ +public class Parent<A>{ + class I1 {} + class I2 extends Parent.I1 {} + + // OKAY: + class I3 extends I1 {} + static class I4 {} + static class I5 extends Parent.I4 {} +} diff --git a/tests/untried/pos/t3938/UseParent.scala b/tests/untried/pos/t3938/UseParent.scala new file mode 100644 index 000000000..685d1a03a --- /dev/null +++ b/tests/untried/pos/t3938/UseParent.scala @@ -0,0 +1,7 @@ +object UseParent { + classOf[Parent[AnyRef]#I2] + + // OKAY + classOf[Parent[AnyRef]#I3] + classOf[Parent.I5] +} diff --git a/tests/untried/pos/t3943/Client_2.scala b/tests/untried/pos/t3943/Client_2.scala new file mode 100644 index 000000000..650ac9b7a --- /dev/null +++ b/tests/untried/pos/t3943/Client_2.scala @@ -0,0 +1,7 @@ +object Test { + val x: Child = new Child + x.getInner.foo("meh") +// error: type mismatch; +// found : java.lang.String("meh") +// required: E +} diff --git a/tests/untried/pos/t3943/Outer_1.java b/tests/untried/pos/t3943/Outer_1.java new file mode 100644 index 000000000..1d38c5e76 --- /dev/null +++ b/tests/untried/pos/t3943/Outer_1.java @@ -0,0 +1,14 @@ +class Outer<E> { + abstract class Inner { + abstract public void foo(E e); + } +} + +class Child extends Outer<String> { + // the implicit prefix for Inner is Outer<E> instead of Outer<String> + public Inner getInner() { + return new Inner() { + public void foo(String e) { System.out.println("meh "+e); } + }; + } +} diff --git a/tests/untried/pos/t3946/A.java b/tests/untried/pos/t3946/A.java new file mode 100644 index 000000000..70265229d --- /dev/null +++ b/tests/untried/pos/t3946/A.java @@ -0,0 +1,5 @@ +package p; + +public class A { + protected void f() {} +} diff --git a/tests/untried/pos/t3946/Test_1.scala b/tests/untried/pos/t3946/Test_1.scala new file mode 100644 index 000000000..8d8c71a92 --- /dev/null +++ b/tests/untried/pos/t3946/Test_1.scala @@ -0,0 +1,12 @@ +package q { + class B extends p.A { + override protected def f(): Unit = { } + } +} + +package p { + object T { + val a = new A() + a.f() + } +} diff --git a/tests/untried/pos/t3951/Coll_1.scala b/tests/untried/pos/t3951/Coll_1.scala new file mode 100644 index 000000000..556c84868 --- /dev/null +++ b/tests/untried/pos/t3951/Coll_1.scala @@ -0,0 +1,36 @@ +trait Document { + sealed trait FieldBase + trait StaticFieldBase extends FieldBase with StaticDocument + trait DynamicFieldBase extends FieldBase with DynamicDocument +} + +sealed trait StaticDocument extends Document { + abstract class AbstractField extends FieldBase +} + +sealed trait DynamicDocument extends Document { + abstract class AbstractField extends FieldBase +} + +class Coll extends StaticDocument + +// similiar issue with annotations +class ann[T] extends annotation.StaticAnnotation + +trait StatDoc extends Doc { + @ann[StatFB] + def foo: Int +} + +trait Doc { + @ann[DynDoc#ForceDynDoc] + def bar: Int + trait StatFB + trait DynFB +} + +trait DynDoc extends Doc { + @ann[DynFB] + def baz: Int + trait ForceDynDoc +} diff --git a/tests/untried/pos/t3951/Test_2.scala b/tests/untried/pos/t3951/Test_2.scala new file mode 100644 index 000000000..251954300 --- /dev/null +++ b/tests/untried/pos/t3951/Test_2.scala @@ -0,0 +1,4 @@ +object Test { + new Coll + trait T extends StatDoc +} diff --git a/tests/untried/pos/t3960.flags b/tests/untried/pos/t3960.flags new file mode 100644 index 000000000..4449dbbdf --- /dev/null +++ b/tests/untried/pos/t3960.flags @@ -0,0 +1 @@ +-Ycheck:typer
\ No newline at end of file diff --git a/tests/untried/pos/t3960.scala b/tests/untried/pos/t3960.scala new file mode 100644 index 000000000..5c658e9fb --- /dev/null +++ b/tests/untried/pos/t3960.scala @@ -0,0 +1,7 @@ +class A { + class C[x] + val cs = new scala.collection.mutable.HashMap[C[_], Int] + def c: C[_] = sys.error("") + val eval: C[_] = c + cs(c) += 1 +} diff --git a/tests/untried/pos/t397.scala b/tests/untried/pos/t397.scala new file mode 100644 index 000000000..87be2987a --- /dev/null +++ b/tests/untried/pos/t397.scala @@ -0,0 +1,16 @@ +abstract class Root { + + abstract class Edge { + type V; + def source: V; + } + + abstract class Graph { + type W; + type E <: Edge{type V = W}; + def edge: E; + } + + val g: Graph{type W = Int}; + val x: Int = g.edge.source; +} diff --git a/tests/untried/pos/t3972.scala b/tests/untried/pos/t3972.scala new file mode 100644 index 000000000..f1a977f26 --- /dev/null +++ b/tests/untried/pos/t3972.scala @@ -0,0 +1,11 @@ +object CompilerCrash { + def main(args: Array[String]): Unit = { + args match { + case Array("a", a @ _*) => { } // The code compiles fine if this line is commented out or "@ _*" is deleted or this line is swapped for the next line + case Array("b") => { } // The code compiles fine if this line is commented out + case Array("c", c) => { + 0 // The code compiles fine if this line is commented out + } + } + } +} diff --git a/tests/untried/pos/t3986.scala b/tests/untried/pos/t3986.scala new file mode 100644 index 000000000..635b00b1c --- /dev/null +++ b/tests/untried/pos/t3986.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + new { val x = "abc" } with AnyRef { } + } +} diff --git a/tests/untried/pos/t3999/a_1.scala b/tests/untried/pos/t3999/a_1.scala new file mode 100644 index 000000000..54c1b86ce --- /dev/null +++ b/tests/untried/pos/t3999/a_1.scala @@ -0,0 +1,9 @@ +package foo + +class Outside + +package object bar { + class Val(b: Boolean) + implicit def boolean2Val(b: Boolean) = new Val(b) + implicit def boolean2Outside(b: Boolean) = new Outside +} diff --git a/tests/untried/pos/t3999/b_2.scala b/tests/untried/pos/t3999/b_2.scala new file mode 100644 index 000000000..775b839d9 --- /dev/null +++ b/tests/untried/pos/t3999/b_2.scala @@ -0,0 +1,7 @@ +package foo +package bar + +class A { + val s: Val = false + val o: Outside = false +} diff --git a/tests/untried/pos/t3999b.scala b/tests/untried/pos/t3999b.scala new file mode 100644 index 000000000..0f3f7d642 --- /dev/null +++ b/tests/untried/pos/t3999b.scala @@ -0,0 +1,20 @@ +object `package` { + trait Score { def toString : String } + trait Test[+T <: Score] { def apply(s : String) : T } + + case class FT(f : Float) extends Score + implicit object FT extends Test[FT] { def apply(s : String) : FT = new FT(s.toFloat) } + + case class IT(i : Int) extends Score + implicit object IT extends Test[IT] { def apply(s : String) : IT = new IT(s.toInt) } +} + +class TT[+T <: Score](implicit val tb : Test[T]) { + def read(s : String) : T = tb(s) +} + +object Tester { + val tt = new TT[FT] + val r = tt.read("1.0") + r.toString +} diff --git a/tests/untried/pos/t4018.scala b/tests/untried/pos/t4018.scala new file mode 100644 index 000000000..2b265c571 --- /dev/null +++ b/tests/untried/pos/t4018.scala @@ -0,0 +1,15 @@ +trait M[V[_]] + +class Cls[V[_]](c: M[V]) + +object Cls{ + def apply[V[_]](c: M[V]): Cls[V] = new Cls[V](c) +} + +object test { + val c: M[Option] = new M[Option] {} + new Cls(c) // does not infer. + new Cls[Option](c) // okay + Cls(c) // okay +} + diff --git a/tests/untried/pos/t402.scala b/tests/untried/pos/t402.scala new file mode 100644 index 000000000..a5a3df482 --- /dev/null +++ b/tests/untried/pos/t402.scala @@ -0,0 +1,7 @@ +object Main { + def main(args: Array[String]): Unit = { + val x: Any = 2 + System.out.println((0.5).isInstanceOf[Int]); + System.out.println(x.isInstanceOf[Int]); + } +} diff --git a/tests/untried/pos/t4020.flags b/tests/untried/pos/t4020.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t4020.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t4020.scala b/tests/untried/pos/t4020.scala new file mode 100644 index 000000000..1231c1339 --- /dev/null +++ b/tests/untried/pos/t4020.scala @@ -0,0 +1,25 @@ +class A { + sealed trait Foo +} + +object a1 extends A { + case class Foo1(i: Int) extends Foo +} + +object a2 extends A { + case class Foo2(i: Int) extends Foo +} + +class B { + def mthd(foo: a2.Foo) = { + foo match { + case a2.Foo2(i) => i + + // Note: This case is impossible. In fact, scalac + // will (correctly) report an error if it is uncommented, + // but a warning if it is commented. + + // case a1.Foo1(i) => i + } + } +} diff --git a/tests/untried/pos/t4036.scala b/tests/untried/pos/t4036.scala new file mode 100644 index 000000000..06486df0f --- /dev/null +++ b/tests/untried/pos/t4036.scala @@ -0,0 +1,13 @@ +object Error { + def f: Unit = { + case class X(b: Boolean = false) + val r = X() + } + def g = { + val x = 0 + var y = 1 // no constant type + def foo(z: Int = y) = 1 + val z = 2 + foo() + } +} diff --git a/tests/untried/pos/t404.scala b/tests/untried/pos/t404.scala new file mode 100644 index 000000000..8f5e8bef5 --- /dev/null +++ b/tests/untried/pos/t404.scala @@ -0,0 +1,12 @@ +trait AbsIterator { + type T + def next: T +} +class StringIterator extends AbsIterator { + type T = Char + def next = 'a' +} +trait SyncIterator extends AbsIterator { + abstract override def next: T = super.next +} +class I extends StringIterator with SyncIterator diff --git a/tests/untried/pos/t4052.scala b/tests/untried/pos/t4052.scala new file mode 100644 index 000000000..561e1704e --- /dev/null +++ b/tests/untried/pos/t4052.scala @@ -0,0 +1,5 @@ +package object test { + trait PackageError + object PackageError +} + diff --git a/tests/untried/pos/t4063.scala b/tests/untried/pos/t4063.scala new file mode 100644 index 000000000..f7033f686 --- /dev/null +++ b/tests/untried/pos/t4063.scala @@ -0,0 +1,39 @@ +trait Parallel +trait Parallelizable[+ParRepr <: Parallel] + +trait PIterableLike[+T, +Repr <: Parallel] extends Parallel with Parallelizable[PIterableLike[T, Repr]] + +trait PMap[K, V] extends PIterableLike[(K, V), PMap[K, V]] +trait PSet[T] extends PIterableLike[T, PSet[T]] + +trait CIterableLike[+T, +Repr] + +trait CSet[T] extends CIterableLike[T, CSet[T]] with Parallelizable[PSet[T]] + +trait CMap[K, V] extends CIterableLike[(K, V), CMap[K, V]] with Parallelizable[PMap[K, V]] + +object Test { + var x = 0 + + def main(): Unit = { + val map: CMap[Int, CSet[Int]] = new CMap[Int, CSet[Int]] {} + val set: CSet[Int] = new CSet[Int] {} + + // should infer type argument + //map.synchronized[CIterableLike[Any, Any] with Parallelizable[PIterableLike[Any, Parallel with Parallelizable[Parallel]]]] { + // or: + //map.synchronized[CIterableLike[Any, Any] with Parallelizable[PIterableLike[Any, Parallel]]] { + // or, maybe it could also infer existential types: + //map.synchronized[CIterableLike[Any, _] with Parallelizable[PIterableLike[Any, _]]] { + + map.synchronized { + if (x == 0) { + map + } else { + set + } + } + + } +} + diff --git a/tests/untried/pos/t4070.scala b/tests/untried/pos/t4070.scala new file mode 100644 index 000000000..a9777f02e --- /dev/null +++ b/tests/untried/pos/t4070.scala @@ -0,0 +1,37 @@ +package a { + // method before classes + trait Foo { + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + + class Dingus[T] + class Bippy[CC[X] <: Seq[X]]() extends Dingus[CC[Int]] + } +} + +package b { + // classes before method + trait Foo { + class Dingus[T] + class Bippy[CC[X] <: Seq[X]]() extends Dingus[CC[Int]] + + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + } +} + + +/* +// With crash below the clasess: +% scalac -Dscalac.debug.tvar ./a.scala +[ create] ?_$1 ( In Foo#crash ) +[ setInst] tv[Int] ( In Foo#crash, _$1=tv[Int] ) +[ create] tv[Int] ( In Foo#crash ) +[ clone] tv[Int] ( Foo#crash ) + +// With crash above the classes: +% scalac -Dscalac.debug.tvar ./a.scala +[ create] ?tv ( In Foo#crash ) +./a.scala:2: error: Invalid type application in TypeVar: List(), List(Int) + def crash(x: Dingus[_]): Unit = x match { case m: Bippy[tv] => () } + ^ +one error found +*/ diff --git a/tests/untried/pos/t4070b.scala b/tests/untried/pos/t4070b.scala new file mode 100644 index 000000000..d6851b8cc --- /dev/null +++ b/tests/untried/pos/t4070b.scala @@ -0,0 +1,35 @@ +package a { + abstract class DeliteOp[B] + abstract class DeliteCollection[A] + abstract class Exp[T] { def Type: T } + + trait DeliteOpMap[A,B,C[X] <: DeliteCollection[X]] extends DeliteOp[C[B]] { + val in: Exp[C[A]] + val func: Exp[B] + val alloc: Exp[C[B]] + } + + object Test { + def f(x: DeliteOp[_]) = x match { + case map: DeliteOpMap[_,_,_] => map.alloc.Type + } + } +} + +package b { + object Test { + def f(x: DeliteOp[_]) = x match { + case map: DeliteOpMap[_,_,_] => map.alloc.Type + } + } + + abstract class DeliteOp[B] + abstract class DeliteCollection[A] + abstract class Exp[T] { def Type: T } + + trait DeliteOpMap[A,B,C[X] <: DeliteCollection[X]] extends DeliteOp[C[B]] { + val in: Exp[C[A]] + val func: Exp[B] + val alloc: Exp[C[B]] + } +} diff --git a/tests/untried/pos/t4112.scala b/tests/untried/pos/t4112.scala new file mode 100644 index 000000000..ab0f36fdc --- /dev/null +++ b/tests/untried/pos/t4112.scala @@ -0,0 +1,12 @@ + + +import collection.immutable._ + + + +object Test { + def main(args: Array[String]): Unit = { + val treemap = TreeMap(1 -> 2, 3 -> 4) ++ TreeMap(5 -> 6) + (treemap: TreeMap[Int, Int]) + } +} diff --git a/tests/untried/pos/t4114.scala b/tests/untried/pos/t4114.scala new file mode 100644 index 000000000..25eb2232c --- /dev/null +++ b/tests/untried/pos/t4114.scala @@ -0,0 +1,8 @@ +abstract class A { + private def foo = List(1, 2) +} +trait B extends A { + private def foo = List("a", "b") + // However it compiles correctly if the type is given: + // private def foo: List[String] = List("a", "b") +} diff --git a/tests/untried/pos/t415.scala b/tests/untried/pos/t415.scala new file mode 100644 index 000000000..355b6136d --- /dev/null +++ b/tests/untried/pos/t415.scala @@ -0,0 +1,9 @@ +abstract class A { + type T <: String; + def x: T; +} + +abstract class B { + def a: A; + val y: String = a.x; +} diff --git a/tests/untried/pos/t4173.scala b/tests/untried/pos/t4173.scala new file mode 100644 index 000000000..33a713191 --- /dev/null +++ b/tests/untried/pos/t4173.scala @@ -0,0 +1,4 @@ +object t4173 { + def bar(a: Int = 0, b: Int = 0)(cs: Any*) = () + bar(b = 1)(Nil: _*) +} diff --git a/tests/untried/pos/t4176.scala b/tests/untried/pos/t4176.scala new file mode 100644 index 000000000..b4f1e705b --- /dev/null +++ b/tests/untried/pos/t4176.scala @@ -0,0 +1,6 @@ +// a.scala +// Fri Jan 20 12:22:51 PST 2012 + +class A(xs: Int*) { def getXs = xs } + +class B extends A { override def getXs = Nil } diff --git a/tests/untried/pos/t4176b.scala b/tests/untried/pos/t4176b.scala new file mode 100644 index 000000000..11914c50c --- /dev/null +++ b/tests/untried/pos/t4176b.scala @@ -0,0 +1,5 @@ +object Test { + def foo(a: String*) = a + val fooEta = foo _ + (foo: Seq[String] => Seq[String]) +} diff --git a/tests/untried/pos/t4188.scala b/tests/untried/pos/t4188.scala new file mode 100644 index 000000000..40e7d4924 --- /dev/null +++ b/tests/untried/pos/t4188.scala @@ -0,0 +1,6 @@ +class A { + object Ding + class B { + (null: Any) match { case _: Ding.type => () } + } +} diff --git a/tests/untried/pos/t419.scala b/tests/untried/pos/t419.scala new file mode 100644 index 000000000..65dcb0435 --- /dev/null +++ b/tests/untried/pos/t419.scala @@ -0,0 +1,11 @@ +trait Bar { + class Config {} + var config: Config; // aha, traits can have variables? +} + +object Foo extends Bar { + + class FooConfig extends Config; + var config: Config = new FooConfig() // or not + +} diff --git a/tests/untried/pos/t4202.scala b/tests/untried/pos/t4202.scala new file mode 100644 index 000000000..b2a0c0120 --- /dev/null +++ b/tests/untried/pos/t4202.scala @@ -0,0 +1,18 @@ +object t4202_1 { + () => { + trait T { + def t = () + } + } +} + +object t4202_2 { + () => { + trait T { + def t = () + } + object T2 extends T { + t + } + } +} diff --git a/tests/untried/pos/t4205/1.scala b/tests/untried/pos/t4205/1.scala new file mode 100644 index 000000000..003763f6c --- /dev/null +++ b/tests/untried/pos/t4205/1.scala @@ -0,0 +1,3 @@ +trait A[OUT[_]] { + null.asInstanceOf[B[OUT]].b1("") +} diff --git a/tests/untried/pos/t4205/2.scala b/tests/untried/pos/t4205/2.scala new file mode 100644 index 000000000..398fbdecc --- /dev/null +++ b/tests/untried/pos/t4205/2.scala @@ -0,0 +1,4 @@ +trait B[OUT[_]] { + def b1[A](a: A) = b2[OUT] + def b2[OUT1[_]] = () +} diff --git a/tests/untried/pos/t4220.scala b/tests/untried/pos/t4220.scala new file mode 100644 index 000000000..98f264976 --- /dev/null +++ b/tests/untried/pos/t4220.scala @@ -0,0 +1,7 @@ +// don't know if our half-working sbt build is meaningfully +// tested for #4220 with this, but it can't hurt. +class Boo(a: Int = 0) + +object test { + class Boo +} diff --git a/tests/untried/pos/t4237.scala b/tests/untried/pos/t4237.scala new file mode 100644 index 000000000..44bc81462 --- /dev/null +++ b/tests/untried/pos/t4237.scala @@ -0,0 +1,6 @@ +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/untried/pos/t4243.scala b/tests/untried/pos/t4243.scala new file mode 100644 index 000000000..e6c66faff --- /dev/null +++ b/tests/untried/pos/t4243.scala @@ -0,0 +1,18 @@ + + + + +object wrap { + + trait DomainLike[@specialized(Int) A, +This <: Domain[A]] + + trait Domain[@specialized(Int) B] + extends DomainLike[B, Domain[B]] + + trait IterableDomainLike[@specialized(Int) C, +This <: IterableDomain[C]] + extends DomainLike[C, This] + + trait IterableDomain[@specialized(Int) D] + extends Domain[D] with IterableDomainLike[D, IterableDomain[D]] + +} diff --git a/tests/untried/pos/t4257.scala b/tests/untried/pos/t4257.scala new file mode 100644 index 000000000..fd150a150 --- /dev/null +++ b/tests/untried/pos/t4257.scala @@ -0,0 +1,15 @@ +object Test { + + class SA[@specialized(Int) A] { + def o[U](f: ((Int, A) => Any)): Unit = {} + + def o[U](f: A => Any): Unit = {} + } + + class X[@specialized(Int) B] { + def x(b: B) = { + new SA[B]().o((x: Any) => x) + } + } +} + diff --git a/tests/untried/pos/t4266.scala b/tests/untried/pos/t4266.scala new file mode 100644 index 000000000..9989ff486 --- /dev/null +++ b/tests/untried/pos/t4266.scala @@ -0,0 +1,27 @@ +object Test { + + trait Tensor2Like[ + @specialized(Int) A1, + +D1 <: DomainLike[A1], + +D <: Product2DomainLike[D1] + ] { + def domain: D; + + def checkKey(k1: A1): Unit = { + domain._1.contains(k1) + } + } + + trait DomainLike[A] { + def contains(key: A): Boolean; + } + + // trait DomainLike[@specialized(Int) A] { + // def contains(key: A): Boolean; + // } + + trait Product2DomainLike[+D1] { + def _1: D1; + } +} + diff --git a/tests/untried/pos/t4269.scala b/tests/untried/pos/t4269.scala new file mode 100644 index 000000000..99a30785b --- /dev/null +++ b/tests/untried/pos/t4269.scala @@ -0,0 +1,5 @@ +class A { + PartialFunction.condOpt(Nil) { + case items@List(_*) if true => + } +} diff --git a/tests/untried/pos/t4273.scala b/tests/untried/pos/t4273.scala new file mode 100644 index 000000000..ed2c62770 --- /dev/null +++ b/tests/untried/pos/t4273.scala @@ -0,0 +1,8 @@ +class A { + implicit def compareComparables[T](x: T)(implicit ord: Ordering[T]) = new ord.Ops(x) + + class Bippy + implicit val bippyOrdering = new Ordering[Bippy] { def compare(x: Bippy, y: Bippy) = util.Random.nextInt } + + (new Bippy) < (new Bippy) +} diff --git a/tests/untried/pos/t4275.scala b/tests/untried/pos/t4275.scala new file mode 100644 index 000000000..1938acead --- /dev/null +++ b/tests/untried/pos/t4275.scala @@ -0,0 +1,13 @@ +object Test { + def f = "abc".count(_ > 'a') + + class A { + private val count: Int = 0 + } + class B extends A { } + object B { + implicit def b2seq(x: B): Seq[Int] = Nil + + def f = (new B) count (_ > 0) + } +} diff --git a/tests/untried/pos/t430-feb09.scala b/tests/untried/pos/t430-feb09.scala new file mode 100644 index 000000000..1499f32b7 --- /dev/null +++ b/tests/untried/pos/t430-feb09.scala @@ -0,0 +1,34 @@ +// Compiles +package a { + case class A[T]() +} + +// Compiles +package b.scala { + class B[T] +} + +// Doesn't compile: type Nothing is not a member of c.scala +package c.scala { + case class C[T]() +} + +// Doesn't compile: type Nothing is not a member of d.scala +package d.scala.d { + case class D[T]() +} + +// Doesn't compile: type Any is not a member of e.scala +package e.scala { + case class E[T >: Nothing]() +} + +// Compiles +package f.scala { + case class F[T >: Nothing <: Any]() +} + +// Doesn't compile: type <byname> is not a member of package h.scala +package h.scala { + case class H(s: String)(t: =>String) +} diff --git a/tests/untried/pos/t430.scala b/tests/untried/pos/t430.scala new file mode 100644 index 000000000..6b8e9070c --- /dev/null +++ b/tests/untried/pos/t430.scala @@ -0,0 +1,20 @@ +object Test extends App { + def foo[T <% Ordered[T]](x: T): Unit = { Console.println(""+(x < x)+" "+(x <= x)) } + def bar(x: Unit ): Unit = foo(x); + def bar(x: Boolean): Unit = foo(x); + def bar(x: Byte ): Unit = foo(x); + def bar(x: Short ): Unit = foo(x); + def bar(x: Int ): Unit = foo(x); + def bar(x: Long ): Unit = foo(x); + def bar(x: Float ): Unit = foo(x); + def bar(x: Double ): Unit = foo(x); + bar(()) + bar(true) + bar(1: Byte) + bar(1: Short) + bar('a') + bar(1) + bar(1l) + bar(1.0f) + bar(1.0) +} diff --git a/tests/untried/pos/t4305.scala b/tests/untried/pos/t4305.scala new file mode 100644 index 000000000..68ec7b712 --- /dev/null +++ b/tests/untried/pos/t4305.scala @@ -0,0 +1,31 @@ +object T1 { + trait T[A] + class C extends T[String] + object Test { + def main(args: Array[String]): Unit = { + classOf[C].getTypeParameters + } + } +} + +object T2 { + trait T[A] + class C extends T[String] + object Test { + def main(args: Array[String]): Unit = { + val x = classOf[C] + x.getTypeParameters + } + } +} + +object T3 { + trait T[A] + class C extends T[String] + object Test { + def main(args: Array[String]): Unit = { + val x: Class[C] = classOf[C] + x.getTypeParameters + } + } +} diff --git a/tests/untried/pos/t432.scala b/tests/untried/pos/t432.scala new file mode 100644 index 000000000..087fd70ab --- /dev/null +++ b/tests/untried/pos/t432.scala @@ -0,0 +1,2 @@ +case class Tata() +object Tata diff --git a/tests/untried/pos/t4336.scala b/tests/untried/pos/t4336.scala new file mode 100644 index 000000000..e10d00158 --- /dev/null +++ b/tests/untried/pos/t4336.scala @@ -0,0 +1,19 @@ +object Main { + class NonGeneric {} + class Generic[T] {} + + class Composite { + def contains(setup : Composite => Unit) : Composite = this + } + + def generic[T](parent: Composite): Generic[T] = new Generic[T] + def nonGeneric(parent: Composite): NonGeneric = new NonGeneric + + new Composite().contains( + nonGeneric // should have type Composite => NonGeneric + ) + + new Composite().contains( + generic[Int] // should have type Composite => Generic[Int] + ) +} diff --git a/tests/untried/pos/t4345.scala b/tests/untried/pos/t4345.scala new file mode 100644 index 000000000..b0131d5fa --- /dev/null +++ b/tests/untried/pos/t4345.scala @@ -0,0 +1,7 @@ +trait C1[+A, +CC[X]] { + protected[this] def f: A => CC[A] = sys.error("") +} + +trait C2[+A, +CC[X]] extends C1[A, CC] { + override protected[this] def f = super.f +} diff --git a/tests/untried/pos/t4363.scala b/tests/untried/pos/t4363.scala new file mode 100644 index 000000000..64cdcd935 --- /dev/null +++ b/tests/untried/pos/t4363.scala @@ -0,0 +1,8 @@ +object Test { + trait Suite { def bar() = () } + + () => { + trait FunkySuite extends Suite { override def bar() = () } + class MySuite extends FunkySuite { } + } +} diff --git a/tests/untried/pos/t4365/a_1.scala b/tests/untried/pos/t4365/a_1.scala new file mode 100644 index 000000000..a24b57772 --- /dev/null +++ b/tests/untried/pos/t4365/a_1.scala @@ -0,0 +1,18 @@ +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/untried/pos/t4365/b_1.scala b/tests/untried/pos/t4365/b_1.scala new file mode 100644 index 000000000..e1423813f --- /dev/null +++ b/tests/untried/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/untried/pos/t439.scala b/tests/untried/pos/t439.scala new file mode 100644 index 000000000..f3191c72f --- /dev/null +++ b/tests/untried/pos/t439.scala @@ -0,0 +1,4 @@ +object test { + abstract class Foo; + object o extends Foo +} diff --git a/tests/untried/pos/t4402/A.scala b/tests/untried/pos/t4402/A.scala new file mode 100644 index 000000000..f43f0865f --- /dev/null +++ b/tests/untried/pos/t4402/A.scala @@ -0,0 +1,3 @@ +package ohmy + +class A extends other.Bar diff --git a/tests/untried/pos/t4402/Bar.java b/tests/untried/pos/t4402/Bar.java new file mode 100644 index 000000000..edc00a5fd --- /dev/null +++ b/tests/untried/pos/t4402/Bar.java @@ -0,0 +1,7 @@ +package other; + +public class Bar extends test.Foo { + void createMeSth(test.Foo.Inner aaa) { + aaa.hello(); + } +} diff --git a/tests/untried/pos/t4402/Foo.java b/tests/untried/pos/t4402/Foo.java new file mode 100644 index 000000000..585a5e0a2 --- /dev/null +++ b/tests/untried/pos/t4402/Foo.java @@ -0,0 +1,8 @@ +package test; + +public abstract class Foo { + protected interface Inner { + public void hello(); + } +} + diff --git a/tests/untried/pos/t443.scala b/tests/untried/pos/t443.scala new file mode 100644 index 000000000..cdaefe9ec --- /dev/null +++ b/tests/untried/pos/t443.scala @@ -0,0 +1,14 @@ +object Test { + + def lookup(): Option[Tuple2[String, String]] = + ((null: Option[Tuple2[String, String]]) : @unchecked) match { + case Some((_, _)) => + if (true) + Some((null, null)) + else + lookup() match { + case Some(_) => Some(null) + case None => None + } + } +} diff --git a/tests/untried/pos/t4430.scala b/tests/untried/pos/t4430.scala new file mode 100644 index 000000000..746ecb271 --- /dev/null +++ b/tests/untried/pos/t4430.scala @@ -0,0 +1,11 @@ +class Crash { + def S(op: => Double) = 0 + def A(a: Int, b: Int) = 0 + + val t = 0 + + val q = A( + b = S { val xxx = t ; 42 }, + a = 0 + ) +} diff --git a/tests/untried/pos/t4432.scala b/tests/untried/pos/t4432.scala new file mode 100644 index 000000000..106312311 --- /dev/null +++ b/tests/untried/pos/t4432.scala @@ -0,0 +1,42 @@ +object Main { + def foo1 = { + class A { + val x = { + lazy val cc = 1 // + cc + () + } + } + new A + } + + def foo2 = { + class B { + val x = { + object cc + cc + () + } + } + new B + } + + def foo3 = { + object C { + val x = { + lazy val cc = 1 + cc + } + } + C + } + + def foo4 = { + class D { + lazy val cc = 1 + cc + } + new D + } + +} diff --git a/tests/untried/pos/t4457_1.scala b/tests/untried/pos/t4457_1.scala new file mode 100644 index 000000000..7192d97f4 --- /dev/null +++ b/tests/untried/pos/t4457_1.scala @@ -0,0 +1,26 @@ +object ImplicitConvAmbiguity2 { + + class N[T] + class NE[T] extends N[T] + class NN[T] extends N[T] + class AA[A] + class BB[A] + + implicit def conv1(i: Float) = new NE[Float] + implicit def conv3(op: AA[java.util.TooManyListenersException]) = new N[java.util.TooManyListenersException] + implicit def conv4(op: AA[Float]) = new N[Float] + implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar] + + def aFunc[A](a: NE[A]) = new AA[A] + def aFunc[A](a: NN[A]) = new BB[A] + + def bFunc[T](e1: N[T]) = {} + + def typeMe1: Unit = { + val x = aFunc(4F) + bFunc(x) + } + def typeMe2: Unit = { + bFunc(aFunc(4F)) + } +} diff --git a/tests/untried/pos/t4494.flags b/tests/untried/pos/t4494.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/t4494.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/t4494.scala b/tests/untried/pos/t4494.scala new file mode 100644 index 000000000..ef38a1908 --- /dev/null +++ b/tests/untried/pos/t4494.scala @@ -0,0 +1,3 @@ +object A { + List(1) +} diff --git a/tests/untried/pos/t4501.scala b/tests/untried/pos/t4501.scala new file mode 100644 index 000000000..f7d45eaa5 --- /dev/null +++ b/tests/untried/pos/t4501.scala @@ -0,0 +1,14 @@ +// After lub modification +import scala.collection.mutable.ListBuffer + +class A { + def foo[T](a:T, b:T):T = a + def f1 = foo(ListBuffer(), List()) + def f2 = foo(ListBuffer(), ListBuffer()) + def f3 = foo(List(), List()) + + // scalap + // def f1 : scala.collection.Seq[scala.Nothing] = { /* compiled code */ } + // def f2 : scala.collection.mutable.ListBuffer[scala.Nothing] = { /* compiled code */ } + // def f3 : scala.collection.immutable.List[scala.Nothing] = { /* compiled code */ } +} diff --git a/tests/untried/pos/t4502.scala b/tests/untried/pos/t4502.scala new file mode 100644 index 000000000..53e4abc39 --- /dev/null +++ b/tests/untried/pos/t4502.scala @@ -0,0 +1,12 @@ +class T { + def send(o: Any, d: Int = 10): Unit = { } + + def c(f: => Any): Unit = { } + + def f(): Unit = { + var a = this + a.send( + c(a.send(())) + ) + } +} diff --git a/tests/untried/pos/t4524.scala b/tests/untried/pos/t4524.scala new file mode 100644 index 000000000..4721a7d06 --- /dev/null +++ b/tests/untried/pos/t4524.scala @@ -0,0 +1,9 @@ +object test { + import A._ + class A(b: B = new A.B()) + object A { + class B + new A() + } +} + diff --git a/tests/untried/pos/t4545.scala b/tests/untried/pos/t4545.scala new file mode 100644 index 000000000..b2b67fa8f --- /dev/null +++ b/tests/untried/pos/t4545.scala @@ -0,0 +1,14 @@ +object Test { + def f[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](table: Tuple20[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T])(fun: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T) => Unit): Unit = { + } + def g[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](table: Tuple21[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U])(fun: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U) => Unit): Unit = { + } + + def g20 = f( + ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) + ) { case ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)) => () } + + def g21 = g( + (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) + ) { case ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)) => () } +} diff --git a/tests/untried/pos/t4547.scala b/tests/untried/pos/t4547.scala new file mode 100644 index 000000000..b771c6967 --- /dev/null +++ b/tests/untried/pos/t4547.scala @@ -0,0 +1,4 @@ +object Main { + def g: BigInt = 5 + BigInt(4) // since we're looking for an implicit that converts an int into something that has a + method that takes a BigInt, BigInt should be in the implicit scope + def g2 = 5 + BigInt(4) +} diff --git a/tests/untried/pos/t4553.scala b/tests/untried/pos/t4553.scala new file mode 100755 index 000000000..4eefe57b2 --- /dev/null +++ b/tests/untried/pos/t4553.scala @@ -0,0 +1,11 @@ +trait VectorLike[+T, +V[A] <: Vector[A]] { + def +[S, VResult[S] >: V[S]](v: VResult[S]) +} + +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/untried/pos/t4579.flags b/tests/untried/pos/t4579.flags new file mode 100644 index 000000000..1182725e8 --- /dev/null +++ b/tests/untried/pos/t4579.flags @@ -0,0 +1 @@ +-optimize
\ No newline at end of file diff --git a/tests/untried/pos/t4579.scala b/tests/untried/pos/t4579.scala new file mode 100644 index 000000000..b298ee579 --- /dev/null +++ b/tests/untried/pos/t4579.scala @@ -0,0 +1,518 @@ +//############################################################################ +// Lisp interpreter (revived as an optimizer test.) +//############################################################################ + +//############################################################################ +// Lisp Scanner + +class LispTokenizer(s: String) extends Iterator[String] { + private var i = 0; + private def isDelimiter(ch: Char) = ch <= ' ' || ch == '(' || ch == ')' + def hasNext: Boolean = { + while (i < s.length() && s.charAt(i) <= ' ') i += 1 + i < s.length() + } + def next: String = + if (hasNext) { + val start = i + if (isDelimiter(s charAt i)) i += 1 + else + do i = i + 1 + while (!isDelimiter(s charAt i)) + s.substring(start, i) + } else sys.error("premature end of string") +} + +//############################################################################ +// Lisp Interface + +trait Lisp { + type Data + + def string2lisp(s: String): Data + def lisp2string(s: Data): String + + def evaluate(d: Data): Data + // !!! def evaluate(s: String): Data = evaluate(string2lisp(s)) + def evaluate(s: String): Data +} + +//############################################################################ +// Lisp Implementation Using Case Classes + +object LispCaseClasses extends Lisp { + + import List.range + + trait Data { + def elemsToString(): String = toString(); + } + case class CONS(car: Data, cdr: Data) extends Data { + override def toString() = "(" + elemsToString() + ")"; + override def elemsToString() = car.toString() + (cdr match { + case NIL() => "" + case _ => " " + cdr.elemsToString(); + }) + } + case class NIL() extends Data { // !!! use case object + override def toString() = "()"; + } + case class SYM(name: String) extends Data { + override def toString() = name; + } + case class NUM(x: Int) extends Data { + override def toString() = x.toString(); + } + case class STR(x: String) extends Data { + override def toString() = "\"" + x + "\""; + } + case class FUN(f: List[Data] => Data) extends Data { + override def toString() = "<fn>"; + } + + def list(): Data = + NIL(); + def list(x0: Data): Data = + CONS(x0, NIL()); + def list(x0: Data, x1: Data): Data = + CONS(x0, list(x1)); + def list(x0: Data, x1: Data, x2: Data): Data = + CONS(x0, list(x1, x2)); + def list(x0: Data, x1: Data, x2: Data, x3: Data): Data = + CONS(x0, list(x1, x2, x3)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data): Data = + CONS(x0, list(x1, x2, x3, x4)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data, x8: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7, x8)); + def list(x0: Data, x1: Data, x2: Data, x3: Data, x4: Data, x5: Data, + x6: Data, x7: Data, x8: Data, x9: Data): Data = + CONS(x0, list(x1, x2, x3, x4, x5, x6, x7, x8, x9)); + + var curexp: Data = null + var trace: Boolean = false + var indent: Int = 0 + + def lispError[a](msg: String): a = + sys.error("error: " + msg + "\n" + curexp); + + trait Environment { + def lookup(n: String): Data; + def extendRec(name: String, expr: Environment => Data) = + new Environment { + def lookup(n: String): Data = + if (n == name) expr(this) else Environment.this.lookup(n); + } + def extend(name: String, v: Data) = extendRec(name, (env1 => v)); + } + val EmptyEnvironment = new Environment { + def lookup(n: String): Data = lispError("undefined: " + n); + } + + def toList(x: Data): List[Data] = x match { + case NIL() => List() + case CONS(y, ys) => y :: toList(ys) + case _ => lispError("malformed list: " + x); + } + + def toBoolean(x: Data) = x match { + case NUM(0) => false + case _ => true + } + + def normalize(x: Data): Data = x match { + case CONS(SYM("def"), + CONS(CONS(SYM(name), args), CONS(body, CONS(expr, NIL())))) => + normalize(list(SYM("def"), + SYM(name), list(SYM("lambda"), args, body), expr)) + case CONS(SYM("cond"), CONS(CONS(SYM("else"), CONS(expr, NIL())),NIL())) => + normalize(expr) + case CONS(SYM("cond"), CONS(CONS(test, CONS(expr, NIL())), rest)) => + normalize(list(SYM("if"), test, expr, CONS(SYM("cond"), rest))) + case CONS(h, t) => CONS(normalize(h), normalize(t)) + case _ => x + } + + def eval(x: Data, env: Environment): Data = { + val prevexp = curexp; + curexp = x; + if (trace) { + for (x <- range(1, indent)) Console.print(" "); + Console.println("===> " + x); + indent = indent + 1; + } + val result = eval1(x, env); + if (trace) { + indent = indent - 1; + for (x <- range(1, indent)) Console.print(" "); + Console.println("<=== " + result); + } + curexp = prevexp; + result + } + + def eval1(x: Data, env: Environment): Data = x match { + case SYM(name) => + env lookup name + case CONS(SYM("def"), CONS(SYM(name), CONS(y, CONS(z, NIL())))) => + eval(z, env.extendRec(name, (env1 => eval(y, env1)))) + case CONS(SYM("val"), CONS(SYM(name), CONS(y, CONS(z, NIL())))) => + eval(z, env.extend(name, eval(y, env))) + case CONS(SYM("lambda"), CONS(params, CONS(y, NIL()))) => + mkLambda(params, y, env) + case CONS(SYM("if"), CONS(c, CONS(t, CONS(e, NIL())))) => + if (toBoolean(eval(c, env))) eval(t, env) else eval(e, env) + case CONS(SYM("quote"), CONS(x, NIL())) => + x + case CONS(y, xs) => + apply(eval(y, env), toList(xs) map (x => eval(x, env))) + case NUM(_) => x + case STR(_) => x + case FUN(_) => x + case _ => + lispError("illegal term") + } + + def apply(fn: Data, args: List[Data]): Data = fn match { + case FUN(f) => f(args); + case _ => lispError("application of non-function: " + fn); + } + + def mkLambda(params: Data, expr: Data, env: Environment): Data = { + + def extendEnv(env: Environment, + ps: List[String], args: List[Data]): Environment = + (ps, args) match { + case (List(), List()) => + env + case (p :: ps1, arg :: args1) => + extendEnv(env.extend(p, arg), ps1, args1) + case _ => + lispError("wrong number of arguments") + } + + val ps: List[String] = toList(params) map { + case SYM(name) => name + case _ => sys.error("illegal parameter list"); + } + + FUN(args => eval(expr, extendEnv(env, ps, args))) + } + + val globalEnv = EmptyEnvironment + .extend("=", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(if (arg1 == arg2) 1 else 0) + case List(STR(arg1),STR(arg2)) => NUM(if (arg1 == arg2) 1 else 0)})) + .extend("+", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 + arg2) + case List(STR(arg1),STR(arg2)) => STR(arg1 + arg2)})) + .extend("-", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 - arg2)})) + .extend("*", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 * arg2)})) + .extend("/", FUN({ + case List(NUM(arg1),NUM(arg2)) => NUM(arg1 / arg2)})) + .extend("car", FUN({ + case List(CONS(x, xs)) => x})) + .extend("cdr", FUN({ + case List(CONS(x, xs)) => xs})) + .extend("null?", FUN({ + case List(NIL()) => NUM(1) + case _ => NUM(0)})) + .extend("cons", FUN({ + case List(x, y) => CONS(x, y)})); + + def evaluate(x: Data): Data = eval(normalize(x), globalEnv); + def evaluate(s: String): Data = evaluate(string2lisp(s)); + + def string2lisp(s: String): Data = { + val it = new LispTokenizer(s); + def parse(token: String): Data = { + if (token == "(") parseList + else if (token == ")") sys.error("unbalanced parentheses") + else if ('0' <= token.charAt(0) && token.charAt(0) <= '9') + NUM(token.toInt) + else if (token.charAt(0) == '\"' && token.charAt(token.length()-1)=='\"') + STR(token.substring(1,token.length() - 1)) + else SYM(token) + } + def parseList: Data = { + val token = it.next; + if (token == ")") NIL() else CONS(parse(token), parseList) + } + parse(it.next) + } + + def lisp2string(d: Data): String = d.toString(); +} + +//############################################################################ +// Lisp Implementation Using Any + +object LispAny extends Lisp { + + import List._; + + type Data = Any; + + case class Lambda(f: List[Data] => Data); + + var curexp: Data = null; + var trace: Boolean = false; + var indent: Int = 0; + + def lispError[a](msg: String): a = + sys.error("error: " + msg + "\n" + curexp); + + trait Environment { + def lookup(n: String): Data; + def extendRec(name: String, expr: Environment => Data) = + new Environment { + def lookup(n: String): Data = + if (n == name) expr(this) else Environment.this.lookup(n); + } + def extend(name: String, v: Data) = extendRec(name, (env1 => v)); + } + val EmptyEnvironment = new Environment { + def lookup(n: String): Data = lispError("undefined: " + n); + } + + def asList(x: Data): List[Data] = x match { + case y: List[_] => y + case _ => lispError("malformed list: " + x) + } + + def asInt(x: Data): Int = x match { + case y: Int => y + case _ => lispError("not an integer: " + x) + } + + def asString(x: Data): String = x match { + case y: String => y + case _ => lispError("not a string: " + x) + } + + def asBoolean(x: Data): Boolean = x != 0 + + def normalize(x: Data): Data = x match { + case 'and :: x :: y :: Nil => + normalize('if :: x :: y :: 0 :: Nil) + case 'or :: x :: y :: Nil => + normalize('if :: x :: 1 :: y :: Nil) + case 'def :: (name :: args) :: body :: expr :: Nil => + normalize('def :: name :: ('lambda :: args :: body :: Nil) :: expr :: Nil) + case 'cond :: ('else :: expr :: Nil) :: rest => + normalize(expr); + case 'cond :: (test :: expr :: Nil) :: rest => + normalize('if :: test :: expr :: ('cond :: rest) :: Nil) + case 'cond :: 'else :: expr :: Nil => + normalize(expr) + case h :: t => + normalize(h) :: asList(normalize(t)) + case _ => + x + } + + def eval(x: Data, env: Environment): Data = { + val prevexp = curexp; + curexp = x; + if (trace) { + for (x <- range(1, indent)) Console.print(" "); + Console.println("===> " + x); + indent += 1; + } + val result = eval1(x, env); + if (trace) { + indent -= 1; + for (x <- range(1, indent)) Console.print(" "); + Console.println("<=== " + result); + } + curexp = prevexp; + result + } + + def eval1(x: Data, env: Environment): Data = x match { + case Symbol(name) => + env lookup name + case 'def :: Symbol(name) :: y :: z :: Nil => + eval(z, env.extendRec(name, (env1 => eval(y, env1)))) + case 'val :: Symbol(name) :: y :: z :: Nil => + eval(z, env.extend(name, eval(y, env))) + case 'lambda :: params :: y :: Nil => + mkLambda(params, y, env) + case 'if :: c :: y :: z :: Nil => + if (asBoolean(eval(c, env))) eval(y, env) else eval(z, env) + case 'quote :: y :: Nil => + y + case y :: z => + apply(eval(y, env), z map (x => eval(x, env))) + case Lambda(_) => x + case y: String => x + case y: Int => x + case y => lispError("illegal term") + } + + def lisp2string(x: Data): String = x match { + case Symbol(name) => name + case Nil => "()" + case y :: ys => + def list2string(xs: List[Data]): String = xs match { + case List() => "" + case y :: ys => " " + lisp2string(y) + list2string(ys) + } + "(" + lisp2string(y) + list2string(ys) + ")" + case _ => if (x.isInstanceOf[String]) "\"" + x + "\""; else x.toString() + } + + def apply(fn: Data, args: List[Data]): Data = fn match { + case Lambda(f) => f(args); + case _ => lispError("application of non-function: " + fn + " to " + args); + } + + def mkLambda(params: Data, expr: Data, env: Environment): Data = { + + def extendEnv(env: Environment, + ps: List[String], args: List[Data]): Environment = + (ps, args) match { + case (List(), List()) => + env + case (p :: ps1, arg :: args1) => + extendEnv(env.extend(p, arg), ps1, args1) + case _ => + lispError("wrong number of arguments") + } + + val ps: List[String] = asList(params) map { + case Symbol(name) => name + case _ => sys.error("illegal parameter list"); + } + + Lambda(args => eval(expr, extendEnv(env, ps, args))) + } + + val globalEnv = EmptyEnvironment + .extend("=", Lambda{ + case List(arg1, arg2) => if(arg1 == arg2) 1 else 0}) + .extend("+", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 + arg2 + case List(arg1: String, arg2: String) => arg1 + arg2}) + .extend("-", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 - arg2}) + .extend("*", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 * arg2}) + .extend("/", Lambda{ + case List(arg1: Int, arg2: Int) => arg1 / arg2}) + .extend("nil", Nil) + .extend("cons", Lambda{ + case List(arg1, arg2) => arg1 :: asList(arg2)}) + .extend("car", Lambda{ + case List(x :: xs) => x}) + .extend("cdr", Lambda{ + case List(x :: xs) => xs}) + .extend("null?", Lambda{ + case List(Nil) => 1 + case _ => 0}); + + def evaluate(x: Data): Data = eval(normalize(x), globalEnv); + def evaluate(s: String): Data = evaluate(string2lisp(s)); + + def string2lisp(s: String): Data = { + val it = new LispTokenizer(s); + def parse(token: String): Data = { + if (token == "(") parseList + else if (token == ")") sys.error("unbalanced parentheses") + //else if (Character.isDigit(token.charAt(0))) + else if (token.charAt(0).isDigit) + token.toInt + else if (token.charAt(0) == '\"' && token.charAt(token.length()-1)=='\"') + token.substring(1,token.length() - 1) + else Symbol(token) + } + def parseList: List[Data] = { + val token = it.next; + if (token == ")") Nil else parse(token) :: parseList + } + parse(it.next) + } +} + +//############################################################################ +// List User + +class LispUser(lisp: Lisp) { + + import lisp._; + + def evaluate(s: String) = lisp2string(lisp.evaluate(s)); + + def run = { + + Console.println(string2lisp("(lambda (x) (+ (* x x) 1))").asInstanceOf[AnyRef]); + Console.println(lisp2string(string2lisp("(lambda (x) (+ (* x x) 1))"))); + Console.println; + + Console.println("( '(1 2 3)) = " + evaluate(" (quote(1 2 3))")); + Console.println("(car '(1 2 3)) = " + evaluate("(car (quote(1 2 3)))")); + Console.println("(cdr '(1 2 3)) = " + evaluate("(cdr (quote(1 2 3)))")); + Console.println("(null? '(2 3)) = " + evaluate("(null? (quote(2 3)))")); + Console.println("(null? '()) = " + evaluate("(null? (quote()))")); + Console.println; + + Console.println("faculty(10) = " + evaluate( + "(def (faculty n) " + + "(if (= n 0) " + + "1 " + + "(* n (faculty (- n 1)))) " + + "(faculty 10))")); + Console.println("faculty(10) = " + evaluate( + "(def (faculty n) " + + "(cond " + + "((= n 0) 1) " + + "(else (* n (faculty (- n 1))))) " + + "(faculty 10))")); + Console.println("foobar = " + evaluate( + "(def (foo n) " + + "(cond " + + "((= n 0) \"a\")" + + "((= n 1) \"b\")" + + "((= (/ n 2) 1) " + + "(cond " + + "((= n 2) \"c\")" + + "(else \"d\")))" + + "(else " + + "(def (bar m) " + + "(cond " + + "((= m 0) \"e\")" + + "((= m 1) \"f\")" + + "(else \"z\"))" + + "(bar (- n 4)))))" + + "(val nil (quote ())" + + "(val v1 (foo 0) " + + "(val v2 (+ (foo 1) (foo 2)) " + + "(val v3 (+ (+ (foo 3) (foo 4)) (foo 5)) " + + "(val v4 (foo 6) " + + "(cons v1 (cons v2 (cons v3 (cons v4 nil))))))))))")); + Console.println; + } +} + +//############################################################################ +// Main + +object Test { + def main(args: Array[String]): Unit = { + new LispUser(LispCaseClasses).run; + new LispUser(LispAny).run; + () + } +} + +//############################################################################ diff --git a/tests/untried/pos/t4593.scala b/tests/untried/pos/t4593.scala new file mode 100644 index 000000000..250f68216 --- /dev/null +++ b/tests/untried/pos/t4593.scala @@ -0,0 +1,20 @@ +// ticket #4593 +trait A { + + class B + case object D extends B + + class C { + + var x: B = D + + def y = synchronized { + x match { + case D => {} + } + } + + } + +} + diff --git a/tests/untried/pos/t460.scala b/tests/untried/pos/t460.scala new file mode 100644 index 000000000..3fc13e4dd --- /dev/null +++ b/tests/untried/pos/t460.scala @@ -0,0 +1,9 @@ +object Bug460 { + def testFun(x : Int, y : Int) = x + y + val fn = testFun _ + + fn(1, 2) // Ok + (testFun(_, _))(1, 2) // Ok + (testFun _).apply(1, 2) + (testFun _)(1, 2) // Error! (but no longer) +} diff --git a/tests/untried/pos/t4603/J.java b/tests/untried/pos/t4603/J.java new file mode 100644 index 000000000..0c3f6b2bf --- /dev/null +++ b/tests/untried/pos/t4603/J.java @@ -0,0 +1,7 @@ +// J.java +public class J<T> { + public static void f(java.lang.Class<? extends J> cls) { } + // correctly it should be like this, and then it would work. + // unfortunately that doesn't mean we don't have to deal with it. + // public static void f(java.lang.Class<? extends J<?>> cls) { } +} diff --git a/tests/untried/pos/t4603/S.scala b/tests/untried/pos/t4603/S.scala new file mode 100644 index 000000000..c1364202b --- /dev/null +++ b/tests/untried/pos/t4603/S.scala @@ -0,0 +1,8 @@ +// S.scala +class S extends J[AnyRef] + +object Test { + def main(args:Array[String]): Unit = { + J.f(classOf[S]) + } +} diff --git a/tests/untried/pos/t464.scala b/tests/untried/pos/t464.scala new file mode 100644 index 000000000..9afa5b804 --- /dev/null +++ b/tests/untried/pos/t464.scala @@ -0,0 +1,13 @@ +class A { + protected[this] def f(): Unit = {} +} +class B extends A { + f() + super.f() +} +class C extends A { + override protected[this] def f() = super.f() +} +class D extends C { + override protected def f() = super.f() +} diff --git a/tests/untried/pos/t4649.flags b/tests/untried/pos/t4649.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t4649.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t4649.scala b/tests/untried/pos/t4649.scala new file mode 100644 index 000000000..0d6caa8d7 --- /dev/null +++ b/tests/untried/pos/t4649.scala @@ -0,0 +1,6 @@ +object Test { + // @annotation.tailrec + def lazyFilter[E](s: Stream[E], p: E => Boolean): Stream[E] = s match { + case h #:: t => if (p(h)) h #:: lazyFilter(t, p) else lazyFilter(t, p) + } +} diff --git a/tests/untried/pos/t4651.scala b/tests/untried/pos/t4651.scala new file mode 100644 index 000000000..0612a8fcf --- /dev/null +++ b/tests/untried/pos/t4651.scala @@ -0,0 +1,12 @@ +object Test { + def analyze(x: Any) = x match { + case s: String => println("It's a string: " + s) + case 1 => println("It's a one") + case (a: Int, b) => println("It's a pair of and int " + a + + " and something " + b) + case 1 :: 2 :: _ => println("It's a list starting with 1, 2") + case List(a, b, c) => println("It's a three-element list with " + + a + ", " + b + ", " + c) + case _ => println("It's something different") + } +} diff --git a/tests/untried/pos/t4692.scala b/tests/untried/pos/t4692.scala new file mode 100644 index 000000000..2ed98a6ee --- /dev/null +++ b/tests/untried/pos/t4692.scala @@ -0,0 +1,27 @@ +class TypeAliasVsImplicitTest { + + class For[m[_], a](x: m[a]) { + def map[b](y: a => b): m[b] = throw new Error + } + implicit def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x) + + trait MyList[A] + + def foo(xs: MyList[Int]) = xs.map(x => x) // compiles fine. + + type MyListOfInt = MyList[Int] + def bar(xs: MyListOfInt) = xs.map(x => x) // doesn't compile: value map is not a member of TypeAliasVsImplicitTest.this.MyListOfInt +} + +// minimal case -- the bug was in type constructor inference where `xs.type` needed to be widened *and* dealiased +// in 2.8.1 implicit conversion search started with a widened type, so that combo never came up +// object Test { +// class For[m[_], a](x: m[a]) +// def toFor[m[_], a](x: m[a]): For[m, a] = new For[m, a](x) +// +// trait MyList[A] +// type MyListOfInt = MyList[Int] +// +// val xs: MyListOfInt = error("") +// toFor(xs : xs.type) +// } diff --git a/tests/untried/pos/t4716.scala b/tests/untried/pos/t4716.scala new file mode 100644 index 000000000..ec29e8d2c --- /dev/null +++ b/tests/untried/pos/t4716.scala @@ -0,0 +1,10 @@ + + + + +trait Bug2[@specialized(Int) +A] extends TraversableOnce[A] { + def ++[B >: A](that: TraversableOnce[B]) = { + lazy val it = that.toIterator + it + } +} diff --git a/tests/untried/pos/t4717.scala b/tests/untried/pos/t4717.scala new file mode 100644 index 000000000..ed35a8ad8 --- /dev/null +++ b/tests/untried/pos/t4717.scala @@ -0,0 +1,35 @@ + + + + + + + +trait Bug1[@specialized(Boolean) A] extends TraversableOnce[A] { + + def ++[B >: A](that: TraversableOnce[B]): Iterator[B] = new Iterator[B] { + lazy val it = that.toIterator + def hasNext = it.hasNext + def next = it.next + } + +} + + + +trait WorksFine[@specialized(Boolean) A] { + class SubBounds[B >: A] extends Bounds[B] { + lazy val it = ??? + } + def x[B >: A]: Unit = new SubBounds[B] +} + + +trait Bounds[@specialized(Boolean) A] { + // okay without `>: A` + def x[B >: A]: Unit = new Bounds[B] { + lazy val it = ??? // def or val okay + } +} + + diff --git a/tests/untried/pos/t4731.scala b/tests/untried/pos/t4731.scala new file mode 100644 index 000000000..d457543c1 --- /dev/null +++ b/tests/untried/pos/t4731.scala @@ -0,0 +1,14 @@ +import java.util.Comparator + +trait Trait1[T] { def foo(arg: Comparator[T]): Unit } + +trait Trait2[T] extends Trait1[T] { def foo(arg: Comparator[String]): Int = 0 } + +class Class1 extends Trait2[String] { } + +object Test { + def main(args: Array[String]): Unit = { + val c = new Class1 + c.foo(Ordering[String]) + } +} diff --git a/tests/untried/pos/t4737/J_1.java b/tests/untried/pos/t4737/J_1.java new file mode 100644 index 000000000..284afd6c1 --- /dev/null +++ b/tests/untried/pos/t4737/J_1.java @@ -0,0 +1,9 @@ +package j; + +public class J_1 { + protected class JavaInnerClass { + } + public void method(JavaInnerClass javaInnerclass) { + System.out.println("hello"); + } +} diff --git a/tests/untried/pos/t4737/S_2.scala b/tests/untried/pos/t4737/S_2.scala new file mode 100644 index 000000000..dc89d1316 --- /dev/null +++ b/tests/untried/pos/t4737/S_2.scala @@ -0,0 +1,10 @@ +package s + +import j.J_1 + +class ScalaSubClass extends J_1 { + override def method(javaInnerClass: J_1#JavaInnerClass): Unit = { + println("world") + } +} + diff --git a/tests/untried/pos/t4744.flags b/tests/untried/pos/t4744.flags new file mode 100644 index 000000000..ca20f5517 --- /dev/null +++ b/tests/untried/pos/t4744.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/untried/pos/t4744/Bar.scala b/tests/untried/pos/t4744/Bar.scala new file mode 100644 index 000000000..1fb6d7897 --- /dev/null +++ b/tests/untried/pos/t4744/Bar.scala @@ -0,0 +1 @@ +class Bar { val quux = new Foo[java.lang.Integer]() } diff --git a/tests/untried/pos/t4744/Foo.java b/tests/untried/pos/t4744/Foo.java new file mode 100644 index 000000000..6c764d047 --- /dev/null +++ b/tests/untried/pos/t4744/Foo.java @@ -0,0 +1 @@ +public class Foo<T extends Comparable<? super T>> {} diff --git a/tests/untried/pos/t4757/A_2.scala b/tests/untried/pos/t4757/A_2.scala new file mode 100644 index 000000000..63106a617 --- /dev/null +++ b/tests/untried/pos/t4757/A_2.scala @@ -0,0 +1,4 @@ +object A { + def ss = P.x(3)(Nil) +} + diff --git a/tests/untried/pos/t4757/B_3.scala b/tests/untried/pos/t4757/B_3.scala new file mode 100644 index 000000000..b50d1cd83 --- /dev/null +++ b/tests/untried/pos/t4757/B_3.scala @@ -0,0 +1,3 @@ +object C { + def x: Seq[S[_]] = A.ss +} diff --git a/tests/untried/pos/t4757/P_1.scala b/tests/untried/pos/t4757/P_1.scala new file mode 100644 index 000000000..8f01a4b66 --- /dev/null +++ b/tests/untried/pos/t4757/P_1.scala @@ -0,0 +1,6 @@ +trait S[T] + +object P { + def x(t: Int)(ss: Seq[S[_]]): Seq[S[_]] = ss +} + diff --git a/tests/untried/pos/t4758.scala b/tests/untried/pos/t4758.scala new file mode 100644 index 000000000..627dfd7a2 --- /dev/null +++ b/tests/untried/pos/t4758.scala @@ -0,0 +1,17 @@ +// /scala/trac/4758/a.scala +// Fri Dec 2 13:41:54 PST 2011 + +package bar { + // works + trait M[F[_]] + class S[X[_] <: M[X], A](val x:X[A]) + object S { + def apply[X[_] <: M[X], A](x: X[A]): S[X, A] = new S[X, A](x) + def unapply[X[_] <: M[X], A](p: S[X, A]) = Some(p.x) + } +} +package foo { + // seemingly equivalent, doesn't work + trait M[F[_]] + case class S[X[_] <: M[X], A](x: X[A]) +} diff --git a/tests/untried/pos/t4760.scala b/tests/untried/pos/t4760.scala new file mode 100644 index 000000000..d4407a86b --- /dev/null +++ b/tests/untried/pos/t4760.scala @@ -0,0 +1,34 @@ + +class Test { + // parses + def f1 = { + import scala._; + } + // b.scala:7: error: ';' expected but '}' found. + // } + // ^ + // one error found + def f2 = { + import scala._ + } + def f2b = { + import scala.collection.mutable.{ Map => MMap } + } + def f(): Unit = { + locally { + import scala.util.Properties.lineSeparator + } + } + + // parses + def f3 = { + import scala._ + 5 + } + locally { (x: Int) => + import scala.util._ + } + 1 match { + case 1 => import scala.concurrent._ + } +} diff --git a/tests/untried/pos/t4786.scala b/tests/untried/pos/t4786.scala new file mode 100644 index 000000000..f0579142b --- /dev/null +++ b/tests/untried/pos/t4786.scala @@ -0,0 +1,24 @@ +trait Matrix[@specialized A, Repr[C] <: Matrix[C, Repr]] { // crash goes away if @specialize is removed + def duplicate(mb: MatrixBuilder[A, Repr]): Repr[A] = { + mb.zeros + } +} +trait DenseMatrix[@specialized A] extends Matrix[A, DenseMatrix] +trait DenseMatrixFlt extends DenseMatrix[Float] + +trait MatrixBuilder[@specialized A, Repr[C] <: Matrix[C, Repr]] { + def zeros: Repr[A] +} +object DenseFloatBuilder extends MatrixBuilder[Float, DenseMatrix] { + val zeros = new Object with DenseMatrixFlt + // Note: + // - in 2.9 crash goes away if the explicit type "DenseMatrixFlt" is assigned to "zeros" + // - in 2.9 crash goes away if DenseMatrixFlt is a class instead of a trait: + // val zeros = new DenseMatrixFlt +} + +object Test extends App { + val m1 = DenseFloatBuilder.zeros // in 2.9 crash goes away if explicit type "DenseMatrixFlt" is assigned to m1 + val m2 = m1.duplicate(DenseFloatBuilder) +} + diff --git a/tests/untried/pos/t4812.scala b/tests/untried/pos/t4812.scala new file mode 100644 index 000000000..2a807ab05 --- /dev/null +++ b/tests/untried/pos/t4812.scala @@ -0,0 +1,4 @@ +trait Test1 { + def m1(sym: Symbol = 'TestSym) + def m2(s: String = "TestString") +} diff --git a/tests/untried/pos/t4831.scala b/tests/untried/pos/t4831.scala new file mode 100644 index 000000000..48002106e --- /dev/null +++ b/tests/untried/pos/t4831.scala @@ -0,0 +1,11 @@ +object O { + val a = 0 +} + + +object test { + val O1: O.type = O + val O2: O.type = O + import O1.a, O2.a + println(a) +} diff --git a/tests/untried/pos/t4840.flags b/tests/untried/pos/t4840.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/untried/pos/t4840.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/untried/pos/t4840.scala b/tests/untried/pos/t4840.scala new file mode 100644 index 000000000..bf44f71d7 --- /dev/null +++ b/tests/untried/pos/t4840.scala @@ -0,0 +1,13 @@ +class Crashy { + def g(): Option[Any] = None + + def crashy() = { + for (_ <- g()) { + (null: Any) match { + case Some(_) => 5 + case None => sys.error("") + } + } + } +} + diff --git a/tests/untried/pos/t4842.scala b/tests/untried/pos/t4842.scala new file mode 100644 index 000000000..17ff68483 --- /dev/null +++ b/tests/untried/pos/t4842.scala @@ -0,0 +1,26 @@ +class Foo (x: AnyRef) { + def this() = { + this(new { } ) // okay + } +} + + +class Blerg (x: AnyRef) { + def this() = { + this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay + } +} + + +class Outer { + class Inner (x: AnyRef) { + def this() = { + this(new { class Bar { println(Bar.this); new { println(Bar.this) } }; new Bar } ) // okay + } + + def this(x: Boolean) = { + this(new { println(Outer.this) } ) // okay + } + } +} + diff --git a/tests/untried/pos/t4853.scala b/tests/untried/pos/t4853.scala new file mode 100644 index 000000000..f227ef36e --- /dev/null +++ b/tests/untried/pos/t4853.scala @@ -0,0 +1,12 @@ +object Animal { + def main(args: Array[String]): Unit = { new Animal[Awake].goToSleep } +} + +class Animal[A <: AwakeOrAsleep] { + def goToSleep[B >: A <: Awake]: Animal[Asleep] = new Animal[Asleep] + def wakeUp[B >: A <: Asleep]: Animal[Awake] = new Animal[Awake] +} + +sealed trait AwakeOrAsleep +trait Awake extends AwakeOrAsleep +trait Asleep extends AwakeOrAsleep diff --git a/tests/untried/pos/t4859.scala b/tests/untried/pos/t4859.scala new file mode 100644 index 000000000..284a39b7a --- /dev/null +++ b/tests/untried/pos/t4859.scala @@ -0,0 +1,17 @@ +object O { + // error: C is not a legal prefix for a constructor + C().CC() + // but this works. + D().DD() +} + +case class C() { + case class CC() +} + +case class D() { + class DD() + object DD { + def apply() = new DD() + } +} diff --git a/tests/untried/pos/t4869.scala b/tests/untried/pos/t4869.scala new file mode 100644 index 000000000..f84aa4ed0 --- /dev/null +++ b/tests/untried/pos/t4869.scala @@ -0,0 +1,8 @@ +// /scala/trac/4869/a.scala +// Wed Jan 4 21:17:29 PST 2012 + +class C[T] +class A { + def f[T](x: T): C[_ <: T] = null + def g = List(1d) map f +} diff --git a/tests/untried/pos/t4910.scala b/tests/untried/pos/t4910.scala new file mode 100644 index 000000000..c66fd523f --- /dev/null +++ b/tests/untried/pos/t4910.scala @@ -0,0 +1,6 @@ +class A { + implicit object foo + // it compiles if we uncomment this + // implicit val bar = foo + implicitly[foo.type] +} diff --git a/tests/untried/pos/t4911.flags b/tests/untried/pos/t4911.flags new file mode 100644 index 000000000..779916d58 --- /dev/null +++ b/tests/untried/pos/t4911.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t4911.scala b/tests/untried/pos/t4911.scala new file mode 100644 index 000000000..cfb3792ae --- /dev/null +++ b/tests/untried/pos/t4911.scala @@ -0,0 +1,16 @@ +import language._ + +object Test { + class Foo[T](val x: T) ; object Foo { def unapply[T](x: Foo[T]) = Some(x.x) } + def f1[T](x: Foo[T]) = x match { case Foo(y) => y } + def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y } + + case class Bar[T](x: T) + def f3[T](x: Bar[T]) = x match { case Bar(y) => y } + def f4[M[_], T](x: M[T]) = x match { case Bar(y) => y } +} +// +// ./b.scala:4: warning: non variable type-argument T in type pattern Test.Foo[T] is unchecked since it is eliminated by erasure +// def f2[M[_], T](x: M[T]) = x match { case Foo(y) => y } +// ^ +// one warning found diff --git a/tests/untried/pos/t4938.scala b/tests/untried/pos/t4938.scala new file mode 100644 index 000000000..6e4131285 --- /dev/null +++ b/tests/untried/pos/t4938.scala @@ -0,0 +1,4 @@ +class A { + import scala.collection.mutable._ + val xs = List(Set(), Seq()) +} diff --git a/tests/untried/pos/t4957.scala b/tests/untried/pos/t4957.scala new file mode 100644 index 000000000..7f037ee25 --- /dev/null +++ b/tests/untried/pos/t4957.scala @@ -0,0 +1,89 @@ +// a.scala +// Sat Oct 29 10:06:51 PDT 2011 + +package simple + +import scala.{Double=>double, Int=>int} + +/** + * @author Christoph Radig + */ + +trait Vector { + + def xd: double + def yd: double +} + +object Vector { + + def apply(x: double, y: double) = Double(x, y) + def apply(x: int, y: int) = Int(x, y) + + trait Companion[@specialized(double, int) T] { + + type I <: Instance[T] + + def apply(x: T, y: T): I // I (= this.type#I) or this.I? + + lazy val zero: I = apply(numeric.zero, numeric.zero) + + val numeric: Numeric[T] + } + + trait Instance[@specialized(double, int) T] extends Vector { + + type C <: Companion[T] + def companion: C + + def numeric: Numeric[T] = companion.numeric + + val x: T + val y: T + + def xd = numeric.toDouble(x) + def yd = numeric.toDouble(y) + + def + (that: C#I): C#I = companion(numeric.plus(this.x, that.x), numeric.plus(this.y, that.y)) + def - (that: C#I): C#I = companion(numeric.minus(this.x, that.x), numeric.minus(this.y, that.y)) + + /** + * scalar multiplication + */ + def * (scalar: T): C#I = companion(numeric.times(this.x, scalar), numeric.times(this.y, scalar)) + } + + object Double extends Companion[double] { + + type I = Double + + def apply(x: double, y: double) = new Double(x, y) + + val numeric = Numeric.DoubleIsFractional + } + + final class Double(val x: double, val y: double) extends Instance[double] { + + type C = Double.type + def companion = Double + + @inline override def xd = x + @inline override def yd = y + } + + + object Int extends Companion[int] { + + type I = Int + + def apply(x: int, y: int) = new Int(x, y) + + val numeric = Numeric.IntIsIntegral + } + + final class Int(val x: int, val y: int) extends Instance[int] { + + type C = Int.type + def companion = Int + } +} diff --git a/tests/untried/pos/t4970.scala b/tests/untried/pos/t4970.scala new file mode 100644 index 000000000..f2f284f91 --- /dev/null +++ b/tests/untried/pos/t4970.scala @@ -0,0 +1,13 @@ +trait OuterClass[V <: OuterClass[V]#InnerClass] { + trait InnerClass {self: V => + def method = () + } +} + +trait SubOuterClass[T <: SubOuterClass[T]#SubInnerClass] extends OuterClass[T] { + class SubInnerClass extends super.InnerClass {self: T => } +} + +trait SubOuterClass2[T <: SubOuterClass2[T]#SubInnerClass2] extends OuterClass[T] { + class SubInnerClass2 extends super.InnerClass {self: InnerClass with T => } +} diff --git a/tests/untried/pos/t4970b.scala b/tests/untried/pos/t4970b.scala new file mode 100644 index 000000000..cf9a6a6ae --- /dev/null +++ b/tests/untried/pos/t4970b.scala @@ -0,0 +1,32 @@ +object Traits { + trait OuterClass[V <: OuterClass[V]#InnerClass] { + trait InnerClass {self: V => + def method = () + } + } + + trait SubOuterClass[T <: SubOuterClass[T]#SubInnerClass] extends OuterClass[T] { + trait SubInnerClass extends super.InnerClass {self: T => } + } + + trait SubOuterClass2[T <: SubOuterClass2[T]#SubInnerClass2] extends OuterClass[T] { + trait SubInnerClass2 extends super.InnerClass {self: InnerClass with T => } + } + +} + +// object Classes { +// class OuterClass[V <: OuterClass[V]#InnerClass] { +// class InnerClass {self: V => +// def method = () +// } +// } + +// class SubOuterClass[T <: SubOuterClass[T]#SubInnerClass] extends OuterClass[T] { +// class SubInnerClass extends super.InnerClass {self: T => } +// } + +// class SubOuterClass2[T <: SubOuterClass2[T]#SubInnerClass2] extends OuterClass[T] { +// class SubInnerClass2 extends super.InnerClass {self: InnerClass with T => } +// } +// } diff --git a/tests/untried/pos/t4975.scala b/tests/untried/pos/t4975.scala new file mode 100644 index 000000000..97ed9369e --- /dev/null +++ b/tests/untried/pos/t4975.scala @@ -0,0 +1,12 @@ +object ImplicitScope { + class A[T] + + def foo: Unit = { + trait B + object B { + implicit def ab = new A[B] + } + + implicitly[A[B]] // Error + } +} diff --git a/tests/untried/pos/t5012.scala b/tests/untried/pos/t5012.scala new file mode 100644 index 000000000..772b8f448 --- /dev/null +++ b/tests/untried/pos/t5012.scala @@ -0,0 +1,12 @@ +class D { + object p // (program point 1) +} + +class C { + def m: D = { + if("abc".length == 0) { + object p // (program point 2) + } + null + } +} diff --git a/tests/untried/pos/t5013/Bar_2.scala b/tests/untried/pos/t5013/Bar_2.scala new file mode 100644 index 000000000..9eac556a2 --- /dev/null +++ b/tests/untried/pos/t5013/Bar_2.scala @@ -0,0 +1,5 @@ +package b + +class Bar extends a.Foo { + println(x) // Error: Not found: value x +} diff --git a/tests/untried/pos/t5013/Foo_1.scala b/tests/untried/pos/t5013/Foo_1.scala new file mode 100644 index 000000000..ee21112a3 --- /dev/null +++ b/tests/untried/pos/t5013/Foo_1.scala @@ -0,0 +1,5 @@ +package a + +class Foo { + protected[Foo] var x = 0 +} diff --git a/tests/untried/pos/t5020.scala b/tests/untried/pos/t5020.scala new file mode 100644 index 000000000..28e674bf0 --- /dev/null +++ b/tests/untried/pos/t5020.scala @@ -0,0 +1,19 @@ +package a { + sealed trait GenericList[U, M[_ <: U]] { + type Transformed[N[MMA <: U]] <: GenericList[U, N] + } + + trait GenericCons[U, M[_ <: U], T <: GenericList[U, M]] extends GenericList[U, M] { + type Transformed[N[MMB <: U]] = GenericCons[U, N, GenericList[U, M]#Transformed[N]] + } +} + +package b { + sealed trait GenericList[L, M[_ >: L]] { + type Transformed[N[MMA >: L]] <: GenericList[L, N] + } + + trait GenericCons[L, M[_ >: L], T <: GenericList[L, M]] extends GenericList[L, M] { + type Transformed[N[MMB >: L]] = GenericCons[L, N, T#Transformed[N]] + } +} diff --git a/tests/untried/pos/t5022.scala b/tests/untried/pos/t5022.scala new file mode 100644 index 000000000..5db71c656 --- /dev/null +++ b/tests/untried/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/untried/pos/t5029.flags b/tests/untried/pos/t5029.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5029.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5029.scala b/tests/untried/pos/t5029.scala new file mode 100644 index 000000000..b68fc0367 --- /dev/null +++ b/tests/untried/pos/t5029.scala @@ -0,0 +1,3 @@ +object Test { + (Vector(): Seq[_]) match { case List() => true; case Nil => false } +} diff --git a/tests/untried/pos/t5031/Id.scala b/tests/untried/pos/t5031/Id.scala new file mode 100644 index 000000000..7bc3ebd34 --- /dev/null +++ b/tests/untried/pos/t5031/Id.scala @@ -0,0 +1,4 @@ +package t5031 + +object ID + diff --git a/tests/untried/pos/t5031/package.scala b/tests/untried/pos/t5031/package.scala new file mode 100644 index 000000000..c02e69db8 --- /dev/null +++ b/tests/untried/pos/t5031/package.scala @@ -0,0 +1,3 @@ +package object t5031 { + type ID = Int +} diff --git a/tests/untried/pos/t5031_2.scala b/tests/untried/pos/t5031_2.scala new file mode 100644 index 000000000..e51215db8 --- /dev/null +++ b/tests/untried/pos/t5031_2.scala @@ -0,0 +1,7 @@ +package object t5031 { + class ID +} + +package t5031 { + object ID +} diff --git a/tests/untried/pos/t5031_3/Foo_1.scala b/tests/untried/pos/t5031_3/Foo_1.scala new file mode 100644 index 000000000..5934a6ba7 --- /dev/null +++ b/tests/untried/pos/t5031_3/Foo_1.scala @@ -0,0 +1,5 @@ +package foo.bar + +object Foo { + def bar = 42 +} diff --git a/tests/untried/pos/t5031_3/Main_2.scala b/tests/untried/pos/t5031_3/Main_2.scala new file mode 100644 index 000000000..2079460b8 --- /dev/null +++ b/tests/untried/pos/t5031_3/Main_2.scala @@ -0,0 +1,6 @@ +package org.example + +object Main extends App { + println(foo.bar.Foo.bar) +} + diff --git a/tests/untried/pos/t5031_3/package.scala b/tests/untried/pos/t5031_3/package.scala new file mode 100644 index 000000000..23fede7d0 --- /dev/null +++ b/tests/untried/pos/t5031_3/package.scala @@ -0,0 +1,6 @@ +package foo + +package object bar { + type Foo = Int => String +} + diff --git a/tests/untried/pos/t5033.scala b/tests/untried/pos/t5033.scala new file mode 100644 index 000000000..3aa9fce5f --- /dev/null +++ b/tests/untried/pos/t5033.scala @@ -0,0 +1,15 @@ +trait Eater { + type Food[T] +} + +trait Fruit { + type Seed +} + +trait PipExtractor { + def extract(a: Fruit)(b: Eater): b.Food[a.Seed] +} + +trait LaserGuidedPipExtractor extends PipExtractor { + def extract(f: Fruit)(g: Eater): g.Food[f.Seed] +} diff --git a/tests/untried/pos/t5041.scala b/tests/untried/pos/t5041.scala new file mode 100644 index 000000000..78a1b27d5 --- /dev/null +++ b/tests/untried/pos/t5041.scala @@ -0,0 +1,9 @@ +case class Token(text: String, startIndex: Int) + +object Comment { + def unapply(s: String): Option[Token] = None +} + +object HiddenTokens { + "foo" match { case Comment(_) => } +} diff --git a/tests/untried/pos/t5071.scala b/tests/untried/pos/t5071.scala new file mode 100644 index 000000000..44ad6276f --- /dev/null +++ b/tests/untried/pos/t5071.scala @@ -0,0 +1,18 @@ +// abstract +trait Foo[@specialized A, Repr] { + self: Repr => +} +trait Bar[A] extends Foo[A, Object] { } +class Baz extends Foo[Int, Baz] { } + +// concrete +trait Bippy { + def f(x: Int) = 5 +} +trait FooC[@specialized A] { + self: Bippy => + + f(10) +} + +class BazC extends FooC[Int] with Bippy { } diff --git a/tests/untried/pos/t5082.scala b/tests/untried/pos/t5082.scala new file mode 100644 index 000000000..63eeda38b --- /dev/null +++ b/tests/untried/pos/t5082.scala @@ -0,0 +1,14 @@ +trait Something[T] +object Test { class A } +case class Test() extends Something[Test.A] + +object User { + val Test() = Test() +} + +object Wrap { + trait Something[T] + object Test { class A } + case class Test(a: Int, b: Int)(c: String) extends Something[Test.A] + val Test(x, y) = Test(1, 2)(""); (x + y).toString +} diff --git a/tests/untried/pos/t5084.scala b/tests/untried/pos/t5084.scala new file mode 100644 index 000000000..17d0a68ad --- /dev/null +++ b/tests/untried/pos/t5084.scala @@ -0,0 +1,5 @@ +case class Search(tpe: Search.Value) + +object Search { + type Value = String +} diff --git a/tests/untried/pos/t5099.scala b/tests/untried/pos/t5099.scala new file mode 100644 index 000000000..b41697e57 --- /dev/null +++ b/tests/untried/pos/t5099.scala @@ -0,0 +1,14 @@ +class LazyValVsFunctionType[a] { + val f: a => a = x => { + lazy val _x: a = throw new java.lang.Error("todo") + _x // error: type mismatch +/* +[error] found : a => => a +[error] required: a => a +[error] val f: a => a = x => { +[error] ^ +[error] one error found +*/ + // _x: a // ok + } +} diff --git a/tests/untried/pos/t5119.scala b/tests/untried/pos/t5119.scala new file mode 100644 index 000000000..4a67244e5 --- /dev/null +++ b/tests/untried/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/untried/pos/t5120.scala b/tests/untried/pos/t5120.scala new file mode 100644 index 000000000..5ec632d73 --- /dev/null +++ b/tests/untried/pos/t5120.scala @@ -0,0 +1,26 @@ +// An example extracted from SBT by Iulian +// that showed that the previous fix to t5120 +// was too strict. +class Test { + class ScopedKey[T] + class Value[T] + + class Compiled[T](val settings: Seq[Tuple2[T]]) + + case class Tuple2[T](k: ScopedKey[T], v: ScopedKey[T]) + + def transform[T](x: T) = x + + def test(compiledSettings: Seq[Compiled[_]]) = { + compiledSettings flatMap { cs => // cd: Compiled[_] in both versions + (cs.settings map { s => // cs.settings: Seq[Compiled[$1]] in trunk, Seq[Compiled[$1]] forSome $1 in 2.9.1 + // s: Pair[$1] in trunk, Pair[$1] in 2.9.1 + val t = transform(s.v) // t: ScopedKey[_] in trunk, ScopedKey[$1] in 2.9.1 + foo(s.k, t) + t + }) : Seq[ScopedKey[_]] + } + } + + def foo[T](x: ScopedKey[T], v: ScopedKey[T]): Unit = {} +} diff --git a/tests/untried/pos/t5127.scala b/tests/untried/pos/t5127.scala new file mode 100644 index 000000000..c2f3b923f --- /dev/null +++ b/tests/untried/pos/t5127.scala @@ -0,0 +1,8 @@ +package foo { + trait Abstract1[C <: Abstract2[C]] + trait Abstract2[C <: Abstract2[C]] extends Abstract1[C] + class Parametrized1[T] extends Abstract1[Parametrized2[T]] { + def bar(a: AnyRef): Unit = { a match { case d: Parametrized1[_] => println("ok") } } + } + class Parametrized2[T] extends Parametrized1[T] with Abstract2[Parametrized2[T]] +} diff --git a/tests/untried/pos/t5130.scala b/tests/untried/pos/t5130.scala new file mode 100644 index 000000000..676d3c705 --- /dev/null +++ b/tests/untried/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/untried/pos/t5137.scala b/tests/untried/pos/t5137.scala new file mode 100644 index 000000000..d5b6036df --- /dev/null +++ b/tests/untried/pos/t5137.scala @@ -0,0 +1,17 @@ +object Test { + + // okay + (1 * (List[BigInt]().map(((x0) => x0 match { + case x => x + })).sum)) + + // okay + ((1: BigInt) * (List[BigInt]().map({ + case x => x + }).sum)) + + // fail + (1 * (List[BigInt]().map({ + case x => x + }).sum)) +} diff --git a/tests/untried/pos/t514.scala b/tests/untried/pos/t514.scala new file mode 100644 index 000000000..188e4f2e5 --- /dev/null +++ b/tests/untried/pos/t514.scala @@ -0,0 +1,7 @@ +object Test extends App { + object Truc { + override def toString() = "oui" + def toString(bool: Boolean) = "chaispas" + } + val tata: String = Truc.toString +} diff --git a/tests/untried/pos/t5156.scala b/tests/untried/pos/t5156.scala new file mode 100644 index 000000000..129e97a52 --- /dev/null +++ b/tests/untried/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) = 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] = new Last[H :: HNil] + implicit def hlistLast[H, T <: HList](implicit lt : Last[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/untried/pos/t516.scala b/tests/untried/pos/t516.scala new file mode 100644 index 000000000..5561b7610 --- /dev/null +++ b/tests/untried/pos/t516.scala @@ -0,0 +1,14 @@ +import scala.collection.mutable._; +import scala.collection.script._; + +class Members; + +object subscriber extends Subscriber[Message[String] with Undoable, Members] { + def notify(pub: Members, event: Message[String] with Undoable): Unit = + (event: Message[String]) match { + case Include(l, elem) => Console.println("ADD: " + elem); + case Remove(l, elem) => Console.println("REM: " + elem); + //case i : Include[HasTree] with Undoable => + //case r : Remove [HasTree] with Undoable => + } + } diff --git a/tests/untried/pos/t5165/TestAnnotation.java b/tests/untried/pos/t5165/TestAnnotation.java new file mode 100644 index 000000000..90886b753 --- /dev/null +++ b/tests/untried/pos/t5165/TestAnnotation.java @@ -0,0 +1,11 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + public enum TestEnumOne { A, B } + public enum TestEnumTwo { C, D } + + public TestEnumOne one(); + public TestEnumTwo two(); + public String strVal(); +} diff --git a/tests/untried/pos/t5165/TestObject.scala b/tests/untried/pos/t5165/TestObject.scala new file mode 100644 index 000000000..eaf244e9d --- /dev/null +++ b/tests/untried/pos/t5165/TestObject.scala @@ -0,0 +1,3 @@ + +object TestObject extends TestTrait + diff --git a/tests/untried/pos/t5165/TestTrait.scala b/tests/untried/pos/t5165/TestTrait.scala new file mode 100644 index 000000000..b317e6c6a --- /dev/null +++ b/tests/untried/pos/t5165/TestTrait.scala @@ -0,0 +1,3 @@ + +@TestAnnotation(one=TestAnnotation.TestEnumOne.A, two=TestAnnotation.TestEnumTwo.C, strVal="something") +trait TestTrait diff --git a/tests/untried/pos/t5165b/TestAnnotation_1.java b/tests/untried/pos/t5165b/TestAnnotation_1.java new file mode 100644 index 000000000..02eb3f9d4 --- /dev/null +++ b/tests/untried/pos/t5165b/TestAnnotation_1.java @@ -0,0 +1,11 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation_1 { + public enum TestEnumOne { A, B } + public enum TestEnumTwo { C, D } + + public TestEnumOne one(); + public TestEnumTwo two(); + public String strVal(); +} diff --git a/tests/untried/pos/t5165b/TestObject_3.scala b/tests/untried/pos/t5165b/TestObject_3.scala new file mode 100644 index 000000000..eaf244e9d --- /dev/null +++ b/tests/untried/pos/t5165b/TestObject_3.scala @@ -0,0 +1,3 @@ + +object TestObject extends TestTrait + diff --git a/tests/untried/pos/t5165b/TestTrait_2.scala b/tests/untried/pos/t5165b/TestTrait_2.scala new file mode 100644 index 000000000..ab4facebc --- /dev/null +++ b/tests/untried/pos/t5165b/TestTrait_2.scala @@ -0,0 +1,3 @@ + +@TestAnnotation_1(one=TestAnnotation_1.TestEnumOne.A, two=TestAnnotation_1.TestEnumTwo.C, strVal="something") +trait TestTrait diff --git a/tests/untried/pos/t5175.flags b/tests/untried/pos/t5175.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5175.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5175.scala b/tests/untried/pos/t5175.scala new file mode 100644 index 000000000..ac909e1d9 --- /dev/null +++ b/tests/untried/pos/t5175.scala @@ -0,0 +1,9 @@ +object Test { + def ==(p: Phase): Int = 0 + + def foo: Unit = { + ==(new Phase()) + } +} + +class Phase diff --git a/tests/untried/pos/t5178.scala b/tests/untried/pos/t5178.scala new file mode 100644 index 000000000..ed0f814ec --- /dev/null +++ b/tests/untried/pos/t5178.scala @@ -0,0 +1,11 @@ +abstract class FileOps { + def withLock[R](start: Long = 0): Option[R] +} + +trait DefaultFileOps { + self: DefaultPath => + + override def withLock[R](start: Long = 5): Option[R] = None +} + +class DefaultPath extends FileOps with DefaultFileOps { } diff --git a/tests/untried/pos/t5198.scala b/tests/untried/pos/t5198.scala new file mode 100644 index 000000000..f403f77f7 --- /dev/null +++ b/tests/untried/pos/t5198.scala @@ -0,0 +1,15 @@ +package gaga + + + + + +trait Sys[Self <: Sys[Self]] { + type Tx +} + + +sealed trait AssocEntry[S <: Sys[S], @specialized(Int) A] { + def value: A + def value(implicit tx: S#Tx): A +} diff --git a/tests/untried/pos/t5210.scala b/tests/untried/pos/t5210.scala new file mode 100644 index 000000000..e85037a90 --- /dev/null +++ b/tests/untried/pos/t5210.scala @@ -0,0 +1,10 @@ +object WithOpTest { + trait WithOp extends Cloneable { + def f: this.type = this + def g1: this.type = f + def g2: this.type = { + val t = f + t + } + } +} diff --git a/tests/untried/pos/t522.scala b/tests/untried/pos/t522.scala new file mode 100644 index 000000000..e6eb25b6c --- /dev/null +++ b/tests/untried/pos/t522.scala @@ -0,0 +1,16 @@ +package imptwice + +class foo(s: String); + +object Util { + def foo(s: String) = new foo(s) +} + +import imptwice.Util._ + + +object User { + def main(args: Array[String]) = { + foo("blah") + } +} diff --git a/tests/untried/pos/t5223.scala b/tests/untried/pos/t5223.scala new file mode 100644 index 000000000..bfd1e153c --- /dev/null +++ b/tests/untried/pos/t5223.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Foo extends App { + reify{def printf(format: String, args: Any*): String = null } + reify{def printf(format: String, args: Any*): String = ("abc": @deprecated)} +} diff --git a/tests/untried/pos/t5240.scala b/tests/untried/pos/t5240.scala new file mode 100644 index 000000000..065d175f2 --- /dev/null +++ b/tests/untried/pos/t5240.scala @@ -0,0 +1,11 @@ + + + + + + +package object foo { + + var labels: Array[_ <: String] = null + +} diff --git a/tests/untried/pos/t5245.scala b/tests/untried/pos/t5245.scala new file mode 100644 index 000000000..45b54a67b --- /dev/null +++ b/tests/untried/pos/t5245.scala @@ -0,0 +1,3 @@ +object Foo { + def bar = { var x = (); def foo() = x } +} diff --git a/tests/untried/pos/t5259.scala b/tests/untried/pos/t5259.scala new file mode 100644 index 000000000..40c508f7d --- /dev/null +++ b/tests/untried/pos/t5259.scala @@ -0,0 +1,21 @@ +class A[T] +class B { + def m(a: A[this.type] = new A[this.type]): Unit = { } +} + +class C { + def foo(a: Int, b: Int = 0) = 0 + def foo() = 0 +} + +object Test { + def newB = new B + newB.m() + + val stableB = new B + stableB.m() + + def f: Unit = { + println((new C).foo(0)) + } +} diff --git a/tests/untried/pos/t530.scala b/tests/untried/pos/t530.scala new file mode 100644 index 000000000..6c887d682 --- /dev/null +++ b/tests/untried/pos/t530.scala @@ -0,0 +1,30 @@ +// scala.tools.nsc.Main.scala +package test; + +/** The main class for NSC, a compiler for the programming + * language Scala. + */ +object Test { +/* + def process(): AnyRef = { + class Compiler; + var compiler$module: Compiler = new Compiler; + def compiler() = compiler$module; + class Generator { + val c : Compiler = compiler() + } + var generator$module: Generator = new Generator; + def generator() = generator$module; + generator() + } +*/ + def process1(): AnyRef = { + object generator { + val c = compiler + } + object compiler; + generator + } + + +} diff --git a/tests/untried/pos/t5305.scala b/tests/untried/pos/t5305.scala new file mode 100644 index 000000000..c0237ca3b --- /dev/null +++ b/tests/untried/pos/t5305.scala @@ -0,0 +1,13 @@ +object t5305 { + def in(a: Any) = {} + + object O { + type F = Int + val v = "" + } + + in { + import O.{F, v} + type x = {type l = (F, v.type)} // not found: type F + } +} diff --git a/tests/untried/pos/t531.scala b/tests/untried/pos/t531.scala new file mode 100644 index 000000000..d18a5c886 --- /dev/null +++ b/tests/untried/pos/t531.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def titi = { + var truc = 0 + val tata = reify{() => { + truc = 6 + }} + () + } +} diff --git a/tests/untried/pos/t5313.scala b/tests/untried/pos/t5313.scala new file mode 100644 index 000000000..605e86879 --- /dev/null +++ b/tests/untried/pos/t5313.scala @@ -0,0 +1,30 @@ +object DepBug { + class A { + class B + def mkB = new B + def m(b : B) = b + } + + trait Dep { + val a : A + val b : a.B + } + + val dep = new Dep { + val a = new A + val b = a.mkB + } + + def useDep(d : Dep): Unit = { + import d._ + a.m(b) // OK + } + + { + import dep._ + a.m(b) // OK with 2.9.1.final, error on trunk + } + + dep.a.m(dep.b) + +} diff --git a/tests/untried/pos/t5317.scala b/tests/untried/pos/t5317.scala new file mode 100644 index 000000000..052e84438 --- /dev/null +++ b/tests/untried/pos/t5317.scala @@ -0,0 +1,12 @@ +object Test { + trait S { type T; val x: AnyRef } + trait A extends S { type T <: A; val x: A = null } + trait B extends S { type T <: B; val x: B = null } + + val a = new A{} + val b = new B{} + val y = if (true) a else b + + // lub of y should allow for this + println(y.x.x) +} diff --git a/tests/untried/pos/t532.scala b/tests/untried/pos/t532.scala new file mode 100644 index 000000000..9604c8afc --- /dev/null +++ b/tests/untried/pos/t532.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def titi: Unit = { + var truc = 0 + val tata = reify{() => { + truc = truc + 6 + }} + () + } +} diff --git a/tests/untried/pos/t533.scala b/tests/untried/pos/t533.scala new file mode 100644 index 000000000..9bc9995d9 --- /dev/null +++ b/tests/untried/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/untried/pos/t5330.scala b/tests/untried/pos/t5330.scala new file mode 100644 index 000000000..813acd4b8 --- /dev/null +++ b/tests/untried/pos/t5330.scala @@ -0,0 +1,22 @@ +trait FM[A] { + def map(f: A => Any) +} + +trait M[A] extends FM[A] { + def map(f: A => Any) +} + +trait N[A] extends FM[A] + +object test { + def kaboom(xs: M[_]) = xs map (x => ()) // missing parameter type. + + def okay1[A](xs: M[A]) = xs map (x => ()) + def okay2(xs: FM[_]) = xs map (x => ()) + def okay3(xs: N[_]) = xs map (x => ()) +} + +class CC2(xs: List[_]) { + def f(x1: Any, x2: Any) = null + def g = xs map (x => f(x, x)) +} diff --git a/tests/untried/pos/t5330b.scala b/tests/untried/pos/t5330b.scala new file mode 100644 index 000000000..dbeb165cd --- /dev/null +++ b/tests/untried/pos/t5330b.scala @@ -0,0 +1,6 @@ +abstract trait Base { + def foo: this.type +}; +class Derived[T] extends Base { + def foo: Nothing = sys.error("!!!") +} diff --git a/tests/untried/pos/t5330c.scala b/tests/untried/pos/t5330c.scala new file mode 100644 index 000000000..af31f3dfd --- /dev/null +++ b/tests/untried/pos/t5330c.scala @@ -0,0 +1,5 @@ +object t5330c { + val s: Set[_ >: Char] = Set('A') + s forall ("ABC" contains _) + s.forall( c => "ABC".toSeq.contains( c )) +} diff --git a/tests/untried/pos/t5359.scala b/tests/untried/pos/t5359.scala new file mode 100644 index 000000000..c22b2b1c7 --- /dev/null +++ b/tests/untried/pos/t5359.scala @@ -0,0 +1,17 @@ +// /scala/trac/5359/a.scala +// Thu Jan 5 13:31:05 PST 2012 + +object test { + trait Step[F[_]] { + // crash: typeConstructor inapplicable for <none> + this match { + case S1() => + } + } + case class S1[F[_]]() extends Step[F] + + // okay + (null: Step[Option]) match { + case S1() => + } +} diff --git a/tests/untried/pos/t5384.scala b/tests/untried/pos/t5384.scala new file mode 100644 index 000000000..4e297d593 --- /dev/null +++ b/tests/untried/pos/t5384.scala @@ -0,0 +1,7 @@ +class A(x: String, y: Int)(implicit o: String) +class B1(implicit o: String) extends A(y = 5, x = "a") +class B2(implicit o: String) extends A("a", 5) +class B3(implicit o: String) extends A(y = 5, x = "a")(o) + +class AM[E: Manifest](val x: Unit = (), y: Unit) +class BM[E: Manifest] extends AM[E](y = ()) diff --git a/tests/untried/pos/t5390.scala b/tests/untried/pos/t5390.scala new file mode 100644 index 000000000..d12bcf789 --- /dev/null +++ b/tests/untried/pos/t5390.scala @@ -0,0 +1,11 @@ +class A { + case class B[A](s: String) +} + +object X { + def foo: Unit = { + val a = new A + val b = new a.B[c.type]("") // not a forward reference + val c = "" + } +} diff --git a/tests/untried/pos/t5399.scala b/tests/untried/pos/t5399.scala new file mode 100644 index 000000000..0e7cce3c1 --- /dev/null +++ b/tests/untried/pos/t5399.scala @@ -0,0 +1,45 @@ +class Test { + class A[T] + class B[T](val a: A[T]) + + case class CaseClass[T](x: T) + + def break(existB: B[_]) = + CaseClass(existB.a) match { case CaseClass(_) => } +} + +class Foo { + trait Init[T] + class ScopedKey[T] extends Init[T] + + trait Setting[T] { + val key: ScopedKey[T] + } + + case class ScopedKey1[T](val foo: Init[T]) extends ScopedKey[T] + + val scalaHome: Setting[Option[String]] = null + val scalaVersion: Setting[String] = null + + def testPatternMatch(s: Setting[_]): Unit = { + s.key match { + case ScopedKey1(scalaHome.key | scalaVersion.key) => () + } + } +} + +class Test2 { + type AnyCyclic = Execute[Task]#CyclicException[_] + + trait Task[T] + + trait Execute[A[_] <: AnyRef] { + class CyclicException[T](val caller: A[T], val target: A[T]) + } + + def convertCyclic(c: AnyCyclic): String = + (c.caller, c.target) match { + case (caller: Task[_], target: Task[_]) => "bazinga!" + } +} + diff --git a/tests/untried/pos/t5399a.scala b/tests/untried/pos/t5399a.scala new file mode 100644 index 000000000..c40cef4f9 --- /dev/null +++ b/tests/untried/pos/t5399a.scala @@ -0,0 +1,19 @@ +class Foo { + trait Init[T] + class ScopedKey[T] extends Init[T] + + trait Setting[T] { + val key: ScopedKey[T] + } + + case class ScopedKey1[T](val foo: Init[T]) extends ScopedKey[T] + + val scalaHome: Setting[Option[String]] = null + val scalaVersion: Setting[String] = null + + def testPatternMatch(s: Setting[_]): Unit = { + s.key match { + case ScopedKey1(scalaHome.key | scalaVersion.key) => () + } + } +} diff --git a/tests/untried/pos/t5406.scala b/tests/untried/pos/t5406.scala new file mode 100644 index 000000000..c2e42c0ac --- /dev/null +++ b/tests/untried/pos/t5406.scala @@ -0,0 +1,4 @@ +object Wuffles { } +object Test { + def f = (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") } +} diff --git a/tests/untried/pos/t5444.scala b/tests/untried/pos/t5444.scala new file mode 100644 index 000000000..d40c01328 --- /dev/null +++ b/tests/untried/pos/t5444.scala @@ -0,0 +1,42 @@ +// /scala/trac/5444/a.scala +// Mon Feb 13 21:01:45 PST 2012 + +// Traits require identical names to reproduce. +class Test { + def a() = { + trait T { + def x() = 1 + } + trait U { + def x1() = 2 + } + class Bippy extends T with U { def z() = x() + x1() } + new Bippy + } + def b(): Unit = { + trait T { + def y() = 3 + trait T2 { + def yy() = 10 + } + } + trait U { + def y1() = 4 + trait T3 { + def yy() = 11 + } + } + class Bippy extends T with U { def z() = y() + y1() + (1 to (new T2 { }).yy()).map(_ + 1).sum } + (new Bippy).z() + } + def c(): Unit = { + trait T { + def z() = 5 + } + trait U { + def z1() = 6 + } + (new Test with T with U).z1() + } +} + diff --git a/tests/untried/pos/t5504/s_1.scala b/tests/untried/pos/t5504/s_1.scala new file mode 100644 index 000000000..35cb2c8ba --- /dev/null +++ b/tests/untried/pos/t5504/s_1.scala @@ -0,0 +1,4 @@ +// a.scala +package object foo { + val m: List[_] = Nil +} diff --git a/tests/untried/pos/t5504/s_2.scala b/tests/untried/pos/t5504/s_2.scala new file mode 100644 index 000000000..03eecf6e1 --- /dev/null +++ b/tests/untried/pos/t5504/s_2.scala @@ -0,0 +1,8 @@ +// b.scala +package foo + +object Test { + def main(args: Array[String]): Unit = { + println(foo.m) + } +} diff --git a/tests/untried/pos/t5508-min-okay.scala b/tests/untried/pos/t5508-min-okay.scala new file mode 100644 index 000000000..3a38b9c5e --- /dev/null +++ b/tests/untried/pos/t5508-min-okay.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private val _st : Int = 0 // crashes if changed to private[this] + val escape = { () => _st } + } +} diff --git a/tests/untried/pos/t5508-min-okay2.scala b/tests/untried/pos/t5508-min-okay2.scala new file mode 100644 index 000000000..935f28609 --- /dev/null +++ b/tests/untried/pos/t5508-min-okay2.scala @@ -0,0 +1,4 @@ +trait TopTrait { // must be nested and a trait + private[this] val _st : Int = 0 // crashes if TopTrait is not top level + val escape = { () => _st } +} diff --git a/tests/untried/pos/t5508-min.scala b/tests/untried/pos/t5508-min.scala new file mode 100644 index 000000000..f59d2bd6a --- /dev/null +++ b/tests/untried/pos/t5508-min.scala @@ -0,0 +1,6 @@ +object Test { + trait NestedTrait { // must be nested and a trait + private[this] val _st : Int = 0 // must be private[this] + val escape = { () => _st } + } +} diff --git a/tests/untried/pos/t5508.scala b/tests/untried/pos/t5508.scala new file mode 100644 index 000000000..2b4975804 --- /dev/null +++ b/tests/untried/pos/t5508.scala @@ -0,0 +1,83 @@ +package TestTestters + +trait Test1 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } +} + +object Base1 { + trait Test2 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = identity(_st) + } + } +} + +class Test3 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } +} + +object Base2 { + class Test4 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +class Base3 { + trait Test5 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => + _st = 1 + } + } +} + +object Base4 { + trait Test6 { + private[this] var _st : Int = 0 + def close : PartialFunction[Any,Any] = { + case x : Int => () + } + } +} + +object Base5 { + trait Test7 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base6 { + class Test8 { + private[this] var _st : Int = 0 + def close = () => { + _st = 1 + } + } +} + +object Base7 { + trait Test9 { + var st : Int = 0 + def close = () => { + st = 1 + } + } +} diff --git a/tests/untried/pos/t5541.scala b/tests/untried/pos/t5541.scala new file mode 100644 index 000000000..90e5e4130 --- /dev/null +++ b/tests/untried/pos/t5541.scala @@ -0,0 +1,61 @@ +package philips.adolf.paul + +trait Sys[ S <: Sys[ S ]] { + type Tx +} + +object HASkipList { + sealed trait NodeLike[ S <: Sys[ S ], @specialized( Int ) A ] { + def size : Int + def key( i: Int ): A + } + sealed trait Node[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def isLeaf : Boolean + def isBranch : Boolean + def asBranch : Branch[ S, A ] + } + sealed trait BranchLike[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def down( i: Int )( implicit tx: S#Tx ) : Node[ S, A ] = sys.error("") + } + sealed trait HeadOrBranch[ S <: Sys[ S ], A ] + final class Branch[ S <: Sys[ S ], @specialized( Int ) A ]() + extends BranchLike[ S, A ] with HeadOrBranch[ S, A ] with Node[ S, A ] { + def size:Int=1234 + def key(i: Int):A=sys.error("TODO") + def isLeaf : Boolean = false + def isBranch : Boolean = true + def asBranch : Branch[ S, A ] = this + } +} +sealed trait HASkipList[ S <: Sys[ S ], @specialized( Int ) A ] + +class HASkipListView[ S <: Sys[ S ], A ]( private val l: HASkipList[ S, A ])( implicit system: S ) { + import HASkipList.Node + private def buildBoxMap( n: Node[ S, A ], isRight: Boolean )( implicit tx: S#Tx ) : (Box, NodeBox) = { + val sz = n.size + val szm = sz - 1 + val keys = IndexedSeq.tabulate( sz ) { i => + val key = n.key( i ) + (key, if( isRight && i == szm ) "M" else key.toString) + } + val chbo = if( n.isLeaf ) None else { + val nb = n.asBranch + Some( IndexedSeq.tabulate( sz )( i => buildBoxMap( nb.down( i ), isRight && (i == szm) ))) + } + val b = NodeBox( n, keys, chbo.map( _.map( _._2 ))) + val bb = chbo match { + case Some( chbt ) => + val chb = chbt.map( _._1 ) + val h = Horiz( bs = chb ) + Vert( bs = IndexedSeq[Box]( b, h )) + case None => b + } + + (bb, b) + } + + private trait Box + private case class Horiz( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class Vert( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class NodeBox( n: Node[ S, A ], keys: IndexedSeq[ (A, String) ], downs: Option[ IndexedSeq[ NodeBox ]]) extends Box +} diff --git a/tests/untried/pos/t5542.flags b/tests/untried/pos/t5542.flags new file mode 100644 index 000000000..464cc20ea --- /dev/null +++ b/tests/untried/pos/t5542.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked
\ No newline at end of file diff --git a/tests/untried/pos/t5542.scala b/tests/untried/pos/t5542.scala new file mode 100644 index 000000000..0f1ef880a --- /dev/null +++ b/tests/untried/pos/t5542.scala @@ -0,0 +1,3 @@ +class Test { + Option(3) match { case Some(n) => n; case None => 0 } +} diff --git a/tests/untried/pos/t5545/S_1.scala b/tests/untried/pos/t5545/S_1.scala new file mode 100644 index 000000000..59ec1fd85 --- /dev/null +++ b/tests/untried/pos/t5545/S_1.scala @@ -0,0 +1,4 @@ +trait F[@specialized(Int) T1, R] { + def f(v1: T1): R + def g = v1 => f(v1) +} diff --git a/tests/untried/pos/t5545/S_2.scala b/tests/untried/pos/t5545/S_2.scala new file mode 100644 index 000000000..59ec1fd85 --- /dev/null +++ b/tests/untried/pos/t5545/S_2.scala @@ -0,0 +1,4 @@ +trait F[@specialized(Int) T1, R] { + def f(v1: T1): R + def g = v1 => f(v1) +} diff --git a/tests/untried/pos/t5546.scala b/tests/untried/pos/t5546.scala new file mode 100644 index 000000000..8269bf18f --- /dev/null +++ b/tests/untried/pos/t5546.scala @@ -0,0 +1 @@ +class A { def foo: Class[_ <: A] = getClass } diff --git a/tests/untried/pos/t5604/ReplConfig.scala b/tests/untried/pos/t5604/ReplConfig.scala new file mode 100644 index 000000000..8c589eba6 --- /dev/null +++ b/tests/untried/pos/t5604/ReplConfig.scala @@ -0,0 +1,53 @@ +/* NSC -- new Scala compiler + * Copyright 2005-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools.nsc +package interpreter + +import util.Exceptional.unwrap +import util.stackTraceString + +trait ReplConfig { + lazy val replProps = new ReplProps + + class TapMaker[T](x: T) { + def tapInfo(msg: => String): T = tap(x => replinfo(parens(x))) + def tapDebug(msg: => String): T = tap(x => repldbg(parens(x))) + def tapTrace(msg: => String): T = tap(x => repltrace(parens(x))) + def tap[U](f: T => U): T = { + f(x) + x + } + } + + private def parens(x: Any) = "(" + x + ")" + private def echo(msg: => String) = + try Console println msg + catch { case x: AssertionError => Console.println("Assertion error printing debugging output: " + x) } + + private[nsc] def repldbg(msg: => String) = if (isReplDebug) echo(msg) + private[nsc] def repltrace(msg: => String) = if (isReplTrace) echo(msg) + private[nsc] def replinfo(msg: => String) = if (isReplInfo) echo(msg) + + private[nsc] def logAndDiscard[T](label: String, alt: => T): PartialFunction[Throwable, T] = { + case t => + repldbg(label + ": " + unwrap(t)) + repltrace(stackTraceString(unwrap(t))) + alt + } + private[nsc] def substituteAndLog[T](alt: => T)(body: => T): T = + substituteAndLog("" + alt, alt)(body) + private[nsc] def substituteAndLog[T](label: String, alt: => T)(body: => T): T = { + try body + catch logAndDiscard(label, alt) + } + private[nsc] def squashAndLog(label: String)(body: => Unit): Unit = + substituteAndLog(label, ())(body) + + def isReplTrace: Boolean = replProps.trace + def isReplDebug: Boolean = replProps.debug || isReplTrace + def isReplInfo: Boolean = replProps.info || isReplDebug + def isReplPower: Boolean = replProps.power +} diff --git a/tests/untried/pos/t5604/ReplReporter.scala b/tests/untried/pos/t5604/ReplReporter.scala new file mode 100644 index 000000000..9423efd8a --- /dev/null +++ b/tests/untried/pos/t5604/ReplReporter.scala @@ -0,0 +1,30 @@ +/* NSC -- new Scala compiler + * Copyright 2002-2011 LAMP/EPFL + * @author Paul Phillips + */ + +package scala.tools.nsc +package interpreter + +import reporters._ +import IMain._ + +class ReplReporter(intp: IMain) extends ConsoleReporter(intp.settings, Console.in, new ReplStrippingWriter(intp)) { + override def printMessage(msg: String): Unit = { + // Avoiding deadlock if the compiler starts logging before + // the lazy val is complete. + if (intp.isInitializeComplete) { + if (intp.totalSilence) { + if (isReplTrace) + super.printMessage("[silent] " + msg) + } + else super.printMessage(msg) + } + else Console.println("[init] " + msg) + } + + override def displayPrompt(): Unit = { + if (intp.totalSilence) () + else super.displayPrompt() + } +} diff --git a/tests/untried/pos/t5604b/T_1.scala b/tests/untried/pos/t5604b/T_1.scala new file mode 100644 index 000000000..179dcb10c --- /dev/null +++ b/tests/untried/pos/t5604b/T_1.scala @@ -0,0 +1,6 @@ +// sandbox/t5604/T.scala +package t6504 + +trait T { + def foo: Boolean = false +} diff --git a/tests/untried/pos/t5604b/T_2.scala b/tests/untried/pos/t5604b/T_2.scala new file mode 100644 index 000000000..179dcb10c --- /dev/null +++ b/tests/untried/pos/t5604b/T_2.scala @@ -0,0 +1,6 @@ +// sandbox/t5604/T.scala +package t6504 + +trait T { + def foo: Boolean = false +} diff --git a/tests/untried/pos/t5604b/Test_1.scala b/tests/untried/pos/t5604b/Test_1.scala new file mode 100644 index 000000000..f7c58ebe8 --- /dev/null +++ b/tests/untried/pos/t5604b/Test_1.scala @@ -0,0 +1,7 @@ +// sandbox/t5604/Test.scala +package t6504 + +object Test { + def blerg1(a: Any): Any = if (foo) blerg1(0) + def blerg2(a: Any): Any = if (t6504.foo) blerg2(0) +} diff --git a/tests/untried/pos/t5604b/Test_2.scala b/tests/untried/pos/t5604b/Test_2.scala new file mode 100644 index 000000000..f7c58ebe8 --- /dev/null +++ b/tests/untried/pos/t5604b/Test_2.scala @@ -0,0 +1,7 @@ +// sandbox/t5604/Test.scala +package t6504 + +object Test { + def blerg1(a: Any): Any = if (foo) blerg1(0) + def blerg2(a: Any): Any = if (t6504.foo) blerg2(0) +} diff --git a/tests/untried/pos/t5604b/pack_1.scala b/tests/untried/pos/t5604b/pack_1.scala new file mode 100644 index 000000000..f50d568bf --- /dev/null +++ b/tests/untried/pos/t5604b/pack_1.scala @@ -0,0 +1,5 @@ +// sandbox/t5604/pack.scala +package t6504 + +object `package` extends T { +} diff --git a/tests/untried/pos/t5606.scala b/tests/untried/pos/t5606.scala new file mode 100644 index 000000000..2545271e3 --- /dev/null +++ b/tests/untried/pos/t5606.scala @@ -0,0 +1,9 @@ + + + + + + + + +case class CaseTest[_](someData:String) diff --git a/tests/untried/pos/t5626.scala b/tests/untried/pos/t5626.scala new file mode 100644 index 000000000..c501dfbe6 --- /dev/null +++ b/tests/untried/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/untried/pos/t5639/Bar.scala b/tests/untried/pos/t5639/Bar.scala new file mode 100644 index 000000000..f577500ac --- /dev/null +++ b/tests/untried/pos/t5639/Bar.scala @@ -0,0 +1,7 @@ +package pack.age + +import pack.age.Implicits._ + +object Quux { + def baz : Baz = 1 +} diff --git a/tests/untried/pos/t5639/Foo.scala b/tests/untried/pos/t5639/Foo.scala new file mode 100644 index 000000000..1a07734a8 --- /dev/null +++ b/tests/untried/pos/t5639/Foo.scala @@ -0,0 +1,7 @@ +package pack.age + +class Baz + +object Implicits { + implicit def Baz(n: Int): Baz = new Baz +} diff --git a/tests/untried/pos/t5644/BoxesRunTime.java b/tests/untried/pos/t5644/BoxesRunTime.java new file mode 100644 index 000000000..74c4c6b4b --- /dev/null +++ b/tests/untried/pos/t5644/BoxesRunTime.java @@ -0,0 +1,836 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2013, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + + +package scala.runtime; + +import java.io.*; +import scala.math.ScalaNumber; + +/** An object (static class) that defines methods used for creating, + * reverting, and calculating with, boxed values. There are four classes + * of methods in this object: + * - Convenience boxing methods which call the static valueOf method + * on the boxed class, thus utilizing the JVM boxing cache. + * - Convenience unboxing methods returning default value on null. + * - The generalised comparison method to be used when an object may + * be a boxed value. + * - Standard value operators for boxed number and quasi-number values. + * + * @author Gilles Dubochet + * @author Martin Odersky + * @contributor Stepan Koltsov + * @version 2.0 */ +public final class BoxesRunTime +{ + private static final int CHAR = 0, BYTE = 1, SHORT = 2, INT = 3, LONG = 4, FLOAT = 5, DOUBLE = 6, OTHER = 7; + + /** We don't need to return BYTE and SHORT, as everything which might + * care widens to INT. + */ + private static int typeCode(Object a) { + if (a instanceof java.lang.Integer) return INT; + if (a instanceof java.lang.Double) return DOUBLE; + if (a instanceof java.lang.Long) return LONG; + if (a instanceof java.lang.Character) return CHAR; + if (a instanceof java.lang.Float) return FLOAT; + if ((a instanceof java.lang.Byte) || (a instanceof java.lang.Short)) return INT; + return OTHER; + } + + private static int eqTypeCode(Number a) { + int code = typeCode(a); + if (code == CHAR) + return OTHER; + else + return code; + } + + private static String boxDescription(Object a) { + return "" + a.getClass().getSimpleName() + "(" + a + ")"; + } + +/* BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING ... BOXING */ + + public static java.lang.Boolean boxToBoolean(boolean b) { + return java.lang.Boolean.valueOf(b); + } + + public static java.lang.Character boxToCharacter(char c) { + return java.lang.Character.valueOf(c); + } + + public static java.lang.Byte boxToByte(byte b) { + return java.lang.Byte.valueOf(b); + } + + public static java.lang.Short boxToShort(short s) { + return java.lang.Short.valueOf(s); + } + + public static java.lang.Integer boxToInteger(int i) { + return java.lang.Integer.valueOf(i); + } + + public static java.lang.Long boxToLong(long l) { + return java.lang.Long.valueOf(l); + } + + public static java.lang.Float boxToFloat(float f) { + return java.lang.Float.valueOf(f); + } + + public static java.lang.Double boxToDouble(double d) { + // System.out.println("box " + d); + // (new Throwable()).printStackTrace(); + return java.lang.Double.valueOf(d); + } + +/* UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING ... UNBOXING */ + + public static boolean unboxToBoolean(Object b) { + return b == null ? false : ((java.lang.Boolean)b).booleanValue(); + } + + public static char unboxToChar(Object c) { + return c == null ? 0 : ((java.lang.Character)c).charValue(); + } + + public static byte unboxToByte(Object b) { + return b == null ? 0 : ((java.lang.Byte)b).byteValue(); + } + + public static short unboxToShort(Object s) { + return s == null ? 0 : ((java.lang.Short)s).shortValue(); + } + + public static int unboxToInt(Object i) { + return i == null ? 0 : ((java.lang.Integer)i).intValue(); + } + + public static long unboxToLong(Object l) { + return l == null ? 0 : ((java.lang.Long)l).longValue(); + } + + public static float unboxToFloat(Object f) { + return f == null ? 0.0f : ((java.lang.Float)f).floatValue(); + } + + public static double unboxToDouble(Object d) { + // System.out.println("unbox " + d); + return d == null ? 0.0d : ((java.lang.Double)d).doubleValue(); + } + + /* COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON ... COMPARISON */ + + public static boolean equals(Object x, Object y) { + if (x == y) return true; + return equals2(x, y); + } + + /** Since all applicable logic has to be present in the equals method of a ScalaNumber + * in any case, we dispatch to it as soon as we spot one on either side. + */ + public static boolean equals2(Object x, Object y) { + if (x instanceof java.lang.Number) + return equalsNumObject((java.lang.Number)x, y); + if (x instanceof java.lang.Character) + return equalsCharObject((java.lang.Character)x, y); + if (x == null) + return y == null; + + return x.equals(y); + } + + public static boolean equalsNumObject(java.lang.Number xn, Object y) { + if (y instanceof java.lang.Number) + return equalsNumNum(xn, (java.lang.Number)y); + if (y instanceof java.lang.Character) + return equalsNumChar(xn, (java.lang.Character)y); + if (xn == null) + return y == null; + + return xn.equals(y); + } + + public static boolean equalsNumNum(java.lang.Number xn, java.lang.Number yn) { + int xcode = eqTypeCode(xn); + int ycode = eqTypeCode(yn); + switch (ycode > xcode ? ycode : xcode) { + case INT: + return xn.intValue() == yn.intValue(); + case LONG: + return xn.longValue() == yn.longValue(); + case FLOAT: + return xn.floatValue() == yn.floatValue(); + case DOUBLE: + return xn.doubleValue() == yn.doubleValue(); + default: + if ((yn instanceof ScalaNumber) && !(xn instanceof ScalaNumber)) + return yn.equals(xn); + } + if (xn == null) + return yn == null; + + return xn.equals(yn); + } + + public static boolean equalsCharObject(java.lang.Character xc, Object y) { + if (y instanceof java.lang.Character) + return xc.charValue() == ((java.lang.Character)y).charValue(); + if (y instanceof java.lang.Number) + return equalsNumChar((java.lang.Number)y, xc); + if (xc == null) + return y == null; + + return xc.equals(y); + } + + private static boolean equalsNumChar(java.lang.Number xn, java.lang.Character yc) { + if (yc == null) + return xn == null; + + char ch = yc.charValue(); + switch (eqTypeCode(xn)) { + case INT: + return xn.intValue() == ch; + case LONG: + return xn.longValue() == ch; + case FLOAT: + return xn.floatValue() == ch; + case DOUBLE: + return xn.doubleValue() == ch; + default: + return xn.equals(yc); + } + } + + /** Hashcode algorithm is driven by the requirements imposed + * by primitive equality semantics, namely that equal objects + * have equal hashCodes. The first priority are the integral/char + * types, which already have the same hashCodes for the same + * values except for Long. So Long's hashCode is altered to + * conform to Int's for all values in Int's range. + * + * Float is problematic because it's far too small to hold + * all the Ints, so for instance Int.MaxValue.toFloat claims + * to be == to each of the largest 64 Ints. There is no way + * to preserve equals/hashCode alignment without compromising + * the hashCode distribution, so Floats are only guaranteed + * to have the same hashCode for whole Floats in the range + * Short.MinValue to Short.MaxValue (2^16 total.) + * + * Double has its hashCode altered to match the entire Int range, + * but is not guaranteed beyond that. (But could/should it be? + * The hashCode is only 32 bits so this is a more tractable + * issue than Float's, but it might be better simply to exclude it.) + * + * Note: BigInt and BigDecimal, being arbitrary precision, could + * be made consistent with all other types for the Int range, but + * as yet have not. + * + * Note: Among primitives, Float.NaN != Float.NaN, but the boxed + * verisons are equal. This still needs reconciliation. + */ + public static int hashFromLong(java.lang.Long n) { + int iv = n.intValue(); + if (iv == n.longValue()) return iv; + else return n.hashCode(); + } + public static int hashFromDouble(java.lang.Double n) { + int iv = n.intValue(); + double dv = n.doubleValue(); + if (iv == dv) return iv; + + long lv = n.longValue(); + if (lv == dv) return java.lang.Long.valueOf(lv).hashCode(); + else return n.hashCode(); + } + public static int hashFromFloat(java.lang.Float n) { + int iv = n.intValue(); + float fv = n.floatValue(); + if (iv == fv) return iv; + + long lv = n.longValue(); + if (lv == fv) return java.lang.Long.valueOf(lv).hashCode(); + else return n.hashCode(); + } + public static int hashFromNumber(java.lang.Number n) { + if (n instanceof java.lang.Long) return hashFromLong((java.lang.Long)n); + else if (n instanceof java.lang.Double) return hashFromDouble((java.lang.Double)n); + else if (n instanceof java.lang.Float) return hashFromFloat((java.lang.Float)n); + else return n.hashCode(); + } + public static int hashFromObject(Object a) { + if (a instanceof Number) return hashFromNumber((Number)a); + else return a.hashCode(); + } + + private static int unboxCharOrInt(Object arg1, int code) { + if (code == CHAR) + return ((java.lang.Character) arg1).charValue(); + else + return ((java.lang.Number) arg1).intValue(); + } + private static long unboxCharOrLong(Object arg1, int code) { + if (code == CHAR) + return ((java.lang.Character) arg1).charValue(); + else + return ((java.lang.Number) arg1).longValue(); + } + private static float unboxCharOrFloat(Object arg1, int code) { + if (code == CHAR) + return ((java.lang.Character) arg1).charValue(); + else + return ((java.lang.Number) arg1).floatValue(); + } + private static double unboxCharOrDouble(Object arg1, int code) { + if (code == CHAR) + return ((java.lang.Character) arg1).charValue(); + else + return ((java.lang.Number) arg1).doubleValue(); + } + +/* OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS ... OPERATORS */ + + /** arg1 + arg2 */ + public static Object add(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + return boxToInteger(unboxCharOrInt(arg1, code1) + unboxCharOrInt(arg2, code2)); + } + if (maxcode <= LONG) { + return boxToLong(unboxCharOrLong(arg1, code1) + unboxCharOrLong(arg2, code2)); + } + if (maxcode <= FLOAT) { + return boxToFloat(unboxCharOrFloat(arg1, code1) + unboxCharOrFloat(arg2, code2)); + } + if (maxcode <= DOUBLE) { + return boxToDouble(unboxCharOrDouble(arg1, code1) + unboxCharOrDouble(arg2, code2)); + } + throw new NoSuchMethodException(); + } + + /** arg1 - arg2 */ + public static Object subtract(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + return boxToInteger(unboxCharOrInt(arg1, code1) - unboxCharOrInt(arg2, code2)); + } + if (maxcode <= LONG) { + return boxToLong(unboxCharOrLong(arg1, code1) - unboxCharOrLong(arg2, code2)); + } + if (maxcode <= FLOAT) { + return boxToFloat(unboxCharOrFloat(arg1, code1) - unboxCharOrFloat(arg2, code2)); + } + if (maxcode <= DOUBLE) { + return boxToDouble(unboxCharOrDouble(arg1, code1) - unboxCharOrDouble(arg2, code2)); + } + throw new NoSuchMethodException(); + } + + /** arg1 * arg2 */ + public static Object multiply(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + return boxToInteger(unboxCharOrInt(arg1, code1) * unboxCharOrInt(arg2, code2)); + } + if (maxcode <= LONG) { + return boxToLong(unboxCharOrLong(arg1, code1) * unboxCharOrLong(arg2, code2)); + } + if (maxcode <= FLOAT) { + return boxToFloat(unboxCharOrFloat(arg1, code1) * unboxCharOrFloat(arg2, code2)); + } + if (maxcode <= DOUBLE) { + return boxToDouble(unboxCharOrDouble(arg1, code1) * unboxCharOrDouble(arg2, code2)); + } + throw new NoSuchMethodException(); + } + + /** arg1 / arg2 */ + public static Object divide(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + + if (maxcode <= INT) + return boxToInteger(unboxCharOrInt(arg1, code1) / unboxCharOrInt(arg2, code2)); + if (maxcode <= LONG) + return boxToLong(unboxCharOrLong(arg1, code1) / unboxCharOrLong(arg2, code2)); + if (maxcode <= FLOAT) + return boxToFloat(unboxCharOrFloat(arg1, code1) / unboxCharOrFloat(arg2, code2)); + if (maxcode <= DOUBLE) + return boxToDouble(unboxCharOrDouble(arg1, code1) / unboxCharOrDouble(arg2, code2)); + + throw new NoSuchMethodException(); + } + + /** arg1 % arg2 */ + public static Object takeModulo(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + + if (maxcode <= INT) + return boxToInteger(unboxCharOrInt(arg1, code1) % unboxCharOrInt(arg2, code2)); + if (maxcode <= LONG) + return boxToLong(unboxCharOrLong(arg1, code1) % unboxCharOrLong(arg2, code2)); + if (maxcode <= FLOAT) + return boxToFloat(unboxCharOrFloat(arg1, code1) % unboxCharOrFloat(arg2, code2)); + if (maxcode <= DOUBLE) + return boxToDouble(unboxCharOrDouble(arg1, code1) % unboxCharOrDouble(arg2, code2)); + + throw new NoSuchMethodException(); + } + + /** arg1 >> arg2 */ + public static Object shiftSignedRight(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + if (code1 <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToInteger(val1 >> val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToInteger(val1 >> val2); + } + } + if (code1 <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToLong(val1 >> val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToLong(val1 >> val2); + } + } + throw new NoSuchMethodException(); + } + + /** arg1 << arg2 */ + public static Object shiftSignedLeft(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + if (code1 <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToInteger(val1 << val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToInteger(val1 << val2); + } + } + if (code1 <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToLong(val1 << val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToLong(val1 << val2); + } + } + throw new NoSuchMethodException(); + } + + /** arg1 >>> arg2 */ + public static Object shiftLogicalRight(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + if (code1 <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToInteger(val1 >>> val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToInteger(val1 >>> val2); + } + } + if (code1 <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + if (code2 <= INT) { + int val2 = unboxCharOrInt(arg2, code2); + return boxToLong(val1 >>> val2); + } + if (code2 <= LONG) { + long val2 = unboxCharOrLong(arg2, code2); + return boxToLong(val1 >>> val2); + } + } + throw new NoSuchMethodException(); + } + + /** -arg */ + public static Object negate(Object arg) throws NoSuchMethodException { + int code = typeCode(arg); + if (code <= INT) { + int val = unboxCharOrInt(arg, code); + return boxToInteger(-val); + } + if (code <= LONG) { + long val = unboxCharOrLong(arg, code); + return boxToLong(-val); + } + if (code <= FLOAT) { + float val = unboxCharOrFloat(arg, code); + return boxToFloat(-val); + } + if (code <= DOUBLE) { + double val = unboxCharOrDouble(arg, code); + return boxToDouble(-val); + } + throw new NoSuchMethodException(); + } + + /** +arg */ + public static Object positive(Object arg) throws NoSuchMethodException { + int code = typeCode(arg); + if (code <= INT) { + return boxToInteger(+unboxCharOrInt(arg, code)); + } + if (code <= LONG) { + return boxToLong(+unboxCharOrLong(arg, code)); + } + if (code <= FLOAT) { + return boxToFloat(+unboxCharOrFloat(arg, code)); + } + if (code <= DOUBLE) { + return boxToDouble(+unboxCharOrDouble(arg, code)); + } + throw new NoSuchMethodException(); + } + + /** arg1 & arg2 */ + public static Object takeAnd(Object arg1, Object arg2) throws NoSuchMethodException { + if ((arg1 instanceof Boolean) || (arg2 instanceof Boolean)) { + if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) + return boxToBoolean(((java.lang.Boolean) arg1).booleanValue() & ((java.lang.Boolean) arg2).booleanValue()); + else + throw new NoSuchMethodException(); + } + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + + if (maxcode <= INT) + return boxToInteger(unboxCharOrInt(arg1, code1) & unboxCharOrInt(arg2, code2)); + if (maxcode <= LONG) + return boxToLong(unboxCharOrLong(arg1, code1) & unboxCharOrLong(arg2, code2)); + + throw new NoSuchMethodException(); + } + + /** arg1 | arg2 */ + public static Object takeOr(Object arg1, Object arg2) throws NoSuchMethodException { + if ((arg1 instanceof Boolean) || (arg2 instanceof Boolean)) { + if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) + return boxToBoolean(((java.lang.Boolean) arg1).booleanValue() & ((java.lang.Boolean) arg2).booleanValue()); + else + throw new NoSuchMethodException(); + } + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + + if (maxcode <= INT) + return boxToInteger(unboxCharOrInt(arg1, code1) | unboxCharOrInt(arg2, code2)); + if (maxcode <= LONG) + return boxToLong(unboxCharOrLong(arg1, code1) | unboxCharOrLong(arg2, code2)); + + throw new NoSuchMethodException(); + } + + /** arg1 ^ arg2 */ + public static Object takeXor(Object arg1, Object arg2) throws NoSuchMethodException { + if ((arg1 instanceof Boolean) || (arg2 instanceof Boolean)) { + if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) + return boxToBoolean(((java.lang.Boolean) arg1).booleanValue() & ((java.lang.Boolean) arg2).booleanValue()); + else + throw new NoSuchMethodException(); + } + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + + if (maxcode <= INT) + return boxToInteger(unboxCharOrInt(arg1, code1) ^ unboxCharOrInt(arg2, code2)); + if (maxcode <= LONG) + return boxToLong(unboxCharOrLong(arg1, code1) ^ unboxCharOrLong(arg2, code2)); + + throw new NoSuchMethodException(); + } + + /** arg1 && arg2 */ + public static Object takeConditionalAnd(Object arg1, Object arg2) throws NoSuchMethodException { + if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) { + return boxToBoolean(((java.lang.Boolean) arg1).booleanValue() && ((java.lang.Boolean) arg2).booleanValue()); + } + throw new NoSuchMethodException(); + } + + /** arg1 || arg2 */ + public static Object takeConditionalOr(Object arg1, Object arg2) throws NoSuchMethodException { + if ((arg1 instanceof Boolean) && (arg2 instanceof Boolean)) { + return boxToBoolean(((java.lang.Boolean) arg1).booleanValue() || ((java.lang.Boolean) arg2).booleanValue()); + } + throw new NoSuchMethodException(); + } + + /** ~arg */ + public static Object complement(Object arg) throws NoSuchMethodException { + int code = typeCode(arg); + if (code <= INT) { + return boxToInteger(~unboxCharOrInt(arg, code)); + } + if (code <= LONG) { + return boxToLong(~unboxCharOrLong(arg, code)); + } + throw new NoSuchMethodException(); + } + + /** !arg */ + public static Object takeNot(Object arg) throws NoSuchMethodException { + if (arg instanceof Boolean) { + return boxToBoolean(!((java.lang.Boolean) arg).booleanValue()); + } + throw new NoSuchMethodException(); + } + + public static Object testEqual(Object arg1, Object arg2) throws NoSuchMethodException { + return boxToBoolean(arg1 == arg2); + } + + public static Object testNotEqual(Object arg1, Object arg2) throws NoSuchMethodException { + return boxToBoolean(arg1 != arg2); + } + + public static Object testLessThan(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + int val2 = unboxCharOrInt(arg2, code2); + return boxToBoolean(val1 < val2); + } + if (maxcode <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + long val2 = unboxCharOrLong(arg2, code2); + return boxToBoolean(val1 < val2); + } + if (maxcode <= FLOAT) { + float val1 = unboxCharOrFloat(arg1, code1); + float val2 = unboxCharOrFloat(arg2, code2); + return boxToBoolean(val1 < val2); + } + if (maxcode <= DOUBLE) { + double val1 = unboxCharOrDouble(arg1, code1); + double val2 = unboxCharOrDouble(arg2, code2); + return boxToBoolean(val1 < val2); + } + throw new NoSuchMethodException(); + } + + public static Object testLessOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + int val2 = unboxCharOrInt(arg2, code2); + return boxToBoolean(val1 <= val2); + } + if (maxcode <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + long val2 = unboxCharOrLong(arg2, code2); + return boxToBoolean(val1 <= val2); + } + if (maxcode <= FLOAT) { + float val1 = unboxCharOrFloat(arg1, code1); + float val2 = unboxCharOrFloat(arg2, code2); + return boxToBoolean(val1 <= val2); + } + if (maxcode <= DOUBLE) { + double val1 = unboxCharOrDouble(arg1, code1); + double val2 = unboxCharOrDouble(arg2, code2); + return boxToBoolean(val1 <= val2); + } + throw new NoSuchMethodException(); + } + + public static Object testGreaterOrEqualThan(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + int val2 = unboxCharOrInt(arg2, code2); + return boxToBoolean(val1 >= val2); + } + if (maxcode <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + long val2 = unboxCharOrLong(arg2, code2); + return boxToBoolean(val1 >= val2); + } + if (maxcode <= FLOAT) { + float val1 = unboxCharOrFloat(arg1, code1); + float val2 = unboxCharOrFloat(arg2, code2); + return boxToBoolean(val1 >= val2); + } + if (maxcode <= DOUBLE) { + double val1 = unboxCharOrDouble(arg1, code1); + double val2 = unboxCharOrDouble(arg2, code2); + return boxToBoolean(val1 >= val2); + } + throw new NoSuchMethodException(); + } + + public static Object testGreaterThan(Object arg1, Object arg2) throws NoSuchMethodException { + int code1 = typeCode(arg1); + int code2 = typeCode(arg2); + int maxcode = (code1 < code2) ? code2 : code1; + if (maxcode <= INT) { + int val1 = unboxCharOrInt(arg1, code1); + int val2 = unboxCharOrInt(arg2, code2); + return boxToBoolean(val1 > val2); + } + if (maxcode <= LONG) { + long val1 = unboxCharOrLong(arg1, code1); + long val2 = unboxCharOrLong(arg2, code2); + return boxToBoolean(val1 > val2); + } + if (maxcode <= FLOAT) { + float val1 = unboxCharOrFloat(arg1, code1); + float val2 = unboxCharOrFloat(arg2, code2); + return boxToBoolean(val1 > val2); + } + if (maxcode <= DOUBLE) { + double val1 = unboxCharOrDouble(arg1, code1); + double val2 = unboxCharOrDouble(arg2, code2); + return boxToBoolean(val1 > val2); + } + throw new NoSuchMethodException(); + } + + public static boolean isBoxedNumberOrBoolean(Object arg) { + return (arg instanceof java.lang.Boolean) || isBoxedNumber(arg); + } + public static boolean isBoxedNumber(Object arg) { + return ( + (arg instanceof java.lang.Integer) + || (arg instanceof java.lang.Long) + || (arg instanceof java.lang.Double) + || (arg instanceof java.lang.Float) + || (arg instanceof java.lang.Short) + || (arg instanceof java.lang.Character) + || (arg instanceof java.lang.Byte) + ); + } + + /** arg.toChar */ + public static java.lang.Character toCharacter(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToCharacter((char)unboxToInt(arg)); + if (arg instanceof java.lang.Short) return boxToCharacter((char)unboxToShort(arg)); + if (arg instanceof java.lang.Character) return (java.lang.Character)arg; + if (arg instanceof java.lang.Long) return boxToCharacter((char)unboxToLong(arg)); + if (arg instanceof java.lang.Byte) return boxToCharacter((char)unboxToByte(arg)); + if (arg instanceof java.lang.Float) return boxToCharacter((char)unboxToFloat(arg)); + if (arg instanceof java.lang.Double) return boxToCharacter((char)unboxToDouble(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toByte */ + public static java.lang.Byte toByte(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToByte((byte)unboxToInt(arg)); + if (arg instanceof java.lang.Character) return boxToByte((byte)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return (java.lang.Byte)arg; + if (arg instanceof java.lang.Long) return boxToByte((byte)unboxToLong(arg)); + if (arg instanceof java.lang.Short) return boxToByte((byte)unboxToShort(arg)); + if (arg instanceof java.lang.Float) return boxToByte((byte)unboxToFloat(arg)); + if (arg instanceof java.lang.Double) return boxToByte((byte)unboxToDouble(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toShort */ + public static java.lang.Short toShort(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToShort((short)unboxToInt(arg)); + if (arg instanceof java.lang.Long) return boxToShort((short)unboxToLong(arg)); + if (arg instanceof java.lang.Character) return boxToShort((short)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return boxToShort((short)unboxToByte(arg)); + if (arg instanceof java.lang.Short) return (java.lang.Short)arg; + if (arg instanceof java.lang.Float) return boxToShort((short)unboxToFloat(arg)); + if (arg instanceof java.lang.Double) return boxToShort((short)unboxToDouble(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toInt */ + public static java.lang.Integer toInteger(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return (java.lang.Integer)arg; + if (arg instanceof java.lang.Long) return boxToInteger((int)unboxToLong(arg)); + if (arg instanceof java.lang.Double) return boxToInteger((int)unboxToDouble(arg)); + if (arg instanceof java.lang.Float) return boxToInteger((int)unboxToFloat(arg)); + if (arg instanceof java.lang.Character) return boxToInteger((int)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return boxToInteger((int)unboxToByte(arg)); + if (arg instanceof java.lang.Short) return boxToInteger((int)unboxToShort(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toLong */ + public static java.lang.Long toLong(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToLong((long)unboxToInt(arg)); + if (arg instanceof java.lang.Double) return boxToLong((long)unboxToDouble(arg)); + if (arg instanceof java.lang.Float) return boxToLong((long)unboxToFloat(arg)); + if (arg instanceof java.lang.Long) return (java.lang.Long)arg; + if (arg instanceof java.lang.Character) return boxToLong((long)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return boxToLong((long)unboxToByte(arg)); + if (arg instanceof java.lang.Short) return boxToLong((long)unboxToShort(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toFloat */ + public static java.lang.Float toFloat(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToFloat((float)unboxToInt(arg)); + if (arg instanceof java.lang.Long) return boxToFloat((float)unboxToLong(arg)); + if (arg instanceof java.lang.Float) return (java.lang.Float)arg; + if (arg instanceof java.lang.Double) return boxToFloat((float)unboxToDouble(arg)); + if (arg instanceof java.lang.Character) return boxToFloat((float)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return boxToFloat((float)unboxToByte(arg)); + if (arg instanceof java.lang.Short) return boxToFloat((float)unboxToShort(arg)); + throw new NoSuchMethodException(); + } + + /** arg.toDouble */ + public static java.lang.Double toDouble(Object arg) throws NoSuchMethodException { + if (arg instanceof java.lang.Integer) return boxToDouble((double)unboxToInt(arg)); + if (arg instanceof java.lang.Float) return boxToDouble((double)unboxToFloat(arg)); + if (arg instanceof java.lang.Double) return (java.lang.Double)arg; + if (arg instanceof java.lang.Long) return boxToDouble((double)unboxToLong(arg)); + if (arg instanceof java.lang.Character) return boxToDouble((double)unboxToChar(arg)); + if (arg instanceof java.lang.Byte) return boxToDouble((double)unboxToByte(arg)); + if (arg instanceof java.lang.Short) return boxToDouble((double)unboxToShort(arg)); + throw new NoSuchMethodException(); + } + +} diff --git a/tests/untried/pos/t5644/other.scala b/tests/untried/pos/t5644/other.scala new file mode 100644 index 000000000..50388fd9e --- /dev/null +++ b/tests/untried/pos/t5644/other.scala @@ -0,0 +1,3 @@ +class Foo { + List(1) exists(_ == (null: Any)) +} diff --git a/tests/untried/pos/t5654.scala b/tests/untried/pos/t5654.scala new file mode 100644 index 000000000..1f8d05bfe --- /dev/null +++ b/tests/untried/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/untried/pos/t566.scala b/tests/untried/pos/t566.scala new file mode 100644 index 000000000..6a2a0a362 --- /dev/null +++ b/tests/untried/pos/t566.scala @@ -0,0 +1,4 @@ +object test { + def foo[a](ys: List[a]): List[a] = + return ys.head :: ys.tail +} diff --git a/tests/untried/pos/t5667.scala b/tests/untried/pos/t5667.scala new file mode 100644 index 000000000..353eec93d --- /dev/null +++ b/tests/untried/pos/t5667.scala @@ -0,0 +1,4 @@ +object Main { + implicit class C(val s: String) extends AnyVal + implicit class C2(val s: String) extends AnyRef +} diff --git a/tests/untried/pos/t5692a.check b/tests/untried/pos/t5692a.check new file mode 100644 index 000000000..7fbfb5dba --- /dev/null +++ b/tests/untried/pos/t5692a.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: this type parameter must be specified + def x = Macros.foo + ^ +one error found diff --git a/tests/untried/pos/t5692a.flags b/tests/untried/pos/t5692a.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/t5692a.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/t5692a/Macros_1.scala b/tests/untried/pos/t5692a/Macros_1.scala new file mode 100644 index 000000000..6e5069aff --- /dev/null +++ b/tests/untried/pos/t5692a/Macros_1.scala @@ -0,0 +1,6 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl[T](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def foo[T] = macro impl[T] +} diff --git a/tests/untried/pos/t5692a/Test_2.scala b/tests/untried/pos/t5692a/Test_2.scala new file mode 100644 index 000000000..72ecd9576 --- /dev/null +++ b/tests/untried/pos/t5692a/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + def x = Macros.foo +} diff --git a/tests/untried/pos/t5692b.check b/tests/untried/pos/t5692b.check new file mode 100644 index 000000000..16796826b --- /dev/null +++ b/tests/untried/pos/t5692b.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: these type parameters must be specified + def x = Macros.foo + ^ +one error found diff --git a/tests/untried/pos/t5692b.flags b/tests/untried/pos/t5692b.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/t5692b.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/t5692b/Macros_1.scala b/tests/untried/pos/t5692b/Macros_1.scala new file mode 100644 index 000000000..82109075f --- /dev/null +++ b/tests/untried/pos/t5692b/Macros_1.scala @@ -0,0 +1,6 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl[T, U](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } + def foo[T, U] = macro impl[T, U] +} diff --git a/tests/untried/pos/t5692b/Test_2.scala b/tests/untried/pos/t5692b/Test_2.scala new file mode 100644 index 000000000..72ecd9576 --- /dev/null +++ b/tests/untried/pos/t5692b/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + def x = Macros.foo +} diff --git a/tests/untried/pos/t5692c.scala b/tests/untried/pos/t5692c.scala new file mode 100644 index 000000000..f9a9c4aa5 --- /dev/null +++ b/tests/untried/pos/t5692c.scala @@ -0,0 +1,4 @@ +class C { + def foo[T: scala.reflect.ClassTag](xs: T*): Array[T] = ??? + foo() +} diff --git a/tests/untried/pos/t5702-pos-infix-star.scala b/tests/untried/pos/t5702-pos-infix-star.scala new file mode 100644 index 000000000..9b2dfafcf --- /dev/null +++ b/tests/untried/pos/t5702-pos-infix-star.scala @@ -0,0 +1,15 @@ + +object Test { + case class *(a: Int, b: Int) + type Star = * + case class P(a: Int, b: Star) // alias still required + + def main(args: Array[String]): Unit = { + val v = new *(6,7) + val x * y = v + printf("%d,%d\n",x,y) + val p = P(5, v) + val P(a, b * c) = p + printf("%d,%d,%d\n",a,b,c) + } +} diff --git a/tests/untried/pos/t5703/Base.java b/tests/untried/pos/t5703/Base.java new file mode 100644 index 000000000..fa75cc3bd --- /dev/null +++ b/tests/untried/pos/t5703/Base.java @@ -0,0 +1,3 @@ +public abstract class Base<Params> { + public abstract void func(Params[] params); +}
\ No newline at end of file diff --git a/tests/untried/pos/t5703/Impl.scala b/tests/untried/pos/t5703/Impl.scala new file mode 100644 index 000000000..f0120ef0b --- /dev/null +++ b/tests/untried/pos/t5703/Impl.scala @@ -0,0 +1,3 @@ +class Implementation extends Base[Object] { + def func(params: Array[Object]): Unit = {} +} diff --git a/tests/untried/pos/t5706.flags b/tests/untried/pos/t5706.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/t5706.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/t5706.scala b/tests/untried/pos/t5706.scala new file mode 100644 index 000000000..6f0207366 --- /dev/null +++ b/tests/untried/pos/t5706.scala @@ -0,0 +1,15 @@ +import scala.reflect.macros.blackbox.{Context => BlackboxContext} +import scala.reflect.macros.whitebox.{Context => WhiteboxContext} + +class Logger { + def error1(message: String) = macro Impls.error1 + def error2(message: String) = macro Impls.error2 +} + +object Impls { + type LoggerContext1 = BlackboxContext { type PrefixType = Logger } + def error1(c: LoggerContext1)(message: c.Expr[String]): c.Expr[Unit] = ??? + + type LoggerContext2 = WhiteboxContext { type PrefixType = Logger } + def error2(c: LoggerContext2)(message: c.Expr[String]): c.Expr[Unit] = ??? +} diff --git a/tests/untried/pos/t5720-ownerous.scala b/tests/untried/pos/t5720-ownerous.scala new file mode 100644 index 000000000..e171ce9c2 --- /dev/null +++ b/tests/untried/pos/t5720-ownerous.scala @@ -0,0 +1,56 @@ + +/* + * The block under qual$1 must be owned by it. + * In the sample bug, the first default arg generates x$4, + * the second default arg generates qual$1, hence the maximal + * minimization. + * + <method> <triedcooking> def model: C.this.M = { + val qual$1: C.this.M = scala.Option.apply[C.this.M]({ + val x$1: lang.this.String("foo") = "foo"; + val x$2: String = C.this.M.apply$default$2("foo"); + C.this.M.apply("foo")(x$2) +}).getOrElse[C.this.M]({ + val x$3: lang.this.String("bar") = "bar"; + val x$4: String = C.this.M.apply$default$2("bar"); + C.this.M.apply("bar")(x$4) + }); + val x$5: lang.this.String("baz") = "baz"; + val x$6: String = qual$1.copy$default$2("baz"); + qual$1.copy("baz")(x$6) + } + */ +class C { + case class M(currentUser: String = "anon")(val message: String = "empty") + val m = M("foo")() + + // reported + //def model = Option(M("foo")()).getOrElse(M("bar")()).copy(currentUser = "")() + + // the bug + def model = Option(m).getOrElse(M("bar")()).copy("baz")("empty") + + // style points for this version + def modish = ((null: Option[M]) getOrElse new M()()).copy()("empty") + + // various simplifications are too simple + case class N(currentUser: String = "anon") + val n = N("fun") + def nudel = Option(n).getOrElse(N()).copy() +} + +object Test { + def main(args: Array[String]): Unit = { + val c = new C + println(c.model.currentUser) + println(c.model.message) + } +} +/* +symbol value x$4$1 does not exist in badcopy.C.model +at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:45) +at scala.tools.nsc.Global.abort(Global.scala:202) +at scala.tools.nsc.backend.icode.GenICode$ICodePhase.liftedTree2$1(GenICode.scala:998) +at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:992) +*/ + diff --git a/tests/untried/pos/t5726.scala b/tests/untried/pos/t5726.scala new file mode 100644 index 000000000..1ef14ac79 --- /dev/null +++ b/tests/untried/pos/t5726.scala @@ -0,0 +1,17 @@ +import scala.language.dynamics + +class DynamicTest extends Dynamic { + def selectDynamic(name: String) = s"value of $name" + def updateDynamic(name: String)(value: Any): Unit = { + println(s"You have just updated property '$name' with value: $value") + } +} + +object MyApp extends App { + def testing(): Unit = { + val test = new DynamicTest + test.firstName = "John" + } + + testing() +} diff --git a/tests/untried/pos/t5727.scala b/tests/untried/pos/t5727.scala new file mode 100644 index 000000000..2c6c0f305 --- /dev/null +++ b/tests/untried/pos/t5727.scala @@ -0,0 +1,31 @@ + +/* + * We like operators, bar none. + */ +object Test { + + trait SomeInfo + case object NoInfo extends SomeInfo + + sealed abstract class Res[+T] + case object NotRes extends Res[Nothing] + + + abstract class Base[+T] { + def apply(f: String): Res[T] + // 'i' crashes the compiler, similarly if we use currying + //def |[U >: T](a: => Base[U], i: SomeInfo = NoInfo): Base[U] = null + def bar[U >: T](a: => Base[U], i: SomeInfo = NoInfo): Base[U] = null + } + + implicit def fromStringToBase(a: String): Base[String] = new Base[String] { def apply(in: String) = NotRes } + + // bug + //def Sample: Base[Any] = ( rep("foo" | "bar") | "sth") + def Sample: Base[Any] = ( rep("foo" bar "bar") bar "sth") + + def rep[T](p: => Base[T]): Base[T] = null // whatever + + def main(args: Array[String]): Unit = { + } +} diff --git a/tests/untried/pos/t5729.scala b/tests/untried/pos/t5729.scala new file mode 100644 index 000000000..944aa04d8 --- /dev/null +++ b/tests/untried/pos/t5729.scala @@ -0,0 +1,6 @@ +trait T[X] +object Test { + def join(in: Seq[T[_]]): Int = ??? + def join[S](in: Seq[T[S]]): String = ??? + join(null: Seq[T[_]]) +} diff --git a/tests/untried/pos/t573.scala b/tests/untried/pos/t573.scala new file mode 100644 index 000000000..694d001e3 --- /dev/null +++ b/tests/untried/pos/t573.scala @@ -0,0 +1,43 @@ +package lampion.collections; + +object DirX { + abstract class Dir { + def reverse : Dir; + } + object BEFORE extends Dir { + def reverse = AFTER; + } + object AFTER extends Dir { + def reverse = BEFORE; + } +} + +import DirX._; + +abstract class Linked { + type Node <: Node0; + + abstract class Node0 { + self: Node => + + var next : Node = _; + var prev : Node = _; + + def get(dir : Dir) = if (dir == BEFORE) prev; else next; + private def set(dir : Dir, node : Node) = + if (dir == BEFORE) prev = node; else next = node; + + def link(dir : Dir, node : Node) = { + assert(get(dir) == null); + assert(node.get(dir.reverse) == null); + set(dir, node); + node.set(dir.reverse, self); + } + + + def end(dir : Dir) : Node = { + if (get(dir) == null) this; + else get(dir).end(dir); + } + } +} diff --git a/tests/untried/pos/t5738.scala b/tests/untried/pos/t5738.scala new file mode 100644 index 000000000..ec2b08e01 --- /dev/null +++ b/tests/untried/pos/t5738.scala @@ -0,0 +1,8 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def f[T](a: T, b: T) = { + reify(a.toString + b) + reify(a + b.toString) + } +} diff --git a/tests/untried/pos/t5742.scala b/tests/untried/pos/t5742.scala new file mode 100644 index 000000000..1cd73e0cb --- /dev/null +++ b/tests/untried/pos/t5742.scala @@ -0,0 +1,8 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def foo[T](a: T) = reify { + val x1 = a + val x2 = reify(a) + } +} diff --git a/tests/untried/pos/t5744/Macros_1.scala b/tests/untried/pos/t5744/Macros_1.scala new file mode 100644 index 000000000..11da37f17 --- /dev/null +++ b/tests/untried/pos/t5744/Macros_1.scala @@ -0,0 +1,22 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def foo[U: Numeric](x: U) = macro foo_impl[U] + def bar[U: Numeric : Equiv, Y <% String](x: U)(implicit s: String) = macro bar_impl[U, Y] + + def foo_impl[U](c: Context)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]]) = { + import c.universe._ + val plusOne = Apply(Select(numeric.tree, newTermName("plus")), List(x.tree, Literal(Constant(1)))) + val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(plusOne)) + c.Expr[Unit](body) + } + + def bar_impl[U, Y](c: Context)(x: c.Expr[U])(numeric: c.Expr[Numeric[U]], equiv: c.Expr[Equiv[U]], viewAsString: c.Expr[Y => String], s: c.Expr[String]) = { + import c.universe._ + val plusOne = Apply(Select(numeric.tree, newTermName("plus")), List(x.tree, Literal(Constant(1)))) + val plusLen = Apply(Select(numeric.tree, newTermName("plus")), List(plusOne, Select(s.tree, newTermName("length")))) + val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(plusLen)) + c.Expr[Unit](body) + } +} diff --git a/tests/untried/pos/t5744/Test_2.scala b/tests/untried/pos/t5744/Test_2.scala new file mode 100644 index 000000000..dc3de03e4 --- /dev/null +++ b/tests/untried/pos/t5744/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Macros._ + foo(42) + implicit val s = "" + bar(43) +} diff --git a/tests/untried/pos/t5756.scala b/tests/untried/pos/t5756.scala new file mode 100644 index 000000000..411f5b05d --- /dev/null +++ b/tests/untried/pos/t5756.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def tagme[T: TypeTag](x: T) = typeTag[T] + val foo = tagme{object Bar; Bar} +} diff --git a/tests/untried/pos/t5760-pkgobj-warn/stalepkg_1.scala b/tests/untried/pos/t5760-pkgobj-warn/stalepkg_1.scala new file mode 100644 index 000000000..a0256f633 --- /dev/null +++ b/tests/untried/pos/t5760-pkgobj-warn/stalepkg_1.scala @@ -0,0 +1,11 @@ + +package object stalepkg { + class Foo +} + +package stalepkg { + object Test { + def main(args: Array[String]): Unit = { + } + } +} diff --git a/tests/untried/pos/t5760-pkgobj-warn/stalepkg_2.scala b/tests/untried/pos/t5760-pkgobj-warn/stalepkg_2.scala new file mode 100644 index 000000000..924bf35fa --- /dev/null +++ b/tests/untried/pos/t5760-pkgobj-warn/stalepkg_2.scala @@ -0,0 +1,11 @@ + +package object stalepkg { +} + +package stalepkg { + class Foo + object Test { + def main(args: Array[String]): Unit = { + } + } +} diff --git a/tests/untried/pos/t5769.scala b/tests/untried/pos/t5769.scala new file mode 100644 index 000000000..d7ec23a56 --- /dev/null +++ b/tests/untried/pos/t5769.scala @@ -0,0 +1,9 @@ +// a.scala +import scala.reflect.{ClassTag, classTag} + +class A { + type AI = Array[Int] + + def f1 = classTag[Array[Int]] + def f2 = classTag[AI] +} diff --git a/tests/untried/pos/t577.scala b/tests/untried/pos/t577.scala new file mode 100644 index 000000000..ede45399a --- /dev/null +++ b/tests/untried/pos/t577.scala @@ -0,0 +1,21 @@ +trait PriorityTree { + type Node <: BasicTreeNode; + + val top = initTree; + top.next = (initTree); + top.next.prev = (top); + + def initTree : Node; + + + + + trait BasicTreeNode { + private[PriorityTree] var next : Node = _; + private[PriorityTree] var prev : Node = _; + private[PriorityTree] var chld : Node = _; + //var next : Node = _; + //var prev : Node = _; + //var chld : Node = _; + } +} diff --git a/tests/untried/pos/t5777.scala b/tests/untried/pos/t5777.scala new file mode 100644 index 000000000..24cea3616 --- /dev/null +++ b/tests/untried/pos/t5777.scala @@ -0,0 +1,45 @@ +// /scala/trac/5777/a.scala +// Wed May 9 08:44:57 PDT 2012 + +trait Ring { + trait E +} + +class Poly[C <: Ring](val ring: C) extends Ring +// This definition of Poly triggers the same failure on *both* versions +// class Poly(val ring: Ring) extends Ring + +object BigInt extends Ring + +object MyApp { + val r = new Poly(BigInt) + + implicitly[r.ring.E <:< BigInt.E] + + // fail on 2.10, works on 2.9.2 + (null.asInstanceOf[BigInt.E] : r.ring.E) + + // works on both versions + val r1 = new Poly[BigInt.type](BigInt) + (null.asInstanceOf[BigInt.E] : r1.ring.E) + + // Oddly, -Xprint:typer reports that r and r1 have the same inferred type. + // + // private[this] val r: Poly[BigInt.type] = new Poly[BigInt.type](BigInt); + // <stable> <accessor> def r: Poly[BigInt.type] = MyApp.this.r; + // (null.asInstanceOf[BigInt.E]: MyApp.r.ring.E); + // private[this] val r1: Poly[BigInt.type] = new Poly[BigInt.type](BigInt); + // <stable> <accessor> def r1: Poly[BigInt.type] = MyApp.this.r1; + // (null.asInstanceOf[BigInt.E]: MyApp.r1.ring.E) + + // diff typer-2.9.2.txt typer-2.10.txt + // ... + // --- + // > object MyApp extends scala.AnyRef { + // > def <init>(): MyApp.type = { + // > MyApp.super.<init>(); + // 30c30 + // < scala.this.Predef.implicitly[<:<[BigInt.E,MyApp.r.ring.E]](scala.this.Predef.conforms[BigInt.E]); + // --- + // > scala.this.Predef.implicitly[<:<[BigInt.E,MyApp.r.ring.E]](); +} diff --git a/tests/untried/pos/t5779-numeq-warn.scala b/tests/untried/pos/t5779-numeq-warn.scala new file mode 100644 index 000000000..61fd734f9 --- /dev/null +++ b/tests/untried/pos/t5779-numeq-warn.scala @@ -0,0 +1,13 @@ + +object Test { + def main(args: Array[String]): Unit = { + val d: Double = (BigInt(1) << 64).toDouble + val f: Float = d.toFloat + val n: java.lang.Number = d.toFloat + assert (d == f) // ok + assert (d == n) // was: comparing values of types Double and Number using `==' will always yield false + assert (n == d) // was: Number and Double are unrelated: they will most likely never compare equal + assert (f == n) + assert (n == f) + } +} diff --git a/tests/untried/pos/t578.scala b/tests/untried/pos/t578.scala new file mode 100644 index 000000000..6f95dd8ce --- /dev/null +++ b/tests/untried/pos/t578.scala @@ -0,0 +1,7 @@ +object Test { + val x = Nil + val x2: Nil.type = x + val y = None + val y2: None.type = y + Console.println("Okay") +} diff --git a/tests/untried/pos/t5796.scala b/tests/untried/pos/t5796.scala new file mode 100644 index 000000000..72ca89f7a --- /dev/null +++ b/tests/untried/pos/t5796.scala @@ -0,0 +1,8 @@ +object Bug { + def foo(): Unit = { + val v = { + lazy val s = 0 + s + } + } +} diff --git a/tests/untried/pos/t5809.flags b/tests/untried/pos/t5809.flags new file mode 100644 index 000000000..e93641e93 --- /dev/null +++ b/tests/untried/pos/t5809.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5809.scala b/tests/untried/pos/t5809.scala new file mode 100644 index 000000000..6101f546b --- /dev/null +++ b/tests/untried/pos/t5809.scala @@ -0,0 +1,6 @@ +package object foo { + implicit class EnrichedInt(foo: Int) { + def bar = ??? + def bippy = foo + } +} diff --git a/tests/untried/pos/t5829.scala b/tests/untried/pos/t5829.scala new file mode 100644 index 000000000..84b450ab3 --- /dev/null +++ b/tests/untried/pos/t5829.scala @@ -0,0 +1,18 @@ +trait Universe { + type Tree + + type SymTree <: Tree + type NameTree <: Tree + type RefTree <: SymTree with NameTree + + type Ident <: RefTree + type Select <: RefTree +} + +object Test extends App { + val universe: Universe = null + import universe._ + def select: Select = ??? + def ident: Ident = ??? + List(select, ident) +} diff --git a/tests/untried/pos/t5845.scala b/tests/untried/pos/t5845.scala new file mode 100644 index 000000000..823c722c1 --- /dev/null +++ b/tests/untried/pos/t5845.scala @@ -0,0 +1,16 @@ +class Num[T] { + def mkOps = new Ops + class Ops { def +++(rhs: T) = () } +} + +class A { + implicit def infixOps[T, CC[X] <: Num[X]](lhs: T)(implicit num: CC[T]) = num.mkOps + implicit val n1 = new Num[Int] { } + println(5 +++ 5) +} + +class B { + implicit def infixOps[T, CC[X] <: Num[X]](lhs: T)(implicit num: CC[T]) : CC[T]#Ops = num.mkOps + implicit val n1 = new Num[Int] {} + println(5 +++ 5) +} diff --git a/tests/untried/pos/t5846.scala b/tests/untried/pos/t5846.scala new file mode 100644 index 000000000..05cabed6a --- /dev/null +++ b/tests/untried/pos/t5846.scala @@ -0,0 +1,10 @@ + + + + +/** Return the most general sorted map type. */ +object Test extends App { + + val empty: collection.SortedMap[String, String] = collection.SortedMap.empty[String, String] + +} diff --git a/tests/untried/pos/t5853.scala b/tests/untried/pos/t5853.scala new file mode 100644 index 000000000..2ebb6667d --- /dev/null +++ b/tests/untried/pos/t5853.scala @@ -0,0 +1,55 @@ + + + + + + + +final class C(val x: Int) extends AnyVal { + def ppp[@specialized(Int) T](y: T) = () +} + + +class Foo { + def f = new C(1) ppp 2 +} + + +/* Original SI-5853 test-case. */ + +object Bippy { + implicit final class C(val x: Int) extends AnyVal { + def +++[@specialized T](y: T) = () + } + def f = 1 +++ 2 +} + + +/* Few more examples. */ + +final class C2(val x: Int) extends AnyVal { + def +++[@specialized(Int) T](y: T) = () +} + + +class Foo2 { + def f = new C2(1) +++ 2 +} + + +object Arrow { + implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { + @inline def ->>[B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) + } + + def foo = 1 ->> 2 +} + + +object SpecArrow { + implicit final class ArrowAssoc[A](val __leftOfArrow: A) extends AnyVal { + @inline def ->> [@specialized(Int) B](y: B): Tuple2[A, B] = Tuple2(__leftOfArrow, y) + } + + def foo = 1 ->> 2 +} diff --git a/tests/untried/pos/t5859.scala b/tests/untried/pos/t5859.scala new file mode 100644 index 000000000..2a31e68ee --- /dev/null +++ b/tests/untried/pos/t5859.scala @@ -0,0 +1,15 @@ + +class A { + def f(xs: List[Int], ys: AnyRef*) = () + def f(xs: AnyRef*) = () + + f() + f(List[AnyRef](): _*) + f(List(): _*) + f(Nil: _*) + f(Array(): _*) + f(Array[AnyRef](): _*) + f(List(1)) + f(List(1), Nil: _*) + f(List(1), Array(): _*) +} diff --git a/tests/untried/pos/t5862.scala b/tests/untried/pos/t5862.scala new file mode 100644 index 000000000..e3006ddc3 --- /dev/null +++ b/tests/untried/pos/t5862.scala @@ -0,0 +1,38 @@ +package test + +import java.io.DataOutput +import java.io.DataInput + +/** Interface for writing outputs from a DoFn. */ +trait Emitter[A] { + def emit(value: A): Unit +} + +/** A wrapper for a 'map' function tagged for a specific output channel. */ +abstract class TaggedMapper[A, K, V] + (val tags: Set[Int]) + (implicit val mA: Manifest[A], val wtA: WireFormat[A], + val mK: Manifest[K], val wtK: WireFormat[K], val ordK: Ordering[K], + val mV: Manifest[V], val wtV: WireFormat[V]) + extends Serializable { +} + +/** Type-class for sending types across the Hadoop wire. */ +trait WireFormat[A] + +class MapReduceJob { + trait DataSource + + import scala.collection.mutable.{ Set => MSet, Map => MMap } + private val mappers: MMap[DataSource, MSet[TaggedMapper[_, _, _]]] = MMap.empty + + def addTaggedMapper[A, K, V](input: DataSource, m: TaggedMapper[A, K, V]): Unit = { + if (!mappers.contains(input)) + mappers += (input -> MSet(m)) + else + mappers(input) += m // : Unit + + m.tags.foreach { tag => + } + } +} diff --git a/tests/untried/pos/t5877.scala b/tests/untried/pos/t5877.scala new file mode 100644 index 000000000..939013cd0 --- /dev/null +++ b/tests/untried/pos/t5877.scala @@ -0,0 +1,14 @@ +package foo { + class Foo + + object Test { + new Foo().huzzah + } +} + +package object foo { + // Crasher: No synthetics for method EnrichedFoo2: synthetics contains + implicit class EnrichedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/tests/untried/pos/t5877b.scala b/tests/untried/pos/t5877b.scala new file mode 100644 index 000000000..43a2ea2f0 --- /dev/null +++ b/tests/untried/pos/t5877b.scala @@ -0,0 +1,13 @@ +package foo + +class Foo + +object Test { + new Foo().huzzah +} + +object `package` { + implicit class EnrichedFoo2(value: Foo) { + def huzzah = "" + } +} diff --git a/tests/untried/pos/t5886.scala b/tests/untried/pos/t5886.scala new file mode 100644 index 000000000..066187322 --- /dev/null +++ b/tests/untried/pos/t5886.scala @@ -0,0 +1,18 @@ +object A { + def f0[T](x: T): T = x + def f1[T](x: => T): T = x + def f2[T](x: () => T): T = x() + + f0(this.getClass) // ok + f1(this.getClass) + f2(this.getClass) // ok + + // a.scala:7: error: type mismatch; + // found : Class[_ <: A.type] + // required: Class[?0(in value x1)] where type ?0(in value x1) <: A.type + // Note: A.type >: ?0, but Java-defined class Class is invariant in type T. + // You may wish to investigate a wildcard type such as `_ >: ?0`. (SLS 3.2.10) + // val x1 = f1(this.getClass) + // ^ + // one error found +} diff --git a/tests/untried/pos/t5892.scala b/tests/untried/pos/t5892.scala new file mode 100644 index 000000000..26dd1f73d --- /dev/null +++ b/tests/untried/pos/t5892.scala @@ -0,0 +1,5 @@ +class foo(a: String) extends annotation.StaticAnnotation +object o { + implicit def i2s(i: Int) = "" + @foo(1: String) def blerg: Unit = { } +} diff --git a/tests/untried/pos/t5897.flags b/tests/untried/pos/t5897.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5897.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5897.scala b/tests/untried/pos/t5897.scala new file mode 100644 index 000000000..2e9751afe --- /dev/null +++ b/tests/untried/pos/t5897.scala @@ -0,0 +1,6 @@ +// no warning here +// (strangely, if there's an unreachable code warning *anywhere in this compilation unit*, +// the non-sensical warning goes away under -Xfatal-warnings) +class Test { + () match { case () => } +} diff --git a/tests/untried/pos/t5899.flags b/tests/untried/pos/t5899.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5899.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5899.scala b/tests/untried/pos/t5899.scala new file mode 100644 index 000000000..852b4e3e7 --- /dev/null +++ b/tests/untried/pos/t5899.scala @@ -0,0 +1,19 @@ +import scala.tools.nsc._ + +trait Foo { + val global: Global + import global.{Name, Symbol, nme} + + case class Bippy(name: Name) + + def f(x: Bippy, sym: Symbol): Int = { + // no warning (!) for + // val Stable = sym.name.toTermName + + val Stable = sym.name + Bippy(Stable) match { + case Bippy(nme.WILDCARD) => 1 + case Bippy(Stable) => 2 // should not be considered unreachable + } + } +} diff --git a/tests/untried/pos/t5900a.scala b/tests/untried/pos/t5900a.scala new file mode 100644 index 000000000..cb02f67fb --- /dev/null +++ b/tests/untried/pos/t5900a.scala @@ -0,0 +1,9 @@ +case class Transition[S](x: S) + +object C + +object Test { + (??? : Any) match { + case Transition(C) => + } +} diff --git a/tests/untried/pos/t5910.java b/tests/untried/pos/t5910.java new file mode 100644 index 000000000..e007a1fbb --- /dev/null +++ b/tests/untried/pos/t5910.java @@ -0,0 +1,2 @@ +class Foo { +};;;;;;;
\ No newline at end of file diff --git a/tests/untried/pos/t592.scala b/tests/untried/pos/t592.scala new file mode 100644 index 000000000..6a941ef51 --- /dev/null +++ b/tests/untried/pos/t592.scala @@ -0,0 +1,71 @@ +trait Graph { + type Edge; + type Node <: NodeIntf; + + trait NodeIntf { + def connectWith(node: Node): Edge; + } + + def nodes: List[Node]; + def edges: List[Edge]; + def addNode: Node; + + protected var ids = 0; +} + +abstract class DirectedGraph extends Graph { + type Edge <: EdgeImpl; + + class EdgeImpl(origin: Node, dest: Node) { + def from = origin; + def to = dest; + override def toString = ""+origin+" --> "+dest + } + + class NodeImpl extends NodeIntf { self: Node => + val id = ids + ids = ids + 1 + def connectWith(node: Node): Edge = { + val edge = newEdge(this, node); + edges = edge :: edges; + edge; + } + override def toString = "Node "+id + } + + protected def newNode: Node; + protected def newEdge(from: Node, to: Node): Edge; + var nodes: List[Node] = Nil; + var edges: List[Edge] = Nil; + + def addNode: Node = { + val node = newNode; + nodes = node :: nodes; + node; + } +} + +class ConcreteDirectedGraph extends DirectedGraph { + type Edge = EdgeImpl; + type Node = NodeImpl; + + protected def newNode: Node = { + new NodeImpl; + } + + protected def newEdge(f: Node, t: Node): Edge = { + new EdgeImpl(f, t); + } +} + +object ExplicitThis { + def main(args: Array[String]): Unit = { + val g: Graph = new ConcreteDirectedGraph; + val n1 = g.addNode; + val n2 = g.addNode; + val n3 = g.addNode; + Console.println(n1.connectWith(n2)) + Console.println(n2.connectWith(n3)) + Console.println(n1.connectWith(n3)) + } +} diff --git a/tests/untried/pos/t5930.flags b/tests/untried/pos/t5930.flags new file mode 100644 index 000000000..c7d406c64 --- /dev/null +++ b/tests/untried/pos/t5930.flags @@ -0,0 +1 @@ +-Ywarn-dead-code -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5930.scala b/tests/untried/pos/t5930.scala new file mode 100644 index 000000000..202765b32 --- /dev/null +++ b/tests/untried/pos/t5930.scala @@ -0,0 +1,4 @@ +// should not warn about dead code (`matchEnd(throw new MatchError)`) + class Test { + 0 match { case x: Int => } +} diff --git a/tests/untried/pos/t5932.flags b/tests/untried/pos/t5932.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5932.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5932.scala b/tests/untried/pos/t5932.scala new file mode 100644 index 000000000..d824523d5 --- /dev/null +++ b/tests/untried/pos/t5932.scala @@ -0,0 +1,15 @@ +class A + +case object B extends A + +object Test { + val x1 = (B: A) + + println(x1 == B) // no warning + println(B == x1) // no warning + + val x2 = (B: A with Product) + + println(x2 == B) // no warning + println(B == x2) // spurious warning: "always returns false" +} diff --git a/tests/untried/pos/t595.scala b/tests/untried/pos/t595.scala new file mode 100644 index 000000000..44124c90c --- /dev/null +++ b/tests/untried/pos/t595.scala @@ -0,0 +1,5 @@ +package lampion.scala; +import _root_.scala.collection._ + +class Foo extends mutable.HashMap + diff --git a/tests/untried/pos/t5953.scala b/tests/untried/pos/t5953.scala new file mode 100644 index 000000000..7ba035ec3 --- /dev/null +++ b/tests/untried/pos/t5953.scala @@ -0,0 +1,16 @@ +import scala.collection.{ mutable, immutable, generic, GenTraversableOnce } + +package object foo { + @inline implicit class TravOps[A, CC[A] <: GenTraversableOnce[A]](val coll: CC[A]) extends AnyVal { + def build[CC2[X]](implicit cbf: generic.CanBuildFrom[Nothing, A, CC2[A]]): CC2[A] = { + cbf() ++= coll.toIterator result + } + } +} + +package foo { + object Test { + def f1[T](xs: Traversable[T]) = xs.to[immutable.Vector] + def f2[T](xs: Traversable[T]) = xs.build[immutable.Vector] + } +} diff --git a/tests/untried/pos/t5954a/A_1.scala b/tests/untried/pos/t5954a/A_1.scala new file mode 100644 index 000000000..10ead0b1c --- /dev/null +++ b/tests/untried/pos/t5954a/A_1.scala @@ -0,0 +1,6 @@ +package p1 { + object `package` { + implicit class Foo(a: Any) + object Foo + } +} diff --git a/tests/untried/pos/t5954a/B_2.scala b/tests/untried/pos/t5954a/B_2.scala new file mode 100644 index 000000000..10ead0b1c --- /dev/null +++ b/tests/untried/pos/t5954a/B_2.scala @@ -0,0 +1,6 @@ +package p1 { + object `package` { + implicit class Foo(a: Any) + object Foo + } +} diff --git a/tests/untried/pos/t5954b/A_1.scala b/tests/untried/pos/t5954b/A_1.scala new file mode 100644 index 000000000..8465e8f8c --- /dev/null +++ b/tests/untried/pos/t5954b/A_1.scala @@ -0,0 +1,6 @@ +package p { + package object base { + class B + object B + } +} diff --git a/tests/untried/pos/t5954b/B_2.scala b/tests/untried/pos/t5954b/B_2.scala new file mode 100644 index 000000000..f7e4704b3 --- /dev/null +++ b/tests/untried/pos/t5954b/B_2.scala @@ -0,0 +1,5 @@ +package p { + package object base { + case class B() + } +} diff --git a/tests/untried/pos/t5954c.flags b/tests/untried/pos/t5954c.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t5954c.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t5954c/A_1.scala b/tests/untried/pos/t5954c/A_1.scala new file mode 100644 index 000000000..29ad9547a --- /dev/null +++ b/tests/untried/pos/t5954c/A_1.scala @@ -0,0 +1,18 @@ +package object A { + // these used to should be prevented by the implementation restriction + // but are now allowed + class B + object B + trait C + object C + case class D() + // all the rest of these should be ok + class E + object F + val g = "omg" + var h = "wtf" + def i = "lol" + type j = String + class K(val k : Int) extends AnyVal + implicit class L(val l : Int) +} diff --git a/tests/untried/pos/t5954c/B_2.scala b/tests/untried/pos/t5954c/B_2.scala new file mode 100644 index 000000000..29ad9547a --- /dev/null +++ b/tests/untried/pos/t5954c/B_2.scala @@ -0,0 +1,18 @@ +package object A { + // these used to should be prevented by the implementation restriction + // but are now allowed + class B + object B + trait C + object C + case class D() + // all the rest of these should be ok + class E + object F + val g = "omg" + var h = "wtf" + def i = "lol" + type j = String + class K(val k : Int) extends AnyVal + implicit class L(val l : Int) +} diff --git a/tests/untried/pos/t5954d.flags b/tests/untried/pos/t5954d.flags new file mode 100644 index 000000000..6ced0e709 --- /dev/null +++ b/tests/untried/pos/t5954d.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xdev diff --git a/tests/untried/pos/t5954d/A_1.scala b/tests/untried/pos/t5954d/A_1.scala new file mode 100644 index 000000000..8465e8f8c --- /dev/null +++ b/tests/untried/pos/t5954d/A_1.scala @@ -0,0 +1,6 @@ +package p { + package object base { + class B + object B + } +} diff --git a/tests/untried/pos/t5954d/B_2.scala b/tests/untried/pos/t5954d/B_2.scala new file mode 100644 index 000000000..a4aa2eb58 --- /dev/null +++ b/tests/untried/pos/t5954d/B_2.scala @@ -0,0 +1,7 @@ +package p { + trait T { + class B + object B + } + package object base extends T +} diff --git a/tests/untried/pos/t5957/T_1.scala b/tests/untried/pos/t5957/T_1.scala new file mode 100644 index 000000000..339dcbf0f --- /dev/null +++ b/tests/untried/pos/t5957/T_1.scala @@ -0,0 +1,8 @@ +abstract class T { + // see: SI-6109 + // def t1: Test$Bar + def t2: Test#Bar + // see: SI-6109 + // def t3: Test$Baz + def t4: Test.Baz +} diff --git a/tests/untried/pos/t5957/Test.java b/tests/untried/pos/t5957/Test.java new file mode 100644 index 000000000..4fbd257d9 --- /dev/null +++ b/tests/untried/pos/t5957/Test.java @@ -0,0 +1,11 @@ +public class Test { + public class Bar { + public Bar(int i) { + } + } + + public static class Baz { + public Baz(int i) { + } + } +} diff --git a/tests/untried/pos/t5958.scala b/tests/untried/pos/t5958.scala new file mode 100644 index 000000000..3e078d2aa --- /dev/null +++ b/tests/untried/pos/t5958.scala @@ -0,0 +1,15 @@ +class Test { + def newComponent(u: Universe): u.Component = ??? + + class Universe { self => + class Component + + newComponent(this): this.Component // error, but should be fine since this is a stable reference + newComponent(self): self.Component // error, but should be fine since this is a stable reference + newComponent(self): this.Component // error, but should be fine since this is a stable reference + newComponent(this): self.Component // error, but should be fine since this is a stable reference + + val u = this + newComponent(u): u.Component // ok + } +} diff --git a/tests/untried/pos/t596.scala b/tests/untried/pos/t596.scala new file mode 100644 index 000000000..b1b5471b2 --- /dev/null +++ b/tests/untried/pos/t596.scala @@ -0,0 +1,7 @@ +trait T1 { + protected abstract class C +} + +trait T2 extends T1 { + class D extends C +} diff --git a/tests/untried/pos/t5967.scala b/tests/untried/pos/t5967.scala new file mode 100644 index 000000000..eb9bd6dfa --- /dev/null +++ b/tests/untried/pos/t5967.scala @@ -0,0 +1,6 @@ +object Test { + def f(a: Int*) = a match { + case 0 :: Nil => "List(0)! My favorite Seq!" + case _ => a.toString + } +} diff --git a/tests/untried/pos/t5968.flags b/tests/untried/pos/t5968.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t5968.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t5968.scala b/tests/untried/pos/t5968.scala new file mode 100644 index 000000000..0093f84fc --- /dev/null +++ b/tests/untried/pos/t5968.scala @@ -0,0 +1,8 @@ +object X { + def f(e: Either[Int, X.type]) = e match { + case Left(i) => i + case Right(X) => 0 + // SI-5986 spurious exhaustivity warning here + } +} + diff --git a/tests/untried/pos/t599.scala b/tests/untried/pos/t599.scala new file mode 100644 index 000000000..968e2deae --- /dev/null +++ b/tests/untried/pos/t599.scala @@ -0,0 +1,19 @@ +abstract class FooA { + type A <: AxA; + abstract class AxA; + abstract class InnerA { + type B <: A; + def doB : B; + } + } + trait FooB extends FooA { + type A <: AxB; + trait AxB extends AxA { def xxx : Int; } + abstract class InnerB extends InnerA { + // type B <: A; + val a : A = doB; + a.xxx; + val aaa: InnerB.this.B = doB + aaa.xxx; + } + } diff --git a/tests/untried/pos/t6008.flags b/tests/untried/pos/t6008.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6008.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6008.scala b/tests/untried/pos/t6008.scala new file mode 100644 index 000000000..50edf2c4b --- /dev/null +++ b/tests/untried/pos/t6008.scala @@ -0,0 +1,12 @@ +// none of these should complain about exhaustivity +class Test { + // It would fail on the following inputs: (_, false), (_, true) + def x(in: (Int, Boolean)) = in match { case (i: Int, b: Boolean) => 3 } + + // There is no warning if the Int is ignored or bound without an explicit type: + def y(in: (Int, Boolean)) = in match { case (_, b: Boolean) => 3 } + + // Keeping the explicit type for the Int but dropping the one for Boolean presents a spurious warning again: + // It would fail on the following input: (_, _) + def z(in: (Int, Boolean)) = in match { case (i: Int, b) => 3 } +} diff --git a/tests/untried/pos/t6014.scala b/tests/untried/pos/t6014.scala new file mode 100644 index 000000000..26e258a27 --- /dev/null +++ b/tests/untried/pos/t6014.scala @@ -0,0 +1,13 @@ +object Test { + case class CC[T](key: T) + type Alias[T] = Seq[CC[T]] + + def f(xs: Seq[CC[_]]) = xs map { case CC(x) => CC(x) } // ok + def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails + // ./a.scala:11: error: missing parameter type for expanded function + // The argument types of an anonymous function must be fully known. (SLS 8.5) + // Expected type was: ? + // def g(xs: Alias[_]) = xs map { case CC(x) => CC(x) } // fails + // ^ + // one error found +} diff --git a/tests/untried/pos/t602.scala b/tests/untried/pos/t602.scala new file mode 100644 index 000000000..18dd40564 --- /dev/null +++ b/tests/untried/pos/t602.scala @@ -0,0 +1,14 @@ +package com.mosol.sl + +case class Span[K <: Ordered[K]](low: Option[K], high: Option[K]) extends Function1[K, Boolean] { + override def equals(x$1: Any): Boolean = x$1 match { + case Span((low$0 @ _), (high$0 @ _)) if low$0.equals(low).$amp$amp(high$0.equals(high)) => true + case _ => false + } + def apply(k: K): Boolean = this match { + case Span(Some(low), Some(high)) => (k >= low && k <= high) + case Span(Some(low), None) => (k >= low) + case Span(None, Some(high)) => (k <= high) + case _ => false + } +} diff --git a/tests/untried/pos/t6022.flags b/tests/untried/pos/t6022.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6022.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6022.scala b/tests/untried/pos/t6022.scala new file mode 100644 index 000000000..87f7cbf3b --- /dev/null +++ b/tests/untried/pos/t6022.scala @@ -0,0 +1,7 @@ +class Test { + (null: Any) match { + case x: AnyRef if false => + case list: Option[_] => + case product: Product => // change Product to String and it's all good + } +} diff --git a/tests/untried/pos/t6022b.scala b/tests/untried/pos/t6022b.scala new file mode 100644 index 000000000..6ceb92816 --- /dev/null +++ b/tests/untried/pos/t6022b.scala @@ -0,0 +1,20 @@ +trait A +trait B +trait C +trait AB extends B with A + +// two types are mutually exclusive if there is no equality symbol whose constant implies both +object Test extends App { + def foo(x: Any) = x match { + case _ : C => println("C") + case _ : AB => println("AB") + case _ : (A with B) => println("AB'") + case _ : B => println("B") + case _ : A => println("A") + } + + foo(new A {}) + foo(new B {}) + foo(new AB{}) + foo(new C {}) +} diff --git a/tests/untried/pos/t6028/t6028_1.scala b/tests/untried/pos/t6028/t6028_1.scala new file mode 100644 index 000000000..6edb76069 --- /dev/null +++ b/tests/untried/pos/t6028/t6028_1.scala @@ -0,0 +1,3 @@ +class C { + def foo(a: Int): Unit = () => a +} diff --git a/tests/untried/pos/t6028/t6028_2.scala b/tests/untried/pos/t6028/t6028_2.scala new file mode 100644 index 000000000..f44048c0a --- /dev/null +++ b/tests/untried/pos/t6028/t6028_2.scala @@ -0,0 +1,4 @@ +object Test { + // ensure that parameter names are untouched by lambdalift + new C().foo(a = 0) +} diff --git a/tests/untried/pos/t6029.scala b/tests/untried/pos/t6029.scala new file mode 100644 index 000000000..8f1bbb4eb --- /dev/null +++ b/tests/untried/pos/t6029.scala @@ -0,0 +1,3 @@ +final case class V[A](x: A) extends AnyVal { + def flatMap[B](f: A => V[B]) = if (true) this else f(x) +} diff --git a/tests/untried/pos/t6033.scala b/tests/untried/pos/t6033.scala new file mode 100644 index 000000000..60142af6b --- /dev/null +++ b/tests/untried/pos/t6033.scala @@ -0,0 +1,5 @@ +object Test extends App { + val b = new java.math.BigInteger("123") + val big1 = BigInt(b) + val big2: BigInt = b +} diff --git a/tests/untried/pos/t6034.scala b/tests/untried/pos/t6034.scala new file mode 100644 index 000000000..3558d7ff0 --- /dev/null +++ b/tests/untried/pos/t6034.scala @@ -0,0 +1 @@ +final class OptPlus[+A](val x: A) extends AnyVal { } diff --git a/tests/untried/pos/t604.scala b/tests/untried/pos/t604.scala new file mode 100644 index 000000000..fb90d5ae3 --- /dev/null +++ b/tests/untried/pos/t604.scala @@ -0,0 +1,8 @@ +object Test +{ + type T = Foo.type + object Foo + + def main(argv : Array[String]) : Unit = { + } +} diff --git a/tests/untried/pos/t6040.scala b/tests/untried/pos/t6040.scala new file mode 100644 index 000000000..7a5b2daed --- /dev/null +++ b/tests/untried/pos/t6040.scala @@ -0,0 +1,3 @@ +import language.dynamics + +class X extends Dynamic diff --git a/tests/untried/pos/t6047.flags b/tests/untried/pos/t6047.flags new file mode 100644 index 000000000..cd66464f2 --- /dev/null +++ b/tests/untried/pos/t6047.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/tests/untried/pos/t6047.scala b/tests/untried/pos/t6047.scala new file mode 100644 index 000000000..e7d0c38c6 --- /dev/null +++ b/tests/untried/pos/t6047.scala @@ -0,0 +1,20 @@ +import scala.reflect.macros.blackbox.Context +import java.io.InputStream + +object Macros { + def unpack[A](input: InputStream): A = macro unpack_impl[A] + + def unpack_impl[A: c.WeakTypeTag](c: Context)(input: c.Expr[InputStream]): c.Expr[A] = { + import c.universe._ + + def unpackcode(tpe: c.Type): c.Expr[_] = { + if (tpe <:< implicitly[c.WeakTypeTag[Traversable[_]]].tpe) { + + } + ??? + } + + unpackcode(implicitly[c.WeakTypeTag[A]].tpe) + ??? + } + } diff --git a/tests/untried/pos/t607.scala b/tests/untried/pos/t607.scala new file mode 100644 index 000000000..42c3a15a8 --- /dev/null +++ b/tests/untried/pos/t607.scala @@ -0,0 +1,11 @@ +object Test +{ + trait Foo { type T } + object FooX extends Foo { type T = X; trait X } + + def test(x : Foo { type T = FooX.X }) = {} + + def main(argv : Array[String]) : Unit = { + test(FooX) + } +} diff --git a/tests/untried/pos/t6072.scala b/tests/untried/pos/t6072.scala new file mode 100644 index 000000000..e25ebbffc --- /dev/null +++ b/tests/untried/pos/t6072.scala @@ -0,0 +1,3 @@ +class A { + object B { def eq(lvl: Int) = ??? } +} diff --git a/tests/untried/pos/t6084.scala b/tests/untried/pos/t6084.scala new file mode 100644 index 000000000..1aa1fed39 --- /dev/null +++ b/tests/untried/pos/t6084.scala @@ -0,0 +1,15 @@ +package object foo { type X[T, U] = (T => U) } + +package foo { + abstract class Foo[T, U](val d: T => U) extends (T => U) { + def f1(r: X[T, U]) = r match { case x: Foo[_,_] => x.d } // inferred ok + def f2(r: X[T, U]): (T => U) = r match { case x: Foo[_,_] => x.d } // dealiased ok + def f3(r: X[T, U]): X[T, U] = r match { case x: Foo[_,_] => x.d } // alias not ok + + // x.d : foo.this.package.type.X[?scala.reflect.internal.Types$NoPrefix$?.T, ?scala.reflect.internal.Types$NoPrefix$?.U] ~>scala.this.Function1[?scala.reflect.internal.Types$NoPrefix$?.T, ?scala.reflect.internal.Types$NoPrefix$?.U] + // at scala.Predef$.assert(Predef.scala:170) + // at scala.tools.nsc.Global.assert(Global.scala:235) + // at scala.tools.nsc.ast.TreeGen.mkCast(TreeGen.scala:252) + // at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:2263) + } +} diff --git a/tests/untried/pos/t6089b.scala b/tests/untried/pos/t6089b.scala new file mode 100644 index 000000000..9378a74a0 --- /dev/null +++ b/tests/untried/pos/t6089b.scala @@ -0,0 +1,18 @@ +// this crazy code simply tries to nest pattern matches so that the last call is in a tricky-to-determine +// tail position (my initial tightenign of tailpos detection for SI-6089 ruled this out) +class BKTree { + @annotation.tailrec + final def -?-[AA](a: AA): Boolean = this match { + case BKTreeEmpty => false + case BKTreeNode(v) => { + val d = 1 + d == 0 || ( Map(1 -> this,2 -> this,3 -> this) get d match { + case None => false + case Some(w) => w -?- a // can tail call here (since || is shortcutting) + }) + } + } +} + +object BKTreeEmpty extends BKTree +case class BKTreeNode[A](v: A) extends BKTree diff --git a/tests/untried/pos/t6091.flags b/tests/untried/pos/t6091.flags new file mode 100644 index 000000000..954eaba35 --- /dev/null +++ b/tests/untried/pos/t6091.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint diff --git a/tests/untried/pos/t6091.scala b/tests/untried/pos/t6091.scala new file mode 100644 index 000000000..72e663ec3 --- /dev/null +++ b/tests/untried/pos/t6091.scala @@ -0,0 +1,10 @@ +object Foo { def eq(x:Int) = x } + +class X { def ==(other: String) = true } + +object Test { + def main(args: Array[String]): Unit = { + Foo eq 1 + new X == null + } +} diff --git a/tests/untried/pos/t611.scala b/tests/untried/pos/t611.scala new file mode 100644 index 000000000..de4e8992e --- /dev/null +++ b/tests/untried/pos/t611.scala @@ -0,0 +1,25 @@ +package bug.contrib_60; + +abstract class Field { + type FieldType; + + var internalValue: FieldType; +} + +case class IntField(value: Int) extends Field { + type FieldType = Int; + + var internalValue: FieldType = value; +} + +case class StringField(value: String) extends Field { + type FieldType = String; + + var internalValue: FieldType = value; +} + +object Test { + def main (args: scala.Array[String]): Unit = { + Console.println(List(new StringField ("bar"), new IntField(8))) + } +} diff --git a/tests/untried/pos/t6117.scala b/tests/untried/pos/t6117.scala new file mode 100644 index 000000000..6aca84f72 --- /dev/null +++ b/tests/untried/pos/t6117.scala @@ -0,0 +1,19 @@ +package test + +trait ImportMe { + def foo(i: Int) = 1 + def foo(s: String) = 2 +} + +class Test(val importMe: ImportMe) { + import importMe._ + import importMe._ + + // A.scala:12: error: reference to foo is ambiguous; + // it is imported twice in the same scope by + // import importMe._ + // and import importMe._ + // println(foo(1)) + // ^ + println(foo(1)) +} diff --git a/tests/untried/pos/t6123-explaintypes-implicits.flags b/tests/untried/pos/t6123-explaintypes-implicits.flags new file mode 100644 index 000000000..b36707c7c --- /dev/null +++ b/tests/untried/pos/t6123-explaintypes-implicits.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/tests/untried/pos/t6123-explaintypes-implicits.scala b/tests/untried/pos/t6123-explaintypes-implicits.scala new file mode 100644 index 000000000..86f522728 --- /dev/null +++ b/tests/untried/pos/t6123-explaintypes-implicits.scala @@ -0,0 +1,13 @@ +object ImplicitBugReport { + trait Exp[+T] + trait CanBuildExp[-Elem, +To] extends (Exp[Elem] => To) + trait TraversableExp[T, ExpT <: Exp[T]] extends Exp[Traversable[T]] + + implicit def canBuildExp[T]: CanBuildExp[T, Exp[T]] = ??? + implicit def canBuildExpTrav[T, ExpT <: Exp[T]](implicit c: CanBuildExp[T, ExpT]): CanBuildExp[Traversable[T], TraversableExp[T, ExpT]] = ??? + def toExpTempl[T, That](t: T)(implicit c: CanBuildExp[T, That]): That = ??? + + def testBug(): Unit = { + val a1 = toExpTempl(Seq(1, 2, 3, 5)) + } +} diff --git a/tests/untried/pos/t613.scala b/tests/untried/pos/t613.scala new file mode 100644 index 000000000..e14083310 --- /dev/null +++ b/tests/untried/pos/t613.scala @@ -0,0 +1,17 @@ +class Outer extends App { + val y: Int = 1 + abstract class C { + val x: Int + } + val foo = new C { + class I { + val z = y + } + val x = (new I).z + } +} + +object Test extends App { + val o = new Outer + println(o.foo.x) +} diff --git a/tests/untried/pos/t6145.scala b/tests/untried/pos/t6145.scala new file mode 100644 index 000000000..4161a24b5 --- /dev/null +++ b/tests/untried/pos/t6145.scala @@ -0,0 +1,11 @@ +object Test { + // the existential causes a cast and the cast makes searchClass not be in tail position + // can we get rid of the useless cast? + @annotation.tailrec + final def searchClass: Class[_] = { + "packageName" match { + case _ => + searchClass + } + } +} diff --git a/tests/untried/pos/t6146.flags b/tests/untried/pos/t6146.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6146.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6146.scala b/tests/untried/pos/t6146.scala new file mode 100644 index 000000000..b5bde826b --- /dev/null +++ b/tests/untried/pos/t6146.scala @@ -0,0 +1,60 @@ +// No unreachable or exhaustiveness warnings, please. + +// +// The reported bug +// + +trait AxisCompanion { + sealed trait Format + object Format { + case object Decimal extends Format + case object Integer extends Format + // Gives an unrelated warning: The outer reference in this type test cannot be checked at run time. + //final case class Time( hours: Boolean = false, millis: Boolean = true ) extends Format + } +} +object Axis extends AxisCompanion +class Axis { + import Axis._ + def test( f: Format ) = f match { + case Format.Integer => "Int" + // case Format.Time( hours, millis ) => "Time" + case Format.Decimal => "Dec" + } +} + + +// +// Some tricksier variations +// + +trait T1[X] { + trait T2[Y] { + sealed trait Format + object Format { + case object Decimal extends Format + case object Integer extends Format + } + } +} + +object O1 extends T1[Any] { + object O2 extends T2[Any] { + + } +} + +case object Shorty extends O1.O2.Format + +class Test1 { + import O1.O2._ + val FI: Format.Integer.type = Format.Integer + def test( f: Format ) = { + val ff: f.type = f + ff match { + case FI => "Int" + case Format.Decimal => "Dec" + case Shorty => "Sho" + } + } +} diff --git a/tests/untried/pos/t615.scala b/tests/untried/pos/t615.scala new file mode 100644 index 000000000..8fefc952e --- /dev/null +++ b/tests/untried/pos/t615.scala @@ -0,0 +1,11 @@ +object test { + abstract class Bar { + type T + def bar: Unit + } + new Bar { + type T = Int + def bar = () + }.bar +} + diff --git a/tests/untried/pos/t6157.flags b/tests/untried/pos/t6157.flags new file mode 100644 index 000000000..0ebca3e7a --- /dev/null +++ b/tests/untried/pos/t6157.flags @@ -0,0 +1 @@ + -optimize diff --git a/tests/untried/pos/t6157.scala b/tests/untried/pos/t6157.scala new file mode 100644 index 000000000..294387cc6 --- /dev/null +++ b/tests/untried/pos/t6157.scala @@ -0,0 +1,25 @@ +// SI-6157 - Compiler crash on inlined function and -optimize option + +object Test { + def main(args: Array[String]): Unit = { + Console.println( + ErrorHandler.defaultIfIOException("String")("String") + ) + } +} + +import java.io.IOException + +object ErrorHandler { + + @inline + def defaultIfIOException[T](default: => T)(closure: => T): T = { + try { + closure + } catch { + case e: IOException => + default + } + } +} + diff --git a/tests/untried/pos/t616.scala b/tests/untried/pos/t616.scala new file mode 100644 index 000000000..bb91c732a --- /dev/null +++ b/tests/untried/pos/t616.scala @@ -0,0 +1,11 @@ +object testImplicit { + implicit def foo2bar(foo: Foo): Bar = foo.bar + class Foo(val bar: Bar) { + def testCoercion = {val a = this; a.baz} // here, foo2bar is inferred by the compiler, as expected + //def testCoercionThisImplicit = baz // --> error: not found: value baz + def testCoercionThisExplicit: Any = this.baz // --> error: value baz is not a member of Foo + } + trait Bar { def baz: Unit } +} +// mentioned before: http://thread.gmane.org/gmane.comp.lang.scala/2038, +// but couldn't find a bug report diff --git a/tests/untried/pos/t6162-inheritance.flags b/tests/untried/pos/t6162-inheritance.flags new file mode 100644 index 000000000..c6bfaf1f6 --- /dev/null +++ b/tests/untried/pos/t6162-inheritance.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/tests/untried/pos/t6162-inheritance.scala b/tests/untried/pos/t6162-inheritance.scala new file mode 100644 index 000000000..fca751eda --- /dev/null +++ b/tests/untried/pos/t6162-inheritance.scala @@ -0,0 +1,22 @@ +package scala.t6126 + +// Don't warn about inheritance in the same file. +// We might use that as a prelude to sealing a class. + +@deprecatedInheritance("`Foo` will be made final in a future version.", "2.10.0") +class Foo + +class SubFoo extends Foo + +@deprecatedInheritance() +trait T + +object SubT extends T + +@deprecatedInheritance() +trait S + +object O { + new S { + } +} diff --git a/tests/untried/pos/t6169/Exist.java b/tests/untried/pos/t6169/Exist.java new file mode 100644 index 000000000..dfc6b36b3 --- /dev/null +++ b/tests/untried/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/untried/pos/t6169/ExistF.java b/tests/untried/pos/t6169/ExistF.java new file mode 100644 index 000000000..70fabd74c --- /dev/null +++ b/tests/untried/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/untried/pos/t6169/ExistIndir.java b/tests/untried/pos/t6169/ExistIndir.java new file mode 100644 index 000000000..e66d1698c --- /dev/null +++ b/tests/untried/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/untried/pos/t6169/OP.java b/tests/untried/pos/t6169/OP.java new file mode 100644 index 000000000..15e4c5640 --- /dev/null +++ b/tests/untried/pos/t6169/OP.java @@ -0,0 +1 @@ +public abstract class OP<T> { } diff --git a/tests/untried/pos/t6169/Skin.java b/tests/untried/pos/t6169/Skin.java new file mode 100644 index 000000000..780de1ee0 --- /dev/null +++ b/tests/untried/pos/t6169/Skin.java @@ -0,0 +1 @@ +public interface Skin<C extends Skinnable> { } diff --git a/tests/untried/pos/t6169/Skinnable.java b/tests/untried/pos/t6169/Skinnable.java new file mode 100644 index 000000000..f91eaa30d --- /dev/null +++ b/tests/untried/pos/t6169/Skinnable.java @@ -0,0 +1,3 @@ +public interface Skinnable { + OP<Skin<?>> skinProperty(); +} diff --git a/tests/untried/pos/t6169/skinnable.scala b/tests/untried/pos/t6169/skinnable.scala new file mode 100644 index 000000000..08204f29d --- /dev/null +++ b/tests/untried/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/untried/pos/t6169/t6169.scala b/tests/untried/pos/t6169/t6169.scala new file mode 100644 index 000000000..84b2d2dad --- /dev/null +++ b/tests/untried/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/untried/pos/t6184.scala b/tests/untried/pos/t6184.scala new file mode 100644 index 000000000..386399963 --- /dev/null +++ b/tests/untried/pos/t6184.scala @@ -0,0 +1,7 @@ +trait Foo[TroubleSome] { + type T <: Foo[TroubleSome] + + this match { + case e: Foo[_]#T => ??? + } +} diff --git a/tests/untried/pos/t6201.scala b/tests/untried/pos/t6201.scala new file mode 100644 index 000000000..9d6667b6f --- /dev/null +++ b/tests/untried/pos/t6201.scala @@ -0,0 +1,19 @@ +// probably needs xml's weirdness to reproduce +// (specifically, _root_.scala.xml.Null being in the root package) +class Elem + +class Test { + def elem: Elem = ??? + + class Foo1 { + def must(x: Elem) = () + } + + class Foo2 { + def must(x: Int) = () + } + implicit def toFoo1(s: Elem) = new Foo1() + implicit def toFoo2(s: Elem) = new Foo2() + + def is: Unit = { (elem) } +} diff --git a/tests/untried/pos/t6204-a.scala b/tests/untried/pos/t6204-a.scala new file mode 100644 index 000000000..dbc1144b4 --- /dev/null +++ b/tests/untried/pos/t6204-a.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Bish { + def m: Unit = { + object Bash { + typeOf[Option[_]] + } + } +} diff --git a/tests/untried/pos/t6204-b.scala b/tests/untried/pos/t6204-b.scala new file mode 100644 index 000000000..62f2b5d5c --- /dev/null +++ b/tests/untried/pos/t6204-b.scala @@ -0,0 +1,10 @@ +import scala.reflect.runtime.universe._ + +object Bosh { + def Besh: Unit = { + new { + val t = typeOf[Option[_]] + val x = t + } + } +} diff --git a/tests/untried/pos/t6205.scala b/tests/untried/pos/t6205.scala new file mode 100644 index 000000000..52078bd5f --- /dev/null +++ b/tests/untried/pos/t6205.scala @@ -0,0 +1,18 @@ +// original code by reporter +class A[T] +class Test1 { + def x(backing: Map[A[_], Any]) = + for( (k: A[kt], v) <- backing) + yield (k: A[kt]) +} + +// this tests same thing as above, but independent of library classes, +// earlier expansions eliminated as well as variance (everything's invariant) +case class Holder[A](a: A) +class Mapped[A] { def map[T](f: Holder[A] => T): Iterable[T] = ??? } +class Test2 { + def works(backing: Mapped[A[_]]): Iterable[A[_]] + = backing.map(x => + x match {case Holder(k: A[kt]) => (k: A[kt])} + ) +} diff --git a/tests/untried/pos/t6208.scala b/tests/untried/pos/t6208.scala new file mode 100644 index 000000000..dac571346 --- /dev/null +++ b/tests/untried/pos/t6208.scala @@ -0,0 +1,4 @@ +object Test { + val col = collection.mutable.Queue(1,2,3) + val WORK: collection.mutable.Queue[Int] = col filterNot (_ % 2 == 0) +} diff --git a/tests/untried/pos/t6210.flags b/tests/untried/pos/t6210.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6210.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6210.scala b/tests/untried/pos/t6210.scala new file mode 100644 index 000000000..855c621b8 --- /dev/null +++ b/tests/untried/pos/t6210.scala @@ -0,0 +1,21 @@ +abstract sealed trait AST +abstract sealed trait AExpr extends AST +case class AAssign(name: String, v: AExpr) extends AExpr +case class AConstBool(v: Boolean) extends AExpr + +trait Ty {} +case class TInt() extends Ty +case class TBool() extends Ty + +object Foo { + def checkExpr(ast: AExpr): Ty = { + var astTy:Ty = ast match { + case AAssign(nm: String, v:AExpr) => TBool() + + case AConstBool(v: Boolean) => TBool() + + case _ => throw new Exception(s"Unhandled case check(ast: ${ast.getClass})") + } + astTy + } +} diff --git a/tests/untried/pos/t6215.scala b/tests/untried/pos/t6215.scala new file mode 100644 index 000000000..2f66892b6 --- /dev/null +++ b/tests/untried/pos/t6215.scala @@ -0,0 +1 @@ +class Foo(val v: String) extends AnyVal { private def len = v.length ; def f = len } diff --git a/tests/untried/pos/t6221.scala b/tests/untried/pos/t6221.scala new file mode 100644 index 000000000..bb2f1dde7 --- /dev/null +++ b/tests/untried/pos/t6221.scala @@ -0,0 +1,33 @@ +class MyFunc[-A, +B] extends (A => B) { def apply(x: A): B = ??? } + +class MyCollection[A] { + def map[B](f: MyFunc[A, B]): MyCollection[B] = new MyCollection[B] +} + +class OtherFunc[-A, +B] {} + +object Test { + implicit def functionToMyFunc[A, B](f: A => B): MyFunc[A, B] = new MyFunc // = new MyFunc[A,Nothing](); + + implicit def otherFuncToMyFunc[A, B](f: OtherFunc[A, B]): MyFunc[A, B] = new MyFunc // = new MyFunc[A,Nothing](); + + def main(args: Array[String]): Unit = { + val col = new MyCollection[Int] + + // Doesn't compile: error: missing parameter type for expanded function ((x$1) => x$1.toString) + println(col.map(_.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x$1: Int) => x$1.toString())))); + + // Doesn't compile: error: missing parameter type + println(col.map(x => x.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x: Int) => x.toString())))); + + // Does compile + println(col.map((x: Int) => x.toString)) + // scala.this.Predef.println(col.map[String](Test.this.functionToMyFunc[Int, String](((x: Int) => x.toString())))); + + // Does compile (even though type params of OtherFunc not given) + println(col.map(new OtherFunc)) + // scala.this.Predef.println(col.map[Nothing](Test.this.otherFuncToMyFunc[Any, Nothing](new OtherFunc[Any,Nothing]()))) + } +} diff --git a/tests/untried/pos/t6225.scala b/tests/untried/pos/t6225.scala new file mode 100644 index 000000000..d3d30d9e1 --- /dev/null +++ b/tests/untried/pos/t6225.scala @@ -0,0 +1,20 @@ + +package library.x { + class X { + class Foo + implicit val foo: Foo = new Foo + } +} +package library { + package object y extends library.x.X +} + +object ko { + import library.y.{Foo, foo} + implicitly[Foo] +} + +object ko2 { + import library.y._ + implicitly[Foo] +} diff --git a/tests/untried/pos/t6231.scala b/tests/untried/pos/t6231.scala new file mode 100644 index 000000000..1e5b4e0e1 --- /dev/null +++ b/tests/untried/pos/t6231.scala @@ -0,0 +1,15 @@ +object Bug { + def bar(ev: Any) = { + trait X { + def qux = { () => ev } + } + new X {}.qux() + + // workaround + trait Y { + val ev2 = ev // manually capture `ev` so that `ev2` is added to the trait interface. + def qux = { () => ev2 } + } + } +} + diff --git a/tests/untried/pos/t6231b.scala b/tests/untried/pos/t6231b.scala new file mode 100644 index 000000000..b4ddfe785 --- /dev/null +++ b/tests/untried/pos/t6231b.scala @@ -0,0 +1,8 @@ +class Test { + def f1(t: String) = { + trait T { + def xs = Nil map (_ => t) + } + () + } +} diff --git a/tests/untried/pos/t6245/Base.java b/tests/untried/pos/t6245/Base.java new file mode 100644 index 000000000..651ea08bf --- /dev/null +++ b/tests/untried/pos/t6245/Base.java @@ -0,0 +1,5 @@ +package t1; + +public class Base { + protected Vis inner; +} diff --git a/tests/untried/pos/t6245/Foo.scala b/tests/untried/pos/t6245/Foo.scala new file mode 100644 index 000000000..ea7a99e12 --- /dev/null +++ b/tests/untried/pos/t6245/Foo.scala @@ -0,0 +1,9 @@ +import t1.Vis + +abstract class Foo extends t1.Base { + trait Nested { + def crash(): Unit = { + inner + } + } +} diff --git a/tests/untried/pos/t6245/Vis.java b/tests/untried/pos/t6245/Vis.java new file mode 100644 index 000000000..4267f4e40 --- /dev/null +++ b/tests/untried/pos/t6245/Vis.java @@ -0,0 +1,3 @@ +package t1; + +public class Vis { } diff --git a/tests/untried/pos/t6260.flags b/tests/untried/pos/t6260.flags new file mode 100644 index 000000000..2349d8294 --- /dev/null +++ b/tests/untried/pos/t6260.flags @@ -0,0 +1 @@ +-Ydelambdafy:inline diff --git a/tests/untried/pos/t6260.scala b/tests/untried/pos/t6260.scala new file mode 100644 index 000000000..8edfe4ac3 --- /dev/null +++ b/tests/untried/pos/t6260.scala @@ -0,0 +1,17 @@ +class Box[X](val x: X) extends AnyVal { + def map[Y](f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(this) +} + +object Test { + def map2[X, Y](self: Box[X], f: X => Y): Box[Y] = + ((bx: Box[X]) => new Box(f(bx.x)))(self) + + def main(args: Array[String]): Unit = { + val f = (x: Int) => x + 1 + val g = (x: String) => x + x + + map2(new Box(42), f) + new Box("abc") map g + } +} diff --git a/tests/untried/pos/t6260a.scala b/tests/untried/pos/t6260a.scala new file mode 100644 index 000000000..194294e98 --- /dev/null +++ b/tests/untried/pos/t6260a.scala @@ -0,0 +1,15 @@ +final class Option[+A](val value: A) extends AnyVal + +// Was: sandbox/test.scala:21: error: bridge generated for member method f: ()Option[A] in class Bar +// which overrides method f: ()Option[A] in class Foo" +abstract class Foo[A] { def f(): Option[A] } + class Bar[A] extends Foo[A] { def f(): Option[A] = ??? } + +// User reported this as erroneous but I couldn't reproduce with 2.10.{0,1,2,3} +// https://issues.scala-lang.org/browse/SI-6260?focusedCommentId=64764&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64764 +// I suspect he whittled down the example too far. +class Wrapper(val value: Int) extends AnyVal +abstract class Test { def check(the: Wrapper): Boolean } +object T { + new Test { def check(the: Wrapper) = true } +} diff --git a/tests/untried/pos/t6260b.scala b/tests/untried/pos/t6260b.scala new file mode 100644 index 000000000..73e2e58f7 --- /dev/null +++ b/tests/untried/pos/t6260b.scala @@ -0,0 +1,3 @@ + +class X(val value: Object) extends AnyVal { def or(alt: => X): X = this } +class Y { def f = new X("") or new X("") } diff --git a/tests/untried/pos/t6274.scala b/tests/untried/pos/t6274.scala new file mode 100644 index 000000000..cf769fc72 --- /dev/null +++ b/tests/untried/pos/t6274.scala @@ -0,0 +1,13 @@ +trait Crash { + + def foo(i: => Int) (j: Int): Int + + def t = { + // var count = 0 + foo { + var count = 0 + count + } _ + } + +} diff --git a/tests/untried/pos/t6275.flags b/tests/untried/pos/t6275.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t6275.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t6275.scala b/tests/untried/pos/t6275.scala new file mode 100644 index 000000000..6b5ec7dce --- /dev/null +++ b/tests/untried/pos/t6275.scala @@ -0,0 +1,11 @@ + +sealed trait A[T] +final class B[T] extends A[T] + +object ParsedAxis { + type BI = B[Int] + + def f1(a: A[Int]) = a match { case b: B[Int] => 3 } + def f2(a: A[Int]) = a match { case b: BI => 3 } + def f3(a: A[Int]) = a match { case b: B[t] => 3 } +} diff --git a/tests/untried/pos/t6278-synth-def.scala b/tests/untried/pos/t6278-synth-def.scala new file mode 100644 index 000000000..a1c93fca8 --- /dev/null +++ b/tests/untried/pos/t6278-synth-def.scala @@ -0,0 +1,30 @@ + +package t6278 + +import language.implicitConversions + +object test { + def ok(): Unit = { + class Foo(val i: Int) { + def foo[A](body: =>A): A = body + } + implicit def toFoo(i: Int): Foo = new Foo(i) + + val k = 1 + k foo println("k?") + val j = 2 + } + def nope(): Unit = { + implicit class Foo(val i: Int) { + def foo[A](body: =>A): A = body + } + + val k = 1 + k foo println("k?") + //lazy + val j = 2 + } + def main(args: Array[String]): Unit = { + ok(); nope() + } +} diff --git a/tests/untried/pos/t628.scala b/tests/untried/pos/t628.scala new file mode 100644 index 000000000..f32c1cad0 --- /dev/null +++ b/tests/untried/pos/t628.scala @@ -0,0 +1,17 @@ +object Test { + abstract class Unit + object NoUnit extends Unit + object Hour extends Unit + + case class Measure(scalar: Double, unit: Unit) { + def *(newUnit: Unit): Measure = Measure(scalar, newUnit) + } + + implicit def double2Measure(scalar: Double) = + Measure(scalar, NoUnit) + + + def main(args: Array[String]): scala.Unit = { + Console.println("3.0 * Hour = " + (3.0 * (Hour: Unit))) + } +} diff --git a/tests/untried/pos/t6301.scala b/tests/untried/pos/t6301.scala new file mode 100644 index 000000000..fa81bbfa7 --- /dev/null +++ b/tests/untried/pos/t6301.scala @@ -0,0 +1,9 @@ +trait LoadedOver[@specialized(Int) A] { + def foo(x: Any): A + def foo(xs: String): A +} + +object Test { + def loaded: AnyRef with LoadedOver[Int] = sys.error("") + loaded.foo("") +} diff --git a/tests/untried/pos/t6311.scala b/tests/untried/pos/t6311.scala new file mode 100644 index 000000000..d27ad2f50 --- /dev/null +++ b/tests/untried/pos/t6311.scala @@ -0,0 +1,5 @@ +class A { + def fooMinimal[T, Coll <: Traversable[T]](msg: String)(param1: Traversable[T])(param2: Coll): Traversable[T] = throw new Exception() + + fooMinimal("")(List(1))(List(2)) +} diff --git a/tests/untried/pos/t6335.scala b/tests/untried/pos/t6335.scala new file mode 100644 index 000000000..50e34092d --- /dev/null +++ b/tests/untried/pos/t6335.scala @@ -0,0 +1,25 @@ +object E extends Z { + def X = 3 + implicit class X(val i: Int) { + def xx = i + } + + def Y(a: Any) = 0 + object Y + implicit class Y(val i: String) { def yy = i } + + implicit class Z(val i: Boolean) { def zz = i } +} + +trait Z { + def Z = 0 +} + +object Test { + import E._ + 0.xx + + "".yy + + true.zz +} diff --git a/tests/untried/pos/t6355pos.scala b/tests/untried/pos/t6355pos.scala new file mode 100644 index 000000000..c0e740dd6 --- /dev/null +++ b/tests/untried/pos/t6355pos.scala @@ -0,0 +1,16 @@ +import scala.language.dynamics + +class A extends Dynamic { + def applyDynamic[T1](method: String)(x1: T1): Any = 1 + def applyDynamic[T1, T2](method: String)(x: T1, y: T2): Any = 2 + def applyDynamic[T1, T2, T3](method: String)(x: T1, y: T2, z: T3): Any = 3 +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + println(x[Int](5)) + println(x[Int, String](5, "a")) + println(x[Int, String, Int](5, "a", 5)) + } +} diff --git a/tests/untried/pos/t6358.scala b/tests/untried/pos/t6358.scala new file mode 100644 index 000000000..25539c885 --- /dev/null +++ b/tests/untried/pos/t6358.scala @@ -0,0 +1,6 @@ +class L(val t: Int) extends AnyVal { + def lazyString = { + lazy val x = t.toString + () => x + } +} diff --git a/tests/untried/pos/t6358_2.scala b/tests/untried/pos/t6358_2.scala new file mode 100644 index 000000000..7c2beb60d --- /dev/null +++ b/tests/untried/pos/t6358_2.scala @@ -0,0 +1,6 @@ +class Y[T](val i: Option[T]) extends AnyVal { + def q: List[T] = { + lazy val e: List[T] = i.toList + e + } +} diff --git a/tests/untried/pos/t6367.scala b/tests/untried/pos/t6367.scala new file mode 100644 index 000000000..1214be741 --- /dev/null +++ b/tests/untried/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/untried/pos/t6386.scala b/tests/untried/pos/t6386.scala new file mode 100644 index 000000000..4031ae267 --- /dev/null +++ b/tests/untried/pos/t6386.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + reify(manifest[Some[_]]) +} diff --git a/tests/untried/pos/t640.scala b/tests/untried/pos/t640.scala new file mode 100644 index 000000000..45608bc3d --- /dev/null +++ b/tests/untried/pos/t640.scala @@ -0,0 +1,2 @@ +class A extends Serializable +class B extends A with Serializable diff --git a/tests/untried/pos/t6447.scala b/tests/untried/pos/t6447.scala new file mode 100644 index 000000000..6ef69d485 --- /dev/null +++ b/tests/untried/pos/t6447.scala @@ -0,0 +1,18 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +class X { type T } + +object X { + // this works + def foo(x: X): x.T = macro fooImpl + def fooImpl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ??? + + // this doesn't + def bar(x: X, y: X): (x.T, y.T) = macro barImpl + def barImpl(c: Context)(x: c.Expr[X], y: c.Expr[X]): c.Expr[(x.value.T, y.value.T)] = ??? + + // neither does this + def baz(x: X)(xs: List[x.T]): Unit = macro bazImpl + def bazImpl(c: Context)(x: c.Expr[X])(xs: c.Expr[List[x.value.T]]): c.Expr[Unit] = ??? +} diff --git a/tests/untried/pos/t6479.scala b/tests/untried/pos/t6479.scala new file mode 100644 index 000000000..e4a4ff601 --- /dev/null +++ b/tests/untried/pos/t6479.scala @@ -0,0 +1,56 @@ +object TailrecAfterTryCatch { + + @annotation.tailrec + final def good1(): Unit = { + 1 match { + case 2 => { + try { + // return + } catch { + case e: ClassNotFoundException => + } + good1() + } + } + } + + @annotation.tailrec + final def good2(): Unit = { + //1 match { + // case 2 => { + try { + return + } catch { + case e: ClassNotFoundException => + } + good2() + // } + //} + } + + @annotation.tailrec + final def good3(): Unit = { + val 1 = 2 + try { + return + } catch { + case e: ClassNotFoundException => + } + good3() + } + + @annotation.tailrec + final def bad(): Unit = { + 1 match { + case 2 => { + try { + return + } catch { + case e: ClassNotFoundException => + } + bad() + } + } + } + +} diff --git a/tests/untried/pos/t6482.scala b/tests/untried/pos/t6482.scala new file mode 100644 index 000000000..24ea38e51 --- /dev/null +++ b/tests/untried/pos/t6482.scala @@ -0,0 +1,11 @@ +final class TraversableOnceOps[+A](val collection: TraversableOnce[A]) extends AnyVal { + def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] = + if (collection.isEmpty) None else Some(collection.reduceLeft[B](op)) +} +// error: type arguments [B] do not conform to method reduceLeft's type parameter bounds [B >: A] +// if (collection.isEmpty) None else Some(collection.reduceLeft[B](op)) +// ^ + +class Foo[+A <: AnyRef](val xs: List[A]) extends AnyVal { + def baz[B >: A](x: B): List[B] = x :: xs +} diff --git a/tests/untried/pos/t6485a/Macros_1.scala b/tests/untried/pos/t6485a/Macros_1.scala new file mode 100644 index 000000000..cc7dc3d3e --- /dev/null +++ b/tests/untried/pos/t6485a/Macros_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def crash(c: Context): c.Expr[Unit] = c.universe.reify(()) +} diff --git a/tests/untried/pos/t6485a/Test_2.scala b/tests/untried/pos/t6485a/Test_2.scala new file mode 100644 index 000000000..54e260ac7 --- /dev/null +++ b/tests/untried/pos/t6485a/Test_2.scala @@ -0,0 +1,5 @@ +import scala.language.experimental.macros + +final class Ops[T](val x: T) extends AnyVal { + def f = macro Macros.crash +} diff --git a/tests/untried/pos/t6485b/Test.scala b/tests/untried/pos/t6485b/Test.scala new file mode 100644 index 000000000..46d707073 --- /dev/null +++ b/tests/untried/pos/t6485b/Test.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +final class Ops[T](val x: T) extends AnyVal { + def f = macro Macros.crash +} + +object Macros { + def crash(c: Context): c.Expr[Unit] = c.universe.reify(()) +} diff --git a/tests/untried/pos/t6499.scala b/tests/untried/pos/t6499.scala new file mode 100644 index 000000000..db376572e --- /dev/null +++ b/tests/untried/pos/t6499.scala @@ -0,0 +1,3 @@ +object Test { + Map(): Map[_, Int] with Map[_, Int] +} diff --git a/tests/untried/pos/t651.scala b/tests/untried/pos/t651.scala new file mode 100644 index 000000000..c146446af --- /dev/null +++ b/tests/untried/pos/t651.scala @@ -0,0 +1,15 @@ +package test; + +trait Test3 { + trait MatchableImpl { + trait MatchImpl; + } + + trait BracePairImpl { + trait BraceImpl extends MatchableImpl { + private object MyMatch1 extends MatchImpl; + protected def match0 : MatchImpl = MyMatch1; + + } + } +} diff --git a/tests/untried/pos/t6514.scala b/tests/untried/pos/t6514.scala new file mode 100644 index 000000000..7c58605d3 --- /dev/null +++ b/tests/untried/pos/t6514.scala @@ -0,0 +1,11 @@ +object Test { + def e(msg: String) = new Exception(msg) + + // this code ain't dead. + def a(b: Boolean) = { + b match { + case true => throw e("true") + case false => throw e("false") + } + } +} diff --git a/tests/untried/pos/t6516.scala b/tests/untried/pos/t6516.scala new file mode 100644 index 000000000..2980d83eb --- /dev/null +++ b/tests/untried/pos/t6516.scala @@ -0,0 +1,19 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context +import scala.collection.TraversableLike + +// This one compiles +object Test { + type Alias[T, CC[_]] = Context { type PrefixType = TraversableLike[T, CC[T]] } + def f() = macro f_impl + def f_impl(c: Alias[Int, List])() = ??? +} + +// This one doesn't +object Test2 { + type Ctx = scala.reflect.macros.blackbox.Context + type Alias[T, CC[_]] = Ctx { type PrefixType = TraversableLike[T, CC[T]] } + + def f() = macro f_impl + def f_impl(c: Alias[Int, List])() = ??? +} diff --git a/tests/untried/pos/t6537.flags b/tests/untried/pos/t6537.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t6537.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t6537.scala b/tests/untried/pos/t6537.scala new file mode 100644 index 000000000..d0ca3ba43 --- /dev/null +++ b/tests/untried/pos/t6537.scala @@ -0,0 +1,16 @@ +package tester + +object PatMatWarning { + + sealed trait X + sealed trait Y + + def f(x: X) = x match { + case _: Y => false + case _ => true + } + + class X1 extends X + class Y1 extends Y + class Z1 extends X with Y +} diff --git a/tests/untried/pos/t6547.flags b/tests/untried/pos/t6547.flags new file mode 100644 index 000000000..c9b68d70d --- /dev/null +++ b/tests/untried/pos/t6547.flags @@ -0,0 +1 @@ +-optimise diff --git a/tests/untried/pos/t6547.scala b/tests/untried/pos/t6547.scala new file mode 100644 index 000000000..53bd79821 --- /dev/null +++ b/tests/untried/pos/t6547.scala @@ -0,0 +1,6 @@ +trait ConfigurableDefault[@specialized V] { + def fillArray(arr: Array[V], v: V) = (arr: Any) match { + case x: Array[Int] => null + case x: Array[Long] => v.asInstanceOf[Long] + } +} diff --git a/tests/untried/pos/t6551.scala b/tests/untried/pos/t6551.scala new file mode 100644 index 000000000..ada4bea44 --- /dev/null +++ b/tests/untried/pos/t6551.scala @@ -0,0 +1,13 @@ +import scala.language.dynamics + +object Test { + def main(args: Array[String]): Unit = { + class Lenser[T] extends Dynamic { + def selectDynamic(propName: String) = ??? + } + + def lens[T] = new Lenser[T] + + val qq = lens[String] + } +} diff --git a/tests/untried/pos/t6552.scala b/tests/untried/pos/t6552.scala new file mode 100644 index 000000000..98e686a1a --- /dev/null +++ b/tests/untried/pos/t6552.scala @@ -0,0 +1,8 @@ +object Repros { + class Bar {} + class Baz(val myFoo: Foo) { } + trait Foo { + this: Bar => + val thing = new Baz(this) + } +} diff --git a/tests/untried/pos/t6556.scala b/tests/untried/pos/t6556.scala new file mode 100644 index 000000000..e1a6f49b8 --- /dev/null +++ b/tests/untried/pos/t6556.scala @@ -0,0 +1,32 @@ +package nl.ndervorst.commons.scalapimps + +trait Adapter[X] {self => + type This = self.type + val adaptee: X + val adapt: This = self +} + +object Adapter { + implicit def adaptee[Adaptee](adapter: Adapter[Adaptee]) = adapter.adaptee +} + + + +object IterableW { + def zipMerge[E](it1: Iterable[E], it2: Iterable[E])(implicit o: Ordering[E]): Iterable[(Option[E], Option[E])] = null +} + + +class Series[X: Ordering, Y](val adaptee: Iterable[(X, Y)]) extends Adapter[Iterable[(X, Y)]] { + val order = implicitly[Ordering[X]] + def zipMerge(other: Series[X, Y]): Series[X, (Option[Y], Option[Y])] = IterableW.zipMerge(this, other)(new Ordering[(X, Y)] { + def compare(xy1: (X, Y), xy2: (X, Y)) = order.compare(xy1._1, xy2._1) + }).map { + case _ => null + } +} + + +object Series { + implicit def wrap[X: Ordering, Y](itble: Iterable[(X, Y)]): Series[X, Y] = new Series(itble) +} diff --git a/tests/untried/pos/t6562.scala b/tests/untried/pos/t6562.scala new file mode 100644 index 000000000..600234a29 --- /dev/null +++ b/tests/untried/pos/t6562.scala @@ -0,0 +1,14 @@ +class Test { + + @inline + def foo: Unit = { + def it = new {} + (_: Any) => it + } + + @inline + private def bar: Unit = { + def it = new {} + (_: Any) => it + } +} diff --git a/tests/untried/pos/t6574.scala b/tests/untried/pos/t6574.scala new file mode 100644 index 000000000..6bb0042c6 --- /dev/null +++ b/tests/untried/pos/t6574.scala @@ -0,0 +1,19 @@ +class Bad[X, Y](val v: Int) extends AnyVal { + def vv = v + @annotation.tailrec final def foo[Z](a: Int)(b: String): Unit = { + this.foo[Z](a)(b) + } + + @annotation.tailrec final def differentReceiver {: Unit = + {(); new Bad[X, Y](0)}.differentReceiver + } + + @annotation.tailrec final def dependent[Z](a: Int)(b: String): b.type = { + this.dependent[Z](a)(b) + } +} + +class HK[M[_]](val v: Int) extends AnyVal { + def hk[N[_]]: Unit = if (false) hk[M] else () +} + diff --git a/tests/untried/pos/t6575a.scala b/tests/untried/pos/t6575a.scala new file mode 100644 index 000000000..f128714da --- /dev/null +++ b/tests/untried/pos/t6575a.scala @@ -0,0 +1,15 @@ +trait X { def foo: PartialFunction[Int, Int] } + +trait Y extends X { + // Inferred type was AbstractPartialFunction[Int, Int] with Serializable + abstract override def foo = { case i => super.foo(i) * 2 } +} +trait Z extends X { + // ditto + abstract override def foo = { case i => super.foo(i) + 3 } +} + +trait Comb extends Y with Z { + // ... which led to a type error here. + abstract override def foo: PartialFunction[Int, Int] = { case i => super.foo(i) - 2 } +} diff --git a/tests/untried/pos/t6575b.scala b/tests/untried/pos/t6575b.scala new file mode 100644 index 000000000..d3e58b2a1 --- /dev/null +++ b/tests/untried/pos/t6575b.scala @@ -0,0 +1,17 @@ +// inferred types were okay here as Function nodes aren't +// translated into anoymous subclasses of AbstractFunctionN +// until after the typer. +// +// So this test is just confirmation. +trait X { def foo: Function1[Int, Int] } + +trait Y extends X { + abstract override def foo = { case i => super.foo(i) * 2 } +} +trait Z extends X { + abstract override def foo = { case i => super.foo(i) + 3 } +} + +trait Comb extends Y with Z { + abstract override def foo: Function1[Int, Int] = { case i => super.foo(i) - 2 } +} diff --git a/tests/untried/pos/t6595.flags b/tests/untried/pos/t6595.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t6595.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t6595.scala b/tests/untried/pos/t6595.scala new file mode 100644 index 000000000..437c0bcf0 --- /dev/null +++ b/tests/untried/pos/t6595.scala @@ -0,0 +1,18 @@ +import scala.annotation.switch + +class Foo extends { + final val b0 = 5 +} with AnyRef { + final val b1 = 10 + + // Using the @switch annotation as a means of testing that the + // type inferred for b0 is Int(5) and not Int. Only in the former + // case can a switch be generated. + def f(p: Int) = (p: @switch) match { + case `b0` => 1 + case `b1` => 2 + case 15 => 3 + case 20 => 4 + case _ => 5 + } +} diff --git a/tests/untried/pos/t6600.scala b/tests/untried/pos/t6600.scala new file mode 100644 index 000000000..1e8137894 --- /dev/null +++ b/tests/untried/pos/t6600.scala @@ -0,0 +1,8 @@ +final class Natural extends scala.math.ScalaNumber with scala.math.ScalaNumericConversions { + def intValue(): Int = 0 + def longValue(): Long = 0L + def floatValue(): Float = 0.0F + def doubleValue(): Double = 0.0D + def isWhole(): Boolean = false + def underlying() = this +} diff --git a/tests/untried/pos/t6601/PrivateValueClass_1.scala b/tests/untried/pos/t6601/PrivateValueClass_1.scala new file mode 100644 index 000000000..dc0137420 --- /dev/null +++ b/tests/untried/pos/t6601/PrivateValueClass_1.scala @@ -0,0 +1 @@ +class V private (val a: Any) extends AnyVal diff --git a/tests/untried/pos/t6601/UsePrivateValueClass_2.scala b/tests/untried/pos/t6601/UsePrivateValueClass_2.scala new file mode 100644 index 000000000..461b8397b --- /dev/null +++ b/tests/untried/pos/t6601/UsePrivateValueClass_2.scala @@ -0,0 +1,10 @@ +object Test { + // After the first attempt to make seprately compiled value + // classes respect the privacy of constructors, we got: + // + // exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply + // constructor V in class V cannot be accessed in object Test in file test/files/pos/t6601/UsePrivateValueClass_2.scala + // scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object Test + def foo(v: V) = v.a == v.a + def bar(v: V) = v == v +} diff --git a/tests/untried/pos/t661.scala b/tests/untried/pos/t661.scala new file mode 100644 index 000000000..3a447241f --- /dev/null +++ b/tests/untried/pos/t661.scala @@ -0,0 +1,17 @@ +package test; + +object test { + abstract class A { + abstract class C { + type M; + def foo(n : M) : Unit = {} + } + } + trait B extends A { + type N; + trait C extends super.C { + type M = N; + override def foo(n : M) : Unit = super.foo(n); + } + } +} diff --git a/tests/untried/pos/t6624.scala b/tests/untried/pos/t6624.scala new file mode 100644 index 000000000..43bc565cb --- /dev/null +++ b/tests/untried/pos/t6624.scala @@ -0,0 +1,28 @@ +sealed trait KList[+M[_]] + +case class KCons[M[_], +T <: KList[M]]( + tail: T +) extends KList[M] + +case class KNil[M[_]]() extends KList[M] + +object Test { + val klist: KCons[Option, KCons[Option, KCons[Option, KNil[Nothing]]]] = ??? + + // crashes with + // "Exception in thread "main" scala.reflect.internal.Types$TypeError: value _1 is not a member + // of KCons[Option,KCons[Option,KNil[Nothing]]]" + klist match { + case KCons(KCons(KCons(_))) => + } + + // fails with a similar message as an error, rather than a crash. + klist match { + case KCons(KCons(_)) => + } + + // succeeds + klist match { + case KCons(_) => + } +} diff --git a/tests/untried/pos/t6648.scala b/tests/untried/pos/t6648.scala new file mode 100644 index 000000000..9593ebfee --- /dev/null +++ b/tests/untried/pos/t6648.scala @@ -0,0 +1,24 @@ +abstract class Node extends NodeSeq +trait NodeSeq extends Seq[Node] +object NodeSeq { + implicit def seqToNodeSeq(ns: Seq[Node]): NodeSeq = ??? + def foo[B, That](f: Seq[B])(implicit bf: scala.collection.generic.CanBuildFrom[Seq[Int], B, That]): That = ??? +} + +class Transformer { + def apply(nodes: Any): Any = ??? +} + +object transformer1 extends Transformer { + // Adding explicit type arguments, or making the impilcit view + // seqToNodeSeq explicit avoids the crash + NodeSeq.foo { + // These both avoid the crash: + // val t = new Transformer {}; t.apply(null) + // new Transformer().apply(null) + new Transformer {}.apply(null) + + null: NodeSeq + }: NodeSeq +} + diff --git a/tests/untried/pos/t6651.scala b/tests/untried/pos/t6651.scala new file mode 100644 index 000000000..55a3b74e4 --- /dev/null +++ b/tests/untried/pos/t6651.scala @@ -0,0 +1,33 @@ +class YouAreYourself[A <: AnyRef](val you: A) extends AnyVal { + def yourself: you.type = you +} + +object Test { + val s = "" + val s1: s.type = new YouAreYourself[s.type](s).yourself +} + +trait Path { + type Dep <: AnyRef +} + +final class ValueClass[P <: Path](val path: P) extends AnyVal { + import path.Dep + + def apply(dep: Dep)(d2: dep.type, foo: Int): (Dep, d2.type) = (d2, d2) + + // This generates dodgy code; note `ValueClass.this`: + // + // final def bounds$extension[D >: Nothing <: ValueClass.this.path.Dep, + // P >: Nothing <: Path] + // ($this: ValueClass[P]) + // (dep: D) + // (d2: dep.type, foo: Int): (D, d2.type) = scala.Tuple2.apply[D, d2.type](d2, d2); + // + // Nothing crashes down the line, but it certainly doesn't conform to best-practices. + // + // An better alternative would be to add a type parameter for the (singleton) type of + // the wrapped value. + def bounds[D <: Dep](dep: D)(d2: dep.type, foo: Int): (D, d2.type) = (d2, d2) +} + diff --git a/tests/untried/pos/t6664.scala b/tests/untried/pos/t6664.scala new file mode 100644 index 000000000..7eb85f619 --- /dev/null +++ b/tests/untried/pos/t6664.scala @@ -0,0 +1,4 @@ +final case class A(i: Int, s: String) { + protected def copy(s2: String): A = A(i, s2) + protected def copy(i2: Int): A = A(i2, s) +} diff --git a/tests/untried/pos/t6664b.scala b/tests/untried/pos/t6664b.scala new file mode 100644 index 000000000..a62286683 --- /dev/null +++ b/tests/untried/pos/t6664b.scala @@ -0,0 +1,5 @@ +object T { + def A(s: String): A = new A(3, s) + def A(i: Int): A = A(i, "abc") + case class A(i: Int, s: String) +} diff --git a/tests/untried/pos/t6675.flags b/tests/untried/pos/t6675.flags new file mode 100644 index 000000000..d1b831ea8 --- /dev/null +++ b/tests/untried/pos/t6675.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6675.scala b/tests/untried/pos/t6675.scala new file mode 100644 index 000000000..f3bebea5b --- /dev/null +++ b/tests/untried/pos/t6675.scala @@ -0,0 +1,20 @@ +object LeftOrRight { + def unapply[A](value: Either[A, A]): Option[A] = value match { + case scala.Left(x) => Some(x) + case scala.Right(x) => Some(x) + } +} + +object Test { + (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { + case LeftOrRight(pair @ (a, b)) => a // false -Xlint warning: "extractor pattern binds a single value to a Product2 of type (Int, Int)" + } + + (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { + case LeftOrRight((a, b)) => a // false -Xlint warning: "extractor pattern binds a single value to a Product2 of type (Int, Int)" + } + + (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { + case LeftOrRight(a, b) => a // false -Xlint warning: "extractor pattern binds a single value to a Product2 of type (Int, Int)" + } +} diff --git a/tests/untried/pos/t6712.scala b/tests/untried/pos/t6712.scala new file mode 100644 index 000000000..f70d1a873 --- /dev/null +++ b/tests/untried/pos/t6712.scala @@ -0,0 +1,5 @@ +class H { + object O + + def foo(): Unit = { object O } +} diff --git a/tests/untried/pos/t6722.scala b/tests/untried/pos/t6722.scala new file mode 100644 index 000000000..576746c91 --- /dev/null +++ b/tests/untried/pos/t6722.scala @@ -0,0 +1,11 @@ +import scala.language.dynamics + +class Dyn extends Dynamic { + def selectDynamic(s: String): Dyn = new Dyn + def get[T]: T = null.asInstanceOf[T] +} + +object Foo { + val dyn = new Dyn + dyn.foo.bar.baz.get[String] +} diff --git a/tests/untried/pos/t6745.scala b/tests/untried/pos/t6745.scala new file mode 100644 index 000000000..2ab8e6d39 --- /dev/null +++ b/tests/untried/pos/t6745.scala @@ -0,0 +1,4 @@ +class Bar(val i: Int) { + self: Any with AnyRef => + def this() = this(0) +} diff --git a/tests/untried/pos/t675.scala b/tests/untried/pos/t675.scala new file mode 100644 index 000000000..905d29d44 --- /dev/null +++ b/tests/untried/pos/t675.scala @@ -0,0 +1,17 @@ +package test; + +trait T { + abstract class Foo; + private object FOO_0 extends Foo { + Console.println("FOO_0 initialized") + } + trait X { + def foo : Foo = FOO_0; + } +} + +object Test extends App { + val t = new T{} + val x = new t.X{} + Console.println(x.foo) +} diff --git a/tests/untried/pos/t6771.flags b/tests/untried/pos/t6771.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6771.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6771.scala b/tests/untried/pos/t6771.scala new file mode 100644 index 000000000..0f0bd4e4a --- /dev/null +++ b/tests/untried/pos/t6771.scala @@ -0,0 +1,9 @@ +object Test { + type Id[X] = X + val a: Id[Option[Int]] = None + + a match { + case Some(x) => println(x) + case None => + } +} diff --git a/tests/untried/pos/t6780.scala b/tests/untried/pos/t6780.scala new file mode 100644 index 000000000..4a358046c --- /dev/null +++ b/tests/untried/pos/t6780.scala @@ -0,0 +1,20 @@ +object O { + implicit def i: Int = 0 +} + +import O._ + +trait Foo { + implicit val v1: Any + implicit def d1: Any + val v2: Any + implicit val v3: Any +} + +trait Bar1 extends Foo { + implicit val v1 = {implicitly[Int]; ()} // failed due to cycle in Context#implicits being broken with Nil. + def d1 = {implicitly[Int]; ()} // okay + implicit val v2 = {implicitly[Int]; ()} // okay + implicit val v3: Any = {implicitly[Int]; ()} // okay + +} diff --git a/tests/untried/pos/t6797.scala b/tests/untried/pos/t6797.scala new file mode 100644 index 000000000..ef1afa1eb --- /dev/null +++ b/tests/untried/pos/t6797.scala @@ -0,0 +1,4 @@ +object Test extends App /* workaround: don't extend App */ { + private class Matcher(aParam: Option[String] = None) + private val stringMatcher = new Matcher +} diff --git a/tests/untried/pos/t6815.scala b/tests/untried/pos/t6815.scala new file mode 100644 index 000000000..9244b3d35 --- /dev/null +++ b/tests/untried/pos/t6815.scala @@ -0,0 +1,17 @@ +trait U { + trait ValOrDefDefApi { + def name: Any + } + type ValOrDefDef <: ValOrDefDefApi + type ValDef <: ValOrDefDef with ValDefApi + trait ValDefApi extends ValOrDefDefApi { this: ValDef => } + val emptyValDef: ValDef // the result type is volatile +} + +object Test { + val u: U = ??? + + u.emptyValDef match { + case u.emptyValDef => // but we shouldn't let that stop us from treating it as a stable identifier pattern. + } +} diff --git a/tests/untried/pos/t6815_import.scala b/tests/untried/pos/t6815_import.scala new file mode 100644 index 000000000..56f4358d5 --- /dev/null +++ b/tests/untried/pos/t6815_import.scala @@ -0,0 +1,16 @@ +trait U { + trait ValOrDefDefApi { + def name: Any + } + type ValOrDefDef <: ValOrDefDefApi + type ValDef <: ValOrDefDef with ValDefApi + trait ValDefApi extends ValOrDefDefApi { this: ValDef => } + val emptyValDef: ValDef // the result type is volatile +} + +object Test { + val u: U = ??? + + // but we shouldn't let that stop us from treating it as a stable identifier for import + import u.emptyValDef.name +} diff --git a/tests/untried/pos/t684.scala b/tests/untried/pos/t684.scala new file mode 100644 index 000000000..fb5cac3a1 --- /dev/null +++ b/tests/untried/pos/t684.scala @@ -0,0 +1,11 @@ +package test; +trait Test { + trait Ti; + class Foo; + def foo(t : Ti) = t match { + case t : Foo => true; + case _ => false; + } + class Bar extends Foo with Ti; + assert(foo(new Bar)); +} diff --git a/tests/untried/pos/t6846.scala b/tests/untried/pos/t6846.scala new file mode 100644 index 000000000..009566493 --- /dev/null +++ b/tests/untried/pos/t6846.scala @@ -0,0 +1,28 @@ +object Test { + class Arb[_] + implicit def foo[M[_], A]: Arb[M[A]] = null + foo: Arb[List[Int]] + type ListInt = List[Int] + foo: Arb[ListInt] +} + +object Test2 { + import scala.collection.immutable.List + + class Carb[_] + implicit def narrow[N, M[_], A](x: Carb[M[A]])(implicit ev: N <:< M[A]): Carb[N] = null + implicit def bar[M[_], A]: Carb[M[A]] = null + + type ListInt = List[Int] + + val x: List[Int] = List(1) + val y: ListInt = List(1) + + type ListSingletonX = x.type + type ListSingletonY = y.type + + bar: Carb[List[Int]] + bar: Carb[ListInt] + bar: Carb[ListSingletonX] + bar: Carb[ListSingletonY] +} diff --git a/tests/untried/pos/t6891.flags b/tests/untried/pos/t6891.flags new file mode 100644 index 000000000..fe048006a --- /dev/null +++ b/tests/untried/pos/t6891.flags @@ -0,0 +1 @@ +-Ycheck:extmethods -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6891.scala b/tests/untried/pos/t6891.scala new file mode 100644 index 000000000..bed2d0d77 --- /dev/null +++ b/tests/untried/pos/t6891.scala @@ -0,0 +1,26 @@ +object O { + implicit class Foo[A](val value: String) extends AnyVal { + def bippy() = { + @annotation.tailrec def loop(x: A): Unit = loop(x) + () + } + + def boppy() = { + @annotation.tailrec def loop(x: value.type): Unit = loop(x) + () + } + + def beppy[C](c: => C) = { + () => c + @annotation.tailrec def loop(x: value.type): Unit = loop(x) + () => c + () + } + } + // uncaught exception during compilation: Types$TypeError("type mismatch; + // found : A(in method bippy$extension) + // required: A(in class Foo)") @ scala.tools.nsc.typechecker.Contexts$Context.issueCommon(Contexts.scala:396) + // error: scala.reflect.internal.Types$TypeError: type mismatch; + // found : A(in method bippy$extension) + // required: A(in class Foo) +} diff --git a/tests/untried/pos/t6896.flags b/tests/untried/pos/t6896.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t6896.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t6896.scala b/tests/untried/pos/t6896.scala new file mode 100644 index 000000000..ab527a804 --- /dev/null +++ b/tests/untried/pos/t6896.scala @@ -0,0 +1,7 @@ +object TooManyMains { + def main(args: Array[String]): Unit = { + println("Hello, World!") + } + def main(a: Int, b: Int) = ??? + def main(s: String, n: String) = ??? +} diff --git a/tests/untried/pos/t690.scala b/tests/untried/pos/t690.scala new file mode 100644 index 000000000..a93c54f00 --- /dev/null +++ b/tests/untried/pos/t690.scala @@ -0,0 +1,14 @@ +package test; +trait test { + type T; + trait Manager { + type T <: test.this.T; + def foo(t : T) = {}; + } + object M0 extends Manager { + override type T = test.this.T; + override def foo(t : T) = super.foo(t); + } + def t : T; + M0.foo(t); +} diff --git a/tests/untried/pos/t6921.scala b/tests/untried/pos/t6921.scala new file mode 100644 index 000000000..36e70e5d2 --- /dev/null +++ b/tests/untried/pos/t6921.scala @@ -0,0 +1,11 @@ +class Message(messageType: String, reason: Option[String]) + +class ReproForSI6921 { + + private[this] var reason = "" + + def decideElection = { + val explanation = None + new Message("", reason = explanation) + } +} diff --git a/tests/untried/pos/t6925.scala b/tests/untried/pos/t6925.scala new file mode 100644 index 000000000..c6f418519 --- /dev/null +++ b/tests/untried/pos/t6925.scala @@ -0,0 +1,9 @@ +class Test { + def f[T](xs: Set[T]) /* no expected type to trigger inference */ = + xs collect { case x => x } + + def g[T](xs: Set[T]): Set[T] = f[T](xs) // check that f's inferred type is Set[T] + + // check that this type checks: + List(1).flatMap(n => Set(1).collect { case w => w }) +} diff --git a/tests/untried/pos/t6925b.scala b/tests/untried/pos/t6925b.scala new file mode 100644 index 000000000..9130e22a6 --- /dev/null +++ b/tests/untried/pos/t6925b.scala @@ -0,0 +1,18 @@ +// code *generated* by test/scaladoc/run/SI-5933.scala +// duplicated here because it's related to SI-6925 + +import language.higherKinds + +abstract class Base[M[_, _]] { + def foo[A, B]: M[(A, B), Any] +} + +class Derived extends Base[PartialFunction] { + def foo[AA, BB] /*: PartialFunction[(A, B) => Any]*/ = { case (a, b) => (a: AA, b: BB) } +} + +object Test { + lazy val lx = { println("hello"); 3 } + def test1(x: Int = lx) = ??? + def test2(x: Int = lx match { case 0 => 1; case 3 => 4 }) = ??? +} diff --git a/tests/untried/pos/t694.scala b/tests/untried/pos/t694.scala new file mode 100644 index 000000000..ebabc658c --- /dev/null +++ b/tests/untried/pos/t694.scala @@ -0,0 +1,10 @@ +object test3 { + trait Type[T]; + case object IntType extends Type[Int]; + case object StringType extends Type[String]; + + def f[T](t : Type[T]) : T = t match { + case IntType => 10; + case StringType => "hello"; + } +} diff --git a/tests/untried/pos/t6942.flags b/tests/untried/pos/t6942.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6942.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6942/Bar.java b/tests/untried/pos/t6942/Bar.java new file mode 100644 index 000000000..592f62efb --- /dev/null +++ b/tests/untried/pos/t6942/Bar.java @@ -0,0 +1,235 @@ +package foo; + +public enum Bar { + ANGUILLA /*("US")*/, + ANTIGUA_AND_BARBUDA /*("US")*/, + ARGENTINA /*("US")*/, + ARUBA /*("US")*/, + BAHAMAS /*("US")*/, + BARBADOS /*("US")*/, + BELIZE /*("US")*/, + BERMUDA /*("US")*/, + BOLIVIA /*("US")*/, + BRAZIL /*("US")*/, + BRITISH_VIRGIN_ISLANDS /*("US")*/, + CANADA /*("US")*/, + CAYMAN_ISLANDS /*("US")*/, + CHILE /*("US")*/, + CHRISTMAS_ISLANDS /*("US")*/, + COCOS /*("US")*/, + COLOMBIA /*("US")*/, + COSTA_RICA /*("US")*/, + CUBA /*("US")*/, + DOMINICA /*("US")*/, + DOMINICAN_REPUBLIC /*("US")*/, + ECUADOR /*("US")*/, + EL_SALVADOR /*("US")*/, + FALKLAND_ISLANDS /*("US")*/, + GRENADA /*("US")*/, + GUADALOUPE /*("US")*/, + GUATEMALA /*("US")*/, + HAITI /*("US")*/, + HONDURAS /*("US")*/, + NETHERLANDS_ANTILLES /*("US")*/, + NICARAGUA /*("US")*/, + PANAMA /*("US")*/, + PARAGUAY /*("US")*/, + PERU /*("US")*/, + PUERTO_RICO /*("US")*/, + JAMAICA /*("US")*/, + MARTINIQUE /*("US")*/, + MEXICO /*("US")*/, + MONTSERRAT /*("US")*/, + ST_KITTS /*("US")*/, + ST_LUCIA /*("US")*/, + ST_VINCENT /*("US")*/, + SUPRA_NATIONAL /*("US")*/, + TRINIDAD /*("US")*/, + TURKS_AND_CAICOS /*("US")*/, + UNITED_STATES /*("US")*/, + URUGUAY /*("US")*/, + VENEZUELA /*("US")*/, + VIRGIN_ISLANDS /*("US")*/, + + AUSTRALIA /*("AP")*/, + BANGLADESH /*("AP")*/, + BHUTAN /*("AP")*/, + CAMBODIA /*("AP")*/, + CHINA /*("AP")*/, + COOK_ISLANDS /*("AP")*/, + EAST_TIMOR /*("AP")*/, + FIJI /*("AP")*/, + GUAM /*("AP")*/, + HONG_KONG /*("AP")*/, + INDIA /*("AP")*/, + INDONESIA /*("AP")*/, + JAPAN /*("AP")*/, + KIRIBATI /*("AP")*/, + LAOS /*("AP")*/, + MACAU /*("AP")*/, + MALAYSIA /*("AP")*/, + MICRONESIA /*("AP")*/, + MONGOLIA /*("AP")*/, + MYANMAR /*("AP")*/, + NEPAL /*("AP")*/, + NEW_CALEDONIA /*("AP")*/, + NEW_ZEALAND /*("AP")*/, + NORFOLK_ISLAND /*("AP")*/, + NORTH_KOREA /*("AP")*/, + PAKISTAN /*("AP")*/, + PALAU /*("AP")*/, + PAPUA_NEW_GUINEA /*("AP")*/, + PHILIPPINES /*("AP")*/, + PITCAIRN_ISLANDS /*("AP")*/, + SAMOA /*("AP")*/, + WEST_SAMOA /*("AP")*/, + SINGAPORE /*("AP")*/, + SOUTH_KOREA /*("AP")*/, + SRI_LANKA /*("AP")*/, + TAIWAN /*("AP")*/, + THAILAND /*("AP")*/, + TOKELAU /*("AP")*/, + TONGA /*("AP")*/, + TUVALU /*("AP")*/, + VANUATU /*("AP")*/, + VIETNAM /*("AP")*/, + + AFGHANISTAN /*("EU")*/, + ALBANIA /*("EU")*/, + ALGERIA /*("EU")*/, + ANDORRA /*("EU")*/, + ANGOLA /*("EU")*/, + ARMENIA /*("EU")*/, + AUSTRIA /*("EU")*/, + AZERBAIJAN /*("EU")*/, + BAHRAIN /*("EU")*/, + BELARUS /*("EU")*/, + BELGIUM /*("EU")*/, + BENIN /*("EU")*/, + BOSNIA_AND_HERZEGOVINA /*("EU")*/, + BOTSWANA /*("EU")*/, + BOUVET_ISLAND /*("EU")*/, + BRUNEI /*("EU")*/, + BULGARIA /*("EU")*/, + BURKINA_FASO /*("EU")*/, + BURUNDI /*("EU")*/, + CAMEROON /*("EU")*/, + CAPE_VERDE /*("EU")*/, + CHAD /*("EU")*/, + COMOROS /*("EU")*/, + CONGO /*("EU")*/, + CROATIA /*("EU")*/, + CYPRUS /*("EU")*/, + CZECH_REPUBLIC /*("EU")*/, + DR_CONGO /*("EU")*/, + DENMARK /*("EU")*/, + DJIBOUTI /*("EU")*/, + EGYPT /*("EU")*/, + EQUATORIAL_GUINEA /*("EU")*/, + ERITREA /*("EU")*/, + ESTONIA /*("EU")*/, + ETHIOPIA /*("EU")*/, + FAEROE_ISLANDS /*("EU")*/, + FINLAND /*("EU")*/, + FRANCE /*("EU")*/, + FRENCH_GUIANA /*("EU")*/, + GABON /*("EU")*/, + GAMBIA /*("EU")*/, + GEORGIA /*("EU")*/, + GERMANY /*("EU")*/, + GHANA /*("EU")*/, + GIBRALTAR /*("EU")*/, + GREAT_BRITAIN /*("EU")*/, + GREECE /*("EU")*/, + GREENLAND /*("EU")*/, + GUINEA /*("EU")*/, + GUINEA_BISSAU /*("EU")*/, + GUYANA /*("EU")*/, + HUNGARY /*("EU")*/, + ICELAND /*("EU")*/, + IRAN /*("EU")*/, + IRAQ /*("EU")*/, + IRELAND /*("EU")*/, + ISLE_OF_MAN /*("EU")*/, + ISRAEL /*("EU")*/, + ITALY /*("EU")*/, + IVORY_COAST /*("EU")*/, + JERSEY /*("EU")*/, + JORDAN /*("EU")*/, + KAZAKHSTAN /*("EU")*/, + KENYA /*("EU")*/, + KUWAIT /*("EU")*/, + KYRGYZSTAN /*("EU")*/, + LATVIA /*("EU")*/, + LEBANON /*("EU")*/, + LESOTHO /*("EU")*/, + LIBERIA /*("EU")*/, + LIBYA /*("EU")*/, + LIECHTENSTEIN /*("EU")*/, + LITHUANIA /*("EU")*/, + LUXEMBOURG /*("EU")*/, + MACEDONIA /*("EU")*/, + MADAGASCAR /*("EU")*/, + MALAWI /*("EU")*/, + MALDIVES /*("EU")*/, + MALI /*("EU")*/, + MALTA /*("EU")*/, + MARSHALL_ISLAND /*("EU")*/, + MAURITANIA /*("EU")*/, + MAURITIUS /*("EU")*/, + MAYOTTE /*("EU")*/, + MOLDOVA /*("EU")*/, + MONACO /*("EU")*/, + MOROCCO /*("EU")*/, + MOZAMBIQUE /*("EU")*/, + NAMIBIA /*("EU")*/, + NETHERLANDS /*("EU")*/, + NIGER_REPUBLIC /*("EU")*/, + NIGERIA /*("EU")*/, + NORWAY /*("EU")*/, + OMAN /*("EU")*/, + PALESTINE /*("EU")*/, + POLAND /*("EU")*/, + PORTUGAL /*("EU")*/, + QATAR /*("EU")*/, + REUNION /*("EU")*/, + ROMANIA /*("EU")*/, + RUSSIA /*("EU")*/, + RWANDA /*("EU")*/, + SAN_MARINO /*("EU")*/, + SAO_TOME /*("EU")*/, + SAUDI_ARABIA /*("EU")*/, + SENEGAL /*("EU")*/, + SERBIA /*("EU")*/, + SEYCHELLES /*("EU")*/, + SEIRRA_LEONE /*("EU")*/, + SLOVAKIA /*("EU")*/, + SLOVENIA /*("EU")*/, + SOMALIA /*("EU")*/, + SOUTH_AFRICA /*("EU")*/, + SPAIN /*("EU")*/, + ST_HELENA /*("EU")*/, + SUDAN /*("EU")*/, + SURINAME /*("EU")*/, + SVALBARD /*("EU")*/, + SWAZILAND /*("EU")*/, + SWEDEN /*("EU")*/, + SWITZERLAND /*("EU")*/, + SYRIA /*("EU")*/, + TAJIKSTAN /*("EU")*/, + TANZANIA /*("EU")*/, + TOGO /*("EU")*/, + TUNISIA /*("EU")*/, + TURKEY /*("EU")*/, + TURKMENISTAN /*("EU")*/, + UAE /*("EU")*/, + UGANDA /*("EU")*/, + UKRAINE /*("EU")*/, + UZBEKISTAN /*("EU")*/, + VATICAN_CITY /*("EU")*/, + WESTERN_SAHARA /*("EU")*/, + YEMEN /*("EU")*/, + ZAMBIA /*("EU")*/, + ZIMBABWE /*("EU")*/; + +}
\ No newline at end of file diff --git a/tests/untried/pos/t6942/t6942.scala b/tests/untried/pos/t6942/t6942.scala new file mode 100644 index 000000000..77963d263 --- /dev/null +++ b/tests/untried/pos/t6942/t6942.scala @@ -0,0 +1,64 @@ +// not a peep out of the pattern matcher's unreachability analysis +// its budget should suffice for these simple matches (they do have a large search space) +class Test { + import foo.Bar // a large enum + def exhaustUnreachabilitysStack_ENUM_STYLE = (null: Bar) match { + case Bar.BULGARIA => + case _ => + } + + // lots of strings + def exhaustUnreachabilitysStack_StringStyle = "foo" match { + case "a" => + case "b" => + case "c" => + case "d" => + case "e" => + case "f" => + case "aa" => + case "ba" => + case "ca" => + case "da" => + case "ea" => + case "f1a" => + case "a1a" => + case "b1a" => + case "c1a" => + case "d1a" => + case "e1a" => + case "f1a2" => + case "f1a0" => + case "a1a2" => + case "b1a2" => + case "c1a2" => + case "d1a2" => + case "e1a2" => + case "f1a3" => + case "_a" => + case "_b" => + case "_c" => + case "_d" => + case "_e" => + case "_f" => + case "_aa" => + case "_ba" => + case "_ca" => + case "_da" => + case "_ea" => + case "_f1a" => + case "_a1a" => + case "_b1a" => + case "_c1a" => + case "_d1a" => + case "_e1a" => + case "_f1a0" => + case "_f1a2" => + case "_a1a2" => + case "_b1a2" => + case "_c1a2" => + case "_d1a2" => + case "_e1a2" => + case "_f1a3" => + case _ => + } +} diff --git a/tests/untried/pos/t6948.scala b/tests/untried/pos/t6948.scala new file mode 100644 index 000000000..12a1d7eaf --- /dev/null +++ b/tests/untried/pos/t6948.scala @@ -0,0 +1,10 @@ +object t6948 { + val rand = new scala.util.Random() + def a1 = rand.shuffle(0 to 5) + // Tis not to be + // def a2 = rand.shuffle(0 until 5) + def a3 = rand.shuffle(Vector(1, 2, 3)) + def a4 = rand.shuffle(scala.collection.Seq(1, 2, 3)) + def a5 = rand.shuffle(scala.collection.immutable.Seq(1, 2, 3)) + def a6 = rand.shuffle(scala.collection.mutable.Seq(1, 2, 3)) +} diff --git a/tests/untried/pos/t6963c.flags b/tests/untried/pos/t6963c.flags new file mode 100644 index 000000000..4d6e04914 --- /dev/null +++ b/tests/untried/pos/t6963c.flags @@ -0,0 +1 @@ +-Xmigration:2.9 -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6963c.scala b/tests/untried/pos/t6963c.scala new file mode 100644 index 000000000..d3c3616eb --- /dev/null +++ b/tests/untried/pos/t6963c.scala @@ -0,0 +1,25 @@ +object Test { + def f1(x: Any) = x.isInstanceOf[Seq[_]] + def f2(x: Any) = x match { + case _: Seq[_] => true + case _ => false + } + + def f3(x: Any) = x match { + case _: Array[_] => true + case _ => false + } + + def f4(x: Any) = x.isInstanceOf[Traversable[_]] + + def f5(x1: Any, x2: Any, x3: AnyRef) = (x1, x2, x3) match { + case (Some(_: Seq[_]), Nil, _) => 1 + case (None, List(_: List[_], _), _) => 2 + case _ => 3 + } + + def f5: Unit = { + import scala.collection.mutable._ + List(1,2,3,4,5).scanRight(0)(_+_) + } +} diff --git a/tests/untried/pos/t6966.scala b/tests/untried/pos/t6966.scala new file mode 100644 index 000000000..a43d7c501 --- /dev/null +++ b/tests/untried/pos/t6966.scala @@ -0,0 +1,17 @@ +import Ordering.{Byte, comparatorToOrdering} +trait Format[T] +trait InputCache[T] +object CacheIvy { + implicit def basicInputCache[I](implicit fmt: Format[I], eqv: Equiv[I]): InputCache[I] = null + implicit def arrEquiv[T](implicit t: Equiv[T]): Equiv[Array[T]] = null + implicit def hNilCache: InputCache[HNil] = null + implicit def ByteArrayFormat: Format[Array[Byte]] = null + type :+:[H, T <: HList] = HCons[H,T] + implicit def hConsCache[H, T <: HList](implicit head: InputCache[H], tail: InputCache[T]): InputCache[H :+: T] = null + hConsCache[Array[Byte], HNil] +} + +sealed trait HList +sealed trait HNil extends HList +object HNil extends HNil +final class HCons[H, T <: HList](head : H, tail : T) extends HList diff --git a/tests/untried/pos/t697.scala b/tests/untried/pos/t697.scala new file mode 100644 index 000000000..6caea418d --- /dev/null +++ b/tests/untried/pos/t697.scala @@ -0,0 +1,3 @@ +object test { + val x = 10 == 20 == 30 < 10; +} diff --git a/tests/untried/pos/t6976/Exts_1.scala b/tests/untried/pos/t6976/Exts_1.scala new file mode 100644 index 000000000..9b3a69edd --- /dev/null +++ b/tests/untried/pos/t6976/Exts_1.scala @@ -0,0 +1,10 @@ +object Exts { + implicit class AnyExts[T](val o: T) extends AnyVal { + def moo = "moo!" + } +} + +trait Exts { + import language.implicitConversions + implicit def AnyExts[T](o: T) = Exts.AnyExts(o) +} diff --git a/tests/untried/pos/t6976/ImplicitBug_1.scala b/tests/untried/pos/t6976/ImplicitBug_1.scala new file mode 100644 index 000000000..50bc247ac --- /dev/null +++ b/tests/untried/pos/t6976/ImplicitBug_1.scala @@ -0,0 +1,27 @@ +// This one is weird and nasty. Not sure if this is scalac or sbt +// (tried with 0.12 & 0.12.2-RC2) bug. +// +// A level of indirection is required to trigger this bug. +// Exts seems to need to be defined in separate file. +// +// Steps to reproduce: +// 1. sbt clean +// 2. sbt run (it works) +// 3. Comment A & uncomment B. +// 4. sbt run (it fails) +// 5. Switch it back & sbt run. It still fails. +// +// In this project sbt clean helps. However in a large project where this +// bug was found compiler crashed even after doing sbt clean. The only +// way to work around this was to reference Exts object explicitly (C) in +// the source file using its implicit classes. + +// Lets suppose this is a mega-trait combining all sorts of helper +// functionality. +trait Support extends Exts + +object ImplicitsBug extends App with Support { // A +// object ImplicitsBug extends App with Exts { // B + //Exts // C) this reference helped in the large project. + println(3.moo) +} diff --git a/tests/untried/pos/t6976/ImplicitBug_2.scala b/tests/untried/pos/t6976/ImplicitBug_2.scala new file mode 100644 index 000000000..2fea5e299 --- /dev/null +++ b/tests/untried/pos/t6976/ImplicitBug_2.scala @@ -0,0 +1,7 @@ +trait Support extends Exts + +// object ImplicitsBug extends App with Support { // A +object ImplicitsBug extends App with Exts { // B + //Exts // C) this reference helped in the large project. + println(3.moo) +} diff --git a/tests/untried/pos/t698.scala b/tests/untried/pos/t698.scala new file mode 100644 index 000000000..00b370797 --- /dev/null +++ b/tests/untried/pos/t698.scala @@ -0,0 +1,12 @@ +abstract class Foo +{ + val x : Bar +} + +abstract class Bar + +object Test + extends Foo with App +{ + object x extends Bar +} diff --git a/tests/untried/pos/t6994.flags b/tests/untried/pos/t6994.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t6994.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t6994.scala b/tests/untried/pos/t6994.scala new file mode 100644 index 000000000..d70719642 --- /dev/null +++ b/tests/untried/pos/t6994.scala @@ -0,0 +1,8 @@ +object Test { + object NF { + def unapply(t: Throwable): Option[Throwable] = None + } + val x = (try { None } catch { case NF(ex) => None }) getOrElse 0 + // Was emitting a spurious warning post typer: + // "This catches all Throwables. If this is really intended, use `case ex6 : Throwable` to clear this warning." +} diff --git a/tests/untried/pos/t7011.flags b/tests/untried/pos/t7011.flags new file mode 100644 index 000000000..a4c161553 --- /dev/null +++ b/tests/untried/pos/t7011.flags @@ -0,0 +1 @@ +-Ydebug -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7011.scala b/tests/untried/pos/t7011.scala new file mode 100644 index 000000000..18d7aeee7 --- /dev/null +++ b/tests/untried/pos/t7011.scala @@ -0,0 +1,7 @@ +object bar { + def foo: Unit = { + lazy val x = 42 + + {()=>x} + } +} diff --git a/tests/untried/pos/t7014/ThreadSafety.java b/tests/untried/pos/t7014/ThreadSafety.java new file mode 100644 index 000000000..ed508804e --- /dev/null +++ b/tests/untried/pos/t7014/ThreadSafety.java @@ -0,0 +1,9 @@ +package t7014; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) // must be exactly RUNTIME retention (those we parse) +public @interface ThreadSafety { + ThreadSafetyLevel level(); +}
\ No newline at end of file diff --git a/tests/untried/pos/t7014/ThreadSafetyLevel.java b/tests/untried/pos/t7014/ThreadSafetyLevel.java new file mode 100644 index 000000000..4df1dc787 --- /dev/null +++ b/tests/untried/pos/t7014/ThreadSafetyLevel.java @@ -0,0 +1,8 @@ +package t7014; // package needed due to other bug in scalac's java parser + +// since we parse eagerly, we have not yet parsed the classfile when parsing the annotation, +// and on doing so, fail to find a symbol for the COMPLETELY_THREADSAFE reference +// from the annotation's argument to the enum's member +// for now, let's just not crash -- should implement lazy completing at some point +@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) +public enum ThreadSafetyLevel { COMPLETELY_THREADSAFE } diff --git a/tests/untried/pos/t7014/t7014.scala b/tests/untried/pos/t7014/t7014.scala new file mode 100644 index 000000000..7c73f700b --- /dev/null +++ b/tests/untried/pos/t7014/t7014.scala @@ -0,0 +1,3 @@ +package t7014 + +import ThreadSafetyLevel.COMPLETELY_THREADSAFE // refer to annotation so it gets parsed diff --git a/tests/untried/pos/t7022.scala b/tests/untried/pos/t7022.scala new file mode 100644 index 000000000..0609e2d25 --- /dev/null +++ b/tests/untried/pos/t7022.scala @@ -0,0 +1,9 @@ +class Catch[+T] { + def either[U >: T](body: => U): Either[Throwable, U] = ??? +} + +object Test { + implicit class RichCatch[T](val c: Catch[T]) extends AnyVal { + def validation[U >: T](u: => U): Either[Throwable, U] = c.either(u) + } +} diff --git a/tests/untried/pos/t703.scala b/tests/untried/pos/t703.scala new file mode 100644 index 000000000..b24d70c92 --- /dev/null +++ b/tests/untried/pos/t703.scala @@ -0,0 +1,29 @@ +object Go { + trait A { + def f : Unit; // = Console.println("A"); + } + trait B extends A { + abstract override def f = { + super.f; + Console.println("B"); + } + } + trait C extends A { + abstract override def f = { + super.f; + Console.println("C"); + } + } + trait D extends B with C { + abstract override def f = { + super.f; + } + } + class Super extends A { + def f: Unit = Console.println("A") + } + def main(args : Array[String]) : Unit = { + object d extends Super with D + d.f; + } +} diff --git a/tests/untried/pos/t7033.scala b/tests/untried/pos/t7033.scala new file mode 100644 index 000000000..a4d256673 --- /dev/null +++ b/tests/untried/pos/t7033.scala @@ -0,0 +1,15 @@ +import language.higherKinds +object Wrap { + implicit class X[X](val a: X) + + X[Int](0) +} + +class Wrap { + implicit class Y[Y](val a: Y) + Y[Int](0) + implicit class Z[Z[_]](val a: Z[Wrap.this.Z[Z]]) + Z[List](List(new Z[List](null))) +} + +case class X[X](val a: X) diff --git a/tests/untried/pos/t7035.scala b/tests/untried/pos/t7035.scala new file mode 100644 index 000000000..f45bd0a87 --- /dev/null +++ b/tests/untried/pos/t7035.scala @@ -0,0 +1,15 @@ +case class Y(final var x: Int, final private var y: String, final val z1: Boolean, final private val z2: Any) { + + import Test.{y => someY} + List(someY.x: Int, someY.y: String, someY.z1: Boolean, someY.z2: Any) + someY.y = "" +} + +object Test { + val y = Y(0, "", true, new {}) + val unapp: Option[(Int, String, Boolean, Any)] = // was (Int, Boolean, String, Any) !! + Y.unapply(y) + + val Y(a, b, c, d) = y + List(a: Int, b: String, c: Boolean, d: Any) +} diff --git a/tests/untried/pos/t704.scala b/tests/untried/pos/t704.scala new file mode 100644 index 000000000..aedd8c03a --- /dev/null +++ b/tests/untried/pos/t704.scala @@ -0,0 +1,23 @@ +trait D { + private val x = "xxxx should appear twice" + private object xxxx { Console.println(x) } + def get_xxxx: AnyRef = xxxx +} + +trait E extends D { + def f(): Unit = { + val y = "yyyy should appear twice" + object yyyy { + val x1 = get_xxxx + Console.println(y) + } + yyyy + } +} +class C extends E {} +object Go extends D { + def main(args : Array[String]): Unit = { + new C().f() + new C().f() + } +} diff --git a/tests/untried/pos/t7091.scala b/tests/untried/pos/t7091.scala new file mode 100644 index 000000000..72e81a2ea --- /dev/null +++ b/tests/untried/pos/t7091.scala @@ -0,0 +1,7 @@ +package p1.p2 + +protected[p2] class C(var x: Int = 0) + +protected[p2] trait T { + new C() +} diff --git a/tests/untried/pos/t711.scala b/tests/untried/pos/t711.scala new file mode 100644 index 000000000..4dd604096 --- /dev/null +++ b/tests/untried/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/untried/pos/t7126.scala b/tests/untried/pos/t7126.scala new file mode 100644 index 000000000..edac56d28 --- /dev/null +++ b/tests/untried/pos/t7126.scala @@ -0,0 +1,11 @@ +import language._ + +object Test { + type T = Any + boom(???): Option[T] // SOE + def boom[CC[U]](t : CC[T]): Option[CC[T]] = None + + // okay + foo(???): Option[Any] + def foo[CC[U]](t : CC[Any]): Option[CC[Any]] = None +} diff --git a/tests/untried/pos/t7180.scala b/tests/untried/pos/t7180.scala new file mode 100644 index 000000000..15582f6df --- /dev/null +++ b/tests/untried/pos/t7180.scala @@ -0,0 +1,13 @@ +trait Higher[F[_]] + +trait Box[A] +object Box { + implicit def HigherBox = new Higher[Box] {} +} + +object Foo { + val box = implicitly[Higher[Box]] // compiles fine !!! + + type Bar[A] = Box[A] + val bar = implicitly[Higher[Bar]] // <-- this doesn't compile in 2.10.1-RC1, but does in 2.10.0 !!! +} diff --git a/tests/untried/pos/t7183.flags b/tests/untried/pos/t7183.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7183.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7183.scala b/tests/untried/pos/t7183.scala new file mode 100644 index 000000000..7647c1634 --- /dev/null +++ b/tests/untried/pos/t7183.scala @@ -0,0 +1,13 @@ +class A +object A { + def unapply(a: A): Some[A] = Some(a) // Change return type to Option[A] and the warning is gone +} + +object Test { + for (A(a) <- List(new A)) yield a // spurious dead code warning. +} + +// List(new A()).withFilter(((check$ifrefutable$2) => check$ifrefutable$2: @scala.unchecked match { +// case A((a @ _)) => true +// case _ => false // this is dead code, but it's compiler generated. +// })) diff --git a/tests/untried/pos/t7190.scala b/tests/untried/pos/t7190.scala new file mode 100644 index 000000000..449e5c83f --- /dev/null +++ b/tests/untried/pos/t7190.scala @@ -0,0 +1,26 @@ +import scala.language.experimental.macros +import scala.reflect.macros._ + +trait A[T] { + def min[U >: T](implicit ord: Numeric[U]): T = macro A.min[T, U] +} + +object A { + def min[T: c.WeakTypeTag, U >: T: c.WeakTypeTag](c: Context)(ord: c.Expr[Numeric[U]]): c.Expr[T] = { + c.universe.reify { + ord.splice.zero.asInstanceOf[T] + } + } +} + +class B extends A[Int] { + override def min[U >: Int](implicit ord: Numeric[U]): Int = macro B.min[U] +} + +object B { + def min[U >: Int: c.WeakTypeTag](c: Context)(ord: c.Expr[Numeric[U]]): c.Expr[Int] = { + c.universe.reify { + ord.splice.zero.asInstanceOf[Int] + } + } +} diff --git a/tests/untried/pos/t720.scala b/tests/untried/pos/t720.scala new file mode 100644 index 000000000..ef04d01be --- /dev/null +++ b/tests/untried/pos/t720.scala @@ -0,0 +1,9 @@ +trait Conv +object Conv { + implicit def one2two (one: One): Two = new Two } +class One extends Conv +class Two +object Test2 extends App { + def fun (two: Two) = () + fun(new One) +} diff --git a/tests/untried/pos/t7200b.scala b/tests/untried/pos/t7200b.scala new file mode 100644 index 000000000..67ef7fcc6 --- /dev/null +++ b/tests/untried/pos/t7200b.scala @@ -0,0 +1,50 @@ +import language.higherKinds + +trait T { + def t = 0 +} +trait Foo { + def coflatMap[A <: T](f: A): A +} + +object O extends Foo { + def coflatMap[A <: T](f: A) = { + val f2 = coflatMap(f) // inferred in 2.9.2 / 2.10.0 as [Nothing] + f2.t // so this does't type check. + f2 + } +} + +// Why? When a return type is inherited, the derived method +// symbol first gets a preliminary type assigned, based on the +// 1) method type of a unique matching super member +// 2) viewed as a member type of the inheritor (to substitute, +// e.g. class type parameters) +// 3) substituted to replace the super-method's type parameters +// with those of the inheritor +// 4) dissected to take just the return type wrapped in thisMethodType(). +// +// In Scala 2.10.0 and earlier, this preliminary method type +// +// 1) [A#11329 <: <empty>#3.this.T#7068](<param> f#11333: A#11329)A#11329 +// 2) [A#11329 <: <empty>#3.this.T#7068](<param> f#11333: A#11329)A#11329 +// 3) (<param> f#12556: A#11336)A#11336 +// 4) [A#11336 <: <empty>#3.this.T#7068](<param> f#12552: A#11337&0)A#11336 +// +// The type #4 from the old version is problematic: the parameter is typed with +// a skolem for the type parameter `A`. It won't be considered to match the +// method it overrides, instead they are seen as being overloaded, and type inference +// goes awry (Nothing is inferred as the type argument for the recursive call +// to coflatMap. +// +// The Namers patch adds one step here: it subsitutes the type parameter symbols +// for the skolems: +// +// https://github.com/scala/scala/commit/b74c33eb#L2R1014 +// +// So we end up with a method symbol info: +// +// 5) [A#11336 <: <empty>#3.this.T#7068](<param> f#12505: A#11336)A#11336 +// +// This *does* match the method in the super class, and type inference +// chooses the correct type argument. diff --git a/tests/untried/pos/t7226.scala b/tests/untried/pos/t7226.scala new file mode 100644 index 000000000..06f0c95dc --- /dev/null +++ b/tests/untried/pos/t7226.scala @@ -0,0 +1,26 @@ +trait HK { + type Rep[X] + + // okay + def unzip2[A, B](ps: Rep[List[(A, B)]]) + unzip2(null.asInstanceOf[Rep[List[(Int, String)]]]) + + // okay + def unzipHK[A, B, C[_]](ps: Rep[C[(A, B)]]) + unzipHK(null.asInstanceOf[Rep[List[(Int, String)]]]) + + def unzipHKRet0[A, C[_]](ps: C[A]): C[Int] + def ls: List[String] + unzipHKRet0(ls) + + // fail + def unzipHKRet[A, C[_]](ps: Rep[C[A]]): Rep[C[Int]] + def rls: Rep[List[String]] + unzipHKRet(rls) +} + +trait HK1 { + type Rep[A] + def unzip1[A, B, C[_]](ps: Rep[C[(A, B)]]): (Rep[C[A]], Rep[C[B]]) + def doUnzip1[A, B](ps: Rep[List[(A, B)]]) = unzip1(ps) +} diff --git a/tests/untried/pos/t7228.scala b/tests/untried/pos/t7228.scala new file mode 100644 index 000000000..5d936f652 --- /dev/null +++ b/tests/untried/pos/t7228.scala @@ -0,0 +1,75 @@ +object AdaptWithWeaklyConformantType { + implicit class D(d: Double) { def double = d*2 } + + val x1: Int = 1 + var x2: Int = 2 + val x3 = 3 + var x4 = 4 + final val x5 = 5 + final var x6 = 6 + + def f1 = x1.double + def f2 = x2.double + def f3 = x3.double + def f4 = x4.double + def f5 = x5.double + def f6 = x6.double +} + +object AdaptAliasWithWeaklyConformantType { + implicit class D(d: Double) { def double = d*2 } + type T = Int + + val x1: T = 1 + var x2: T = 2 + val x3 = (3: T) + var x4 = (4: T) + final val x5 = (5: T) + final var x6 = (6: T) + + def f1 = x1.double + def f2 = x2.double + def f3 = x3.double + def f4 = x4.double + def f5 = x5.double + def f6 = x6.double +} + +object AdaptToAliasWithWeaklyConformantType { + type U = Double + implicit class D(d: U) { def double = d*2 } + + val x1: Int = 1 + var x2: Int = 2 + val x3 = (3: Int) + var x4 = (4: Int) + final val x5 = (5: Int) + final var x6 = (6: Int) + + def f1 = x1.double + def f2 = x2.double + def f3 = x3.double + def f4 = x4.double + def f5 = x5.double + def f6 = x6.double +} + +object AdaptAliasToAliasWithWeaklyConformantType { + type U = Double + type T = Int + implicit class D(d: U) { def double = d*2 } + + val x1: T = 1 + var x2: T = 2 + val x3 = (3: T) + var x4 = (4: T) + final val x5 = (5: T) + final var x6 = (6: T) + + def f1 = x1.double + def f2 = x2.double + def f3 = x3.double + def f4 = x4.double + def f5 = x5.double + def f6 = x6.double +} diff --git a/tests/untried/pos/t7232.flags b/tests/untried/pos/t7232.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7232.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7232/Foo.java b/tests/untried/pos/t7232/Foo.java new file mode 100644 index 000000000..3478301b3 --- /dev/null +++ b/tests/untried/pos/t7232/Foo.java @@ -0,0 +1,9 @@ +package pack; + +import java.util.List; + +public class Foo { + public static java.util.List okay() { throw new Error(); } + + public static List wrong() { throw new Error(); } +} diff --git a/tests/untried/pos/t7232/List.java b/tests/untried/pos/t7232/List.java new file mode 100644 index 000000000..e42c63aa6 --- /dev/null +++ b/tests/untried/pos/t7232/List.java @@ -0,0 +1,4 @@ +package pack; + +public class List { +} diff --git a/tests/untried/pos/t7232/Test.scala b/tests/untried/pos/t7232/Test.scala new file mode 100644 index 000000000..49c3c12ae --- /dev/null +++ b/tests/untried/pos/t7232/Test.scala @@ -0,0 +1,5 @@ +object Test { + import pack._ + Foo.okay().size() + Foo.wrong().size() +} diff --git a/tests/untried/pos/t7232b.flags b/tests/untried/pos/t7232b.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7232b.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7232b/Foo.java b/tests/untried/pos/t7232b/Foo.java new file mode 100644 index 000000000..94f08d545 --- /dev/null +++ b/tests/untried/pos/t7232b/Foo.java @@ -0,0 +1,8 @@ +package pack; + +import java.util.*; + +public class Foo { + // should be pack.List. + public static List list() { throw new Error(); } +} diff --git a/tests/untried/pos/t7232b/List.java b/tests/untried/pos/t7232b/List.java new file mode 100644 index 000000000..ce977152b --- /dev/null +++ b/tests/untried/pos/t7232b/List.java @@ -0,0 +1,5 @@ +package pack; + +public class List { + public void packList() {} +} diff --git a/tests/untried/pos/t7232b/Test.scala b/tests/untried/pos/t7232b/Test.scala new file mode 100644 index 000000000..6377e26be --- /dev/null +++ b/tests/untried/pos/t7232b/Test.scala @@ -0,0 +1,5 @@ +object Test { + import pack._ + + Foo.list().packList() +} diff --git a/tests/untried/pos/t7232c.flags b/tests/untried/pos/t7232c.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7232c.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7232c/Foo.java b/tests/untried/pos/t7232c/Foo.java new file mode 100644 index 000000000..bbda09a2d --- /dev/null +++ b/tests/untried/pos/t7232c/Foo.java @@ -0,0 +1,10 @@ +package pack; + +import java.util.List; + +public class Foo { + public static class List { + public void isInnerList() {} + } + public static List innerList() { throw new Error(); } +} diff --git a/tests/untried/pos/t7232c/Test.scala b/tests/untried/pos/t7232c/Test.scala new file mode 100644 index 000000000..aa7c71094 --- /dev/null +++ b/tests/untried/pos/t7232c/Test.scala @@ -0,0 +1,4 @@ +object Test { + import pack._ + Foo.innerList().isInnerList() +} diff --git a/tests/untried/pos/t7232d.flags b/tests/untried/pos/t7232d.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7232d.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7232d/Entry.java b/tests/untried/pos/t7232d/Entry.java new file mode 100644 index 000000000..0cfb6fb25 --- /dev/null +++ b/tests/untried/pos/t7232d/Entry.java @@ -0,0 +1,4 @@ +package pack; + +public class Entry { +} diff --git a/tests/untried/pos/t7232d/Foo.java b/tests/untried/pos/t7232d/Foo.java new file mode 100644 index 000000000..df7114a0f --- /dev/null +++ b/tests/untried/pos/t7232d/Foo.java @@ -0,0 +1,8 @@ +package pack; + +import java.util.Map.Entry; + +public class Foo { + public static Entry mapEntry() { throw new Error(); } + public static void javaTest() { mapEntry().getKey(); } +} diff --git a/tests/untried/pos/t7232d/Test.scala b/tests/untried/pos/t7232d/Test.scala new file mode 100644 index 000000000..89a8063b3 --- /dev/null +++ b/tests/untried/pos/t7232d/Test.scala @@ -0,0 +1,4 @@ +object Test { + import pack._ + Foo.mapEntry().getKey() +} diff --git a/tests/untried/pos/t7233.scala b/tests/untried/pos/t7233.scala new file mode 100644 index 000000000..ae15c08c3 --- /dev/null +++ b/tests/untried/pos/t7233.scala @@ -0,0 +1,14 @@ +object Foo { + def bar(i: Int) = i + + def ol(i: Int) = i + def ol(i: String) = i +} +object Test { + import Foo.{ bar => quux, toString => bar, ol => olRenamed} + + val f1 = quux _ + val f1Typed: (Int => Int) = f1 + + val f2: String => String = olRenamed _ +} diff --git a/tests/untried/pos/t7233b.scala b/tests/untried/pos/t7233b.scala new file mode 100644 index 000000000..927c7fcfd --- /dev/null +++ b/tests/untried/pos/t7233b.scala @@ -0,0 +1,8 @@ +object Test { + // crash + def foo(a: Any) = { import a.{toString => toS}; toS } + + // okay + def ok1(a: String) = { import a.{isInstanceOf => iio}; iio[String] } + def ok2(a: Int) = { import a.{toInt => ti}; ti } +} diff --git a/tests/untried/pos/t7239.scala b/tests/untried/pos/t7239.scala new file mode 100644 index 000000000..16e9d00f1 --- /dev/null +++ b/tests/untried/pos/t7239.scala @@ -0,0 +1,38 @@ +object Test { + def BrokenMethod(): HasFilter[(Int, String)] = ??? + + trait HasFilter[B] { + def filter(p: B => Boolean) = ??? + } + + trait HasWithFilter { + def withFilter = ??? + } + + object addWithFilter { + trait NoImplicit + implicit def enrich(v: Any) + (implicit F0: NoImplicit): HasWithFilter = ??? + } + + BrokenMethod().withFilter(_ => true) // okay + BrokenMethod().filter(_ => true) // okay + + locally { + import addWithFilter._ + BrokenMethod().withFilter((_: (Int, String)) => true) // okay + } + + locally { + import addWithFilter._ + // adaptToMemberWithArgs sets the type of the tree `x` + // to ErrorType (while in silent mode, so the error is not + // reported. Later, when the fallback from `withFilter` + // to `filter` is attempted, the closure is taken to have + // have the type `<error> => Boolean`, which conforms to + // `(B => Boolean)`. Only later during pickling does the + // defensive check for erroneous types in the tree pick up + // the problem. + BrokenMethod().withFilter(x => true) // erroneous or inaccessible type. + } +} diff --git a/tests/untried/pos/t7264/A_1.scala b/tests/untried/pos/t7264/A_1.scala new file mode 100644 index 000000000..044d0110a --- /dev/null +++ b/tests/untried/pos/t7264/A_1.scala @@ -0,0 +1,11 @@ +object Foo { + object Values { + implicit def fromInt(x: Int): Values = ??? + } + trait Values +} +final class Foo(name: String) { + def bar(values: Foo.Values): Bar = ??? +} + +trait Bar diff --git a/tests/untried/pos/t7264/B_2.scala b/tests/untried/pos/t7264/B_2.scala new file mode 100644 index 000000000..a8af2e727 --- /dev/null +++ b/tests/untried/pos/t7264/B_2.scala @@ -0,0 +1,7 @@ +object Test { + // if the following line is uncommented, things compile + // type X = Foo.Values + + + def foo(f: Foo) = f.bar(0 /* : Foo.Values */) +} diff --git a/tests/untried/pos/t7285a.flags b/tests/untried/pos/t7285a.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7285a.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7285a.scala b/tests/untried/pos/t7285a.scala new file mode 100644 index 000000000..34e79c741 --- /dev/null +++ b/tests/untried/pos/t7285a.scala @@ -0,0 +1,83 @@ +sealed abstract class Base + +object Test { + case object Up extends Base + + def foo(d1: Base) = + d1 match { + case Up => + } + + // Sealed subtype: ModuleTypeRef <empty>.this.Test.Up.type + // Pattern: UniqueThisType Test.this.type +} + + +object Test1 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + (d1: Base, d2: Base) => + (d1, d2) match { + case (Up, Up) | (Down, Down) => false + case (Down, Up) => true + case (Up, Down) => false + } + } +} + +object Test2 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + (d1: Base, d2: Base) => + (d1) match { + case Up | Down => false + } + } +} + +object Test3 { + sealed abstract class Base + + object Base { + case object Down extends Base + + (d1: Base, d2: Base) => + (d1, d2) match { + case (Down, Down) => false + } + } +} + +object Test4 { + sealed abstract class Base + + object Base { + case object Down extends Base { + } + + case object Up extends Base { + } + + } + import Test4.Base._ + (d1: Base, d2: Base) => + (d1, d2) match { + case (Up, Up) | (Down, Down) => false + case (Down, Test4.Base.Up) => true + case (Up, Down) => false + } +} diff --git a/tests/untried/pos/t7294.scala b/tests/untried/pos/t7294.scala new file mode 100644 index 000000000..ccac2b140 --- /dev/null +++ b/tests/untried/pos/t7294.scala @@ -0,0 +1,6 @@ +object Test { + // no fruitless warning as Tuple2 isn't (yet) final. + // The corresponding `neg` test will treat it as final + // for the purposes of these tests under -Xfuture. + (1, 2) match { case Seq() => 0; case _ => 1 } +} diff --git a/tests/untried/pos/t7296.scala b/tests/untried/pos/t7296.scala new file mode 100644 index 000000000..0c078d365 --- /dev/null +++ b/tests/untried/pos/t7296.scala @@ -0,0 +1,6 @@ +object Test { + type A = Int + // Emits the implementation restriction but then proceeds to crash + // when creating the Foo.unapply. + case class Foo(a: A, b: A, c: A, d: A, e: A, f: A, g: A, h: A, i: A, j: A, k: A, l: A, m: A, n: A, o: A, p: A, q: A, r: A, s: A, t: A, u: A, v: A, w: A, x: A, y: A, Z: A) +} diff --git a/tests/untried/pos/t7315.flags b/tests/untried/pos/t7315.flags new file mode 100644 index 000000000..d1b831ea8 --- /dev/null +++ b/tests/untried/pos/t7315.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7315.scala b/tests/untried/pos/t7315.scala new file mode 100644 index 000000000..5033600fd --- /dev/null +++ b/tests/untried/pos/t7315.scala @@ -0,0 +1,4 @@ +package scala.pack + +@deprecatedInheritance +class C[@specialized A] diff --git a/tests/untried/pos/t7322.scala b/tests/untried/pos/t7322.scala new file mode 100644 index 000000000..006bf89e9 --- /dev/null +++ b/tests/untried/pos/t7322.scala @@ -0,0 +1,11 @@ + +package object t7322 { + implicit class X(sc: StringContext) { + def x_?(args: Any*) = "hi there" + } +} +package t7322 { + trait Y { + x_?"junk" // assume that if it compiles, it works + } +} diff --git a/tests/untried/pos/t7329.scala b/tests/untried/pos/t7329.scala new file mode 100644 index 000000000..143ea3cd1 --- /dev/null +++ b/tests/untried/pos/t7329.scala @@ -0,0 +1 @@ +class TwoParamSpecializedWithDefault[@specialized A, @specialized B](a: A, b: B = (??? : B)) diff --git a/tests/untried/pos/t7364/BadList.java b/tests/untried/pos/t7364/BadList.java new file mode 100644 index 000000000..2692fa085 --- /dev/null +++ b/tests/untried/pos/t7364/BadList.java @@ -0,0 +1,3 @@ +public class BadList extends java.util.ArrayList { + public java.util.ArrayList foo() { return null; } +} diff --git a/tests/untried/pos/t7364/UseIt.scala b/tests/untried/pos/t7364/UseIt.scala new file mode 100644 index 000000000..384716532 --- /dev/null +++ b/tests/untried/pos/t7364/UseIt.scala @@ -0,0 +1,4 @@ +class UseIt { + val list = new BadList + list.foo() +} diff --git a/tests/untried/pos/t7364b/BadList_1.java b/tests/untried/pos/t7364b/BadList_1.java new file mode 100644 index 000000000..fbb428adb --- /dev/null +++ b/tests/untried/pos/t7364b/BadList_1.java @@ -0,0 +1,3 @@ +public class BadList_1 extends java.util.ArrayList { + public java.util.ArrayList foo() { return null; } +} diff --git a/tests/untried/pos/t7364b/UseIt_2.scala b/tests/untried/pos/t7364b/UseIt_2.scala new file mode 100644 index 000000000..06b50f676 --- /dev/null +++ b/tests/untried/pos/t7364b/UseIt_2.scala @@ -0,0 +1,5 @@ +class UseIt { + val list = new BadList_1 + list.foo() + list.set(0, list.get(0)) +} diff --git a/tests/untried/pos/t7369.flags b/tests/untried/pos/t7369.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/t7369.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/t7369.scala b/tests/untried/pos/t7369.scala new file mode 100644 index 000000000..2b43bcaab --- /dev/null +++ b/tests/untried/pos/t7369.scala @@ -0,0 +1,37 @@ +object Test { + val X, Y = true + (null: Tuple1[Boolean]) match { + case Tuple1(X) => + case Tuple1(Y) => // unreachable + case _ => + } +} + + +sealed abstract class B; +case object True extends B; +case object False extends B; + +object Test2 { + + val X: B = True + val Y: B = False + + (null: Tuple1[B]) match { + case Tuple1(X) => + case Tuple1(Y) => // no warning + case _ => + } +} + +object Test3 { + val X, O = true + def classify(neighbourhood: (Boolean, Boolean, Boolean)): String = { + neighbourhood match { + case (X, X, X) => "middle" + case (X, X, O) => "right" + case (O, X, X) => "left" + case _ => throw new IllegalArgumentException("Invalid") + } + } +} diff --git a/tests/untried/pos/t7377/Client_2.scala b/tests/untried/pos/t7377/Client_2.scala new file mode 100644 index 000000000..5728956cc --- /dev/null +++ b/tests/untried/pos/t7377/Client_2.scala @@ -0,0 +1,11 @@ +object Test { + M.noop(List(1) match { case Nil => 0; case (x::xs) => x }) + + case class Foo(a: Int) + val FooAlias: Foo.type = Foo + M.noop(Foo(0) match { case FooAlias(_) => 0 }) + + case class Bar() + val BarAlias: Bar.type = Bar + M.noop(Bar() match { case BarAlias() => 0 }) +} diff --git a/tests/untried/pos/t7377/Macro_1.scala b/tests/untried/pos/t7377/Macro_1.scala new file mode 100644 index 000000000..b38687c8b --- /dev/null +++ b/tests/untried/pos/t7377/Macro_1.scala @@ -0,0 +1,7 @@ +import language.experimental._ +import scala.reflect.macros.blackbox.Context + +object M { + def noopImpl[A](c: Context)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typecheck(c.untypecheck(expr.tree))) + def noop[A](expr: A): A = macro noopImpl[A] +} diff --git a/tests/untried/pos/t7377b.scala b/tests/untried/pos/t7377b.scala new file mode 100644 index 000000000..aeee800d5 --- /dev/null +++ b/tests/untried/pos/t7377b.scala @@ -0,0 +1,13 @@ +object Test { + List(1) match { case Nil => 0; case (x::xs) => x } + + case class Foo(a: Int) + val FooAlias: Foo.type = Foo + Foo(0) match { case FooAlias(_) => 0 } + Foo(0) match { case Foo(_) => 0 } + + case class Bar() + val BarAlias: Bar.type = Bar + Bar() match { case BarAlias() => 0 } + Bar() match { case Bar() => 0 } +} diff --git a/tests/untried/pos/t7426.scala b/tests/untried/pos/t7426.scala new file mode 100644 index 000000000..8e42ad181 --- /dev/null +++ b/tests/untried/pos/t7426.scala @@ -0,0 +1,3 @@ +class foo(x: Any) extends annotation.StaticAnnotation + +@foo(new AnyRef { }) trait A diff --git a/tests/untried/pos/t7427.flags b/tests/untried/pos/t7427.flags new file mode 100644 index 000000000..9c7d6400f --- /dev/null +++ b/tests/untried/pos/t7427.flags @@ -0,0 +1 @@ +-Ydebug diff --git a/tests/untried/pos/t7427.scala b/tests/untried/pos/t7427.scala new file mode 100644 index 000000000..cca52950d --- /dev/null +++ b/tests/untried/pos/t7427.scala @@ -0,0 +1,4 @@ +// Compiles with no options +// Compiles with -Ydebug -Ydisable-unreachable-prevention +// Crashes with -Ydebug +trait Bippy { 3 match { case 3 => } } diff --git a/tests/untried/pos/t7433.flags b/tests/untried/pos/t7433.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t7433.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t7433.scala b/tests/untried/pos/t7433.scala new file mode 100644 index 000000000..22e7e3434 --- /dev/null +++ b/tests/untried/pos/t7433.scala @@ -0,0 +1,10 @@ +object Test { + def foo(): Unit = { + try { + for (i <- 1 until 5) return + } catch { + case _: NullPointerException | _: RuntimeException => + // was: "catch block may intercept non-local return from method check" + } + } +} diff --git a/tests/untried/pos/t7461/Macros_1.scala b/tests/untried/pos/t7461/Macros_1.scala new file mode 100644 index 000000000..74ebf5af9 --- /dev/null +++ b/tests/untried/pos/t7461/Macros_1.scala @@ -0,0 +1,13 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Macros { + def impl(c: Context) = { + import c.universe._ + val wut = c.typecheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true) + // println(showRaw(wut, printIds = true, printTypes = true)) + c.Expr[Unit](q"()") + } + + def foo = macro impl +} diff --git a/tests/untried/pos/t7461/Test_2.scala b/tests/untried/pos/t7461/Test_2.scala new file mode 100644 index 000000000..866e3dc6f --- /dev/null +++ b/tests/untried/pos/t7461/Test_2.scala @@ -0,0 +1,3 @@ +class C { + def foo = Macros.foo +} diff --git a/tests/untried/pos/t7475a.scala b/tests/untried/pos/t7475a.scala new file mode 100644 index 000000000..810ce9a05 --- /dev/null +++ b/tests/untried/pos/t7475a.scala @@ -0,0 +1,11 @@ +trait AbstractPublic { + def queue: Any +} +trait ConcretePrivate { + private val queue: Any = () +} + +abstract class Mix + extends ConcretePrivate with AbstractPublic { + final def queue: Any = () +} diff --git a/tests/untried/pos/t7475b.scala b/tests/untried/pos/t7475b.scala new file mode 100644 index 000000000..a34743b8b --- /dev/null +++ b/tests/untried/pos/t7475b.scala @@ -0,0 +1,8 @@ +trait U { +} + +trait T { + type TT = Any with T with U + private val priv = 0 + (??? : TT).priv +} diff --git a/tests/untried/pos/t7475d.scala b/tests/untried/pos/t7475d.scala new file mode 100644 index 000000000..497c2bf44 --- /dev/null +++ b/tests/untried/pos/t7475d.scala @@ -0,0 +1,11 @@ +trait T { + type TT = T with Any + private val priv = 0 + (??? : TT).priv +} + +trait U { + type UU = Any with U + private val priv = 0 + (??? : UU).priv +} diff --git a/tests/untried/pos/t7475e.scala b/tests/untried/pos/t7475e.scala new file mode 100644 index 000000000..fbc965c4c --- /dev/null +++ b/tests/untried/pos/t7475e.scala @@ -0,0 +1,13 @@ +trait U { + private val priv = 0 + type TT = U with T // should allow `priv` + (??? : TT).priv +} + +trait Base { + +} + +trait T extends Base { + +} diff --git a/tests/untried/pos/t7486-named.scala b/tests/untried/pos/t7486-named.scala new file mode 100644 index 000000000..253293e5f --- /dev/null +++ b/tests/untried/pos/t7486-named.scala @@ -0,0 +1,8 @@ + +object Test { + def fold(empty: Any) = () + implicit val notAnnotatedImplicit = new { + fold(empty = 0) + def empty[A]: Any = ??? + } +} diff --git a/tests/untried/pos/t7486.scala b/tests/untried/pos/t7486.scala new file mode 100644 index 000000000..6dd7f4c4a --- /dev/null +++ b/tests/untried/pos/t7486.scala @@ -0,0 +1,8 @@ +object Test{ + var locker = 0 + // remove implicit, or change to `locker = locker + 1` to make it compile. + implicit val davyJones0 = { + locker += 0 + 0 + } +} diff --git a/tests/untried/pos/t7505.scala b/tests/untried/pos/t7505.scala new file mode 100644 index 000000000..bc8c7fad6 --- /dev/null +++ b/tests/untried/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/untried/pos/t7516/A_1.scala b/tests/untried/pos/t7516/A_1.scala new file mode 100644 index 000000000..3bd477dcd --- /dev/null +++ b/tests/untried/pos/t7516/A_1.scala @@ -0,0 +1,9 @@ +import scala.reflect._,macros._, scala.language.experimental.macros + +object A { + def impl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[List[T]] = { + val r = c.universe.reify { List(t.splice) } + c.Expr[List[T]]( c.untypecheck(r.tree) ) + } + def demo[T](t: T): List[T] = macro impl[T] +} diff --git a/tests/untried/pos/t7516/B_2.scala b/tests/untried/pos/t7516/B_2.scala new file mode 100644 index 000000000..1b8531bc8 --- /dev/null +++ b/tests/untried/pos/t7516/B_2.scala @@ -0,0 +1,4 @@ +object B { + final case class CV(p: Int = 3, g: Int = 2) + A.demo { val d = 4; CV(g = d); "a" } +} diff --git a/tests/untried/pos/t7517.scala b/tests/untried/pos/t7517.scala new file mode 100644 index 000000000..df4f40130 --- /dev/null +++ b/tests/untried/pos/t7517.scala @@ -0,0 +1,22 @@ +trait Box[ K[A[x]] ] + +object Box { + // type constructor composition + sealed trait ∙[A[_], B[_]] { type l[T] = A[B[T]] } + + // composes type constructors inside K + type SplitBox[K[A[x]], B[x]] = Box[ ({ type l[A[x]] = K[ (A ∙ B)#l] })#l ] + + def split[ K[A[x]], B[x] ](base: Box[K]): SplitBox[K,B] = ??? + + class Composed[B[_], L[A[x]] ] { + val box: Box[L] = ??? + + type Split[ A[x] ] = L[ (A ∙ B)#l ] + val a: Box[Split] = Box.split(box) + + //Either of these work: + val a1: Box[Split] = Box.split[L,B](box) + val a2: Box[ ({ type l[A[x]] = L[ (A ∙ B)#l ] })#l ] = Box.split(box) + } +} diff --git a/tests/untried/pos/t7520.scala b/tests/untried/pos/t7520.scala new file mode 100644 index 000000000..747f5278e --- /dev/null +++ b/tests/untried/pos/t7520.scala @@ -0,0 +1,10 @@ +class A { + val x: Singleton with this.type = this + val y: this.type = x +} + +class B { + val x = "" + val xs: x.type with Singleton = x + val y: x.type = xs +} diff --git a/tests/untried/pos/t7532/A_1.java b/tests/untried/pos/t7532/A_1.java new file mode 100644 index 000000000..1ade76cc7 --- /dev/null +++ b/tests/untried/pos/t7532/A_1.java @@ -0,0 +1,6 @@ +class R { + public class attr { // Will have the bytecode name `R$attr`, not to be confused with `R@tr`! + } + public static class attr1 { + } +} diff --git a/tests/untried/pos/t7532/B_2.scala b/tests/untried/pos/t7532/B_2.scala new file mode 100644 index 000000000..40bc0615a --- /dev/null +++ b/tests/untried/pos/t7532/B_2.scala @@ -0,0 +1,5 @@ +object Test { + val r = new R + new r.attr() // Was: error while loading attr, class file '.../t7532-pos.obj/R$attr.class' has location not matching its contents: contains class + new R.attr1 +} diff --git a/tests/untried/pos/t7532b/A_1.scala b/tests/untried/pos/t7532b/A_1.scala new file mode 100644 index 000000000..586465ee6 --- /dev/null +++ b/tests/untried/pos/t7532b/A_1.scala @@ -0,0 +1,7 @@ +package pack +class R { + class attr // Will have the bytecode name `R$attr`, not to be confused with `R@tr`! + class `@` +} + +class `@` diff --git a/tests/untried/pos/t7532b/B_2.scala b/tests/untried/pos/t7532b/B_2.scala new file mode 100644 index 000000000..c4f15daf5 --- /dev/null +++ b/tests/untried/pos/t7532b/B_2.scala @@ -0,0 +1,8 @@ +import pack._ + +object Test { + val r = new R + new r.attr() + new r.`@` + new `@` +} diff --git a/tests/untried/pos/t756.scala b/tests/untried/pos/t756.scala new file mode 100644 index 000000000..a3c790c65 --- /dev/null +++ b/tests/untried/pos/t756.scala @@ -0,0 +1,6 @@ +object test { + for { + n <- Some(42) + _ <- Some(24) + } yield n +} diff --git a/tests/untried/pos/t757.scala b/tests/untried/pos/t757.scala new file mode 100644 index 000000000..602f3cd4d --- /dev/null +++ b/tests/untried/pos/t757.scala @@ -0,0 +1,13 @@ +package foo { + object C { + def foo: Unit = { + Console.println("foo") + } + } +} + +package bar { + object Main extends App { + foo.C.foo + } +} diff --git a/tests/untried/pos/t757a.scala b/tests/untried/pos/t757a.scala new file mode 100644 index 000000000..f52652b1b --- /dev/null +++ b/tests/untried/pos/t757a.scala @@ -0,0 +1 @@ +package foo diff --git a/tests/untried/pos/t758.scala b/tests/untried/pos/t758.scala new file mode 100644 index 000000000..160bf3717 --- /dev/null +++ b/tests/untried/pos/t758.scala @@ -0,0 +1,7 @@ +trait A { type T; type M >: T } +trait B extends A { + val x : String; + val u : A { type T = B.this.T } ; + type T = x.type; + type M = u.M +} diff --git a/tests/untried/pos/t759.scala b/tests/untried/pos/t759.scala new file mode 100644 index 000000000..4fa0ca0b2 --- /dev/null +++ b/tests/untried/pos/t759.scala @@ -0,0 +1,6 @@ +object Test extends App { + + def f[A](x : => A) = x + + Console.println(f(Array(42))(0)) +} diff --git a/tests/untried/pos/t7591/Demo.scala b/tests/untried/pos/t7591/Demo.scala new file mode 100644 index 000000000..696d53585 --- /dev/null +++ b/tests/untried/pos/t7591/Demo.scala @@ -0,0 +1,83 @@ +/* NEST (New Scala Test) + * Copyright 2007-2013 LAMP/EPFL + * @author Paul Phillips + */ + +import scala.tools.cmd._ + +/** A sample command specification for illustrative purposes. + * First take advantage of the meta-options: + * + * // this command creates an executable runner script "demo" + * % scala scala.tools.cmd.Demo --self-update demo + * + * // this one creates and sources a completion file - note backticks + * % `./demo --bash` + * + * // and now you have a runner with working completion + * % ./demo --<tab> + * --action --defint --int + * --bash --defstr --str + * --defenv --self-update --unary + * + * The normal option configuration is plausibly self-explanatory. + */ +trait DemoSpec extends Spec with Meta.StdOpts with Interpolation { + lazy val referenceSpec = DemoSpec + lazy val programInfo = Spec.Info("demo", "Usage: demo [<options>]", "scala.tools.cmd.Demo") + + help("""Usage: demo [<options>]""") + heading("Unary options:") + + val optIsUnary = "unary" / "a unary option" --? ; + ("action" / "a body which may be run") --> println("Hello, I am the --action body.") + + heading("Binary options:") + val optopt = "str" / "an optional String" --| + val optoptInt = ("int" / "an optional Int") . --^[Int] + val optEnv = "defenv" / "an optional String" defaultToEnv "PATH" + val optDefault = "defstr" / "an optional String" defaultTo "default" + val optDefaultInt = "defint" / "an optional Int" defaultTo -1 + val optExpand = "alias" / "an option which expands" expandTo ("--int", "15") +} + +object DemoSpec extends DemoSpec with Property { + lazy val propMapper = new PropertyMapper(DemoSpec) + + type ThisCommandLine = SpecCommandLine + def creator(args: List[String]) = + new SpecCommandLine(args) { + override def errorFn(msg: String) = { println("Error: " + msg) ; sys.exit(0) } + } +} + +class Demo(args: List[String]) extends { + val parsed = DemoSpec(args: _*) +} with DemoSpec with Instance { + import java.lang.reflect._ + + def helpMsg = DemoSpec.helpMsg + def demoSpecMethods = this.getClass.getMethods.toList + private def isDemo(m: Method) = (m.getName startsWith "opt") && !(m.getName contains "$") && (m.getParameterTypes.isEmpty) + + def demoString(ms: List[Method]) = { + val longest = ms map (_.getName.length) max + val formatStr = " %-" + longest + "s: %s" + val xs = ms map (m => formatStr.format(m.getName, m.invoke(this))) + + xs mkString ("Demo(\n ", "\n ", "\n)\n") + } + + override def toString = demoString(demoSpecMethods filter isDemo) +} + +object Demo { + def main(args: Array[String]): Unit = { + val runner = new Demo(args.toList) + + if (args.isEmpty) + println(runner.helpMsg) + + println(runner) + } +} diff --git a/tests/untried/pos/t762.scala b/tests/untried/pos/t762.scala new file mode 100644 index 000000000..76860272e --- /dev/null +++ b/tests/untried/pos/t762.scala @@ -0,0 +1,2 @@ +trait Foo { type T } +trait Bar extends Foo { val x : Foo { type T <: Bar.this.T } = this : this.type } diff --git a/tests/untried/pos/t7649.flags b/tests/untried/pos/t7649.flags new file mode 100644 index 000000000..fcf951d90 --- /dev/null +++ b/tests/untried/pos/t7649.flags @@ -0,0 +1 @@ +-Yrangepos
\ No newline at end of file diff --git a/tests/untried/pos/t7649.scala b/tests/untried/pos/t7649.scala new file mode 100644 index 000000000..d70dc05ea --- /dev/null +++ b/tests/untried/pos/t7649.scala @@ -0,0 +1,20 @@ +object Test { + val c: scala.reflect.macros.blackbox.Context = ??? + import c.universe._ + reify { + // The lookup of the implicit WeakTypeTag[Any] + // was triggering an unpositioned tree. + c.Expr[Any](q"0").splice + } + + import scala.reflect.ClassTag + def ct[A: ClassTag]: Expr[A] = ??? + def tt[A: TypeTag]: Expr[A] = ??? + def wtt[A: WeakTypeTag]: Expr[A] = ??? + + reify { + ct[String].splice + tt[String].splice + wtt[String].splice + } +} diff --git a/tests/untried/pos/t7668.scala b/tests/untried/pos/t7668.scala new file mode 100644 index 000000000..222a13d03 --- /dev/null +++ b/tests/untried/pos/t7668.scala @@ -0,0 +1,12 @@ +trait Space { + type T + val x: T +} + +trait Extractor { + def extract(s: Space): s.T +} + +class Sub extends Extractor { + def extract(s: Space) = s.x +} diff --git a/tests/untried/pos/t767.scala b/tests/untried/pos/t767.scala new file mode 100644 index 000000000..c3da64f1e --- /dev/null +++ b/tests/untried/pos/t767.scala @@ -0,0 +1,18 @@ +abstract class AbsCell { + type T = Node + val init: T + private var value: T = init + def get: T = value + def set (x: T): Unit = { value = x } + + class Node { + val foo = 1 + } +} + +object inner { + def main(args: Array[String]): Unit = { + val cell = new AbsCell { val init = new Node() } + cell.set(new cell.type#T()) // nullpointer exception + } +} diff --git a/tests/untried/pos/t7688.scala b/tests/untried/pos/t7688.scala new file mode 100644 index 000000000..5a846b97e --- /dev/null +++ b/tests/untried/pos/t7688.scala @@ -0,0 +1,7 @@ +import scala.reflect.macros._ + +class A[C <: Context with Singleton](position: C#Position) + +object A { + def apply(c: Context)(in: c.Tree): A[c.type] = new A(in.pos) +} diff --git a/tests/untried/pos/t7689.scala b/tests/untried/pos/t7689.scala new file mode 100644 index 000000000..022e7ab7a --- /dev/null +++ b/tests/untried/pos/t7689.scala @@ -0,0 +1,7 @@ +object A { + // The default getter must have an explicit return type (List[_] => Int) + // This wasn't happening since e28c3edda4. That commit encoded upper/lower + // bounds of Any/Nothing as EmptyTree, which were triggering an .isEmpty + // check in Namers#TypeTreeSubstitutor + def x(f: List[_] => Int = _ => 3) = 9 +} diff --git a/tests/untried/pos/t7690.scala b/tests/untried/pos/t7690.scala new file mode 100644 index 000000000..4d88c3348 --- /dev/null +++ b/tests/untried/pos/t7690.scala @@ -0,0 +1,17 @@ +object A +trait B[T] + +object C { + implicit def notUsed[L[x]](in: L[Int]): B[L[Int]] = ??? + + class E(val ls: Int) { + def x(f: Int => Boolean): Boolean = f(ls) + } + implicit def isUsed(ls: Int): E = new E(ls) + + def amethod(in: Int): Boolean = + in.x { i => + import A._ + "asdf" == i.toString + } +} diff --git a/tests/untried/pos/t7694.scala b/tests/untried/pos/t7694.scala new file mode 100644 index 000000000..9852d5ec7 --- /dev/null +++ b/tests/untried/pos/t7694.scala @@ -0,0 +1,40 @@ +trait A +trait B + +trait L[A2, B2 <: A2] { + def bar(a: Any, b: Any) = 0 +} + +object Lub { + // use named args transforms to include TypeTree(<lub.tpe>) in the AST before refchecks. + def foo(a: L[_, _], b: Any) = 0 + + foo(b = 0, a = if (true) (null: L[A, A]) else (null: L[B, B])) + + (if (true) (null: L[A, A]) else (null: L[B, B])).bar(b = 0, a = 0) +} + +/* +The LUB ends up as: + +TypeRef( + TypeSymbol( + abstract trait L#7038[A2#7039, B2#7040 <: A2#7039] extends AnyRef#2197 + + ) + args = List( + AbstractTypeRef( + AbstractType( + type _1#13680 >: A#7036 with B#7037 <: Object#1752 + ) + ) + AbstractTypeRef( + AbstractType( + type _2#13681 >: A#7036 with B#7037 <: Object#1752 + ) + ) + ) +) + +Note that type _2#13681 is *not* bound by _1#13680 +*/ diff --git a/tests/untried/pos/t7716.scala b/tests/untried/pos/t7716.scala new file mode 100644 index 000000000..40117051e --- /dev/null +++ b/tests/untried/pos/t7716.scala @@ -0,0 +1,16 @@ +object Test { + def test: Unit = { + val e: java.lang.Enum[_] = java.util.concurrent.TimeUnit.SECONDS + e match { case x => println(x) } + + + trait TA[X <: CharSequence] + val ta: TA[_] = new TA[String] {} + + ta match { + case _ => println("hi") + } + + def f(ta: TA[_]) = ta match { case _ => "hi" } + } +} diff --git a/tests/untried/pos/t7753.scala b/tests/untried/pos/t7753.scala new file mode 100644 index 000000000..80e2f1c66 --- /dev/null +++ b/tests/untried/pos/t7753.scala @@ -0,0 +1,36 @@ +import scala.language.{ higherKinds, implicitConversions } + +trait Foo { type Out } + +trait SI { + val instance: Foo + type Out +} + +object Test { + def test: Unit = { + def indirect(si: SI)(v: si.instance.Out) = v + + val foo: Foo { type Out = Int } = ??? + def conv(i: Foo): SI { type Out = i.Out; val instance: i.type } = ??? + + val converted = conv(foo) + + val v1: Int = indirect(converted)(23) // Okay (after refining the return type `instance` in the return type of `conv`) + /* + indirect(converted){(v: converted.instance.Out)converted.instance.Out}( + 23{Int(23)} + ){converted.instance.Out}; + */ + + val v2: Int = indirect(conv(foo))(23) // Used to fail as follows: + /* + indirect( + conv(foo){si.SI{type Out = foo.Out; val instance: si.Test.<refinement>.type}} + ){(v: si.instance.Out)si.instance.Out}( + 23{<error>} + ){<error>}; + */ + + } +} diff --git a/tests/untried/pos/t7776.check b/tests/untried/pos/t7776.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t7776.check diff --git a/tests/untried/pos/t7776.scala b/tests/untried/pos/t7776.scala new file mode 100644 index 000000000..627d20dd6 --- /dev/null +++ b/tests/untried/pos/t7776.scala @@ -0,0 +1,20 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +class MacroErasure { + def app(f: Any => Any, x: Any): Any = macro MacroErasure.appMacro + def app[A](f: A => Any, x: Any): Any = macro MacroErasure.appMacroA[A] +} + +object MacroErasure { + def appMacro(c: Context)( + f: c.Expr[Any => Any], x: c.Expr[Any]): c.Expr[Any] = { + import c.universe._ + c.Expr(q"$f($x)") + } + def appMacroA[A](c: Context)(f: c.Expr[A => Any], x: c.Expr[Any])( + implicit tt: c.WeakTypeTag[A]): c.Expr[Any] = { + import c.universe._ + c.Expr(q"$f[${tt.tpe}]($x)") + } +} diff --git a/tests/untried/pos/t7782.scala b/tests/untried/pos/t7782.scala new file mode 100644 index 000000000..037bdad67 --- /dev/null +++ b/tests/untried/pos/t7782.scala @@ -0,0 +1,25 @@ +package pack + +object Test { + import O.empty + empty // this will trigger completion of `test` + // with skolemizationLevel = 1 +} + +object O { + // order matters (!!!) + + // this order breaks under 2.10.x + def empty[E]: C[E] = ??? + def empty(implicit a: Any): Any = ??? +} + +abstract class C[E] { + def foo[BB](f: BB) + def test[B](f: B): Any = foo(f) + // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1) + // --- because --- + // argument expression's type is not compatible with formal parameter type; + // found : B&1 + // required: ?BB +} diff --git a/tests/untried/pos/t7782b.scala b/tests/untried/pos/t7782b.scala new file mode 100644 index 000000000..09da4a5c5 --- /dev/null +++ b/tests/untried/pos/t7782b.scala @@ -0,0 +1,25 @@ +package pack + +object Test { + import O.empty + empty // this will trigger completion of `test` + // with skolemizationLevel = 1 +} + +object O { + // order matters (!!!) + + // this order breaks under 2.11.x + def empty(implicit a: Any): Any = ??? + def empty[E]: C[E] = ??? +} + +abstract class C[E] { + def foo[BB](f: BB) + def test[B](f: B): Any = foo(f) + // error: no type parameters for method foo: (<param> f: BB)scala.this.Unit exist so that it can be applied to arguments (B&1) + // --- because --- + // argument expression's type is not compatible with formal parameter type; + // found : B&1 + // required: ?BB +} diff --git a/tests/untried/pos/t7785.scala b/tests/untried/pos/t7785.scala new file mode 100644 index 000000000..1de693d13 --- /dev/null +++ b/tests/untried/pos/t7785.scala @@ -0,0 +1,34 @@ +import scala.language._ + +trait R[+Repr] + +trait TraversableOps { + implicit val R: R[Nothing] = ??? + + // Removing the implicit parameter in both fixes the crash + // removing it into one only gives a valid compiler error. + trait OpsDup1[Repr] { + def force(implicit bf: R[Repr]): Any + } + + trait Ops[Repr] extends OpsDup1[Repr] { + def force(implicit bf: R[Repr], dummy: DummyImplicit): Any + } + + implicit def ct2ops[T, C[+X]](t: C[T]): + Ops[C[T]] + + def force[T](t: Option[T]) = + // ct2ops(t).force + t.force //Fails compilation on 2.10.2. + + + /* To get a closer look at the crash: + :power + val foo = typeOf[C].member(TermName("foo")) + val pt = analyzer.HasMember(TermName("force")) + val instantiated = foo.info.finalResultType.instantiateTypeParams(foo.typeParams, foo.typeParams.map(TypeVar(_))) + instantiated <:< pt + */ + def foo[T, C[+X]]: Ops[C[T]] +} diff --git a/tests/untried/pos/t7788.scala b/tests/untried/pos/t7788.scala new file mode 100644 index 000000000..c97cb34ce --- /dev/null +++ b/tests/untried/pos/t7788.scala @@ -0,0 +1,8 @@ +class Test { + // Predef used to define a method `conforms` to produce the implicit evidence below + // all this does is ensure we don't rename Predef.$conforms back to conforms when $ goes out of fashion + // or that there is some other way of generating the implicit value that witnesses T => U for T <: U + def conforms(x: Int, y: Int) = x < y + def foo[A](implicit ev: Int => A) = ??? + foo[Int] +} diff --git a/tests/untried/pos/t780.scala b/tests/untried/pos/t780.scala new file mode 100644 index 000000000..7ed6745d9 --- /dev/null +++ b/tests/untried/pos/t780.scala @@ -0,0 +1,2 @@ +class B extends A { protected val x = false } +trait A { self: B => x } diff --git a/tests/untried/pos/t7815.scala b/tests/untried/pos/t7815.scala new file mode 100644 index 000000000..12a434c5b --- /dev/null +++ b/tests/untried/pos/t7815.scala @@ -0,0 +1,30 @@ +import language.higherKinds + +trait Foo[A <: AnyRef] { + type Repr + def f(a: A): Repr + def g(a: A): Option[Repr] + + type M[X] + def m(a: A): M[a.type] + + type Id[X] = X + def n(a: A): Id[(Repr, M[a.type])] + +} + +object Foo { + type Aux[A <: AnyRef, B] = Foo[A] { type Repr = B; type M[X] = Int } + +} + +object Main extends App { + def mapWithFoo[A <: AnyRef, B](as: List[A])(implicit foo: Foo.Aux[A, B]) = { + // Should be Eta expandable because the result type of `f` is not + // dependant on the value, it is just `B`. + as map foo.f + as map foo.g + as map foo.m + as map foo.n + } +} diff --git a/tests/untried/pos/t7818.scala b/tests/untried/pos/t7818.scala new file mode 100644 index 000000000..77b99e7d5 --- /dev/null +++ b/tests/untried/pos/t7818.scala @@ -0,0 +1,10 @@ +class Observable1[+T](val asJava: JObservable[_ <: T]) extends AnyVal { + private def foo[X](a: JObservable[X]): JObservable[X] = ??? + // was generating a type error as the type of the RHS included an existential + // skolem based on the class type parameter `T`, which did not conform + // to the typer parameter of the extension method into which the RHS is + // transplanted. + def synchronize: Observable1[T] = new Observable1(foo(asJava)) +} + +class JObservable[T] diff --git a/tests/untried/pos/t7834.scala b/tests/untried/pos/t7834.scala new file mode 100644 index 000000000..fc9a0aa09 --- /dev/null +++ b/tests/untried/pos/t7834.scala @@ -0,0 +1,6 @@ +class S { val q = "" } + +class B extends S { + val x1: B.super.q.type = q + val x2: B.this.q.type = q +} diff --git a/tests/untried/pos/t7847/A.scala b/tests/untried/pos/t7847/A.scala new file mode 100644 index 000000000..b6cce6ee7 --- /dev/null +++ b/tests/untried/pos/t7847/A.scala @@ -0,0 +1,5 @@ +case class Blah(a: Int) + +object Blah { + def apply2(a: Int) = apply(a) +} diff --git a/tests/untried/pos/t7847/B.java b/tests/untried/pos/t7847/B.java new file mode 100644 index 000000000..c214f2dca --- /dev/null +++ b/tests/untried/pos/t7847/B.java @@ -0,0 +1,10 @@ +public final class B { + void blah() { + Blah x = Blah.apply2(1); + Blah y = Blah.apply(1); + Blah z = Blah$.MODULE$.apply(1); + + scala.Option un1 = Blah.unapply(null); + scala.Option un2 = Blah$.MODULE$.unapply(null); + } +} diff --git a/tests/untried/pos/t7853-partial-function.scala b/tests/untried/pos/t7853-partial-function.scala new file mode 100644 index 000000000..b09254e99 --- /dev/null +++ b/tests/untried/pos/t7853-partial-function.scala @@ -0,0 +1,7 @@ +object Test { + + def testCons: Unit = { + def x[A](a: PartialFunction[Any, A]): A = a(0) + val eval0 = x { case list: List[Int @unchecked] => list } + } +} diff --git a/tests/untried/pos/t7853.scala b/tests/untried/pos/t7853.scala new file mode 100644 index 000000000..b0e9221e2 --- /dev/null +++ b/tests/untried/pos/t7853.scala @@ -0,0 +1,11 @@ +trait S { + trait T { + this: Any => + + trait U { + trait V { + S.this + } + } + } +} diff --git a/tests/untried/pos/t7864.flags b/tests/untried/pos/t7864.flags new file mode 100644 index 000000000..7ccd56103 --- /dev/null +++ b/tests/untried/pos/t7864.flags @@ -0,0 +1 @@ +-Xlint
\ No newline at end of file diff --git a/tests/untried/pos/t7864.scala b/tests/untried/pos/t7864.scala new file mode 100644 index 000000000..b2d8911a1 --- /dev/null +++ b/tests/untried/pos/t7864.scala @@ -0,0 +1,5 @@ +object Test { + val f = 0; + ({ toString; (x: Any) => x})("$f ") +} + diff --git a/tests/untried/pos/t788.scala b/tests/untried/pos/t788.scala new file mode 100644 index 000000000..19638dd17 --- /dev/null +++ b/tests/untried/pos/t788.scala @@ -0,0 +1,19 @@ +package test; + +trait Test { + type Node <: NodeImpl; + trait NodeImpl; + type Expression <: Node with ExpressionImpl; + trait ExpressionImpl extends NodeImpl { + def self : Expression; + } + type Named <: Node with NamedImpl; + trait NamedImpl extends NodeImpl { + def self : Named; + } + def asExpression(e : ExpressionImpl) : Named = { + e match { + case f : NamedImpl => f.self; + } + } +} diff --git a/tests/untried/pos/t789.scala b/tests/untried/pos/t789.scala new file mode 100644 index 000000000..7a17f10b0 --- /dev/null +++ b/tests/untried/pos/t789.scala @@ -0,0 +1,32 @@ +object main { // don't do this at home + + trait Impl + + trait SizeImpl extends Impl { def size = 42 } + + trait ColorImpl extends Impl { def color = "red" } + + type Both = SizeImpl with ColorImpl + + def info(x:Impl) = x match { + case x:Both => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + def info2(x:Impl) = x match { + case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + + def main(args:Array[String]): Unit = { + // make up some class that has a size + class MyNode extends SizeImpl + Console.println("hello " + info(new MyNode)) + Console.println("hello " + info2(new MyNode)) + } +} diff --git a/tests/untried/pos/t7902.scala b/tests/untried/pos/t7902.scala new file mode 100644 index 000000000..47c525c17 --- /dev/null +++ b/tests/untried/pos/t7902.scala @@ -0,0 +1,17 @@ +import scala.language.higherKinds + +object Bug { + class Tag[W[M1[X1]]] + + def ofType[W[M2[X2]]]: Tag[W] = ??? + type InSeq [M3[X3]] = Some[M3[Any]] + + // fail + val x = ofType[InSeq] + + // okay + val y: Any = ofType[InSeq] + object T { + val z = ofType[InSeq] + } +} diff --git a/tests/untried/pos/t7919.scala b/tests/untried/pos/t7919.scala new file mode 100644 index 000000000..64f261ec1 --- /dev/null +++ b/tests/untried/pos/t7919.scala @@ -0,0 +1,6 @@ + +object X { + val x = s"" + val y = true +} + diff --git a/tests/untried/pos/t7928.scala b/tests/untried/pos/t7928.scala new file mode 100644 index 000000000..d9e29935b --- /dev/null +++ b/tests/untried/pos/t7928.scala @@ -0,0 +1,16 @@ +trait OuterTrait { + trait InnerTrait { + type Element + type Collection <: Iterable[Inner.Element] + } + + val Inner: InnerTrait + +} + +object OuterObject extends OuterTrait { + object Inner extends InnerTrait { + type Element = String + override type Collection = Seq[Inner.Element] + } +} diff --git a/tests/untried/pos/t7944.scala b/tests/untried/pos/t7944.scala new file mode 100644 index 000000000..2fe2c5866 --- /dev/null +++ b/tests/untried/pos/t7944.scala @@ -0,0 +1,24 @@ +class M[+A, +B] + +object Test { + implicit class EitherOps[A, B](self: Either[A, B]) { + def disjunction: M[A, B] = null + } + + def foo = { + val l: Either[Int, Nothing] = Left[Int, Nothing](1) + + var ok = EitherOps(l).disjunction + + val runawayTypeVar = l.disjunction + + // reported bug: + // found : M[Int,B]; required: M[Int,Nothing] + val assign: M[Int, Nothing] = runawayTypeVar + + // variations on the theme, all failed before similarly. + val assign1: M[Int, Nothing] = {val temp = runawayTypeVar; temp} + val assign2: M[Int, String] = runawayTypeVar + val assign3: M[Int, Nothing] = {val temp = Left(1).disjunction; temp} + } +} diff --git a/tests/untried/pos/t796.scala b/tests/untried/pos/t796.scala new file mode 100644 index 000000000..066625179 --- /dev/null +++ b/tests/untried/pos/t796.scala @@ -0,0 +1,26 @@ +/** I know what I am doing is wrong -- since I am about to look into + * this bug, I add a test in pending/pos... however, I am afraid that + * once this bug is fixed, this test case might go into test/pos + * there it adds to the huge number of tiny little test cases. + * + * Ideally, an option in the bugtracking system would automatically + * handle "pos" bugs. + */ +object Test extends App { + + object Twice { + def apply(x: Int) = x * 2 + def unapply(x: Int): Option[Tuple1[Int]] = + if (x % 2 == 0) Some(Tuple1(x / 2)) + else None + } + + def test(x: Int) = x match { + case Twice(y) => "x is two times "+y + case _ => "x is odd" + } + + Console.println(test(3)) + Console.println(test(4)) + +} diff --git a/tests/untried/pos/t7983.scala b/tests/untried/pos/t7983.scala new file mode 100644 index 000000000..bae9f3333 --- /dev/null +++ b/tests/untried/pos/t7983.scala @@ -0,0 +1,31 @@ +package foo.bar.baz // the package nesting level material to this bug + +class DivergenceTest { + + trait ColumnBase[T] + + trait ShapeLevel + trait Flat extends ShapeLevel + trait Lower extends Flat + + class Shape2[Level <: ShapeLevel, -M, U] + + implicit final def columnBaseShape[Level >: Flat <: ShapeLevel, T, C <: ColumnBase[_]] + (implicit ev: C <:< ColumnBase[T] + ): Shape2[Level, C, T] = ??? + + implicit final def intShape[Level <: ShapeLevel, T]: Shape2[Level, Int, Int] = ??? + implicit final def tuple2Shape[Level <: ShapeLevel, M1,M2, U1,U2] + (implicit u1: Shape2[_ <: Level, M1, U1], + u2: Shape2[_ <: Level, M2, U2] + ): Shape2[Level, (M1,M2), (U1,U2)] = ??? + + def foo: Unit = { + class Coffees extends ColumnBase[Int] + + def map1[F, T](f: F)(implicit shape: Shape2[_ <: Flat, F, T]) = ??? + + map1(((1, null: Coffees), 1)) + map1(((null: Coffees, 1), 1)) // fails with implicit divergence error in 2.11.0-M6, works under 2.10.3 + } +} diff --git a/tests/untried/pos/t7987/Macro_1.scala b/tests/untried/pos/t7987/Macro_1.scala new file mode 100644 index 000000000..81f717b9c --- /dev/null +++ b/tests/untried/pos/t7987/Macro_1.scala @@ -0,0 +1,6 @@ +import scala.language.experimental._ + +object Macro { + def apply[A](a: A): A = macro impl[A] + def impl[A](c: reflect.macros.Context)(a: c.Expr[A]): c.Expr[A] = a +} diff --git a/tests/untried/pos/t7987/Test_2.scala b/tests/untried/pos/t7987/Test_2.scala new file mode 100644 index 000000000..5896fdb51 --- /dev/null +++ b/tests/untried/pos/t7987/Test_2.scala @@ -0,0 +1,12 @@ +class C[T] { + def foo = 0 +} + +object Test { + implicit def AnyToC[T](a: Any): C[T] = new C[T] + // was: "macro not expanded" + Macro { + "".foo + () + } +} diff --git a/tests/untried/pos/t8001.check b/tests/untried/pos/t8001.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8001.check diff --git a/tests/untried/pos/t8001.flags b/tests/untried/pos/t8001.flags new file mode 100644 index 000000000..e8fb65d50 --- /dev/null +++ b/tests/untried/pos/t8001.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/t8001/Macros_1.scala b/tests/untried/pos/t8001/Macros_1.scala new file mode 100644 index 000000000..077082a9c --- /dev/null +++ b/tests/untried/pos/t8001/Macros_1.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def foo: Unit = macro impl + def impl(c: Context) = { + import c.universe._ + q"()" + } +} diff --git a/tests/untried/pos/t8001/Test_2.scala b/tests/untried/pos/t8001/Test_2.scala new file mode 100644 index 000000000..55024506e --- /dev/null +++ b/tests/untried/pos/t8001/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + Macros.foo + (): Unit +} diff --git a/tests/untried/pos/t8002-nested-scope.scala b/tests/untried/pos/t8002-nested-scope.scala new file mode 100644 index 000000000..a2088bce7 --- /dev/null +++ b/tests/untried/pos/t8002-nested-scope.scala @@ -0,0 +1,20 @@ +// This test serves to capture the status quo, but should really +// emit an accessibiltiy error. + +// `Namers#companionSymbolOf` seems too lenient, and currently doesn't +// implement the same-scope checks mentioned: +// +// https://github.com/scala/scala/pull/2816#issuecomment-22555206 +// +class C { + def foo = { + class C { private def x = 0 } + + { + val a = 0 + object C { + new C().x + } + } + } +} diff --git a/tests/untried/pos/t8011.scala b/tests/untried/pos/t8011.scala new file mode 100644 index 000000000..451590d77 --- /dev/null +++ b/tests/untried/pos/t8011.scala @@ -0,0 +1,8 @@ +class ThingOps1(val x: String) extends AnyVal { + def fn[A]: Any = { + new X[A] { def foo(a: A) = a } + 0 + } +} + +trait X[B] { def foo(a: B): Any } diff --git a/tests/untried/pos/t8013.flags b/tests/untried/pos/t8013.flags new file mode 100644 index 000000000..954eaba35 --- /dev/null +++ b/tests/untried/pos/t8013.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint diff --git a/tests/untried/pos/t8013/inpervolated_2.scala b/tests/untried/pos/t8013/inpervolated_2.scala new file mode 100644 index 000000000..90e571b42 --- /dev/null +++ b/tests/untried/pos/t8013/inpervolated_2.scala @@ -0,0 +1,11 @@ +/* + * scalac: -Xfatal-warnings -Xlint + */ +package t8013 + +// unsuspecting user of perverse macro +trait User { + import Perverse.Impervolator + val foo = "bar" + Console println p"Hello, $foo" +} diff --git a/tests/untried/pos/t8013/inpervolator_1.scala b/tests/untried/pos/t8013/inpervolator_1.scala new file mode 100644 index 000000000..612e1d727 --- /dev/null +++ b/tests/untried/pos/t8013/inpervolator_1.scala @@ -0,0 +1,33 @@ + +package t8013 + +// perverse macro to confuse Xlint + +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Perverse { + + implicit class Impervolator(sc: StringContext) { + def p(args: Any*): String = macro pImpl + } + + // turn a nice interpolation into something that looks + // nothing like an interpolation or anything we might + // recognize, but which includes a "$id" in an apply. + def pImpl(c: Context)(args: c.Expr[Any]*): c.Expr[String] = { + import c.universe._ + val macroPos = c.macroApplication.pos + val text = macroPos.source.lineToString(macroPos.line - 1) substring macroPos.column + val tt = Literal(Constant(text)) + val tree = q"t8013.Perverse.pervert($tt)" + c.Expr[String](tree) + } + + // identity doesn't seem very perverse in this context + //def pervert(text: String): String = text + def pervert(text: String): String = { + Console println s"Perverting [$text]" + text + } +} diff --git a/tests/untried/pos/t802.scala b/tests/untried/pos/t802.scala new file mode 100644 index 000000000..2dea7036d --- /dev/null +++ b/tests/untried/pos/t802.scala @@ -0,0 +1,27 @@ +package test; +trait Test { + abstract class BracesImpl { + type Singleton; + type Brace <: Singleton with BraceImpl; + trait BraceImpl; + trait ForFile; + } + abstract class ParensImpl extends BracesImpl { + type Brace <: Singleton with BraceImpl; + trait BraceImpl extends super.BraceImpl; + } + val parens : ParensImpl; + abstract class BracksImpl extends BracesImpl { + type Brace <: Singleton with BraceImpl; + trait BraceImpl extends super.BraceImpl; + } + val bracks : BracksImpl; + trait File { + def parens0 : parens.BraceImpl; + def bracks0 : bracks.BraceImpl; + def braces(b : BracesImpl) = b match { + case b if b == parens => parens0; + case b if b == bracks => bracks0; + } + } +} diff --git a/tests/untried/pos/t8023.scala b/tests/untried/pos/t8023.scala new file mode 100644 index 000000000..86824084e --- /dev/null +++ b/tests/untried/pos/t8023.scala @@ -0,0 +1,22 @@ +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/untried/pos/t8023b.scala b/tests/untried/pos/t8023b.scala new file mode 100644 index 000000000..94c9b2f8d --- /dev/null +++ b/tests/untried/pos/t8023b.scala @@ -0,0 +1,2 @@ +// this fails with naive attempts to fix SI-8023 +trait T[A <: T[A]] diff --git a/tests/untried/pos/t803.scala b/tests/untried/pos/t803.scala new file mode 100644 index 000000000..066abecff --- /dev/null +++ b/tests/untried/pos/t803.scala @@ -0,0 +1,2 @@ +class B(x : () => Int) +class A(i : Int) extends B(() => i) { i } diff --git a/tests/untried/pos/t8045.scala b/tests/untried/pos/t8045.scala new file mode 100644 index 000000000..21154e386 --- /dev/null +++ b/tests/untried/pos/t8045.scala @@ -0,0 +1,17 @@ +object Test extends App { + case class Number(i: Int) + + object UnliftNumber { + def unapply(t: Any): Option[Number] = t match { + case i: Int => Some(Number(i)) + case _ => None + } + } + + def eval(expr: Any): Option[Number] = expr match { + case UnliftNumber(n) => Some(n) + case _ => None + } + + println(eval(1)) +} diff --git a/tests/untried/pos/t8046.scala b/tests/untried/pos/t8046.scala new file mode 100644 index 000000000..304d70b6b --- /dev/null +++ b/tests/untried/pos/t8046.scala @@ -0,0 +1,20 @@ +trait One { + type Op[A] + type Alias[A] = Op[A] +} + +trait Two extends One { + trait Op[A] extends (A => A) + + // This compiles + class View1 extends Op[Int] { def apply(xs: Int) = xs } + + // ??? base class View2 not found in basetypes of class View2 + // ./a.scala:9: error: class View2 needs to be abstract, since \ + // method apply in trait Function1 of type (v1: T1)R is not defined + // (Note that T1 does not match Int) + // class View2 extends Alias[Int] { def apply(xs: Int) = xs } + // ^ + // one error found + class View2 extends Alias[Int] { def apply(xs: Int) = xs } +} diff --git a/tests/untried/pos/t8046b.scala b/tests/untried/pos/t8046b.scala new file mode 100644 index 000000000..45b99fd7e --- /dev/null +++ b/tests/untried/pos/t8046b.scala @@ -0,0 +1,16 @@ +trait One { + type Op[A] + type Alias = Op[Int] +} + +trait Two extends One { + trait Op[A] extends M[A] + //(a: Alias) => a.value.toChar // okay + // (=> A).asSeenFrom(a.type, trait M): => Int + class View2 extends Alias { value.toChar } // toChar is not a member of type parameter A + // (=> A).asSeenFrom(View2.this.type, trait M): => A + + // override type Alias = Op[Int] // works with this +} + +trait M[A] { def value: A = sys.error("") } diff --git a/tests/untried/pos/t8046c.scala b/tests/untried/pos/t8046c.scala new file mode 100644 index 000000000..f05b4c15b --- /dev/null +++ b/tests/untried/pos/t8046c.scala @@ -0,0 +1,19 @@ +trait One { + type Op[A] + type Alias[A] = Op[A] +} + +trait Three extends One { + trait Op[A] extends (A => A) + + def f1(f: Op[Int]) = f(5) + def f2(f: Alias[Int]) = f(5) + def f3[T <: Op[Int]](f: T) = f(5) + def f4[T <: Alias[Int]](f: T) = f(5) + // ./a.scala:12: error: type mismatch; + // found : Int(5) + // required: T1 + // def f4[T <: Alias[Int]](f: T) = f(5) + // ^ +} + diff --git a/tests/untried/pos/t805.scala b/tests/untried/pos/t805.scala new file mode 100644 index 000000000..37bf6b5ef --- /dev/null +++ b/tests/untried/pos/t805.scala @@ -0,0 +1,19 @@ +trait MatcherYYY { + trait NodeImpl; + trait Matchable extends NodeImpl { + protected def doMatch : Unit = {} + } +} +trait BraceMatcherXXX extends MatcherYYY { + trait NodeImpl extends super.NodeImpl { + def doMatch (braces : BracePair) : Unit + } + trait BracePair { + trait BraceImpl extends NodeImpl with Matchable { + override def doMatch : Unit = { + super.doMatch; + (); + } + } + } +} diff --git a/tests/untried/pos/t8054.scala b/tests/untried/pos/t8054.scala new file mode 100644 index 000000000..66a55e8b5 --- /dev/null +++ b/tests/untried/pos/t8054.scala @@ -0,0 +1,31 @@ +trait D { + trait Manifest { + class Entry + } + + val M: Manifest + + def m: M.Entry = ??? +} + +object D1 extends D { + object M extends Manifest +} + +object D2 extends D { + val M: Manifest = ??? +} + +object Hello { + + def main(args: Array[String]): Unit = { + // 2.10.3 - ok + // 2.11.0-M7 - type mismatch; found : Seq[DB1.MANIFEST.Entry] + // required: Seq[DB1.MANIFEST.Entry] + val t1: D1.M.Entry = D1.m + + // 2.10.3 - ok + // 2.11.0-M7 - ok + val t2: D2.M.Entry = D2.m + } +} diff --git a/tests/untried/pos/t8060.scala b/tests/untried/pos/t8060.scala new file mode 100644 index 000000000..90e014d74 --- /dev/null +++ b/tests/untried/pos/t8060.scala @@ -0,0 +1,11 @@ +trait M[F[_]] + +trait P[A] { + type CC[X] = P[X] + def f(p: A => Boolean): M[CC] +} + +trait Other { + // was infinite loop trying to dealias `x$1.CC` + def g[A](p: A => Boolean): P[A] => M[P] = _ f p +} diff --git a/tests/untried/pos/t8062.flags b/tests/untried/pos/t8062.flags new file mode 100644 index 000000000..49d036a88 --- /dev/null +++ b/tests/untried/pos/t8062.flags @@ -0,0 +1 @@ +-optimize diff --git a/tests/untried/pos/t8062/A_1.scala b/tests/untried/pos/t8062/A_1.scala new file mode 100644 index 000000000..ca0411dae --- /dev/null +++ b/tests/untried/pos/t8062/A_1.scala @@ -0,0 +1,5 @@ +package warmup + +object Warmup { + def filter[A](p: Any => Boolean): Any = filter[Any](p) +} diff --git a/tests/untried/pos/t8062/B_2.scala b/tests/untried/pos/t8062/B_2.scala new file mode 100644 index 000000000..f0a676148 --- /dev/null +++ b/tests/untried/pos/t8062/B_2.scala @@ -0,0 +1,3 @@ +object Test { + warmup.Warmup.filter[Any](x => false) +} diff --git a/tests/untried/pos/t8064.flags b/tests/untried/pos/t8064.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/t8064.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/t8064/Client_2.scala b/tests/untried/pos/t8064/Client_2.scala new file mode 100644 index 000000000..42c9b21ce --- /dev/null +++ b/tests/untried/pos/t8064/Client_2.scala @@ -0,0 +1,8 @@ +object Test { + Macro { + def s = "" + Macro(s): @unchecked + ??? + } +} +// Was: a range position validation error (unpositioned tree) diff --git a/tests/untried/pos/t8064/Macro_1.scala b/tests/untried/pos/t8064/Macro_1.scala new file mode 100644 index 000000000..9f1e6955b --- /dev/null +++ b/tests/untried/pos/t8064/Macro_1.scala @@ -0,0 +1,10 @@ +import language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macro { + def apply(a: Any): Any = macro impl + + def impl(c: Context)(a: c.Tree): c.Tree = { + c.untypecheck(a) + } +} diff --git a/tests/untried/pos/t8064b.flags b/tests/untried/pos/t8064b.flags new file mode 100644 index 000000000..281f0a10c --- /dev/null +++ b/tests/untried/pos/t8064b.flags @@ -0,0 +1 @@ +-Yrangepos diff --git a/tests/untried/pos/t8064b/Client_2.scala b/tests/untried/pos/t8064b/Client_2.scala new file mode 100644 index 000000000..055b7a606 --- /dev/null +++ b/tests/untried/pos/t8064b/Client_2.scala @@ -0,0 +1,6 @@ +object Test { + Macro { + "".reverse + } +} +// Was: a range position validation error (tree with offset position enclosing tree with range position) diff --git a/tests/untried/pos/t8064b/Macro_1.scala b/tests/untried/pos/t8064b/Macro_1.scala new file mode 100644 index 000000000..60996bfec --- /dev/null +++ b/tests/untried/pos/t8064b/Macro_1.scala @@ -0,0 +1,11 @@ +import language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macro { + def apply(a: Any): Any = macro impl + def impl(c: Context)(a: c.Tree): c.Tree = { + import c.universe._ + + q"{$a; true}" + } +} diff --git a/tests/untried/pos/t807.scala b/tests/untried/pos/t807.scala new file mode 100644 index 000000000..0eeb92ea2 --- /dev/null +++ b/tests/untried/pos/t807.scala @@ -0,0 +1,45 @@ +trait Matcher { + trait Link { + type Self <: Link; + type Match <: Link { type Match = Link.this.Self; } + } + trait HasLinks { + def link(b : Boolean) : Link = null; + } + +} +trait BraceMatcher extends Matcher { + trait BracePair { + trait BraceLink extends Link; + trait OpenLink extends BraceLink { + type Self = OpenLink; + type Match = CloseLink; + } + trait CloseLink extends BraceLink { + type Self = CloseLink; + type Match = OpenLink; + } + } +} +trait IfElseMatcher extends BraceMatcher { + trait IfElseLink extends Link; + trait IfLink extends IfElseLink { + type Self = IfLink; + type Match = ElseImpl; + } + trait ElseImpl extends IfElseLink with HasLinks { + type Self = ElseImpl; + type Match = IfLink; + override def link(b : Boolean) = this; + } + val parenPair : BracePair; + trait IfWithParenImpl extends HasLinks { + object ifLink extends IfLink; + object openParen extends parenPair.OpenLink; + override def link(b : Boolean): Link = b match { + case true => ifLink; + case false => openParen; + } + } +} + diff --git a/tests/untried/pos/t8111.scala b/tests/untried/pos/t8111.scala new file mode 100644 index 000000000..7ec002c9b --- /dev/null +++ b/tests/untried/pos/t8111.scala @@ -0,0 +1,24 @@ +trait T { + + def crashy(ma: Any): Unit = { + // okay + val f1 = (u: Unit) => ma + foo(f1)() + foo((u: Unit) => ma) + foo(0, (u: Any) => ma) apply () + + // crash due to side effects on the onwer of the symbol in the + // qualifier or arguments of the application during an abandoned + // names/defaults transform. The code type checkes because of + // autp-tupling which promotes and empty parmater list to `(): Unit` + foo((u: Any) => ma)() + + {{(u: Any) => ma}; this}.foo(0)() + + foo({def foo = ma; 0})() + + {def foo = ma; this}.foo(0)() + } + + def foo(f: Any): Any => Any +} diff --git a/tests/untried/pos/t812.scala b/tests/untried/pos/t812.scala new file mode 100644 index 000000000..709b59c19 --- /dev/null +++ b/tests/untried/pos/t812.scala @@ -0,0 +1,7 @@ +package test; +import scala.{App => Main}; +class Test extends Main { + import test.{Test => Hello} + super[App].main(Array("test")); + private[Test] def xxx = 10; +} diff --git a/tests/untried/pos/t8120.scala b/tests/untried/pos/t8120.scala new file mode 100644 index 000000000..e06f38d5d --- /dev/null +++ b/tests/untried/pos/t8120.scala @@ -0,0 +1,9 @@ +object A { + class C { + def m(a: Nothing): Int = 0 + } + implicit class RichAny(a: Any) { + def m(a: Any): Int = 0 + } + (new C).m({ case (x, y) => x } : Any => Any) +} diff --git a/tests/untried/pos/t8128.scala b/tests/untried/pos/t8128.scala new file mode 100644 index 000000000..b6f76691b --- /dev/null +++ b/tests/untried/pos/t8128.scala @@ -0,0 +1,15 @@ +object G { + def unapply(m: Any): Option[_] = Some("") +} + +object H { + def unapplySeq(m: Any): Option[Seq[_]] = None +} + +object Test { + (0: Any) match { + case G(v) => v + case H(v) => v + case _ => + } +} diff --git a/tests/untried/pos/t8132.scala b/tests/untried/pos/t8132.scala new file mode 100644 index 000000000..b4d6fd944 --- /dev/null +++ b/tests/untried/pos/t8132.scala @@ -0,0 +1,5 @@ +trait T { + protected def s: String +} + +case class G(override protected val s: String) extends T diff --git a/tests/untried/pos/t8134/A_1.scala b/tests/untried/pos/t8134/A_1.scala new file mode 100644 index 000000000..32bce003f --- /dev/null +++ b/tests/untried/pos/t8134/A_1.scala @@ -0,0 +1,4 @@ +// a.scala +package object pkg { + class AnyOps(val x: Any) extends AnyVal +} diff --git a/tests/untried/pos/t8134/B_2.scala b/tests/untried/pos/t8134/B_2.scala new file mode 100644 index 000000000..32bce003f --- /dev/null +++ b/tests/untried/pos/t8134/B_2.scala @@ -0,0 +1,4 @@ +// a.scala +package object pkg { + class AnyOps(val x: Any) extends AnyVal +} diff --git a/tests/untried/pos/t8138.scala b/tests/untried/pos/t8138.scala new file mode 100644 index 000000000..b98093095 --- /dev/null +++ b/tests/untried/pos/t8138.scala @@ -0,0 +1,24 @@ + +class U { + trait Transformer { + def transform(a: Tree): Tree = ??? + } + trait Tree +} + +object Test { + def m(u: U) = { + class C extends u.Transformer { + override def transform(t: u.Tree): u.Tree = { + null match { + case _ => + // crashes in GenICode: + // error: Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false + (y: Any) => super.transform(???) + null + } + ??? + } + } + } +} diff --git a/tests/untried/pos/t8146a.scala b/tests/untried/pos/t8146a.scala new file mode 100644 index 000000000..e4eb8d3fd --- /dev/null +++ b/tests/untried/pos/t8146a.scala @@ -0,0 +1,9 @@ +trait M[+A] + +object Test { + type Inty = Int + def t1( + x: M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[Int @unchecked]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] + ): M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[M[Inty @unchecked]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] + = x +} diff --git a/tests/untried/pos/t8146b.scala b/tests/untried/pos/t8146b.scala new file mode 100644 index 000000000..dd031f66c --- /dev/null +++ b/tests/untried/pos/t8146b.scala @@ -0,0 +1,77 @@ +// non-deterministic type errors, non-termination. +// seems to be due to inconsistent hashing/equality in SubTypePair + +import scala.language.{existentials, implicitConversions} +import scala.annotation.unchecked.uncheckedVariance + +trait Column[T] + +// Turning this into a trait reduces (eliminates?) the likelihood of type errors (but not of non-termination) +abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + +trait ShapeLevel +trait NestedShapeLevel extends ShapeLevel +trait FlatShapeLevel extends NestedShapeLevel +trait ColumnsShapeLevel extends FlatShapeLevel + +trait ProvenShape[U] + +object ProvenShape { + implicit def proveShapeOf[T, U](v: T)(implicit sh: Shape[_ <: FlatShapeLevel, T, U, _]): ProvenShape[U] = ??? +} + +sealed abstract class HList { + type Self <: HList + type :: [E] = HCons[E, Self] + final def :: [E](elem: E): :: [E] = ??? +} + +final class HCons[+H, +T <: HList](val head: H, val tail: T) extends HList { + type Self = HCons[H @uncheckedVariance, T @uncheckedVariance] +} + +final object HNil extends HList { + type Self = HNil.type +} + +// Success is more likely when not using these aliases +object syntax { + type :: [+H, +T <: HList] = HCons[H, T] + type HNil = HNil.type +} + +class HListBench { + + import syntax._ + + implicit def columnShape[T, Level <: ShapeLevel]: Shape[Level, Column[T], T, Column[T]] = ??? + implicit def provenShape[T, P](implicit shape: Shape[_ <: FlatShapeLevel, T, _, P]): Shape[FlatShapeLevel, ProvenShape[T], T, P] = ??? + final class HListShape[Level <: ShapeLevel, M <: HList, U <: HList, P <: HList](val shapes: Seq[Shape[_ <: ShapeLevel, _, _, _]]) extends Shape[Level, M, U, P] + implicit def hnilShape[Level <: ShapeLevel] = new HListShape[Level, HNil.type, HNil.type, HNil.type](Nil) + implicit def hconsShape[Level <: ShapeLevel, M1, M2 <: HList, U1, U2 <: HList, P1, P2 <: HList] + (implicit s1: Shape[_ <: Level, M1, U1, P1], s2: HListShape[_ <: Level, M2, U2, P2]) = + new HListShape[Level, M1 :: M2, U1 :: U2, P1 :: P2](s1 +: s2.shapes) + + trait A[T] { + def * : ProvenShape[T] + } + + trait B extends A[ + Int :: Int :: Int :: Int :: Int :: + Int :: Int :: Int :: Int :: Int :: + Int :: Int :: Int :: Int :: Int :: + Int :: Int :: Int :: Int :: Int :: + Int :: Int :: Int :: Int :: Int :: + Int :: Int :: HNil ] { + + def c: Column[Int] + + def * = c :: c :: c :: c :: c :: + c :: c :: c :: c :: c :: + c :: c :: c :: c :: c :: + c :: c :: c :: c :: c :: + c :: c :: c :: c :: c :: + c :: c :: HNil + + } +} diff --git a/tests/untried/pos/t8170.scala b/tests/untried/pos/t8170.scala new file mode 100644 index 000000000..1991da72f --- /dev/null +++ b/tests/untried/pos/t8170.scala @@ -0,0 +1,27 @@ +object O { + trait X + trait B extends A { + override type T[F1 <: X] = F1 + } + trait A { + type T[F <: X] + } +} + +object Test { + import O._ + val a: B = ??? + val b: a.T[X] = ??? + b.ensuring(x => true) // trigger an implicit search +} + + +/* +this = {AliasArgsTypeRef@3004}"Test#7680.a#14899.T#14823[O#7702.X#7793]" + sym = type T#14823 + info = namer: [F#14824 <: O#7703.X#7793]F#14824 +result = {AbstractNoArgsTypeRef@3237}"F#24451" +tp = {PolyType@3235}"[F#14824 <: O#7703.X#7793]F#14824" +tparams = + (0) = {AbstractTypeSymbol@3247}"type F#24451" +*/ diff --git a/tests/untried/pos/t8170b.scala b/tests/untried/pos/t8170b.scala new file mode 100644 index 000000000..53036f6c8 --- /dev/null +++ b/tests/untried/pos/t8170b.scala @@ -0,0 +1,25 @@ +import language._ + +object ScalaZeee { + trait HFold[M[_], U] { + type Apply[E, A <: U] <: U + } + trait GenericCons[M[_], H, +T <: GenericList[M]] extends GenericList[M] { + val tail: T + override type Folded[N[X] >: M[X], U, F <: HFold[N, U]] = F#Apply[H, tail.Folded[N, U, F]] + } + val KNil: GenericList[Nothing] = ??? + sealed trait GenericList[+M[_]] { + type Folded[N[X] >: M[X], U, F <: HFold[N, U]] <: U + } +} + +object TypelevelUsage { + import ScalaZeee._ + type T = GenericCons[Some, String, KNil.type] + val klist1: T = ??? + type T2 = klist1.Folded[Option, Int, HFold[Option, Int]] + val count2: T2 = ??? + + count2.ensuring(x => true).toChar // trigger an implicit search +} diff --git a/tests/untried/pos/t8177.scala b/tests/untried/pos/t8177.scala new file mode 100644 index 000000000..fe265f8d0 --- /dev/null +++ b/tests/untried/pos/t8177.scala @@ -0,0 +1,12 @@ +// exercise coevolveSym: SingleType with an underlying RefinedType +trait Thing { type A } +object IntThing extends Thing { type A = Int } + +// The following erroneously failed with error: method f overrides nothing. +// because asSeenFrom produced a typeref of the shape T'#A where A referred to a symbol defined in a T of times past +// More precisely, the TypeRef case of TypeMap's mapOver correctly modified prefix +// from having an underlying type of { type A = Ain } to { type A = Int }, with a new symbol for A (now with info Int), +// but the symbol in the outer type ref wasn't co-evolved (so it still referred to the { type A = AIn } underlying the old prefix) +// coEvolveSym used to only look at prefixes that were directly RefinedTypes, but they could also be SingleTypes with an underlying RefinedType +class View[AIn](val in: Thing { type A = AIn }) { def f(p: in.A): in.A = p } +class SubView extends View[Int](IntThing) { override def f(p: in.A): in.A = p } diff --git a/tests/untried/pos/t8177a.scala b/tests/untried/pos/t8177a.scala new file mode 100644 index 000000000..7e2cfb386 --- /dev/null +++ b/tests/untried/pos/t8177a.scala @@ -0,0 +1,9 @@ +// exercise coevolveSym +trait Thing { type A; var p: A = _ } +class AA[T](final val x: Thing { type A = T }) { + def foo: x.A = ??? +} + +class B extends AA[Int](null) { + override def foo: B.this.x.A = super.foo +} diff --git a/tests/untried/pos/t8177b.scala b/tests/untried/pos/t8177b.scala new file mode 100644 index 000000000..82f41b615 --- /dev/null +++ b/tests/untried/pos/t8177b.scala @@ -0,0 +1,13 @@ +// exercise coevolveSym: SingleType with an underlying RefinedType, via a type alias +trait Thing { type A } +object IntThing extends Thing { type A = Int } +object ThingHolder { type Alias[AIn] = Thing { type A = AIn } } + +// The following erroneously failed with error: method f overrides nothing. +// because asSeenFrom produced a typeref of the shape T'#A where A referred to a symbol defined in a T of times past +// More precisely, the TypeRef case of TypeMap's mapOver correctly modified prefix +// from having an underlying type of { type A = Ain } to { type A = Int }, with a new symbol for A (now with info Int), +// but the symbol in the outer type ref wasn't co-evolved (so it still referred to the { type A = AIn } underlying the old prefix) +// coEvolveSym used to only look at prefixes that were directly RefinedTypes, but they could also be SingleTypes with an underlying RefinedType +class View[AIn](val in: ThingHolder.Alias[AIn]) { def f(p: in.A): in.A = p } +class SubView extends View[Int](IntThing) { override def f(p: in.A): in.A = p } diff --git a/tests/untried/pos/t8177d.scala b/tests/untried/pos/t8177d.scala new file mode 100644 index 000000000..d15a05a35 --- /dev/null +++ b/tests/untried/pos/t8177d.scala @@ -0,0 +1,12 @@ +// exercise coevolveSym +trait HasElem { type A } +trait View[AIn] { + val tc: HasElem { type A = AIn } + def f2(p: tc.A): tc.A = p +} + +object Test { + val view: View[Int] = null + + view f2 5 // fails +} diff --git a/tests/untried/pos/t8177e.scala b/tests/untried/pos/t8177e.scala new file mode 100644 index 000000000..cb1136ff1 --- /dev/null +++ b/tests/untried/pos/t8177e.scala @@ -0,0 +1,3 @@ +// exercise coevolveSym +trait T[A] { val foo: { type B = A } = ???; def bar(b: foo.B) = () } +object O extends T[Int] { bar(0) } diff --git a/tests/untried/pos/t8177g.scala b/tests/untried/pos/t8177g.scala new file mode 100644 index 000000000..237257b69 --- /dev/null +++ b/tests/untried/pos/t8177g.scala @@ -0,0 +1,11 @@ +// exercise coevolveSym: ThisType +trait HasA { type A } +class AA[T] { + type HasAT[T] = HasA{ type A = T } + val x: HasAT[T] = ??? + def foo: x.A = ??? +} + +class B extends AA[Int] { + override def foo: B.this.x.A = super.foo +} diff --git a/tests/untried/pos/t8177h.scala b/tests/untried/pos/t8177h.scala new file mode 100644 index 000000000..90b8a26ce --- /dev/null +++ b/tests/untried/pos/t8177h.scala @@ -0,0 +1,5 @@ +class Module { self => + type settingsType <: Any + final type commonModuleType = Module {type settingsType = self.settingsType} + def foo(s: self.type): commonModuleType = s +} diff --git a/tests/untried/pos/t8187.check b/tests/untried/pos/t8187.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8187.check diff --git a/tests/untried/pos/t8187.scala b/tests/untried/pos/t8187.scala new file mode 100644 index 000000000..84b8cd0f4 --- /dev/null +++ b/tests/untried/pos/t8187.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + val tyn: TypeName = (??? : TypeSymbol).name + val ten: TermName = (??? : TermSymbol).name +} diff --git a/tests/untried/pos/t8207.scala b/tests/untried/pos/t8207.scala new file mode 100644 index 000000000..680b40f37 --- /dev/null +++ b/tests/untried/pos/t8207.scala @@ -0,0 +1,6 @@ +class C { me => + import me.{toString => ts} + locally(this: me.type) + trait T + type X = me.T +} diff --git a/tests/untried/pos/t8209a.check b/tests/untried/pos/t8209a.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8209a.check diff --git a/tests/untried/pos/t8209a/Macros_1.scala b/tests/untried/pos/t8209a/Macros_1.scala new file mode 100644 index 000000000..5d7852cb7 --- /dev/null +++ b/tests/untried/pos/t8209a/Macros_1.scala @@ -0,0 +1,17 @@ +import scala.language.experimental.macros +import scala.language.implicitConversions +import scala.reflect.macros.blackbox.Context + +class A +object A { implicit def a2b(a: A): B = ??? } +class B +class C extends A + +object Macros { + def impl(c: Context) = { + import c.universe._ + q"new C" + } + + def foo: A = macro impl +} diff --git a/tests/untried/pos/t8209a/Test_2.scala b/tests/untried/pos/t8209a/Test_2.scala new file mode 100644 index 000000000..bedef776f --- /dev/null +++ b/tests/untried/pos/t8209a/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + val a: A = Macros.foo + val b: B = Macros.foo +} diff --git a/tests/untried/pos/t8209b.check b/tests/untried/pos/t8209b.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8209b.check diff --git a/tests/untried/pos/t8209b/Macros_1.scala b/tests/untried/pos/t8209b/Macros_1.scala new file mode 100644 index 000000000..fa521d38d --- /dev/null +++ b/tests/untried/pos/t8209b/Macros_1.scala @@ -0,0 +1,17 @@ +import scala.language.experimental.macros +import scala.language.implicitConversions +import scala.reflect.macros.whitebox.Context + +class A +object A { implicit def a2b(a: A): B = ??? } +class B +class C extends A + +object Macros { + def impl(c: Context) = { + import c.universe._ + q"new C" + } + + def foo: A = macro impl +} diff --git a/tests/untried/pos/t8209b/Test_2.scala b/tests/untried/pos/t8209b/Test_2.scala new file mode 100644 index 000000000..bedef776f --- /dev/null +++ b/tests/untried/pos/t8209b/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + val a: A = Macros.foo + val b: B = Macros.foo +} diff --git a/tests/untried/pos/t8219.scala b/tests/untried/pos/t8219.scala new file mode 100644 index 000000000..e1653b623 --- /dev/null +++ b/tests/untried/pos/t8219.scala @@ -0,0 +1,15 @@ +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.. + "" == "" // this no longer triggers the bug, as Object#== now overrides Any#== + } + + // We can still trigger the bug with a structural type, see pending/neg/t8219.scala +} diff --git a/tests/untried/pos/t8219b.scala b/tests/untried/pos/t8219b.scala new file mode 100644 index 000000000..d55d3139e --- /dev/null +++ b/tests/untried/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) = "" + implicit def any2str2(a: Any) = "" + T.foo("") + } +} diff --git a/tests/untried/pos/t8223.scala b/tests/untried/pos/t8223.scala new file mode 100644 index 000000000..52d6b0098 --- /dev/null +++ b/tests/untried/pos/t8223.scala @@ -0,0 +1,29 @@ +package p { + class ViewEnv[AIn] { + type A = AIn + class SubView { def has(x: A): Boolean = ??? } + def get: SubView = new SubView + } + + trait HasA { type A } + trait Indexable[R] extends HasA + class ArrayTC[AIn] extends Indexable[Array[AIn]] { type A = AIn } +} + +package object p { + implicit def arrayTypeClass[A] : ArrayTC[A] = new ArrayTC[A] + object intArrayTC extends ArrayTC[Int] + + type EnvAlias[W <: HasA] = ViewEnv[W#A] + type SubAlias[W <: HasA] = ViewEnv[W#A]#SubView + + def f0[R](xs: R)(implicit tc: Indexable[R]): ViewEnv[tc.A]#SubView = new ViewEnv[tc.A]() get + def f1[R](xs: R)(implicit tc: Indexable[R]): EnvAlias[tc.type]#SubView = new ViewEnv[tc.A]() get + def f2[R](xs: R)(implicit tc: Indexable[R]): SubAlias[tc.type] = new ViewEnv[tc.A]() get + + def g0 = f0(Array(1)) has 2 // ok + def g1 = f1(Array(1)) has 2 // ok + def g2 = f2(Array(1)) has 2 // "found: Int(2), required: tc.A" + def g3 = f2(Array(1))(new ArrayTC[Int]) has 2 // "found: Int(2), required: tc.A" + def g4 = f2(Array(1))(intArrayTC) has 2 // ok +} diff --git a/tests/untried/pos/t8224.scala b/tests/untried/pos/t8224.scala new file mode 100644 index 000000000..2fae925df --- /dev/null +++ b/tests/untried/pos/t8224.scala @@ -0,0 +1,12 @@ +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/untried/pos/t8237.scala b/tests/untried/pos/t8237.scala new file mode 100644 index 000000000..005089079 --- /dev/null +++ b/tests/untried/pos/t8237.scala @@ -0,0 +1,29 @@ +import scala.language.higherKinds + +object TestExplicit { + trait TC[A] + def fTt[A,E[X] <: List[X]](a: A)(implicit tt: TC[E[A]]) = a + implicit def tc[T]: TC[T] = ??? + + // Typechecking results in SOE in TypeVar.isGround + fTt(1)(tc) + // fun = TestExplicit.this.fTt[Int, E](1) + // args = TestExplicit.this.tc[E[Int]] + // argTpes.head.instantiateTypeParams = TC[?E#1[Int]] + // formals.head.instantiateTypeParams = TC[?E#2[Int]] + // (where ?E#1 and ?E#2 as distinct AppliedTypeVars that resulted + // from separate applications of type args to the same HKTypeVar, ?E) + // + // As we check if the argument conforms to the formal, we would have + // AppliedTypeVars sharing the same TypeConstraints on the LHS and RHS, + // which leads to a cyclic constraint. +} + +object TestImplicit { + trait TC[A] + def fTt[A,E[X] <: List[X]](a: A)(implicit tt: TC[E[A]]) = a + implicit def tc[T]: TC[T] = ??? + + // Oddly enough, this one works. + fTt(1) +} diff --git a/tests/untried/pos/t8237b.scala b/tests/untried/pos/t8237b.scala new file mode 100644 index 000000000..52bb310e8 --- /dev/null +++ b/tests/untried/pos/t8237b.scala @@ -0,0 +1,10 @@ +import scala.language.higherKinds +import scala.reflect.runtime.universe._ +object Test { + + def fTt[A,E[X]<:List[X]](a: A)(implicit tt: TypeTag[E[A]]) = a + + trait TC[A] + implicit def TCListInt[A]: TC[A] = ??? + fTt(1) +} diff --git a/tests/untried/pos/t8244d/InodeBase_1.java b/tests/untried/pos/t8244d/InodeBase_1.java new file mode 100644 index 000000000..36c212341 --- /dev/null +++ b/tests/untried/pos/t8244d/InodeBase_1.java @@ -0,0 +1,6 @@ +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; + +abstract class INodeBase_1<K, V> { + @SuppressWarnings("rawtypes") + public static final AtomicReferenceFieldUpdater<INodeBase_1, Object> updater = null; +} diff --git a/tests/untried/pos/t8244d/Test_2.scala b/tests/untried/pos/t8244d/Test_2.scala new file mode 100644 index 000000000..cb39c9692 --- /dev/null +++ b/tests/untried/pos/t8244d/Test_2.scala @@ -0,0 +1,3 @@ +class INodeX[K, V] extends INodeBase_1[K, V] { + INodeBase_1.updater.set(this, null) +} diff --git a/tests/untried/pos/t8300-conversions-a.scala b/tests/untried/pos/t8300-conversions-a.scala new file mode 100644 index 000000000..1a24da750 --- /dev/null +++ b/tests/untried/pos/t8300-conversions-a.scala @@ -0,0 +1,23 @@ +// cf. pos/t8300-conversions-b.scala +trait Universe { + type Symbol >: Null <: AnyRef with SymbolApi + trait SymbolApi + + type TypeSymbol >: Null <: Symbol with TypeSymbolApi + trait TypeSymbolApi extends SymbolApi + + type FreeTypeSymbol >: Null <: TypeSymbol with FreeTypeSymbolApi + trait FreeTypeSymbolApi extends TypeSymbolApi + + implicit class CompatibleSymbol(sym: Symbol) { + def asFreeType: FreeTypeSymbol = ??? + } +} + +object Test extends App { + val u: Universe = ??? + import u._ + + val sym: Symbol = ??? + sym.asFreeType +} diff --git a/tests/untried/pos/t8300-conversions-b.scala b/tests/untried/pos/t8300-conversions-b.scala new file mode 100644 index 000000000..a571dbea9 --- /dev/null +++ b/tests/untried/pos/t8300-conversions-b.scala @@ -0,0 +1,23 @@ +// cf. pos/t8300-conversions-a.scala +trait Universe { + type Symbol >: Null <: AnyRef with SymbolApi + trait SymbolApi + + type TypeSymbol >: Null <: TypeSymbolApi with Symbol + trait TypeSymbolApi extends SymbolApi + + type FreeTypeSymbol >: Null <: FreeTypeSymbolApi with TypeSymbol + trait FreeTypeSymbolApi extends TypeSymbolApi + + implicit class CompatibleSymbol(sym: Symbol) { + def asFreeType: FreeTypeSymbol = ??? + } +} + +object Test extends App { + val u: Universe = ??? + import u._ + + val sym: Symbol = ??? + sym.asFreeType +} diff --git a/tests/untried/pos/t8300-overloading.scala b/tests/untried/pos/t8300-overloading.scala new file mode 100644 index 000000000..2eeba0a66 --- /dev/null +++ b/tests/untried/pos/t8300-overloading.scala @@ -0,0 +1,16 @@ +// cf. neg/t8300-overloading.scala +trait Universe { + type Name >: Null <: AnyRef with NameApi + trait NameApi + + type TermName >: Null <: TermNameApi with Name + trait TermNameApi extends NameApi +} + +object Test extends App { + val u: Universe = ??? + import u._ + + def foo(name: Name) = ??? + def foo(name: TermName) = ??? +} diff --git a/tests/untried/pos/t8300-patmat-a.scala b/tests/untried/pos/t8300-patmat-a.scala new file mode 100644 index 000000000..ab3a3c960 --- /dev/null +++ b/tests/untried/pos/t8300-patmat-a.scala @@ -0,0 +1,20 @@ +// cf. pos/t8300-patmat-b.scala +trait Universe { + type Name >: Null <: AnyRef with NameApi + trait NameApi + + type TermName >: Null <: Name with TermNameApi + trait TermNameApi extends NameApi +} + +object Test extends App { + val u: Universe = ??? + import u._ + + locally { + val ScalaName: TermName = ??? + ??? match { + case ScalaName => ??? + } + } +} diff --git a/tests/untried/pos/t8300-patmat-b.scala b/tests/untried/pos/t8300-patmat-b.scala new file mode 100644 index 000000000..0acad4406 --- /dev/null +++ b/tests/untried/pos/t8300-patmat-b.scala @@ -0,0 +1,20 @@ +// cf. pos/t8300-patmat-a.scala +trait Universe { + type Name >: Null <: AnyRef with NameApi + trait NameApi + + type TermName >: Null <: TermNameApi with Name + trait TermNameApi extends NameApi +} + +object Test extends App { + val u: Universe = ??? + import u._ + + locally { + val ScalaName: TermName = ??? + ??? match { + case ScalaName => ??? + } + } +} diff --git a/tests/untried/pos/t8301.scala b/tests/untried/pos/t8301.scala new file mode 100644 index 000000000..2d10864c5 --- /dev/null +++ b/tests/untried/pos/t8301.scala @@ -0,0 +1,19 @@ +trait Universe { + type Symbol >: Null <: AnyRef with SymbolApi + trait SymbolApi + + type TypeSymbol >: Null <: TypeSymbolApi with Symbol + trait TypeSymbolApi + + implicit class CompatibleSymbol(sym: Symbol) { + def asFreeType: TypeSymbol = ??? + } +} + +object Test extends App { + val u: Universe = ??? + import u._ + + val sym: Symbol = ??? + sym.asFreeType +} diff --git a/tests/untried/pos/t8301b.scala b/tests/untried/pos/t8301b.scala new file mode 100644 index 000000000..5641547c1 --- /dev/null +++ b/tests/untried/pos/t8301b.scala @@ -0,0 +1,36 @@ +// cf. pos/t8300-patmat.scala +trait Universe { + type Name >: Null <: AnyRef with NameApi + trait NameApi + + type TermName >: Null <: TermNameApi with Name + trait TermNameApi extends NameApi +} + +object Test extends App { + val u: Universe = ??? + import u._ + + val ScalaName: TermName = ??? + locally { + + ??? match { + case Test.ScalaName => ??? + } + import Test.ScalaName._ + + ??? match { + case ScalaName => ??? + } + import ScalaName._ + + // both the pattern and import led to + // stable identifier required, but SN found. Note that value SN + // is not stable because its type, Test.u.TermName, is volatile. + val SN = ScalaName + ??? match { + case SN => ??? + } + import SN._ + } +} diff --git a/tests/untried/pos/t8306.flags b/tests/untried/pos/t8306.flags new file mode 100644 index 000000000..49d036a88 --- /dev/null +++ b/tests/untried/pos/t8306.flags @@ -0,0 +1 @@ +-optimize diff --git a/tests/untried/pos/t8306.scala b/tests/untried/pos/t8306.scala new file mode 100644 index 000000000..e04b054eb --- /dev/null +++ b/tests/untried/pos/t8306.scala @@ -0,0 +1,8 @@ +class Si8306 { + def foo: Int = 123 + lazy val extension: Int = + foo match { + case idx if idx != -1 => 15 + case _ => 17 + } +} diff --git a/tests/untried/pos/t8315.flags b/tests/untried/pos/t8315.flags new file mode 100644 index 000000000..c926ad649 --- /dev/null +++ b/tests/untried/pos/t8315.flags @@ -0,0 +1 @@ +-Yinline -Ydead-code diff --git a/tests/untried/pos/t8315.scala b/tests/untried/pos/t8315.scala new file mode 100644 index 000000000..2f7742ed6 --- /dev/null +++ b/tests/untried/pos/t8315.scala @@ -0,0 +1,12 @@ +object Test { + def crash(as: Listt): Unit = { + map(as, (_: Any) => return) + } + + final def map(x: Listt, f: Any => Any): Any = { + if (x eq Nill) "" else f("") + } +} + +object Nill extends Listt +class Listt diff --git a/tests/untried/pos/t8315b.flags b/tests/untried/pos/t8315b.flags new file mode 100644 index 000000000..c926ad649 --- /dev/null +++ b/tests/untried/pos/t8315b.flags @@ -0,0 +1 @@ +-Yinline -Ydead-code diff --git a/tests/untried/pos/t8315b.scala b/tests/untried/pos/t8315b.scala new file mode 100644 index 000000000..d7a2bf565 --- /dev/null +++ b/tests/untried/pos/t8315b.scala @@ -0,0 +1,11 @@ +object Test extends Object { + def crash: Unit = { + val key = "" + try map(new F(key)) + catch { case _: Throwable => } + }; + final def map(f: F): Any = f.apply(""); +}; +final class F(key: String) { + final def apply(a: Any): Any = throw new RuntimeException(key); +} diff --git a/tests/untried/pos/t8324.scala b/tests/untried/pos/t8324.scala new file mode 100644 index 000000000..2cb156232 --- /dev/null +++ b/tests/untried/pos/t8324.scala @@ -0,0 +1,16 @@ +package p1 + +private abstract class ProjectDef(val autoPlugins: Any) extends ProjectDefinition +sealed trait ResolvedProject extends ProjectDefinition { + def autoPlugins: Any +} + +sealed trait ProjectDefinition { + private[p1] def autoPlugins: Any +} + + +object Test { + // was "error: value autoPlugins in class ProjectDef of type Any cannot override final member" + new ProjectDef(null) with ResolvedProject +} diff --git a/tests/untried/pos/t8352.check b/tests/untried/pos/t8352.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8352.check diff --git a/tests/untried/pos/t8352/Macros_1.scala b/tests/untried/pos/t8352/Macros_1.scala new file mode 100644 index 000000000..c1c63e57b --- /dev/null +++ b/tests/untried/pos/t8352/Macros_1.scala @@ -0,0 +1,7 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +object Macros { + def impl(c: Context)(x: c.Expr[Boolean]): c.Expr[Boolean] = x + def foo(x: Boolean): Boolean = macro impl +} diff --git a/tests/untried/pos/t8352/Test_2.scala b/tests/untried/pos/t8352/Test_2.scala new file mode 100644 index 000000000..1f84c3ca1 --- /dev/null +++ b/tests/untried/pos/t8352/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + def expectUnit(): Unit = { + Macros.foo(true) + } +} diff --git a/tests/untried/pos/t8363.flags b/tests/untried/pos/t8363.flags new file mode 100644 index 000000000..48b438ddf --- /dev/null +++ b/tests/untried/pos/t8363.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/tests/untried/pos/t8363.scala b/tests/untried/pos/t8363.scala new file mode 100644 index 000000000..639faf412 --- /dev/null +++ b/tests/untried/pos/t8363.scala @@ -0,0 +1,7 @@ +class C(a: Any) +class Test { + def foo: Any = { + def form = 0 + class C1 extends C(() => form) + } +} diff --git a/tests/untried/pos/t8364.check b/tests/untried/pos/t8364.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8364.check diff --git a/tests/untried/pos/t8364.scala b/tests/untried/pos/t8364.scala new file mode 100644 index 000000000..7a7ea1ff1 --- /dev/null +++ b/tests/untried/pos/t8364.scala @@ -0,0 +1,12 @@ +import scala.language.dynamics + +object MyDynamic extends Dynamic { + def selectDynamic(name: String): Any = ??? +} + +object Test extends App { + locally { + import java.lang.String + MyDynamic.id + } +} diff --git a/tests/untried/pos/t8367.scala b/tests/untried/pos/t8367.scala new file mode 100644 index 000000000..9ac2ce7c2 --- /dev/null +++ b/tests/untried/pos/t8367.scala @@ -0,0 +1,11 @@ +package java.lang + +// SI-8367 shows something is wrong with primaryConstructor and it was made worse with the fix for SI-8192 +// perhaps primaryConstructor should not return NoSymbol when isJavaDefined +// or, perhaps isJavaDefined should be refined (the package definition above is pretty sneaky) +// also, why does this only happen for a (scala-defined!) class with this special name? +// (there are a couple of others: CloneNotSupportedException,InterruptedException) +class Throwable + +// class CloneNotSupportedException +// class InterruptedException diff --git a/tests/untried/pos/t8369a.check b/tests/untried/pos/t8369a.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8369a.check diff --git a/tests/untried/pos/t8369a.scala b/tests/untried/pos/t8369a.scala new file mode 100644 index 000000000..13046007f --- /dev/null +++ b/tests/untried/pos/t8369a.scala @@ -0,0 +1,5 @@ +object Bug { + trait Sys[S] + def test[S <: Sys[S]] = read[S]() + def read[S <: Sys[S]](baz: Any = 0): Some[S] = ??? +} diff --git a/tests/untried/pos/t8369b.check b/tests/untried/pos/t8369b.check new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/untried/pos/t8369b.check diff --git a/tests/untried/pos/t8369b.scala b/tests/untried/pos/t8369b.scala new file mode 100644 index 000000000..3194463fb --- /dev/null +++ b/tests/untried/pos/t8369b.scala @@ -0,0 +1,18 @@ +object Bug { + trait Sys[S] { + type Tx + } + + trait Baz[-Tx] + + trait Foo[S <: Sys[S]] { + def bar: Bar[S] = Bar.read[S]() + } + + object Bar { + object NoBaz extends Baz[Any] + + def read[S <: Sys[S]](baz: Baz[S#Tx] = NoBaz): Bar[S] = ??? + } + trait Bar[S <: Sys[S]] +} diff --git a/tests/untried/pos/t8376/BindingsX.java b/tests/untried/pos/t8376/BindingsX.java new file mode 100644 index 000000000..165fdaf5f --- /dev/null +++ b/tests/untried/pos/t8376/BindingsX.java @@ -0,0 +1,13 @@ +/** + * A simple Java class implementing methods similar to new JavaFX `Bindings`. + */ +public final class BindingsX { + + public static void select(String root, String... steps) { + throw new UnsupportedOperationException("Not implemented"); + } + + public static void select(Object root, String... steps) { + throw new UnsupportedOperationException("Not implemented"); + } +} diff --git a/tests/untried/pos/t8376/Test.scala b/tests/untried/pos/t8376/Test.scala new file mode 100644 index 000000000..ba078a353 --- /dev/null +++ b/tests/untried/pos/t8376/Test.scala @@ -0,0 +1,10 @@ +class Test { + BindingsX.select("", "") // okay in 2.10, fails in 2.11 + + BindingsY.select1("", "") // okay in both +} + +object BindingsY { + def select1(root: String, steps: String*) = () + def select1(root: Any, steps: String*) = () +} diff --git a/tests/untried/pos/t839.scala b/tests/untried/pos/t839.scala new file mode 100644 index 000000000..72f6ca0ec --- /dev/null +++ b/tests/untried/pos/t839.scala @@ -0,0 +1,26 @@ +// see pending/pos/t112606A.scala +package test; +trait Test { + trait Global { + type Tree; + def get : Tree; + } + trait TreeBuilder { + val global : Global; + def set(tree : global.Tree) = {} + } + val nsc : Global; + trait FileImpl { + object treeBuilder extends TreeBuilder { + val global : nsc.type = nsc; + } + // OK + treeBuilder.set(nsc.get); + } + val file0 : FileImpl; + // OK + file0.treeBuilder.set(nsc.get); + def file : FileImpl; + // type mismatch + file.treeBuilder.set(nsc.get); +} diff --git a/tests/untried/pos/t851.scala b/tests/untried/pos/t851.scala new file mode 100644 index 000000000..70f18673c --- /dev/null +++ b/tests/untried/pos/t851.scala @@ -0,0 +1,28 @@ +object test { + def ok1: String = { + val x = 1 + """ok1""" + } + def ok2: String = { + val x = "0".length + """ok2""" + } + def ok3: String = { + val x = "0".length + """ok3 + """// + } + def ok4: String = { + val x = "0".length + """ok4 + """ + x + } + def bad: String = { + val x = "0".length + """bad + """ + } + def main(args: Array[String]): Unit = { + Console.println(ok1 + ok2 + ok3 + ok4 + bad) + } +} diff --git a/tests/untried/pos/t873.scala b/tests/untried/pos/t873.scala new file mode 100644 index 000000000..b8c50afd3 --- /dev/null +++ b/tests/untried/pos/t873.scala @@ -0,0 +1,10 @@ +abstract class Foo { + + val x:Option[List[String]] + val y:List[Int] + + val z = (0:Any) match { + case 1 => x + case 2 => y + } +} diff --git a/tests/untried/pos/t892.scala b/tests/untried/pos/t892.scala new file mode 100644 index 000000000..41da7095b --- /dev/null +++ b/tests/untried/pos/t892.scala @@ -0,0 +1,14 @@ +package test; +object Test { + trait Core { + abstract class Visitor[T <: Visitor[T]]; + trait HasVisitor { + def visit[T <: Visitor[T]](initial : T) : T; + } + } + trait Ext extends Core { + class Foo { + def visit[T <: Visitor[T]](initial : T) : T = initial; + } + } +} diff --git a/tests/untried/pos/t911.scala b/tests/untried/pos/t911.scala new file mode 100644 index 000000000..cfa4f49dc --- /dev/null +++ b/tests/untried/pos/t911.scala @@ -0,0 +1,6 @@ +object Test { + def foo: Any = { + case class Foo() {} + Foo; + } +} diff --git a/tests/untried/pos/t927.scala b/tests/untried/pos/t927.scala new file mode 100644 index 000000000..c903f1986 --- /dev/null +++ b/tests/untried/pos/t927.scala @@ -0,0 +1,11 @@ +object Test { + + def sum(stream: Stream[Int]): Int = + stream match { + case Stream.Empty => 0 + case Stream.cons(hd, tl) => hd + sum(tl) + } + val str: Stream[Int] = List(1,2,3).iterator.toStream + assert(sum(str) == 6) + +} diff --git a/tests/untried/pos/t942/Amount_1.java b/tests/untried/pos/t942/Amount_1.java new file mode 100644 index 000000000..d9d37d127 --- /dev/null +++ b/tests/untried/pos/t942/Amount_1.java @@ -0,0 +1,5 @@ +import java.util.concurrent.Callable; + +public abstract class Amount_1<Q> extends Object + implements Callable<Amount_1<?>> { +} diff --git a/tests/untried/pos/t942/Test_2.scala b/tests/untried/pos/t942/Test_2.scala new file mode 100644 index 000000000..3cc84dae3 --- /dev/null +++ b/tests/untried/pos/t942/Test_2.scala @@ -0,0 +1,3 @@ +abstract class Foo { + val x: Amount_1[Foo] +} diff --git a/tests/untried/pos/t946.scala b/tests/untried/pos/t946.scala new file mode 100644 index 000000000..c4bd6e9ba --- /dev/null +++ b/tests/untried/pos/t946.scala @@ -0,0 +1,8 @@ +object pmbugbounds { + trait Bar + class Foo[t <: Bar] {} + + (new Foo[Bar]) match { + case _ : Foo[x] => null + } +} diff --git a/tests/untried/pos/tcpoly_boundedmonad.scala b/tests/untried/pos/tcpoly_boundedmonad.scala new file mode 100644 index 000000000..8c605dc7b --- /dev/null +++ b/tests/untried/pos/tcpoly_boundedmonad.scala @@ -0,0 +1,19 @@ +trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] { + def map[S <: Bound[S]](f: T => S): MyType[S] + + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S]): Result[S] + + def filter(p: T => Boolean): MyType[T] +} + +class Set[T <: Ordered[T]] extends Monad[T, Set, Ordered] { + def map[S <: Ordered[S]](f: T => S): Set[S] = sys.error("TODO") + + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S]): Result[S] = sys.error("TODO") + + def filter(p: T => Boolean): Set[T] = sys.error("TODO") +} diff --git a/tests/untried/pos/tcpoly_bounds1.scala b/tests/untried/pos/tcpoly_bounds1.scala new file mode 100644 index 000000000..63263cb15 --- /dev/null +++ b/tests/untried/pos/tcpoly_bounds1.scala @@ -0,0 +1,14 @@ +class Foo[t[x]<: Tuple2[Int, x]] + +// +class MyPair[z](a: Int, b: z) extends Tuple2[Int, z](a,b) + +object foo extends Foo[MyPair] + + +trait Monad[m[x <: Bound[x]], Bound[x], a] // TODO: variances! +trait ListMonad[a] extends Monad[List, Any, a] + +trait MyOrdered[a] +trait MySet[x <: MyOrdered[x]] +trait SetMonad[a <: MyOrdered[a]] extends Monad[MySet, MyOrdered, a] diff --git a/tests/untried/pos/tcpoly_checkkinds_mix.scala b/tests/untried/pos/tcpoly_checkkinds_mix.scala new file mode 100644 index 000000000..3734405f8 --- /dev/null +++ b/tests/untried/pos/tcpoly_checkkinds_mix.scala @@ -0,0 +1,10 @@ +trait Iterable[A <: Bound[A], Bound[_]] { + type MyType[x <: Bound[x]] <: Iterable[x, Bound] + def map[B <: Bound[B]](f: A => B): MyType[B] + def flatMap[B <: Bound[B]](f: A => MyType[B]): MyType[B] + def filter(p: A => Boolean): MyType[A] +} + +trait OrderedSet[T <: Ordered[T]] extends Iterable[T, Ordered] { + type MyType[x <: Ordered[x]] = OrderedSet[x] +} diff --git a/tests/untried/pos/tcpoly_gm.scala b/tests/untried/pos/tcpoly_gm.scala new file mode 100644 index 000000000..89b66cfba --- /dev/null +++ b/tests/untried/pos/tcpoly_gm.scala @@ -0,0 +1,14 @@ +trait Rep[a] { + def rep[m[x]]: m[a] // typedTypeApply must use asSeenFrom to adapt the return type + // since rep is called on x: Rep[t] + // a must become t +} + +case class ShowBin[b](app: b => String) + +object foo { + def showBin[t](x: Rep[t], y: t): String = { + val r: ShowBin[t] = x.rep[ShowBin] + r.app(y) + } +} diff --git a/tests/untried/pos/tcpoly_higherorder_bound_method.scala b/tests/untried/pos/tcpoly_higherorder_bound_method.scala new file mode 100644 index 000000000..3905b3b96 --- /dev/null +++ b/tests/untried/pos/tcpoly_higherorder_bound_method.scala @@ -0,0 +1,3 @@ +trait SkolemisationOfHigherOrderBoundInMethod { + def method[A, N[X <: A], M[X <: N[A]]]: Unit +} diff --git a/tests/untried/pos/tcpoly_infer_easy.scala b/tests/untried/pos/tcpoly_infer_easy.scala new file mode 100644 index 000000000..0f1929502 --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_easy.scala @@ -0,0 +1,5 @@ +object Test { + def test[CC[+X] <: Iterable[X], A](xs: CC[A]): CC[A] = xs + val xs = test(List(1,2)) + val xs2: List[Int] = test(List(1,2)) +} diff --git a/tests/untried/pos/tcpoly_infer_explicit_tuple_wrapper.scala b/tests/untried/pos/tcpoly_infer_explicit_tuple_wrapper.scala new file mode 100644 index 000000000..f719972a1 --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_explicit_tuple_wrapper.scala @@ -0,0 +1,16 @@ +import scala.collection.generic.GenericTraversableTemplate +import scala.collection.Iterable + +class IterableOps[CC[+B] <: Iterable[B] with GenericTraversableTemplate[B, CC], A1, A2](tuple: (CC[A1], Iterable[A2])) { + def unzip: (CC[A1], CC[A2]) = sys.error("foo") +} + +object Test { + + implicit def tupleOfIterableWrapper[CC[+B] <: Iterable[B] with GenericTraversableTemplate[B, CC], A1, A2](tuple: (CC[A1], Iterable[A2])) + = new IterableOps[CC, A1, A2](tuple) + + val t = (List(1, 2, 3), List(6, 5, 4)) + + tupleOfIterableWrapper(t) unzip +} diff --git a/tests/untried/pos/tcpoly_infer_implicit_tuple_wrapper.scala b/tests/untried/pos/tcpoly_infer_implicit_tuple_wrapper.scala new file mode 100644 index 000000000..19243505b --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_implicit_tuple_wrapper.scala @@ -0,0 +1,18 @@ +import scala.collection.generic.GenericTraversableTemplate +import scala.collection.Iterable + +class IterableOps[CC[+B] <: Iterable[B] with GenericTraversableTemplate[B, CC], A1, A2](tuple: (CC[A1], Iterable[A2])) { + def unzip: (CC[A1], CC[A2]) = sys.error("foo") +} + +object Test { + + implicit def tupleOfIterableWrapper[CC[+B] <: Iterable[B] with GenericTraversableTemplate[B, CC], A1, A2](tuple: (CC[A1], Iterable[A2])) + = new IterableOps[CC, A1, A2](tuple) + + val t = (List(1, 2, 3), List(6, 5, 4)) + + tupleOfIterableWrapper(t) unzip + + t unzip +} diff --git a/tests/untried/pos/tcpoly_infer_ticket1864.scala b/tests/untried/pos/tcpoly_infer_ticket1864.scala new file mode 100644 index 000000000..70cfac062 --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_ticket1864.scala @@ -0,0 +1,51 @@ +import scala.collection.mutable.{Buffer, ArrayBuffer} + +class RichBuffer[T, B[U] <: Buffer[U]](buffer: Buffer[T]) { + def mymap[S](f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } +} + +object App { + def mymap2[T, B[U] <: Buffer[U], S](buffer: B[T], f: T => S)(implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap3[T, B <: Buffer[T], S](buffer: B, f: T => T)(implicit rv: B): B = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + def mymap4[T, B[U] <: Buffer[U], S](buffer: B[T])(f: T => S) (implicit rv: B[S]): B[S] = { + buffer.foreach{ e => + rv += f(e) + } + rv + } + + + def main(args: Array[String]): Unit = { + implicit def richBuffer[T, B[U] <: Buffer[U]](buffer: B[T]): RichBuffer[T, B] = + new RichBuffer[T, B](buffer) + + implicit val rv = new ArrayBuffer[Int] + val buf = new ArrayBuffer[Int] + (1 to 5).foreach(buf += _) + buf.mymap(x => x*x) + richBuffer(buf).mymap[Int](x => x*x) + richBuffer[Int, ArrayBuffer](buf).mymap[Int](x => x*x) + mymap2(buf, (x: Int) => x*x) + mymap2[Int, ArrayBuffer, Int](buf, (x: Int) => x*x) + // mymap3(buf, x => x*x) // compiler error + mymap3(buf, (x: Int) => x*x) + mymap4(buf)(x => x*x) + } +} diff --git a/tests/untried/pos/tcpoly_infer_ticket474.scala b/tests/untried/pos/tcpoly_infer_ticket474.scala new file mode 100644 index 000000000..80459a6ad --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_ticket474.scala @@ -0,0 +1,27 @@ +trait Builder[C[_], T] { + def +=(x: T) + def finalise: C[T] +} + +trait Buildable[C[_]] { + def builder[T]: Builder[C,T] +} + +object Test { + + implicit object buildableList extends Buildable[List] { + def builder[T] = new Builder[List,T] { + val buf = new scala.collection.mutable.ListBuffer[T] + def +=(x: T) = buf += x + def finalise = buf.toList + } + } + + def foo[C[_],T](x: T)(implicit b: Buildable[C]): C[T] = { + val builder = b.builder[T] + builder += x + builder.finalise + } + + val l: List[Int] = foo(8) +} diff --git a/tests/untried/pos/tcpoly_infer_ticket716.scala b/tests/untried/pos/tcpoly_infer_ticket716.scala new file mode 100644 index 000000000..24e8f663b --- /dev/null +++ b/tests/untried/pos/tcpoly_infer_ticket716.scala @@ -0,0 +1,26 @@ + +trait Functor[F[_]] { + def fmap[A,B](fun: A=>B, arg:F[A]): F[B] +} +object Functor{ + implicit val ListFunctor: Functor[List] = new Functor[List] { + def fmap[A, B](f: A => B, arg: List[A]):List[B] = arg map f + } + + final class OOFunctor[F[_],A](arg:F[A])(implicit ftr: Functor[F]) { + def fmap[B](fun: A=>B):F[B] = ftr.fmap(fun,arg) + } + + //breaks if uncommented + implicit def lifttoOO[F[_],A](arg:F[A])(implicit ftr: Functor[F]) = new OOFunctor[F,A](arg)(ftr) + + //works if uncommented + //implicit def liftListtoOO[A](arg:List[A]):OOFunctor[List,A] = new OOFunctor[List,A](arg) +} + +object GeneralLiftingDemo extends App { + import Functor._ + val l = List(1,2,3) + val res = l fmap( 1+) // TODO: should not need explicit call to lifttoOO + println("OO : " + res ) +} diff --git a/tests/untried/pos/tcpoly_late_method_params.scala b/tests/untried/pos/tcpoly_late_method_params.scala new file mode 100644 index 000000000..e2f0bcffb --- /dev/null +++ b/tests/untried/pos/tcpoly_late_method_params.scala @@ -0,0 +1,5 @@ +trait Foo { + def flatMap[RT <: RBound[RT], RBound[_], Result[x <: RBound[x]]]: Result[RT] +// bounds for RT& = >: scala.this.Nothing <: RBound&[RT&] + // bounds for x = >: scala.this.Nothing <: RBound&[x] +} diff --git a/tests/untried/pos/tcpoly_method.scala b/tests/untried/pos/tcpoly_method.scala new file mode 100644 index 000000000..294b53b91 --- /dev/null +++ b/tests/untried/pos/tcpoly_method.scala @@ -0,0 +1,6 @@ +trait Iterable[m[+x], +t] { + def flatMap[resColl[+x] <: Iterable[resColl, x], s](f: t => resColl[s]): resColl[s] + + def foo[a[x]] = "a" + val x = foo[List] +} diff --git a/tests/untried/pos/tcpoly_overloaded.scala b/tests/untried/pos/tcpoly_overloaded.scala new file mode 100644 index 000000000..4f6334685 --- /dev/null +++ b/tests/untried/pos/tcpoly_overloaded.scala @@ -0,0 +1,25 @@ +trait Monad[T <: Bound[T], MyType[x <: Bound[x]], Bound[_]] { + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S]): Result[S] + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S], foo: String): Result[S] + def flatMap[S <: Bound[S]] + (f: T => MyType[S], foo: Int): MyType[S] +} + +trait Test { + def moo: MList[Int] + class MList[T](el: T) extends Monad[T, List, Any] { + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S]): Result[S] = sys.error("foo") + def flatMap[S <: RBound[S], RContainer[x <: RBound[x]], RBound[_], + Result[x <: RBound[x]] <: Monad[x, RContainer, RBound]] + (f: T => Result[S], foo: String): Result[S] = sys.error("foo") + def flatMap[S] + (f: T => List[S], foo: Int): List[S] = sys.error("foo") + } + val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) +} diff --git a/tests/untried/pos/tcpoly_param_scoping.scala b/tests/untried/pos/tcpoly_param_scoping.scala new file mode 100644 index 000000000..f8a03f664 --- /dev/null +++ b/tests/untried/pos/tcpoly_param_scoping.scala @@ -0,0 +1,8 @@ +trait FOO[B, m[A <: B]] +trait FOO2[A <: B, B] +trait FOO3[m[A <: B], B] + +class Test { + def foo[a[x]] = "a" +} +//trait Idiom[idi[x]] { def foo: idi[Int]} diff --git a/tests/untried/pos/tcpoly_poly.scala b/tests/untried/pos/tcpoly_poly.scala new file mode 100644 index 000000000..1ba04e29d --- /dev/null +++ b/tests/untried/pos/tcpoly_poly.scala @@ -0,0 +1,3 @@ +class Monad[m[x]] + +object ml extends Monad[List] diff --git a/tests/untried/pos/tcpoly_return_overriding.scala b/tests/untried/pos/tcpoly_return_overriding.scala new file mode 100644 index 000000000..57ec8da76 --- /dev/null +++ b/tests/untried/pos/tcpoly_return_overriding.scala @@ -0,0 +1,13 @@ +trait Generic[g[x]] { + def unit: g[Unit] +} + +trait Rep[t] { + def rep[m[x]](implicit gen: Generic[m]): m[t] +} + +// testing that the return type is also transformed when checking overriding +// + that substitution (of types&symbols) preserves isHigherKinded when replacing a higher-kinded type with another one +object foo extends Rep[Unit] { + def rep[g[x]](implicit gen: Generic[g]): g[Unit]= gen.unit +} diff --git a/tests/untried/pos/tcpoly_seq.scala b/tests/untried/pos/tcpoly_seq.scala new file mode 100644 index 000000000..731fe048a --- /dev/null +++ b/tests/untried/pos/tcpoly_seq.scala @@ -0,0 +1,175 @@ +package examples.tcpoly.collection; + +trait HOSeq { + // an internal interface that encapsulates the accumulation of elements (of type elT) to produce + // a structure of type coll[elT] -- different kinds of collections should provide different implicit + // values implementing this interface, in order to provide more performant ways of building that structure + trait Accumulator[+coll[x], elT] { + def += (el: elT): Unit + def result: coll[elT] + } + + + // Iterable abstracts over the type of its structure as well as its elements (see PolyP's Bifunctor) + // m[x] is intentionally unbounded: fold can then be defined nicely + // variance: if we write m[+x] instead of +m[+x], x is an invariant position because its enclosing type + // is an invariant position -- should probably rule that out? + trait Iterable[+m[+x], +t] { + //def unit[a](orig: a): m[a] + def iterator: Iterator[t] + + // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t + def accumulator[t]: Accumulator[m, t] + + def filter(p: t => Boolean): m[t] = { + val buf = accumulator[t] + val elems = iterator + while (elems.hasNext) { val x = elems.next; if (p(x)) buf += x } + buf.result + } + + def map[s](f: t => s): m[s] = { + val buf = accumulator[s] + val elems = iterator + while (elems.hasNext) buf += f(elems.next) + buf.result + } + + // flatMap is a more specialized map, it only works if the mapped function produces Iterable values, + // which are then added to the result one by one + // the compiler should be able to find the right accumulator (implicit buf) to build the result + // to get concat, resColl = SingletonIterable, f = unit for SingletonIterable + def flatMap[resColl[+x] <: Iterable[resColl, x], s](f: t => resColl[s])(implicit buf: Accumulator[resColl, s]): resColl[s] = { + // TODO: would a viewbound for resColl[x] be better? + // -- 2nd-order type params are not yet in scope in view bound + val elems = iterator + while (elems.hasNext) { + val elemss: Iterator[s] = f(elems.next).iterator + while (elemss.hasNext) buf += elemss.next + } + buf.result + } + } + + final class ListBuffer[A] { + private var start: List[A] = Nil + private var last: ::[A] = _ + private var exported: Boolean = false + + /** Appends a single element to this buffer. + * + * @param x the element to append. + */ + def += (x: A): Unit = { + if (exported) copy + if (start.isEmpty) { + last = new HOSeq.this.:: (x, Nil) + start = last + } else { + val last1 = last + last = new HOSeq.this.:: (x, null) // hack: ::'s tail will actually be last + //last1.tl = last + } + } + + /** Converts this buffer to a list + */ + def toList: List[A] = { + exported = !start.isEmpty + start + } + + /** Clears the buffer contents. + */ + def clear: Unit = { + start = Nil + exported = false + } + + /** Copy contents of this buffer */ + private def copy: Unit = { + var cursor = start + val limit = last.tail + clear + while (cursor ne limit) { + this += cursor.head + cursor = cursor.tail + } + } + } + + implicit def listAccumulator[elT]: Accumulator[List, elT] = new Accumulator[List, elT] { + private[this] val buff = new ListBuffer[elT] + def += (el: elT): Unit = buff += el + def result: List[elT] = buff.toList + } + + trait List[+t] extends Iterable[List, t] { + def head: t + def tail: List[t] + def isEmpty: Boolean + def iterator: Iterator[t] = new Iterator[t] { + var these = List.this + def hasNext: Boolean = !these.isEmpty + def next: t = + if (!hasNext) + throw new NoSuchElementException("next on empty Iterator") + else { + val result = these.head; these = these.tail; result + } + } + // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t + def accumulator[t]: Accumulator[List, t] = listAccumulator[t] + } + + // TODO: the var tl approach does not seem to work because subtyping isn't fully working yet + final case class ::[+b](hd: b, private val tl: List[b]) extends List[b] { + def head = hd + def tail = if(tl==null) this else tl // hack + override def isEmpty: Boolean = false + } + + case object Nil extends List[Nothing] { + def isEmpty = true + def head: Nothing = + throw new NoSuchElementException("head of empty list") + def tail: List[Nothing] = + throw new NoSuchElementException("tail of empty list") + } +} + + + +// misc signatures collected from mailing list / library code: + /*override def flatMap[B](f: A => Iterable[B]): Set[B] + final override def flatMap[b](f: Any => Iterable[b]): Array[b] + def flatMap[b](f: a => Parser[b]) = new Parser[b] + override def flatMap[b](f: a => Iterable[b]): List[b] + + + MapResult[K] <: Seq[K] + FilterResult <: Seq[T] + Concat <: Seq[T] + Subseq <: Seq[T] + + + def map[K](f: T=>K): MapResult[K] + def filter(f: T=>Boolean): FilterResult + def subseq(from: Int, to: Int): Subseq + def flatMap[S <: Seq[K], K](f: T => S): S#Concat // legal? + def concat(others: Seq[T]): Concat + */ + +/*trait Iterator[t] { + // @post hasAdvanced implies hasNext + // model def hasAdvanced: Boolean + + def hasNext: Boolean // pure + + // @pre hasAdvanced + def current: t // pure + + // @pre hasNext + // @post hasAdvanced + def advance: Unit +}*/ diff --git a/tests/untried/pos/tcpoly_seq_typealias.scala b/tests/untried/pos/tcpoly_seq_typealias.scala new file mode 100644 index 000000000..8d2f6e7c3 --- /dev/null +++ b/tests/untried/pos/tcpoly_seq_typealias.scala @@ -0,0 +1,143 @@ +package examples.tcpoly.collection + +trait HOSeq { + // an internal interface that encapsulates the accumulation of elements (of type elT) to produce + // a structure of type coll[elT] -- different kinds of collections should provide different implicit + // values implementing this interface, in order to provide more performant ways of building that structure + trait Accumulator[+coll[x], elT] { + def += (el: elT): Unit + def result: coll[elT] + } + + + // Iterable abstracts over the type of its structure as well as its elements (see PolyP's Bifunctor) + // m[x] is intentionally unbounded: fold can then be defined nicely + // variance: if we write m[+x] instead of +m[+x], x is an invariant position because its enclosing type + // is an invariant position -- should probably rule that out? + trait Iterable[+t] { + type m[+x] + + //def unit[a](orig: a): m[a] + def iterator: Iterator[t] + + // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t + def accumulator[t]: Accumulator[m, t] + + def filter(p: t => Boolean): m[t] = { + val buf = accumulator[t] + val elems = iterator + while (elems.hasNext) { val x = elems.next; if (p(x)) buf += x } + buf.result + } + + def map[s](f: t => s): m[s] = { + val buf = accumulator[s] + val elems = iterator + while (elems.hasNext) buf += f(elems.next) + buf.result + } + + // flatMap is a more specialized map, it only works if the mapped function produces Iterable values, + // which are then added to the result one by one + // the compiler should be able to find the right accumulator (implicit buf) to build the result + // to get concat, resColl = SingletonIterable, f = unit for SingletonIterable + def flatMap[resColl[+x] <: Iterable[x], s](f: t => resColl[s])(implicit buf: Accumulator[resColl, s]): resColl[s] = { + // TODO: would a viewbound for resColl[x] be better? + // -- 2nd-order type params are not yet in scope in view bound + val elems = iterator + while (elems.hasNext) { + val elemss: Iterator[s] = f(elems.next).iterator + while (elemss.hasNext) buf += elemss.next + } + buf.result + } + } + + final class ListBuffer[A] { + private var start: List[A] = Nil + private var last: ::[A] = _ + private var exported: Boolean = false + + /** Appends a single element to this buffer. + * + * @param x the element to append. + */ + def += (x: A): Unit = { + if (exported) copy + if (start.isEmpty) { + last = new HOSeq.this.:: (x, Nil) + start = last + } else { + val last1 = last + last = new HOSeq.this.:: (x, null) // hack: ::'s tail will actually be last + //last1.tl = last + } + } + + /** Converts this buffer to a list + */ + def toList: List[A] = { + exported = !start.isEmpty + start + } + + /** Clears the buffer contents. + */ + def clear: Unit = { + start = Nil + exported = false + } + + /** Copy contents of this buffer */ + private def copy: Unit = { + var cursor = start + val limit = last.tail + clear + while (cursor ne limit) { + this += cursor.head + cursor = cursor.tail + } + } + } + + implicit def listAccumulator[elT]: Accumulator[List, elT] = new Accumulator[List, elT] { + private[this] val buff = new ListBuffer[elT] + def += (el: elT): Unit = buff += el + def result: List[elT] = buff.toList + } + + trait List[+t] extends Iterable[t] { + type m[+x] = List[x] + + def head: t + def tail: List[t] + def isEmpty: Boolean + def iterator: Iterator[t] = new Iterator[t] { + var these = List.this + def hasNext: Boolean = !these.isEmpty + def next: t = + if (!hasNext) + throw new NoSuchElementException("next on empty Iterator") + else { + val result = these.head; these = these.tail; result + } + } + // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t + def accumulator[t]: Accumulator[List, t] = listAccumulator[t] + } + + // TODO: the var tl approach does not seem to work because subtyping isn't fully working yet + final case class ::[+b](hd: b, private val tl: List[b]) extends List[b] { + def head = hd + def tail = if(tl==null) this else tl // hack + override def isEmpty: Boolean = false + } + + case object Nil extends List[Nothing] { + def isEmpty = true + def head: Nothing = + throw new NoSuchElementException("head of empty list") + def tail: List[Nothing] = + throw new NoSuchElementException("tail of empty list") + } +} diff --git a/tests/untried/pos/tcpoly_subst.scala b/tests/untried/pos/tcpoly_subst.scala new file mode 100644 index 000000000..88cc4d061 --- /dev/null +++ b/tests/untried/pos/tcpoly_subst.scala @@ -0,0 +1,4 @@ +object test { + def make[m[x], b]: m[b] = sys.error("foo") + val lst: List[Int] = make[List, Int] +} diff --git a/tests/untried/pos/tcpoly_ticket2096.scala b/tests/untried/pos/tcpoly_ticket2096.scala new file mode 100644 index 000000000..d2387b36b --- /dev/null +++ b/tests/untried/pos/tcpoly_ticket2096.scala @@ -0,0 +1,30 @@ +// smallest expression of monad i can find +trait MBrace[C[X] <: MBrace[C,X],A] { + def nest( a : A ) : C[A] + def flatten[T <: C[C[A]]]( bsq : T ) : C[A] +} + +// a monad that is a Seq +trait MBraceSeq[C[X] <: MBrace[C,X] with Seq[X],A] extends MBrace[C,A] + +// one of the simplest witnesses of monad i can find +case class MSequitor[A]( a_ : A* ) extends Seq[A] with MBrace[MSequitor,A] +{ + override def nest( a : A ) = new MSequitor[A]( a ) + override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ) : MSequitor[A] = { + (new MSequitor[A]( ) /: bsq)( { + ( acc : MSequitor[A], e : MSequitor[A] ) => ( acc ++ e ).asInstanceOf[MSequitor[A]] + } ) + } + override def length = a_.length + override def iterator = a_.iterator + override def apply( n : Int ) = a_.apply( n ) +} + +// type arguments [MSequitor,A] do not conform to trait MBraceSeq's type parameter bounds [C[_] <: MBrace[C,A] with Seq[A],A] +// a statement of the instance relation +class MBraceSequitor[A] extends MBraceSeq[MSequitor,A] { + val empty : MSequitor[A] = new MSequitor[A]( ) + override def nest( a : A ) = empty.nest( a ) + override def flatten[T <: MSequitor[MSequitor[A]]]( bsq : T ): MSequitor[A] = empty.flatten( bsq ) +} diff --git a/tests/untried/pos/tcpoly_typeapp.scala b/tests/untried/pos/tcpoly_typeapp.scala new file mode 100644 index 000000000..4cb1da4f7 --- /dev/null +++ b/tests/untried/pos/tcpoly_typeapp.scala @@ -0,0 +1,4 @@ +abstract class x { + type t[m[x] <: Bound[x], Bound[x]] + val x: t[scala.collection.mutable.MutableList, Iterable] +} diff --git a/tests/untried/pos/tcpoly_typesub.scala b/tests/untried/pos/tcpoly_typesub.scala new file mode 100644 index 000000000..a56d0a254 --- /dev/null +++ b/tests/untried/pos/tcpoly_typesub.scala @@ -0,0 +1,14 @@ +// contributed by Lauri Alanko +trait TypeSub { + type l + type u + def castSub[f[+x]](fl : f[l]) : f[u] + def castSuper[f[-x]](fu : f[u]) : f[l] = { + type c[+y] = f[y] => f[l] + castSub[c]{ fl : f[l] => fl }(fu) + } + def castValue[t](lt : l with t) : u with t = { + type c[+y] = y with t + castSub[c](lt) + } +} diff --git a/tests/untried/pos/tcpoly_variance_pos.scala b/tests/untried/pos/tcpoly_variance_pos.scala new file mode 100644 index 000000000..b63abce20 --- /dev/null +++ b/tests/untried/pos/tcpoly_variance_pos.scala @@ -0,0 +1,7 @@ +class A[m[+x]] { + def str: m[Object] = sys.error("foo") +} + +class B[m[+x]] extends A[m] { + override def str: m[String] = sys.error("foo") +} diff --git a/tests/untried/pos/tcpoly_wildcards.scala b/tests/untried/pos/tcpoly_wildcards.scala new file mode 100644 index 000000000..f6d1b666d --- /dev/null +++ b/tests/untried/pos/tcpoly_wildcards.scala @@ -0,0 +1,3 @@ +trait test[b[_,_]] { + def moo[a[_, _]] = sys.error("a") +} diff --git a/tests/untried/pos/ted.scala b/tests/untried/pos/ted.scala new file mode 100644 index 000000000..314f10932 --- /dev/null +++ b/tests/untried/pos/ted.scala @@ -0,0 +1,18 @@ +object App +{ + def exponentiate(base : Double, exponent : Double) : Double = + (base, exponent) match + { + case (0, 0) => 1.0 + case (b, 0) => 1.0 + case (b, 1) => b + case (b, e) => b * exponentiate(b, e - 1) + } + + + + def main(args : Array[String]) = + System.out.println(exponentiate(2, 2)) + +} + diff --git a/tests/untried/pos/test1.scala b/tests/untried/pos/test1.scala new file mode 100644 index 000000000..a36d2436e --- /dev/null +++ b/tests/untried/pos/test1.scala @@ -0,0 +1,5 @@ +object test { + + def f() = 5; + +} diff --git a/tests/untried/pos/test4.scala b/tests/untried/pos/test4.scala new file mode 100644 index 000000000..4fe65a8f1 --- /dev/null +++ b/tests/untried/pos/test4.scala @@ -0,0 +1,47 @@ +package test; + +trait C {} +trait D {} +trait E {} + +object test { + def c: C = c; + def d: D = d; + def e: E = e; +} + +import test._; + +trait S extends ooo.I[D] { + def bar: E = foo(c,d); +} + +class O[X]() { + trait I[Y] { + def foo(x: X, y: Y): E = e; + } + val i:I[E] = null; + val j:I[X] = null; +} + +object ooo extends O[C]() { + + def main = { + val s: S = null; + import s._; + foo(c,d); + ooo.i.foo(c,e); + ooo.j.foo(c,c); + bar + } +} + +class Main() { + val s: S = null; + import s._; + foo(c,d); + ooo.i.foo(c,e); + ooo.j.foo(c,c); + bar; +} + diff --git a/tests/untried/pos/test4a.scala b/tests/untried/pos/test4a.scala new file mode 100644 index 000000000..ada0ba4e5 --- /dev/null +++ b/tests/untried/pos/test4a.scala @@ -0,0 +1,16 @@ +trait C {} + +class O[X]() { + trait I[Y] { + def foo(y: Y): Y = y; + } + val j:I[X] = null; +} + +object o extends O[C]() { + def c: C = c; + def main = { + o.j.foo(c); + } +} + diff --git a/tests/untried/pos/test4refine.scala b/tests/untried/pos/test4refine.scala new file mode 100644 index 000000000..671096293 --- /dev/null +++ b/tests/untried/pos/test4refine.scala @@ -0,0 +1,49 @@ +trait C {} +trait D {} +trait E {} + +object test { + def c: C = c; + def d: D = d; + def e: E = e; +} + +import test._; + +trait S extends o.I { + type Y = D; + def bar: E = foo(c,d); +} + +abstract class O() { + type X; + abstract trait I { + type Y; + def foo(x: X, y: Y): E = e; + } + val i:I { type Y = E } = null; + val j:I { type Y = X } = null; +} + +object o extends O() { + type X = C; + + def main = { + val s: S = null; + import s._; + foo(c,d); + o.i.foo(c,e); + o.j.foo(c,c); + bar + } +} + +class Main() { + val s: S = null; + import s._; + foo(c,d); + o.i.foo(c,e); + o.j.foo(c,c); + bar; +} + diff --git a/tests/untried/pos/test5.scala b/tests/untried/pos/test5.scala new file mode 100644 index 000000000..4dbafc9ac --- /dev/null +++ b/tests/untried/pos/test5.scala @@ -0,0 +1,68 @@ +import scala._; + +object test { + + trait F[If] {} + + def f[Jf](h: Jf):F[Jf] = f[Jf](h); + + trait G[Ig] {} + + def g[Jg](h: Jg):G[Jg] = g[Jg](h); + + class M[P]() { + abstract class I[X]() { + // Methods to check the type X and P as seen from instances of I + def chk_ix(x: X): Unit = (); + def chk_ip(p: P): Unit; + + // Value with type X as seen from instances of I + def val_ix: X = val_ix; + } + + val i:I[G[P]] = null; + + // Values with types P and i.X as seen from instances of M + def val_mp: P = val_mp; + def val_mix: G[P] = g[P](val_mp); + } + + class N[Q]() extends M[F[Q]]() { + val j:J[G[Q]] = null; + + abstract class J[Y]() extends I[G[Y]]() { + // Values with types Y and X as seen from instances of J + def val_jy: Y = val_jy; + def val_jx: G[Y] = g[Y](val_jy); + + // Check type P + chk_ip(val_mp); + chk_ip(val_np); + } + + // Values with types Q, X.P, i.X, j.Y and j.X as seen from instances of N + def val_nq: Q = val_nq; + def val_np: F[Q] = f[Q](val_nq); + def val_nix: G[F[Q]] = g[F[Q]](val_np); + def val_njy: G[Q] = g[Q](val_nq); + def val_njx: G[G[Q]] = g[G[Q]](val_njy); + + // Check type i.P + i.chk_ip(val_mp); + i.chk_ip(val_np); + + // Check type j.P + j.chk_ip(val_mp); + j.chk_ip(val_np); + + // Check type i.X + i.chk_ix(i.val_ix); + i.chk_ix(val_mix); + i.chk_ix(val_nix); + + // Check j.X + j.chk_ix(j.val_ix); + j.chk_ix(j.val_jx); + j.chk_ix(val_njx); + } +} diff --git a/tests/untried/pos/test5refine.scala b/tests/untried/pos/test5refine.scala new file mode 100644 index 000000000..5459b3b97 --- /dev/null +++ b/tests/untried/pos/test5refine.scala @@ -0,0 +1,75 @@ +import scala._; + +object test { + + abstract trait F { type If; } + + def f[Jf](h: Jf):F { type If = Jf } = f[Jf](h); + + abstract trait G { type Ig; } + + def g[Jg](h: Jg):G { type Ig = Jg } = g[Jg](h); + + abstract class M() { + type P; + abstract class I() { + type X; + + // Methods to check the type X and P as seen from instances of I + def chk_ix(x: X): Unit = {} + def chk_ip(p: P): Unit = {} + + // Value with type X as seen from instances of I + def val_ix: X = val_ix; + } + + val i: I { type X = G { type Ig = P } } = null; + + // Values with types P and i.X as seen from instances of M + def val_mp: P = val_mp; + def val_mix: G { type Ig = P } = g[P](val_mp); + } + + abstract class N() extends M() { + type Q; + type P = F { type If = Q }; + val j:J { type Y = G { type Ig = Q } } = null; + + abstract class J() extends I() { + type Y; + type X = G { type Ig = Y; }; + // Values with types Y and X as seen from instances of J + def val_jy: Y = val_jy; + def val_jx: G { type Ig = Y; } = g[Y](val_jy); + + // Check type P + chk_ip(val_mp); + chk_ip(val_np); + } + + // Values with types Q, X.P, i.X, j.Y and j.X as seen from instances of N + def val_nq: Q = val_nq; + def val_np: F { type If = Q } = f[Q](val_nq); + def val_nix: G { type Ig = F { type If = Q } } = g[F { type If = Q }](val_np); + def val_njy: G { type Ig = Q; } = g[Q](val_nq); + def val_njx: G { type Ig = G { type Ig = Q }} = g[G { type Ig = Q; }](val_njy); + + // Check type i.P + i.chk_ip(val_mp); + i.chk_ip(val_np); + + // Check type j.P + j.chk_ip(val_mp); + j.chk_ip(val_np); + + // Check type i.X + i.chk_ix(i.val_ix); + i.chk_ix(val_mix); + i.chk_ix(val_nix); + + // Check j.X + j.chk_ix(j.val_ix); + j.chk_ix(j.val_jx); + j.chk_ix(val_njx); + } +} diff --git a/tests/untried/pos/testCoercionThis.scala b/tests/untried/pos/testCoercionThis.scala new file mode 100644 index 000000000..5631b3330 --- /dev/null +++ b/tests/untried/pos/testCoercionThis.scala @@ -0,0 +1,19 @@ +object Test { + implicit def foo2bar(foo: Foo): Bar = foo.bar + + class Foo(val bar: Bar) { + def testCoercion = { + val a: this.type = this + a.baz /* here, foo2bar is inferred by the compiler, as expected */ + } + // def testCoercionThis0 = baz + // --> error: not found: value baz + // PP: is that something we really want to work? Seems like sketchville. + // + // These work, so I moved this out of pending. + def testCoercionThis1 = this.baz + def testCoercionThis2 = (this: Foo).baz + } + + class Bar { def baz = System.out.println("baz") } +} diff --git a/tests/untried/pos/testcast.scala b/tests/untried/pos/testcast.scala new file mode 100644 index 000000000..d4184e4f0 --- /dev/null +++ b/tests/untried/pos/testcast.scala @@ -0,0 +1,27 @@ +package test + +class A; + +class B extends A { + def foo: Int = 1 +} + +object B { + def view(x: B): B1 = null +} + +class B1 { + def bar: Int = 1 +} + +object C { + implicit def view(x: A): B1 = null +} + +object Test { + import C.view + + val b: B = null + + println(b.bar) +} diff --git a/tests/untried/pos/thistype.scala b/tests/untried/pos/thistype.scala new file mode 100644 index 000000000..265c821ad --- /dev/null +++ b/tests/untried/pos/thistype.scala @@ -0,0 +1,15 @@ +object Test { + + class Ctl { + def enable: this.type = { Console.println("enable"); this } + } + + class MouseCtl extends Ctl { + def mouseDown(x: Int, y: Int): Unit = { Console.println("mouse down") } + } + + def main(args: Array[String]): Unit = { + new MouseCtl().enable.mouseDown(1, 2) + } + +} diff --git a/tests/untried/pos/thistypes.scala b/tests/untried/pos/thistypes.scala new file mode 100644 index 000000000..7319cc1ec --- /dev/null +++ b/tests/untried/pos/thistypes.scala @@ -0,0 +1,8 @@ +trait B { + trait I {} + def foo: B.this.I; +} + +trait C extends B { + def foo: C.this.I; +} diff --git a/tests/untried/pos/ticket0137.scala b/tests/untried/pos/ticket0137.scala new file mode 100644 index 000000000..94ef8e49f --- /dev/null +++ b/tests/untried/pos/ticket0137.scala @@ -0,0 +1,8 @@ +trait AbsM { + abstract class MonadCompanion[M[_]] + abstract class AbsMonadCompanion extends MonadCompanion[AM] { + def newTag: Int + } + + type AM[_] // to trigger the bug, this must be an abstract type member that comes after the reference to it +} diff --git a/tests/untried/pos/ticket2197.scala b/tests/untried/pos/ticket2197.scala new file mode 100644 index 000000000..3c9a04f8b --- /dev/null +++ b/tests/untried/pos/ticket2197.scala @@ -0,0 +1,7 @@ +trait PartialType[T[_, _], A] { + type Apply[B] = T[A, B] +} + +sealed trait State[S, +A] +trait Pure[P[_]] +trait StatePure[X] extends Pure[PartialType[State, X]#Apply] diff --git a/tests/untried/pos/ticket2201.scala b/tests/untried/pos/ticket2201.scala new file mode 100644 index 000000000..21af170cf --- /dev/null +++ b/tests/untried/pos/ticket2201.scala @@ -0,0 +1,8 @@ +class Test +object Test { implicit def view(x : Test) = 0 } + +object Call { + def call(implicit view : Test => Int) = view(null) + call + call +} diff --git a/tests/untried/pos/ticket2251.scala b/tests/untried/pos/ticket2251.scala new file mode 100644 index 000000000..c220e8535 --- /dev/null +++ b/tests/untried/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[X] forSome { type X <: 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/untried/pos/tinondefcons.scala b/tests/untried/pos/tinondefcons.scala new file mode 100644 index 000000000..5e5641710 --- /dev/null +++ b/tests/untried/pos/tinondefcons.scala @@ -0,0 +1,13 @@ +// Tests instantiating a type parameter when a non-default +// constructor is used. + + +class Atom[T](b: Boolean) { + var elem: T = _; + def this(s: T) = this(true) +} + + +object AtomTest { + new Atom("hello").elem = "abc" +} diff --git a/tests/untried/pos/trait-force-info.flags b/tests/untried/pos/trait-force-info.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/untried/pos/trait-force-info.flags @@ -0,0 +1 @@ +-optimise
\ No newline at end of file diff --git a/tests/untried/pos/trait-force-info.scala b/tests/untried/pos/trait-force-info.scala new file mode 100644 index 000000000..c2b33869c --- /dev/null +++ b/tests/untried/pos/trait-force-info.scala @@ -0,0 +1,18 @@ +/** This does NOT crash unless it's in the interactive package. + */ + +package scala.tools.nsc +package interactive + +trait MyContextTrees { + val self: Global + val NoContext = self.analyzer.NoContext +} +// +// error: java.lang.AssertionError: assertion failed: trait Contexts.NoContext$ linkedModule: <none>List() +// at scala.Predef$.assert(Predef.scala:160) +// at scala.tools.nsc.symtab.classfile.ClassfileParser$innerClasses$.innerSymbol$1(ClassfileParser.scala:1211) +// at scala.tools.nsc.symtab.classfile.ClassfileParser$innerClasses$.classSymbol(ClassfileParser.scala:1223) +// at scala.tools.nsc.symtab.classfile.ClassfileParser.classNameToSymbol(ClassfileParser.scala:489) +// at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:757) +// at scala.tools.nsc.symtab.classfile.ClassfileParser.sig2type$1(ClassfileParser.scala:789) diff --git a/tests/untried/pos/trait-parents.scala b/tests/untried/pos/trait-parents.scala new file mode 100644 index 000000000..c5908cdcd --- /dev/null +++ b/tests/untried/pos/trait-parents.scala @@ -0,0 +1,16 @@ +trait Bip extends Any +trait Foo extends Any +trait Bar extends AnyRef +trait Quux + +object Test { + def f(x: Bip) = 1 + def g1(x: Foo with Bip) = f(x) + + def main(args: Array[String]): Unit = { + f(new Bip with Foo { }) + f(new Foo with Bip { }) + g1(new Bip with Foo { }) + g1(new Foo with Bip { }) + } +} diff --git a/tests/untried/pos/traits.scala b/tests/untried/pos/traits.scala new file mode 100644 index 000000000..3c6f9437a --- /dev/null +++ b/tests/untried/pos/traits.scala @@ -0,0 +1,40 @@ +object Test { + type Color = Int + trait Shape { + override def equals(other: Any) = true + } + trait Bordered extends Shape { + val thickness: Int + override def equals(other: Any) = other match { + case that: Bordered => this.thickness == that.thickness + case _ => false + } + } + trait Colored extends Shape { + val color: Color + override def equals(other: Any) = other match { + case that: Colored => this.color == that.color + case _ => false + } + } + trait BorderedColoredShape extends Shape with Bordered with Colored { + override def equals(other: Any) = other match { + case that: BorderedColoredShape => ( + super.equals(that) && + super[Bordered].equals(that) && + super[Colored].equals(that)) + case _ => false + } + } + + val bcs1 = new BorderedColoredShape { + val thickness = 1 + val color = 0 + } + val bcs2 = new BorderedColoredShape { + val thickness = 2 + val color = 0 + } + Console.println(bcs1 == bcs1) + Console.println(bcs1 == bcs2) +} diff --git a/tests/untried/pos/tryexpr.scala b/tests/untried/pos/tryexpr.scala new file mode 100644 index 000000000..c6c2febf7 --- /dev/null +++ b/tests/untried/pos/tryexpr.scala @@ -0,0 +1,10 @@ +// stretching more flexible try/catch's legs a bit +object o { + try Integer.parseInt("xxxx") catch { case e => 5 } + try 5 + try try try 10 + try try try 10 catch { case e => 20 } finally 30 + try try try 10 catch { case e => 20 } finally 30 finally 40 + try try try 10 catch { case e => 20 } finally 30 finally 40 finally 50 + try try try 10 finally 50 +} diff --git a/tests/untried/pos/typealias_dubious.scala b/tests/untried/pos/typealias_dubious.scala new file mode 100644 index 000000000..cdba1a64d --- /dev/null +++ b/tests/untried/pos/typealias_dubious.scala @@ -0,0 +1,15 @@ +class MailBox { + //class Message + type Message = AnyRef +} + +abstract class Actor { + private val in = new MailBox + + def send(msg: in.Message) = sys.error("foo") + + def unstable: Actor = sys.error("foo") + + def dubiousSend(msg: MailBox#Message) = + unstable.send(msg) // in.Message becomes unstable.Message, but that's ok since Message is a concrete type member +} diff --git a/tests/untried/pos/typealiases.scala b/tests/untried/pos/typealiases.scala new file mode 100644 index 000000000..93d1dce4d --- /dev/null +++ b/tests/untried/pos/typealiases.scala @@ -0,0 +1,20 @@ +package foo + +trait Test[T] { + type Check[T] = Array[T] => Unit; + type MyPair[S] = (T, S) + + val pair1: (T, Int) + val pair: MyPair[Int] = pair1 + + def check(xs: Array[T], c: Check[T]) = c(xs) + def check2[S](xs: Array[S], c: Check[S]) = c(xs) +} + +object main extends Test[Int] { + val pair1 = (1,1) + + implicit def topair(x: Int): Tuple2[Int, Int] = (x,x) + val pair2: MyPair[Int] = 1 + val x: Short = 1 +} diff --git a/tests/untried/pos/typerep-stephane.scala b/tests/untried/pos/typerep-stephane.scala new file mode 100644 index 000000000..2cb899591 --- /dev/null +++ b/tests/untried/pos/typerep-stephane.scala @@ -0,0 +1,48 @@ +object typerep { + + class TypeRep[T] { + def getType: TypeRep[T] = this + } + + object BooleanRep extends TypeRep[Boolean] { + override def toString = "Boolean" + } + object CharRep extends TypeRep[Char] { + override def toString = "Char" + } + object IntRep extends TypeRep[Int] { + override def toString = "Int" + } + object LongRep extends TypeRep[Long] { + override def toString = "Long" + } + object FloatRep extends TypeRep[Float] { + override def toString = "Float" + } + object DoubleRep extends TypeRep[Double] { + override def toString = "Double" + } + class ListRep[U, T <: List[U]](val elemRep: TypeRep[U]) extends TypeRep[T] { + override def toString = "List[" + elemRep + "]" + } + + implicit def typeRep(x: Boolean): TypeRep[Boolean] = BooleanRep + implicit def typeRep(x: Char ): TypeRep[Char ] = CharRep + implicit def typeRep(x: Long ): TypeRep[Long ] = LongRep + implicit def typeRep(x: Float ): TypeRep[Float ] = FloatRep + implicit def typeRep(x: Double ): TypeRep[Double ] = DoubleRep + implicit def typeRep(x: Int ): TypeRep[Int ] = IntRep +/* + implicit def typeRep[T](xs: List[T])(implicit rep: T => TypeRep[T]): TypeRep[List[T]] = + new ListRep(rep(xs.head)) +*/ + implicit def typeRep[T <% TypeRep[T]](xs: List[T]): TypeRep[List[T]] = + new ListRep(xs.head) + +} + +object test extends App { + import typerep._ + println(3.getType) + println(List(3).getType) +} diff --git a/tests/untried/pos/typerep_pos.scala b/tests/untried/pos/typerep_pos.scala new file mode 100644 index 000000000..ebb643d32 --- /dev/null +++ b/tests/untried/pos/typerep_pos.scala @@ -0,0 +1,21 @@ +object typerep extends App { + class TypeRep[T] {} + case object IntRep extends TypeRep[Int] { + override def toString = "Int" + } + case object BooleanRep extends TypeRep[Boolean] { + override def toString = "Boolean" + } + case class ListRep[T](elemrep: TypeRep[T]) extends TypeRep[List[T]] { + override def toString = "List" + } + + implicit def intRep: TypeRep[Int] = IntRep + implicit def booleanRep: TypeRep[Boolean] = BooleanRep + implicit def listRep[T](implicit elemrep: TypeRep[T]): TypeRep[List[T]] = ListRep(elemrep) + + def getType[T](x: T)(implicit rep: TypeRep[T]): TypeRep[T] = rep + + println(getType(1)) + println(getType(List(1))) +} diff --git a/tests/untried/pos/typesafecons.scala b/tests/untried/pos/typesafecons.scala new file mode 100644 index 000000000..524328016 --- /dev/null +++ b/tests/untried/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/untried/pos/typetags.scala b/tests/untried/pos/typetags.scala new file mode 100644 index 000000000..684ea1018 --- /dev/null +++ b/tests/untried/pos/typetags.scala @@ -0,0 +1,16 @@ +// TODO come up with a non-trivial universe different from ru +// an rewrite this test, so that it makes sure that cross-universe implicit searches work +// +// import scala.reflect.{basis => rb} +// import scala.reflect.runtime.{universe => ru} +// object Test { +// def main(args: Array[String]) { +// def foo(implicit t: rb.TypeTag[List[Int]]) { +// println(t) +// val t2: ru.TypeTag[_] = t in ru.rootMirror +// println(t2) +// } +// } +// } + +object Test extends App diff --git a/tests/untried/pos/unapplyComplex.scala b/tests/untried/pos/unapplyComplex.scala new file mode 100644 index 000000000..148fcc1bb --- /dev/null +++ b/tests/untried/pos/unapplyComplex.scala @@ -0,0 +1,39 @@ +trait Complex extends Product2[Double, Double] { + def canEqual(other: Any) = other.isInstanceOf[Complex] +} + +class ComplexRect(val _1: Double, val _2: Double) extends Complex { + override def toString = "ComplexRect("+_1+","+_2+")" +} + +class ComplexPolar(val _1: Double, val _2: Double) extends Complex { + override def toString = "ComplexPolar("+_1+","+_2+")" +} + +object ComplexRect { + def unapply(z:Complex): Option[Complex] = { + if(z.isInstanceOf[ComplexRect]) Some(z) else z match { + case ComplexPolar(mod, arg) => + Some(new ComplexRect(mod*math.cos(arg), mod*math.sin(arg))) +} } } + +object ComplexPolar { + def unapply(z:Complex): Option[Complex] = { + if(z.isInstanceOf[ComplexPolar]) Some(z) else z match { + case ComplexRect(re,im) => + Some(new ComplexPolar(math.sqrt(re*re + im*im), math.atan(re/im))) +} } } + +object Test { + def main(args:Array[String]) = { + new ComplexRect(1,1) match { + case ComplexPolar(mod,arg) => // z @ ??? + Console.println("mod"+mod+"arg"+arg) + } + val Komplex = ComplexRect + new ComplexPolar(math.sqrt(2),math.Pi / 4.0) match { + case Komplex(re,im) => // z @ ??? + Console.println("re"+re+" im"+im) + } + } +} diff --git a/tests/untried/pos/unapplyContexts2.scala b/tests/untried/pos/unapplyContexts2.scala new file mode 100644 index 000000000..1db8c5160 --- /dev/null +++ b/tests/untried/pos/unapplyContexts2.scala @@ -0,0 +1,11 @@ +trait Analyzer { + val WILDCARD = "23" +} + +trait Contexts2 { self: Analyzer => + class Context { + def collect(sels: List[String]): List[String] = sels match { + case List(WILDCARD) => val dummy = WILDCARD; Nil + } + } +} diff --git a/tests/untried/pos/unapplyGeneric.scala b/tests/untried/pos/unapplyGeneric.scala new file mode 100644 index 000000000..987efdd95 --- /dev/null +++ b/tests/untried/pos/unapplyGeneric.scala @@ -0,0 +1,13 @@ +object Bar { + def unapply[A,B](bar:Bar[A,B]) = Some(bar) +} + +class Bar[A,B](val _1:A, val _2:B) extends Product2[A,B] { + def canEqual(other: Any) = other.isInstanceOf[Bar[_,_]] +} + +object Test { + new Bar(2, 'a') match { + case Bar(x,y) => + } +} diff --git a/tests/untried/pos/unapplyNeedsMemberType.scala b/tests/untried/pos/unapplyNeedsMemberType.scala new file mode 100644 index 000000000..3a96e189a --- /dev/null +++ b/tests/untried/pos/unapplyNeedsMemberType.scala @@ -0,0 +1,25 @@ +// error with -Xunapply, (because of missing call to memberType?) + +trait Gunk[a] { + + type Seq + + object Cons { + def unapply(s: Seq) = unapply_Cons(s) + } + def unapply_Cons(s: Any): Option[Tuple2[a, Seq]] +} + +class Join[a] extends Gunk[a] { + type Seq = JoinSeq + + abstract class JoinSeq + case class App(xs: Seq, ys: Seq) extends JoinSeq + + def append(s1: Seq, s2: Seq): Seq = s1 // mock implementation + + def unapply_Cons(s: Any) = s match { + case App(Cons(x, xs), ys) => Some((x, append(xs, ys))) + case _ => null + } +} diff --git a/tests/untried/pos/unapplySeq.scala b/tests/untried/pos/unapplySeq.scala new file mode 100644 index 000000000..6d13cc8b5 --- /dev/null +++ b/tests/untried/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") +} + diff --git a/tests/untried/pos/unapplyVal.scala b/tests/untried/pos/unapplyVal.scala new file mode 100644 index 000000000..368b9b937 --- /dev/null +++ b/tests/untried/pos/unapplyVal.scala @@ -0,0 +1,37 @@ +package test // bug #1215 + +class Async { + def unapply(scrut: Any): Option[Any] = None +} + +class Buffer { + val Put = new Async + //case class Put(x: Int) + + def joinPat(x: Any): Unit = { + x match { + case Put => + case Put(y) => + println("returning "+y) + } + } +} + + +object unapplyJoins extends App { // bug #1257 + + class Sync { + def apply(): Int = 42 + def unapply(scrut: Any): Boolean = false + } + + class Buffer { + object Get extends Sync + + val jp: PartialFunction[Any, Any] = { + case Get() => + } + } + + println((new Buffer).jp.isDefinedAt(42)) +} diff --git a/tests/untried/pos/unchecked-a.flags b/tests/untried/pos/unchecked-a.flags new file mode 100644 index 000000000..779916d58 --- /dev/null +++ b/tests/untried/pos/unchecked-a.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings
\ No newline at end of file diff --git a/tests/untried/pos/unchecked-a.scala b/tests/untried/pos/unchecked-a.scala new file mode 100644 index 000000000..deceb91c3 --- /dev/null +++ b/tests/untried/pos/unchecked-a.scala @@ -0,0 +1,15 @@ +trait Y +trait Z extends Y +class X[+A <: Y] + +object Test { + def f1(x: X[_ <: Y]) = x match { + case _: X[Any] => // looks a little funny; `Any` is outside the bounds for `A` + } + def f2(x: X[_ <: Y]) = x match { + case _: X[Y] => // looks better, let's allow this (too) + } + + // NonLocalReturnControl[_] warnings + def foo: Int = List(0).foldLeft(0){case _ => return 0} +} diff --git a/tests/untried/pos/unicode-decode.scala b/tests/untried/pos/unicode-decode.scala new file mode 100644 index 000000000..9818ed64a --- /dev/null +++ b/tests/untried/pos/unicode-decode.scala @@ -0,0 +1,9 @@ +object Test { + + val ↑ = 3 + val x$u20A2 = 4 + val y$ub = 5 + val y$u0A = 6 + val z$up = 2 + +} diff --git a/tests/untried/pos/valdefs.scala b/tests/untried/pos/valdefs.scala new file mode 100644 index 000000000..c8f78cd2b --- /dev/null +++ b/tests/untried/pos/valdefs.scala @@ -0,0 +1,16 @@ +object test { + + abstract class Base() { + val x: String; + val y = 1.0; + } + + case class Sub() extends Base() { + val x = "hello"; + override val y = 2.0; + } + + abstract class Sub2() extends Base() { + override val (x, y) = ("abc", 2.0); + } +} diff --git a/tests/untried/pos/value-class-override-no-spec.flags b/tests/untried/pos/value-class-override-no-spec.flags new file mode 100644 index 000000000..a7e64e4f0 --- /dev/null +++ b/tests/untried/pos/value-class-override-no-spec.flags @@ -0,0 +1 @@ +-no-specialization
\ No newline at end of file diff --git a/tests/untried/pos/value-class-override-no-spec.scala b/tests/untried/pos/value-class-override-no-spec.scala new file mode 100644 index 000000000..79de5d930 --- /dev/null +++ b/tests/untried/pos/value-class-override-no-spec.scala @@ -0,0 +1,9 @@ +// There are two versions of this tests: one with and one without specialization. +// The bug was only exposed *without* specialization. +trait T extends Any { + def x: Any +} + +final class StringOps(val repr0: String) extends AnyVal with T { + def x = () +} diff --git a/tests/untried/pos/value-class-override-spec.scala b/tests/untried/pos/value-class-override-spec.scala new file mode 100644 index 000000000..79de5d930 --- /dev/null +++ b/tests/untried/pos/value-class-override-spec.scala @@ -0,0 +1,9 @@ +// There are two versions of this tests: one with and one without specialization. +// The bug was only exposed *without* specialization. +trait T extends Any { + def x: Any +} + +final class StringOps(val repr0: String) extends AnyVal with T { + def x = () +} diff --git a/tests/untried/pos/variances-flip.scala b/tests/untried/pos/variances-flip.scala new file mode 100644 index 000000000..c3ea7b571 --- /dev/null +++ b/tests/untried/pos/variances-flip.scala @@ -0,0 +1,7 @@ +trait Foo[-A, +B, -C, +D] { + private[this] def b: B = ??? + private[this] def d: D = ??? + + def f(p1: B => A, p2: D => C) = g(p1(b), p2(d)) + def g(x: A, y: C) = ((b, d)) +} diff --git a/tests/untried/pos/variances-local.scala b/tests/untried/pos/variances-local.scala new file mode 100644 index 000000000..35e395095 --- /dev/null +++ b/tests/untried/pos/variances-local.scala @@ -0,0 +1,7 @@ +class Foo1[+T] { + private[this] type MyType = T +} + +class Foo2[+T] { + protected[this] type MyType = T +} diff --git a/tests/untried/pos/variances_pos.scala b/tests/untried/pos/variances_pos.scala new file mode 100644 index 000000000..7dc56b022 --- /dev/null +++ b/tests/untried/pos/variances_pos.scala @@ -0,0 +1,8 @@ +abstract class P[+a, +b] { // SLS, Example 4.4.2 + def fst: a; + def snd: b +} + +trait Vector[+a] { // SLS, Example 4.4.3 b) + def append[b >: a](x: Vector[b]): Vector[b] +} diff --git a/tests/untried/pos/viewtest1.scala b/tests/untried/pos/viewtest1.scala new file mode 100644 index 000000000..38945ad2f --- /dev/null +++ b/tests/untried/pos/viewtest1.scala @@ -0,0 +1,42 @@ +package test + +trait Ordered[a] { + def < (x: a): Boolean +} + +object O { + implicit def view (x: String): Ordered[String] = new Ordered[String] { + def < (y: String) = x.compareTo(y) < 0 + } +} + +object Empty extends Tree[Nothing] +case class Node[c <% Ordered[c]](elem: c, l: Tree[c], r: Tree[c]) extends Tree[c] + +abstract class Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = this match { + case Empty => + new Node(x, Empty, Empty) + case Node(elem, l, r) => + if (x == elem) this + else if (x < elem) Node(elem, l insert x, r) + else Node(elem, l, r insert x) + } + def elements: List[a] = this match { + case Empty => List() + case Node(elem, l, r) => + l.elements ::: List(elem) ::: r.elements + } +} + +object Test { + import O.view + + def main(args: Array[String]): Unit = { + var t: Tree[String] = Empty + for (s <- args) { + t = t insert s + } + println(t.elements) + } +} diff --git a/tests/untried/pos/viewtest2.scala b/tests/untried/pos/viewtest2.scala new file mode 100644 index 000000000..6dd0389c8 --- /dev/null +++ b/tests/untried/pos/viewtest2.scala @@ -0,0 +1,115 @@ +package test + +/** A trait for totally ordered data. + */ +trait Ordered[+a] { + + /** Result of comparing `this' with operand `that'. + * returns `x' where + * x < 0 iff this < that + * x == 0 iff this == that + * x > 0 iff this > that + */ + def compareTo [b >: a <% Ordered[b]](that: b): Int + + def < [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) < 0 + + def > [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) > 0 + + def <= [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) <= 0 + + def >= [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) >= 0 +} + + +object O { + + implicit def view1(x: String): Ordered[String] = new Ordered[String] { + def compareTo [b >: String <% Ordered[b]](y: b): Int = y match { + case y1: String => x compareTo y1 + case _ => -(y compareTo x) + } + } + implicit def view2(x: Char): Ordered[Char] = new Ordered[Char] { + def compareTo [b >: Char <% Ordered[b]](y: b): Int = y match { + case y1: Char => x - y1 + case _ => -(y compareTo x) + } + } + + implicit def view3[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = + new Ordered[List[a]] { + def compareTo [b >: List[a] <% Ordered[b]](y: b): Int = y match { + case y1: List[a1] => compareLists(x, y1.asInstanceOf[List[a]]) + case _ => -(y compareTo x) + } + private def compareLists(xs: List[a], ys: List[a]): Int = { + if (xs.isEmpty && ys.isEmpty) 0 + else if (xs.isEmpty) -1 + else if (ys.isEmpty) 1 + else { + val s = xs.head compareTo ys.head; + if (s != 0) s + else compareLists(xs.tail, ys.tail) + } + } + } +} + +abstract class Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] + def elements: List[a] +} + +object Empty extends Tree[Nothing] { + def insert[b >: Nothing <% Ordered[b]](x: b): Tree[b] = new Node(x, Empty, Empty) + def elements: List[Nothing] = List() +} + +class Node[a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = + if (x == elem) this + else if (x < elem) new Node(elem, l insert x, r) + else new Node(elem, l, r insert x) + def elements: List[a] = + l.elements ::: List(elem) ::: r.elements +} + +case class Str(elem: String) extends Ordered[Str] { + def compareTo[b >: Str <% Ordered[b]](that: b): Int = that match { + case that1: Str => this.elem compareTo that1.elem + case _ => -(that compareTo this) + } +} + +object Test { + import O._ + + private def toCharList(s: String): List[Char] = + if (s.length() == 0) List() + else s.charAt(0) :: toCharList(s.substring(1)) + + def main(args: Array[String]): Unit = { + { + var t: Tree[String] = Empty + for (s <- args) { + t = t insert s + } + Console.println(t.elements) + } + { + var t: Tree[Str] = Empty + for (s <- args) { + t = t insert Str(s) + } + Console.println(t.elements) + } + { + var t: Tree[List[Char]] = Empty + for (s <- args) { + t = t insert toCharList(s) + } + Console.println(t.elements) + } + } +} diff --git a/tests/untried/pos/virtpatmat_alts_subst.flags b/tests/untried/pos/virtpatmat_alts_subst.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_alts_subst.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_alts_subst.scala b/tests/untried/pos/virtpatmat_alts_subst.scala new file mode 100644 index 000000000..e27c52f9c --- /dev/null +++ b/tests/untried/pos/virtpatmat_alts_subst.scala @@ -0,0 +1,6 @@ +case class Foo(s: String) { + def appliedType(tycon: Any) = + tycon match { + case Foo(sym @ ("NothingClass" | "AnyClass")) => println(sym) + } +} diff --git a/tests/untried/pos/virtpatmat_anonfun_for.scala b/tests/untried/pos/virtpatmat_anonfun_for.scala new file mode 100644 index 000000000..73b54b18b --- /dev/null +++ b/tests/untried/pos/virtpatmat_anonfun_for.scala @@ -0,0 +1,8 @@ +trait Foo { + def bla = { + val tvs = "tvs" + Nil.foreach(x => x match { + case _ => println(tvs) + }) + } +} diff --git a/tests/untried/pos/virtpatmat_binding_opt.flags b/tests/untried/pos/virtpatmat_binding_opt.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_binding_opt.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_binding_opt.scala b/tests/untried/pos/virtpatmat_binding_opt.scala new file mode 100644 index 000000000..8ec931fe7 --- /dev/null +++ b/tests/untried/pos/virtpatmat_binding_opt.scala @@ -0,0 +1,11 @@ +class Test { + def combine = this match { + case that if that eq this => this // just return this + case that: Test2 => + println(that) + this + case _ => sys.error("meh") + } +} + +class Test2 extends Test diff --git a/tests/untried/pos/virtpatmat_castbinder.flags b/tests/untried/pos/virtpatmat_castbinder.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_castbinder.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_castbinder.scala b/tests/untried/pos/virtpatmat_castbinder.scala new file mode 100644 index 000000000..ffe74eda7 --- /dev/null +++ b/tests/untried/pos/virtpatmat_castbinder.scala @@ -0,0 +1,15 @@ +class IntMap[+V] +case class Bin[+T](m: IntMap[T]) extends IntMap[T] +case class Tip[+T](x: T) extends IntMap[T] + +trait IntMapIterator[V, T] { + def valueOf(tip: Tip[V]): T + def pop: IntMap[V] + + def next: T = + pop match { + case Bin(t@Tip(_)) => { + valueOf(t) + } + } +} diff --git a/tests/untried/pos/virtpatmat_exhaust.scala b/tests/untried/pos/virtpatmat_exhaust.scala new file mode 100644 index 000000000..a2f47c88c --- /dev/null +++ b/tests/untried/pos/virtpatmat_exhaust.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = opt match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} diff --git a/tests/untried/pos/virtpatmat_exhaust_unchecked.flags b/tests/untried/pos/virtpatmat_exhaust_unchecked.flags new file mode 100644 index 000000000..85d8eb2ba --- /dev/null +++ b/tests/untried/pos/virtpatmat_exhaust_unchecked.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/pos/virtpatmat_exhaust_unchecked.scala b/tests/untried/pos/virtpatmat_exhaust_unchecked.scala new file mode 100644 index 000000000..641f2b4f9 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exhaust_unchecked.scala @@ -0,0 +1,24 @@ +sealed trait Option {} +case class Choice(a: Option, b: Option) extends Option; +case class Some(x: Boolean) extends Option; +case object None extends Option; + +object test { + +// drop any case and it will report an error +// note that booleans are taken into account + def f(opt: Option) = (opt: @unchecked) match { + case Choice(None, None) => 1; + case Choice(None, Some(_)) => 1; + case Choice(None, Choice(_, _)) => 1; + case Choice(Some(true), None) => 1; + // case Choice(Some(false), None) => 1; + case Choice(Some(_), Some(_)) => 1; + case Choice(Some(_), Choice(_, _)) => 1; + case Choice(Choice(_, _), None) => 1; + case Choice(Choice(_, _), Some(_)) => 1; + case Choice(Choice(_, _), Choice(_, _)) => 1; + case Some(b) => 4; + case None => 5; + } +} diff --git a/tests/untried/pos/virtpatmat_exist1.flags b/tests/untried/pos/virtpatmat_exist1.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist1.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_exist1.scala b/tests/untried/pos/virtpatmat_exist1.scala new file mode 100644 index 000000000..6cad017b0 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist1.scala @@ -0,0 +1,24 @@ +import annotation.unchecked.{ uncheckedVariance=> uV } +import scala.collection.immutable.{ListMap, HashMap, ListSet, HashSet} + +object Test { + class HashMapCollision1[A, +B](var hash: Int, var kvs: ListMap[A, B @uV]) extends HashMap[A, B @uV] + class HashSetCollision1[A](var hash: Int, var ks: ListSet[A]) extends HashSet[A] + + def splitArray[T](ad: Array[Iterable[T]]): Any = + ad(0) match { + case _: HashMapCollision1[_, _] | _: HashSetCollision1[_] => null + } + + // without type ascription for the one in the body of the last flatmap of each alternative, type inference borks on the existentials + // def splitArray[T >: Nothing <: Any](ad: Array[Iterable[T]]): Any = { import OptionMatching._ + // runOrElse(ad.apply(0))(((x1: Iterable[T]) => ( + // or(((x4: Iterable[T]) => one(null)), + // guard(x1.isInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]], x1.asInstanceOf[Iterable[T] with Test.HashMapCollision1[_,_]]).flatMap(((x2: Iterable[T] with Test.HashMapCollision1[_,_]) => one(x2))), + // guard(x1.isInstanceOf[Test.HashSetCollision1[_]], x1.asInstanceOf[Iterable[T] with Test.HashSetCollision1[_]]).flatMap(((x3: Iterable[T] with Test.HashSetCollision1[_]) => one(x3)))): Option[Any]).orElse( + // (zero: Option[Any]))) + // ) + // } + +} + diff --git a/tests/untried/pos/virtpatmat_exist2.flags b/tests/untried/pos/virtpatmat_exist2.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist2.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_exist2.scala b/tests/untried/pos/virtpatmat_exist2.scala new file mode 100644 index 000000000..f6ebb3ee2 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist2.scala @@ -0,0 +1,20 @@ +class ParseResult[+T] +case class MemoEntry[+T](var r: Either[Nothing,ParseResult[_]]) + +object Test { + def grow[T]: ParseResult[T] = (null: MemoEntry[T]) match { + case MemoEntry(Right(x: ParseResult[_])) => x.asInstanceOf[ParseResult[T]] + } + + // what's the _$1 doing there? + // def grow[T >: Nothing <: Any]: ParseResult[T] = { + // import OptionMatching._ + // runOrElse[MemoEntry[T], ParseResult[T]]((null: MemoEntry[T]))(((x1: MemoEntry[T]) => + // (MemoEntry.unapply[T](x1).flatMap[ParseResult[T]](((x4: Either[Nothing,ParseResult[_]]) => + // guard[Right[Nothing,ParseResult[_]]](x4.isInstanceOf[Right[Nothing,ParseResult[_]]], x4.asInstanceOf[Right[Nothing,ParseResult[_]]]).flatMap[ParseResult[T]](((cp3: Right[Nothing,ParseResult[_]]) => + // scala.Right.unapply[Nothing, ParseResult[_]](cp3).flatMap[ParseResult[T]](((x5: ParseResult[_]) => + // guard[ParseResult[_$1]](x5.ne(null), x5.asInstanceOf[ParseResult[_]]).flatMap[ParseResult[T]](((x6: ParseResult[_]) => + // one[ParseResult[T]](x6.asInstanceOf[ParseResult[T]]))))))))): Option[ParseResult[T]] + // ).orElse[ParseResult[T]]((zero: Option[ParseResult[T]])))) + // } +} diff --git a/tests/untried/pos/virtpatmat_exist3.flags b/tests/untried/pos/virtpatmat_exist3.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist3.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_exist3.scala b/tests/untried/pos/virtpatmat_exist3.scala new file mode 100644 index 000000000..6a6d428b1 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist3.scala @@ -0,0 +1,12 @@ +class ReferenceQueue[T] { + def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = + jref match { + case null => null + } + + // def wrapper(jref: ReferenceQueue[_]): ReferenceQueue[T] = OptionMatching.runOrElse(jref)(((x1: ReferenceQueue[_]) => + // (OptionMatching.guard(null.==(x1), x1.asInstanceOf[ReferenceQueue[_]]).flatMap(((x2: ReferenceQueue[_]) => + // OptionMatching.one(null))): Option[ReferenceQueue[T]]).orElse( + // (OptionMatching.zero: Option[ReferenceQueue[T]]))) + // ) +} diff --git a/tests/untried/pos/virtpatmat_exist4.scala b/tests/untried/pos/virtpatmat_exist4.scala new file mode 100644 index 000000000..728006276 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist4.scala @@ -0,0 +1,35 @@ +trait Global { + trait Tree + trait Symbol { def foo: Boolean } +} + +trait IMain { self: MemberHandlers => + val global: Global + def handlers: List[MemberHandler] +} + +trait MemberHandlers { + val intp: IMain + import intp.global._ + sealed abstract class MemberHandler(val member: Tree) { + def importedSymbols: List[Symbol] + } +} + +object Test { + var intp: IMain with MemberHandlers = null + + val handlers = intp.handlers + handlers.filterNot(_.importedSymbols.isEmpty).zipWithIndex foreach { + case (handler, idx) => + val (types, terms) = handler.importedSymbols partition (_.foo) + } +} + +object Test2 { + type JClass = java.lang.Class[_] + + def tvarString(bounds: List[AnyRef]) = { + bounds collect { case x: JClass => x } + } +} diff --git a/tests/untried/pos/virtpatmat_exist_uncurry.scala b/tests/untried/pos/virtpatmat_exist_uncurry.scala new file mode 100644 index 000000000..727922b31 --- /dev/null +++ b/tests/untried/pos/virtpatmat_exist_uncurry.scala @@ -0,0 +1,6 @@ +object Test { + trait Leaf[T] { + def collect[U](f: PartialFunction[Leaf[_], U]): List[U] + def leaves: List[Leaf[T]] = collect { case l: Leaf[T] => l } + } +} diff --git a/tests/untried/pos/virtpatmat_gadt_array.flags b/tests/untried/pos/virtpatmat_gadt_array.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_gadt_array.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_gadt_array.scala b/tests/untried/pos/virtpatmat_gadt_array.scala new file mode 100644 index 000000000..02dbad68d --- /dev/null +++ b/tests/untried/pos/virtpatmat_gadt_array.scala @@ -0,0 +1,15 @@ +import scala.collection.mutable._ +object Test { + def genericArrayOps[T](xs: Array[T]): ArrayOps[T] = xs match { + case x: Array[AnyRef] => refArrayOps[AnyRef](x).asInstanceOf[ArrayOps[T]] + case null => null + } + // def genericArrayOps[T >: Nothing <: Any](xs: Array[T]): scala.collection.mutable.ArrayOps[T] + // = OptionMatching.runOrElse(xs)(((x1: Array[T]) => + // ((OptionMatching.guard(x1.isInstanceOf[Array[AnyRef]], x1.asInstanceOf[Array[T] with Array[AnyRef]]).flatMap(((x2: Array[T] with Array[AnyRef]) => + // OptionMatching.one(Test.this.refArrayOps[AnyRef](x2).asInstanceOf[scala.collection.mutable.ArrayOps[T]]))): Option[scala.collection.mutable.ArrayOps[T]]).orElse( + // (OptionMatching.guard(null.==(x1), x1.asInstanceOf[Array[T]]).flatMap(((x3: Array[T]) => + // OptionMatching.one(null))): Option[scala.collection.mutable.ArrayOps[T]])): Option[scala.collection.mutable.ArrayOps[T]]).orElse((OptionMatching.zero: Option[scala.collection.mutable.ArrayOps[T]])))) + + def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T] = new ArrayOps.ofRef[T](xs) +} diff --git a/tests/untried/pos/virtpatmat_infer_single_1.flags b/tests/untried/pos/virtpatmat_infer_single_1.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_infer_single_1.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_infer_single_1.scala b/tests/untried/pos/virtpatmat_infer_single_1.scala new file mode 100644 index 000000000..0e2a7817b --- /dev/null +++ b/tests/untried/pos/virtpatmat_infer_single_1.scala @@ -0,0 +1,7 @@ +case class TypeBounds(a: Type, b: Type) +class Type { + def bounds: TypeBounds = bounds match { + case TypeBounds(_: this.type, _: this.type) => TypeBounds(this, this) + case oftp => oftp + } +} diff --git a/tests/untried/pos/virtpatmat_instof_valuetype.flags b/tests/untried/pos/virtpatmat_instof_valuetype.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_instof_valuetype.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_instof_valuetype.scala b/tests/untried/pos/virtpatmat_instof_valuetype.scala new file mode 100644 index 000000000..46bcf7aa1 --- /dev/null +++ b/tests/untried/pos/virtpatmat_instof_valuetype.scala @@ -0,0 +1,8 @@ +case class Data(private val t: Option[String] = None, only: Boolean = false) { + def add(other: Data) = { + other match { + case Data(None, b) => () + case Data(Some(_), b) => () + } + } +} diff --git a/tests/untried/pos/virtpatmat_obj_in_case.flags b/tests/untried/pos/virtpatmat_obj_in_case.flags new file mode 100644 index 000000000..3f5a3100e --- /dev/null +++ b/tests/untried/pos/virtpatmat_obj_in_case.flags @@ -0,0 +1 @@ + -Xexperimental diff --git a/tests/untried/pos/virtpatmat_obj_in_case.scala b/tests/untried/pos/virtpatmat_obj_in_case.scala new file mode 100644 index 000000000..63bb98dd5 --- /dev/null +++ b/tests/untried/pos/virtpatmat_obj_in_case.scala @@ -0,0 +1,5 @@ +class ObjInCase { + 0 match { + case _ => object o + } +} diff --git a/tests/untried/pos/virtpatmat_partialfun_nsdnho.scala b/tests/untried/pos/virtpatmat_partialfun_nsdnho.scala new file mode 100644 index 000000000..2a2a23d88 --- /dev/null +++ b/tests/untried/pos/virtpatmat_partialfun_nsdnho.scala @@ -0,0 +1,18 @@ +class Test { + // m.$minus(1) + // at scala.Predef$.assert(Predef.scala:185) + // at scala.tools.nsc.Global.assert(Global.scala:187) + // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.transform(SuperAccessors.scala:291) + val a: (Map[Int, Int] => (Any => Any)) = { m => { case _ => m - 1} } + + // patmat-crash.scala:9: error: erroneous or inaccessible type + val b: (Int => (Any => Any)) = { m => { case _ => m } } + + // no-symbol does not have an owner (this is a bug: scala version 2.10.0-20120420-170445-56c1f29250) + // at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:45) + // at scala.tools.nsc.Global.abort(Global.scala:202) + // at scala.reflect.internal.Symbols$NoSymbol.owner(Symbols.scala:3031) + // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.hostForAccessorOf(SuperAccessors.scala:474) + // at scala.tools.nsc.typechecker.SuperAccessors$SuperAccTransformer.needsProtectedAccessor(SuperAccessors.scala:457) + val c: (Int => (Any => Any)) = { m => { case _ => m.toInt } } +} diff --git a/tests/untried/pos/virtpatmat_reach_const.scala b/tests/untried/pos/virtpatmat_reach_const.scala new file mode 100644 index 000000000..562f7e146 --- /dev/null +++ b/tests/untried/pos/virtpatmat_reach_const.scala @@ -0,0 +1,11 @@ +// check the interaction between constants and type tests in creating the equality axioms +object Test { + type Formula = List[String] + val TrueF: Formula = List() + def distribute(a: Formula, b: Formula) = (a, b) match { + case (TrueF, _) => + case (_, TrueF) => // bug: considered unreachable + case (a :: Nil, b :: Nil) => + case _ => + } +} diff --git a/tests/untried/pos/widen-existential.scala b/tests/untried/pos/widen-existential.scala new file mode 100644 index 000000000..7c10d60e1 --- /dev/null +++ b/tests/untried/pos/widen-existential.scala @@ -0,0 +1,7 @@ +class A { + { val x = classOf[List[_]] } + def f = { + val g = classOf[List[_]] + List(g, g) + } +} diff --git a/tests/untried/pos/xlint1.flags b/tests/untried/pos/xlint1.flags new file mode 100644 index 000000000..7949c2afa --- /dev/null +++ b/tests/untried/pos/xlint1.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/untried/pos/xlint1.scala b/tests/untried/pos/xlint1.scala new file mode 100644 index 000000000..27936d8b1 --- /dev/null +++ b/tests/untried/pos/xlint1.scala @@ -0,0 +1,13 @@ +package object foo { + implicit class Bar[T](val x: T) extends AnyVal { + def bippy = 1 + } +} + +package foo { + object Baz { + def main(args: Array[String]): Unit = { + "abc".bippy + } + } +} diff --git a/tests/untried/pos/z1720.scala b/tests/untried/pos/z1720.scala new file mode 100644 index 000000000..7394d428c --- /dev/null +++ b/tests/untried/pos/z1720.scala @@ -0,0 +1,16 @@ +package test + +class Thing { + def info: Info[this.type] = InfoRepository.getInfo(this) + def info2: Info[this.type] = { + def self: this.type = this + InfoRepository.getInfo(self) + } +} + +trait Info[T] +case class InfoImpl[T](thing: T) extends Info[T] + +object InfoRepository { + def getInfo(t: Thing): Info[t.type] = InfoImpl(t) +} diff --git a/tests/untried/pos/z1730.flags b/tests/untried/pos/z1730.flags new file mode 100644 index 000000000..531968159 --- /dev/null +++ b/tests/untried/pos/z1730.flags @@ -0,0 +1 @@ +-Ycheck:all
\ No newline at end of file diff --git a/tests/untried/pos/z1730.scala b/tests/untried/pos/z1730.scala new file mode 100644 index 000000000..574b9bbd0 --- /dev/null +++ b/tests/untried/pos/z1730.scala @@ -0,0 +1,13 @@ +// /scala/trac/z1730/a.scala +// Wed May 23 07:41:25 PDT 2012 + +class X[R] { + def xx(value: => R, addTweak: Boolean = true) = 0 +} + +class Boo { + implicit def toX[R](v: R) : X[R] = null + def goo2: Unit = { + 3.xx(34) + } +} |