diff --git a/tests/untried/.gitignore b/tests/untried/.gitignore new file mode 100644 index 000000000000..161be5b55fad --- /dev/null +++ b/tests/untried/.gitignore @@ -0,0 +1,2 @@ +*.log +*.obj/ diff --git a/tests/untried/filters b/tests/untried/filters new file mode 100644 index 000000000000..51a75078487c --- /dev/null +++ b/tests/untried/filters @@ -0,0 +1,8 @@ +# +#Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve shared memory (errno = 28). +Java HotSpot\(TM\) .* warning: +# Hotspot receiving VM options through the $_JAVA_OPTIONS +# env variable outputs them on stderr +Picked up _JAVA_OPTIONS: +# Filter out a message caused by this bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8021205 +objc\[\d+\]: Class JavaLaunchHelper is implemented in both .* and .*\. One of the two will be used\. Which one is undefined\. diff --git a/tests/untried/neg/abstract-class-2.check b/tests/untried/neg/abstract-class-2.check new file mode 100644 index 000000000000..ca79dd8293c8 --- /dev/null +++ b/tests/untried/neg/abstract-class-2.check @@ -0,0 +1,5 @@ +abstract-class-2.scala:11: error: object creation impossible, since method f in trait S2 of type (x: P2.this.p.S1)Int is not defined +(Note that P.this.p.S1 does not match P2.this.S1: their prefixes (i.e. enclosing instances) differ) + object O2 extends S2 { + ^ +one error found diff --git a/tests/untried/neg/abstract-class-2.scala b/tests/untried/neg/abstract-class-2.scala new file mode 100644 index 000000000000..19f74f3da664 --- /dev/null +++ b/tests/untried/neg/abstract-class-2.scala @@ -0,0 +1,14 @@ +class P { + trait S1 + val p = new P + + trait S2 { + def f(x: p.S1): Int + } +} + +class P2 extends P { + object O2 extends S2 { + def f(x: S1) = 5 + } +} diff --git a/tests/untried/neg/abstract-class-error.check b/tests/untried/neg/abstract-class-error.check new file mode 100644 index 000000000000..87d148ecc51d --- /dev/null +++ b/tests/untried/neg/abstract-class-error.check @@ -0,0 +1,5 @@ +S.scala:1: error: class S needs to be abstract, since method g in class J of type (y: Int, z: java.util.List)Int is not defined +(Note that java.util.List does not match java.util.List[String]. To implement a raw type, use java.util.List[_]) +class S extends J { + ^ +one error found diff --git a/tests/untried/neg/abstract-class-error/J.java b/tests/untried/neg/abstract-class-error/J.java new file mode 100644 index 000000000000..5877f5cc5bc1 --- /dev/null +++ b/tests/untried/neg/abstract-class-error/J.java @@ -0,0 +1,4 @@ +public abstract class J { + public abstract int f(); + public abstract int g(int y, java.util.List z); +} \ No newline at end of file diff --git a/tests/untried/neg/abstract-class-error/S.scala b/tests/untried/neg/abstract-class-error/S.scala new file mode 100644 index 000000000000..67f6d8593e1c --- /dev/null +++ b/tests/untried/neg/abstract-class-error/S.scala @@ -0,0 +1,4 @@ +class S extends J { + def f() = 55 + def g(y: Int, z: java.util.List[String]) = 11 +} diff --git a/tests/untried/neg/abstract-concrete-methods.check b/tests/untried/neg/abstract-concrete-methods.check new file mode 100644 index 000000000000..e128f77e2654 --- /dev/null +++ b/tests/untried/neg/abstract-concrete-methods.check @@ -0,0 +1,5 @@ +abstract-concrete-methods.scala:7: error: class Outer2 needs to be abstract, since method score in trait Outer of type (i: Outer2#Inner)Double is not defined +(Note that This#Inner does not match Outer2#Inner: class Inner in class Outer2 is a subclass of trait Inner in trait Outer, but method parameter types must match exactly.) +class Outer2 extends Outer[Outer2] { + ^ +one error found diff --git a/tests/untried/neg/abstract-concrete-methods.scala b/tests/untried/neg/abstract-concrete-methods.scala new file mode 100644 index 000000000000..7f1aea0dbcb1 --- /dev/null +++ b/tests/untried/neg/abstract-concrete-methods.scala @@ -0,0 +1,10 @@ +trait Outer[This <: Outer[This]] { + self: This => + + trait Inner + def score(i: This#Inner): Double +} +class Outer2 extends Outer[Outer2] { + class Inner extends super.Inner + def score(i: Outer2#Inner) = 0.0 +} diff --git a/tests/untried/neg/abstract-explaintypes.check b/tests/untried/neg/abstract-explaintypes.check new file mode 100644 index 000000000000..e303b45a3251 --- /dev/null +++ b/tests/untried/neg/abstract-explaintypes.check @@ -0,0 +1,15 @@ +abstract-explaintypes.scala:6: error: type mismatch; + found : A + required: A.this.T + def foo2: T = bar().baz(); + ^ +A <: A.this.T? +false +abstract-explaintypes.scala:9: error: type mismatch; + found : A + required: A.this.T + def foo5: T = baz().baz(); + ^ +A <: A.this.T? +false +two errors found diff --git a/tests/untried/neg/abstract-explaintypes.flags b/tests/untried/neg/abstract-explaintypes.flags new file mode 100644 index 000000000000..b36707c7cfcf --- /dev/null +++ b/tests/untried/neg/abstract-explaintypes.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/tests/untried/neg/abstract-explaintypes.scala b/tests/untried/neg/abstract-explaintypes.scala new file mode 100644 index 000000000000..f8ecae16fa73 --- /dev/null +++ b/tests/untried/neg/abstract-explaintypes.scala @@ -0,0 +1,11 @@ +trait A { + type T <: A; + def baz(): A; + def bar(): T; + def foo1: A = bar().bar(); + def foo2: T = bar().baz(); + def foo3 = bar().baz(); + def foo4: A = baz().bar(); + def foo5: T = baz().baz(); + def foo6 = baz().baz(); +} diff --git a/tests/untried/neg/abstract-inaccessible.check b/tests/untried/neg/abstract-inaccessible.check new file mode 100644 index 000000000000..d56f5691be8d --- /dev/null +++ b/tests/untried/neg/abstract-inaccessible.check @@ -0,0 +1,15 @@ +abstract-inaccessible.scala:5: warning: method implementMe in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to provide a concrete implementation of implementMe. + def implementMe(f: Int => (String, Bippy)): Unit + ^ +abstract-inaccessible.scala:6: warning: method overrideMe in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to override overrideMe. + def overrideMe[T <: Bippy](x: T): T = x + ^ +abstract-inaccessible.scala:7: warning: method overrideMeAlso in trait YourTrait references private[foo] trait Bippy. +Classes which cannot access Bippy may be unable to override overrideMeAlso. + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/abstract-inaccessible.flags b/tests/untried/neg/abstract-inaccessible.flags new file mode 100644 index 000000000000..6c1dd108aea5 --- /dev/null +++ b/tests/untried/neg/abstract-inaccessible.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint \ No newline at end of file diff --git a/tests/untried/neg/abstract-inaccessible.scala b/tests/untried/neg/abstract-inaccessible.scala new file mode 100644 index 000000000000..3c80f305224c --- /dev/null +++ b/tests/untried/neg/abstract-inaccessible.scala @@ -0,0 +1,9 @@ +package foo { + private[foo] trait Bippy { } + + trait YourTrait { + def implementMe(f: Int => (String, Bippy)): Unit + def overrideMe[T <: Bippy](x: T): T = x + def overrideMeAlso(x: Map[Int, Set[Bippy]]) = 5 + } +} diff --git a/tests/untried/neg/abstract-report.check b/tests/untried/neg/abstract-report.check new file mode 100644 index 000000000000..1ffeac060bd3 --- /dev/null +++ b/tests/untried/neg/abstract-report.check @@ -0,0 +1,24 @@ +abstract-report.scala:1: error: class Unimplemented needs to be abstract, since: +it has 12 unimplemented members. +/** As seen from class Unimplemented, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + // Members declared in scala.collection.GenTraversableOnce + def isTraversableAgain: Boolean = ??? + def toIterator: Iterator[String] = ??? + def toStream: Stream[String] = ??? + + // Members declared in scala.collection.TraversableOnce + def copyToArray[B >: String](xs: Array[B],start: Int,len: Int): Unit = ??? + def exists(p: String => Boolean): Boolean = ??? + def find(p: String => Boolean): Option[String] = ??? + def forall(p: String => Boolean): Boolean = ??? + def foreach[U](f: String => U): Unit = ??? + def hasDefiniteSize: Boolean = ??? + def isEmpty: Boolean = ??? + def seq: scala.collection.TraversableOnce[String] = ??? + def toTraversable: Traversable[String] = ??? + +class Unimplemented extends TraversableOnce[String] { } + ^ +one error found diff --git a/tests/untried/neg/abstract-report.scala b/tests/untried/neg/abstract-report.scala new file mode 100644 index 000000000000..f9145a6f030b --- /dev/null +++ b/tests/untried/neg/abstract-report.scala @@ -0,0 +1 @@ +class Unimplemented extends TraversableOnce[String] { } diff --git a/tests/untried/neg/abstract-report2.check b/tests/untried/neg/abstract-report2.check new file mode 100644 index 000000000000..9be3d822f2a5 --- /dev/null +++ b/tests/untried/neg/abstract-report2.check @@ -0,0 +1,103 @@ +abstract-report2.scala:3: error: class Foo needs to be abstract, since: +it has 13 unimplemented members. +/** As seen from class Foo, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def add(x$1: Int): Boolean = ??? + def addAll(x$1: java.util.Collection[_ <: Int]): Boolean = ??? + def clear(): Unit = ??? + def contains(x$1: Any): Boolean = ??? + def containsAll(x$1: java.util.Collection[_]): Boolean = ??? + def isEmpty(): Boolean = ??? + def iterator(): java.util.Iterator[Int] = ??? + def remove(x$1: Any): Boolean = ??? + def removeAll(x$1: java.util.Collection[_]): Boolean = ??? + def retainAll(x$1: java.util.Collection[_]): Boolean = ??? + def size(): Int = ??? + def toArray[T](x$1: Array[T with Object]): Array[T with Object] = ??? + def toArray(): Array[Object] = ??? + +class Foo extends Collection[Int] + ^ +abstract-report2.scala:5: error: class Bar needs to be abstract, since: +it has 13 unimplemented members. +/** As seen from class Bar, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def add(x$1: List[_ <: String]): Boolean = ??? + def addAll(x$1: java.util.Collection[_ <: List[_ <: String]]): Boolean = ??? + def clear(): Unit = ??? + def contains(x$1: Any): Boolean = ??? + def containsAll(x$1: java.util.Collection[_]): Boolean = ??? + def isEmpty(): Boolean = ??? + def iterator(): java.util.Iterator[List[_ <: String]] = ??? + def remove(x$1: Any): Boolean = ??? + def removeAll(x$1: java.util.Collection[_]): Boolean = ??? + def retainAll(x$1: java.util.Collection[_]): Boolean = ??? + def size(): Int = ??? + def toArray[T](x$1: Array[T with Object]): Array[T with Object] = ??? + def toArray(): Array[Object] = ??? + +class Bar extends Collection[List[_ <: String]] + ^ +abstract-report2.scala:7: error: class Baz needs to be abstract, since: +it has 13 unimplemented members. +/** As seen from class Baz, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def add(x$1: T): Boolean = ??? + def addAll(x$1: java.util.Collection[_ <: T]): Boolean = ??? + def clear(): Unit = ??? + def contains(x$1: Any): Boolean = ??? + def containsAll(x$1: java.util.Collection[_]): Boolean = ??? + def isEmpty(): Boolean = ??? + def iterator(): java.util.Iterator[T] = ??? + def remove(x$1: Any): Boolean = ??? + def removeAll(x$1: java.util.Collection[_]): Boolean = ??? + def retainAll(x$1: java.util.Collection[_]): Boolean = ??? + def size(): Int = ??? + def toArray[T](x$1: Array[T with Object]): Array[T with Object] = ??? + def toArray(): Array[Object] = ??? + +class Baz[T] extends Collection[T] + ^ +abstract-report2.scala:15: error: class Dingus needs to be abstract, since: +it has 24 unimplemented members. +/** As seen from class Dingus, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + // Members declared in java.util.Collection + def add(x$1: String): Boolean = ??? + def addAll(x$1: java.util.Collection[_ <: String]): Boolean = ??? + def clear(): Unit = ??? + def contains(x$1: Any): Boolean = ??? + def containsAll(x$1: java.util.Collection[_]): Boolean = ??? + def iterator(): java.util.Iterator[String] = ??? + def remove(x$1: Any): Boolean = ??? + def removeAll(x$1: java.util.Collection[_]): Boolean = ??? + def retainAll(x$1: java.util.Collection[_]): Boolean = ??? + def toArray[T](x$1: Array[T with Object]): Array[T with Object] = ??? + def toArray(): Array[Object] = ??? + + // Members declared in scala.collection.GenTraversableOnce + def isTraversableAgain: Boolean = ??? + def toIterator: Iterator[(Set[Int], String)] = ??? + def toStream: Stream[(Set[Int], String)] = ??? + + // Members declared in scala.collection.TraversableOnce + def copyToArray[B >: (Set[Int], String)](xs: Array[B],start: Int,len: Int): Unit = ??? + def exists(p: ((Set[Int], String)) => Boolean): Boolean = ??? + def find(p: ((Set[Int], String)) => Boolean): Option[(Set[Int], String)] = ??? + def forall(p: ((Set[Int], String)) => Boolean): Boolean = ??? + def foreach[U](f: ((Set[Int], String)) => U): Unit = ??? + def hasDefiniteSize: Boolean = ??? + def isEmpty: Boolean = ??? + def seq: scala.collection.TraversableOnce[(Set[Int], String)] = ??? + def toTraversable: Traversable[(Set[Int], String)] = ??? + + // Members declared in Xyz + def foo(x: List[Int]): Boolean = ??? + +class Dingus extends Bippy[String, Set[Int], List[Int]] + ^ +four errors found diff --git a/tests/untried/neg/abstract-report2.scala b/tests/untried/neg/abstract-report2.scala new file mode 100644 index 000000000000..3262fee7f60b --- /dev/null +++ b/tests/untried/neg/abstract-report2.scala @@ -0,0 +1,15 @@ +import java.util.Collection + +class Foo extends Collection[Int] + +class Bar extends Collection[List[_ <: String]] + +class Baz[T] extends Collection[T] + +trait Xyz[T] { + def foo(x: T): Boolean +} + +trait Bippy[T1, T2, T3] extends Collection[T1] with TraversableOnce[(T2, String)] with Xyz[T3] + +class Dingus extends Bippy[String, Set[Int], List[Int]] diff --git a/tests/untried/neg/abstract-vars.check b/tests/untried/neg/abstract-vars.check new file mode 100644 index 000000000000..8aa47745f667 --- /dev/null +++ b/tests/untried/neg/abstract-vars.check @@ -0,0 +1,21 @@ +abstract-vars.scala:5: error: class Fail1 needs to be abstract, since variable x is not defined +(Note that variables need to be initialized to be defined) +class Fail1 extends A { + ^ +abstract-vars.scala:9: error: class Fail2 needs to be abstract, since variable x in class A of type Int is not defined +(Note that variables need to be initialized to be defined) +class Fail2 extends A { } + ^ +abstract-vars.scala:11: error: class Fail3 needs to be abstract, since variable x in class A of type Int is not defined +(Note that an abstract var requires a setter in addition to the getter) +class Fail3 extends A { + ^ +abstract-vars.scala:14: error: class Fail4 needs to be abstract, since variable x in class A of type Int is not defined +(Note that an abstract var requires a setter in addition to the getter) +class Fail4 extends A { + ^ +abstract-vars.scala:18: error: class Fail5 needs to be abstract, since variable x in class A of type Int is not defined +(Note that an abstract var requires a getter in addition to the setter) +class Fail5 extends A { + ^ +5 errors found diff --git a/tests/untried/neg/abstract-vars.scala b/tests/untried/neg/abstract-vars.scala new file mode 100644 index 000000000000..df6109d3a80a --- /dev/null +++ b/tests/untried/neg/abstract-vars.scala @@ -0,0 +1,29 @@ +abstract class A { + var x: Int +} + +class Fail1 extends A { + var x: Int +} + +class Fail2 extends A { } + +class Fail3 extends A { + val x: Int = 5 +} +class Fail4 extends A { + def x: Int = 5 +} + +class Fail5 extends A { + def x_=(y: Int) = () +} + +class Success1 extends A { + val x: Int = 5 + def x_=(y: Int) = () +} + +class Success2 extends A { + var x: Int = 5 +} diff --git a/tests/untried/neg/abstract.check b/tests/untried/neg/abstract.check new file mode 100644 index 000000000000..811708ccff4f --- /dev/null +++ b/tests/untried/neg/abstract.check @@ -0,0 +1,11 @@ +abstract.scala:6: error: type mismatch; + found : A + required: A.this.T + def foo2: T = bar().baz(); + ^ +abstract.scala:9: error: type mismatch; + found : A + required: A.this.T + def foo5: T = baz().baz(); + ^ +two errors found diff --git a/tests/untried/neg/abstract.scala b/tests/untried/neg/abstract.scala new file mode 100644 index 000000000000..f8ecae16fa73 --- /dev/null +++ b/tests/untried/neg/abstract.scala @@ -0,0 +1,11 @@ +trait A { + type T <: A; + def baz(): A; + def bar(): T; + def foo1: A = bar().bar(); + def foo2: T = bar().baz(); + def foo3 = bar().baz(); + def foo4: A = baz().bar(); + def foo5: T = baz().baz(); + def foo6 = baz().baz(); +} diff --git a/tests/untried/neg/abstraction-from-volatile-type-error.check b/tests/untried/neg/abstraction-from-volatile-type-error.check new file mode 100644 index 000000000000..34ba0551a53d --- /dev/null +++ b/tests/untried/neg/abstraction-from-volatile-type-error.check @@ -0,0 +1,4 @@ +abstraction-from-volatile-type-error.scala:9: error: illegal abstraction from value with volatile type a.Tv + val tv : a.Tv + ^ +one error found diff --git a/tests/untried/neg/abstraction-from-volatile-type-error.scala b/tests/untried/neg/abstraction-from-volatile-type-error.scala new file mode 100644 index 000000000000..5afcb3ec7d1e --- /dev/null +++ b/tests/untried/neg/abstraction-from-volatile-type-error.scala @@ -0,0 +1,11 @@ +class A { + type T + type Tv = AnyRef with T +} + +object Test { + type B = a.type forSome { + val a : A + val tv : a.Tv + } +} diff --git a/tests/untried/neg/accesses.check b/tests/untried/neg/accesses.check new file mode 100644 index 000000000000..db58af12ce9e --- /dev/null +++ b/tests/untried/neg/accesses.check @@ -0,0 +1,17 @@ +accesses.scala:23: error: overriding method f2 in class A of type ()Unit; + method f2 has weaker access privileges; it should not be private + private def f2(): Unit = () + ^ +accesses.scala:24: error: overriding method f3 in class A of type ()Unit; + method f3 has weaker access privileges; it should be at least protected + private[p2] def f3(): Unit = () + ^ +accesses.scala:25: error: overriding method f4 in class A of type ()Unit; + method f4 has weaker access privileges; it should be at least private[p1] + private[p2] def f4(): Unit + ^ +accesses.scala:26: error: overriding method f5 in class A of type ()Unit; + method f5 has weaker access privileges; it should be at least protected[p1] + protected[p2] def f5(): Unit + ^ +four errors found diff --git a/tests/untried/neg/accesses.scala b/tests/untried/neg/accesses.scala new file mode 100644 index 000000000000..b1df6c0e6c32 --- /dev/null +++ b/tests/untried/neg/accesses.scala @@ -0,0 +1,27 @@ +package test.p1.p2 + +abstract class A { + private[p2] def f2(): Unit + protected def f3(): Unit + private[p1] def f4(): Unit + protected[p1] def f5(): Unit +} + +abstract class OK1 extends A { + private[p1] def f2(): Unit + protected[p2] def f3(): Unit + private[test] def f4(): Unit + protected[test] def f5(): Unit +} +abstract class OK2 extends A { + protected[p1] def f2(): Unit + def f3(): Unit + protected[p1] def f4(): Unit + def f5(): Unit +} +abstract class Err1 extends A { + private def f2(): Unit = () + private[p2] def f3(): Unit = () + private[p2] def f4(): Unit + protected[p2] def f5(): Unit +} diff --git a/tests/untried/neg/accesses2.check b/tests/untried/neg/accesses2.check new file mode 100644 index 000000000000..66cf9a116e8f --- /dev/null +++ b/tests/untried/neg/accesses2.check @@ -0,0 +1,12 @@ +accesses2.scala:6: error: overriding method f2 in class A of type ()Int; + method f2 has weaker access privileges; it should not be private + private def f2(): Int = 1 + ^ +accesses2.scala:5: error: class B1 needs to be abstract, since method f2 in class A of type ()Int is not defined + class B1 extends A { + ^ +accesses2.scala:9: error: overriding method f2 in class A of type ()Int; + method f2 has weaker access privileges; it should not be private + private def f2(): Int = 1 + ^ +three errors found diff --git a/tests/untried/neg/accesses2.scala b/tests/untried/neg/accesses2.scala new file mode 100644 index 000000000000..c7640f84b5be --- /dev/null +++ b/tests/untried/neg/accesses2.scala @@ -0,0 +1,11 @@ +package p2 { + abstract class A { + private[p2] def f2(): Int + } + class B1 extends A { + private def f2(): Int = 1 + } + abstract class B2 extends A { + private def f2(): Int = 1 + } +} diff --git a/tests/untried/neg/ambiguous-float-dots2.check b/tests/untried/neg/ambiguous-float-dots2.check new file mode 100644 index 000000000000..40c9b4186d65 --- /dev/null +++ b/tests/untried/neg/ambiguous-float-dots2.check @@ -0,0 +1,7 @@ +ambiguous-float-dots2.scala:3: error: identifier expected but '}' found. +} +^ +ambiguous-float-dots2.scala:11: error: ';' expected but integer literal found. + 1. + 2 + ^ +two errors found diff --git a/tests/untried/neg/ambiguous-float-dots2.scala b/tests/untried/neg/ambiguous-float-dots2.scala new file mode 100644 index 000000000000..b1615c9273f9 --- /dev/null +++ b/tests/untried/neg/ambiguous-float-dots2.scala @@ -0,0 +1,13 @@ +class A { + val x0 = 5. +} + +class B { + val x1 = 5.f +} + +class D { + 1.+(2) + 1. + 2 + 1 + 2 +} diff --git a/tests/untried/neg/annot-nonconst.check b/tests/untried/neg/annot-nonconst.check new file mode 100644 index 000000000000..5b3da7a13c93 --- /dev/null +++ b/tests/untried/neg/annot-nonconst.check @@ -0,0 +1,18 @@ +annot-nonconst.scala:1: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class Length(value: Int) extends annotation.ClassfileAnnotation + ^ +annot-nonconst.scala:2: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class Ann2(value: String) extends annotation.ClassfileAnnotation + ^ +annot-nonconst.scala:6: error: annotation argument needs to be a constant; found: Test.this.n + @Length(n) def foo = "foo" + ^ +annot-nonconst.scala:7: error: annotation argument cannot be null + @Ann2(null) def bar = "bar" + ^ +two warnings found +two errors found diff --git a/tests/untried/neg/annot-nonconst.scala b/tests/untried/neg/annot-nonconst.scala new file mode 100644 index 000000000000..1b5856f8b256 --- /dev/null +++ b/tests/untried/neg/annot-nonconst.scala @@ -0,0 +1,8 @@ +class Length(value: Int) extends annotation.ClassfileAnnotation +class Ann2(value: String) extends annotation.ClassfileAnnotation + +object Test { + def n = 15 + @Length(n) def foo = "foo" + @Ann2(null) def bar = "bar" +} diff --git a/tests/untried/neg/any-vs-anyref.check b/tests/untried/neg/any-vs-anyref.check new file mode 100644 index 000000000000..7378f0495fec --- /dev/null +++ b/tests/untried/neg/any-vs-anyref.check @@ -0,0 +1,80 @@ +any-vs-anyref.scala:6: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Equals, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo1[A <: Product](a: A) = { type X = a.type } + ^ +any-vs-anyref.scala:7: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Product, Quux, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo2[A <: Product with Quux](a: A) = { type X = a.type } + ^ +any-vs-anyref.scala:8: error: type mismatch; + found : a.type (with underlying type Product) + required: AnyRef +Note that Product extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo3(a: Product) = { type X = a.type } + ^ +any-vs-anyref.scala:9: error: type mismatch; + found : Product with Quux + required: AnyRef +Note that the parents of this type (Product, Quux) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo4(a: Product with Quux) = { type X = a.type } + ^ +any-vs-anyref.scala:10: error: value eq is not a member of Quux with Product +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:10: error: type mismatch; + found : Quux with Product + required: AnyRef +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:11: error: value eq is not a member of Quux with Product{def f: Int} +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:11: error: type mismatch; + found : Quux with Product{def f: Int} + required: AnyRef +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:12: error: type mismatch; + found : Quux with Product{def eq(other: String): Boolean} + required: AnyRef +Note that the parents of this type (Quux, Product) extend Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo7(x: Quux with Product { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + ^ +any-vs-anyref.scala:22: error: value eq is not a member of Bippy +Note that Bippy extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def bad1(x: Bippy, y: Bippy) = x eq y + ^ +any-vs-anyref.scala:27: error: type mismatch; + found : Quux{def g(x: String): String} + required: Quux{def g(x: Int): Int} + f(new Quux { def g(x: String) = x }) + ^ +11 errors found diff --git a/tests/untried/neg/any-vs-anyref.scala b/tests/untried/neg/any-vs-anyref.scala new file mode 100644 index 000000000000..8d237fbaeca4 --- /dev/null +++ b/tests/untried/neg/any-vs-anyref.scala @@ -0,0 +1,29 @@ +trait Quux extends Any +trait QuuxRef extends AnyRef +final class Bippy(val x: Any) extends AnyVal with Quux + +object Foo { + def foo1[A <: Product](a: A) = { type X = a.type } + def foo2[A <: Product with Quux](a: A) = { type X = a.type } + def foo3(a: Product) = { type X = a.type } + def foo4(a: Product with Quux) = { type X = a.type } + def foo5(x: Quux with Product) = (x eq "abc") && ("abc" eq x) + def foo6(x: Quux with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + def foo7(x: Quux with Product { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + + def ok1[A <: QuuxRef](a: A) = { type X = a.type } + def ok2[A <: Product with QuuxRef](a: A) = { type X = a.type } + def ok3(a: QuuxRef) = { type X = a.type } + def ok4(a: Product with QuuxRef) = { type X = a.type } + def ok5(x: QuuxRef with Product) = (x eq "abc") && ("abc" eq x) + def ok6(x: QuuxRef with Product { def f: Int }) = (x eq "abc") && ("abc" eq x) + def ok7(x: QuuxRef { def eq(other: String): Boolean }) = (x eq "abc") && ("abc" eq x) + + def bad1(x: Bippy, y: Bippy) = x eq y +} + +object Bar { + def f(x: Quux { def g(x: Int): Int }): Int = x g 5 + f(new Quux { def g(x: String) = x }) + f(new Quux { def g(x: Int) = x }) +} diff --git a/tests/untried/neg/anytrait.check b/tests/untried/neg/anytrait.check new file mode 100644 index 000000000000..fabe74d379e4 --- /dev/null +++ b/tests/untried/neg/anytrait.check @@ -0,0 +1,7 @@ +anytrait.scala:3: error: field definition is not allowed in universal trait extending from class Any + var x = 1 + ^ +anytrait.scala:5: error: this statement is not allowed in universal trait extending from class Any + { x += 1 } + ^ +two errors found diff --git a/tests/untried/neg/anytrait.scala b/tests/untried/neg/anytrait.scala new file mode 100644 index 000000000000..e76164f63dde --- /dev/null +++ b/tests/untried/neg/anytrait.scala @@ -0,0 +1,10 @@ +trait T extends Any { + + var x = 1 + + { x += 1 } + + type T = Int + + val y: T +} diff --git a/tests/untried/neg/anyval-anyref-parent.check b/tests/untried/neg/anyval-anyref-parent.check new file mode 100644 index 000000000000..8a00fb394dff --- /dev/null +++ b/tests/untried/neg/anyval-anyref-parent.check @@ -0,0 +1,23 @@ +anyval-anyref-parent.scala:2: error: only classes (not traits) are allowed to extend AnyVal +trait Foo2 extends AnyVal // fail + ^ +anyval-anyref-parent.scala:5: error: Any does not have a constructor +class Bar1 extends Any // fail + ^ +anyval-anyref-parent.scala:6: error: value class parameter must be a val and not be private[this] +class Bar2(x: Int) extends AnyVal // fail + ^ +anyval-anyref-parent.scala:10: error: illegal inheritance; superclass Any + is not a subclass of the superclass Object + of the mixin trait Immutable +trait Foo4 extends Any with Immutable // fail + ^ +anyval-anyref-parent.scala:11: error: illegal inheritance; superclass AnyVal + is not a subclass of the superclass Object + of the mixin trait Immutable +trait Foo5 extends AnyVal with Immutable // fail + ^ +anyval-anyref-parent.scala:11: error: only classes (not traits) are allowed to extend AnyVal +trait Foo5 extends AnyVal with Immutable // fail + ^ +6 errors found diff --git a/tests/untried/neg/anyval-anyref-parent.scala b/tests/untried/neg/anyval-anyref-parent.scala new file mode 100644 index 000000000000..f927992e595d --- /dev/null +++ b/tests/untried/neg/anyval-anyref-parent.scala @@ -0,0 +1,12 @@ +trait Foo1 extends Any +trait Foo2 extends AnyVal // fail +trait Foo3 extends AnyRef + +class Bar1 extends Any // fail +class Bar2(x: Int) extends AnyVal // fail +class Bar3(val x: Int) extends AnyVal // fail +class Bar4 extends AnyRef + +trait Foo4 extends Any with Immutable // fail +trait Foo5 extends AnyVal with Immutable // fail +trait Foo6 extends AnyRef with Immutable diff --git a/tests/untried/neg/applydynamic_sip.check b/tests/untried/neg/applydynamic_sip.check new file mode 100644 index 000000000000..2cb2e7f095ee --- /dev/null +++ b/tests/untried/neg/applydynamic_sip.check @@ -0,0 +1,73 @@ +applydynamic_sip.scala:7: error: applyDynamic does not support passing a vararg parameter + qual.sel(a, a2: _*) + ^ +applydynamic_sip.scala:8: error: applyDynamicNamed does not support passing a vararg parameter + qual.sel(arg = a, a2: _*) + ^ +applydynamic_sip.scala:8: error: not found: value arg + qual.sel(arg = a, a2: _*) + ^ +applydynamic_sip.scala:9: error: applyDynamicNamed does not support passing a vararg parameter + qual.sel(arg, arg2 = "a2", a2: _*) + ^ +applydynamic_sip.scala:9: error: not found: value arg + qual.sel(arg, arg2 = "a2", a2: _*) + ^ +applydynamic_sip.scala:9: error: not found: value arg2 + qual.sel(arg, arg2 = "a2", a2: _*) + ^ +applydynamic_sip.scala:18: error: type mismatch; + found : String("sel") + required: Int +error after rewriting to Test.this.bad1.selectDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad1.sel + ^ +applydynamic_sip.scala:19: error: type mismatch; + found : String("sel") + required: Int +error after rewriting to Test.this.bad1.applyDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad1.sel(1) + ^ +applydynamic_sip.scala:20: error: type mismatch; + found : String("sel") + required: Int +error after rewriting to Test.this.bad1.applyDynamicNamed("sel") +possible cause: maybe a wrong Dynamic method signature? + bad1.sel(a = 1) + ^ +applydynamic_sip.scala:20: error: reassignment to val + bad1.sel(a = 1) + ^ +applydynamic_sip.scala:21: error: type mismatch; + found : String("sel") + required: Int +error after rewriting to Test.this.bad1.updateDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad1.sel = 1 + ^ +applydynamic_sip.scala:29: error: Int does not take parameters +error after rewriting to Test.this.bad2.selectDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad2.sel + ^ +applydynamic_sip.scala:30: error: Int does not take parameters +error after rewriting to Test.this.bad2.applyDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad2.sel(1) + ^ +applydynamic_sip.scala:31: error: Int does not take parameters +error after rewriting to Test.this.bad2.applyDynamicNamed("sel") +possible cause: maybe a wrong Dynamic method signature? + bad2.sel(a = 1) + ^ +applydynamic_sip.scala:31: error: reassignment to val + bad2.sel(a = 1) + ^ +applydynamic_sip.scala:32: error: Int does not take parameters +error after rewriting to Test.this.bad2.updateDynamic("sel") +possible cause: maybe a wrong Dynamic method signature? + bad2.sel = 1 + ^ +16 errors found diff --git a/tests/untried/neg/applydynamic_sip.flags b/tests/untried/neg/applydynamic_sip.flags new file mode 100644 index 000000000000..1141f975075d --- /dev/null +++ b/tests/untried/neg/applydynamic_sip.flags @@ -0,0 +1 @@ +-language:dynamics diff --git a/tests/untried/neg/applydynamic_sip.scala b/tests/untried/neg/applydynamic_sip.scala new file mode 100644 index 000000000000..ee4432ebe604 --- /dev/null +++ b/tests/untried/neg/applydynamic_sip.scala @@ -0,0 +1,33 @@ +object Test extends App { + val qual: Dynamic = ??? + val expr = "expr" + val a = "a" + val a2 = "a2" + + qual.sel(a, a2: _*) + qual.sel(arg = a, a2: _*) + qual.sel(arg, arg2 = "a2", a2: _*) + + val bad1 = new Dynamic { + def selectDynamic(n: Int) = n + def applyDynamic(n: Int) = n + def applyDynamicNamed(n: Int) = n + def updateDynamic(n: Int) = n + + } + bad1.sel + bad1.sel(1) + bad1.sel(a = 1) + bad1.sel = 1 + + val bad2 = new Dynamic { + def selectDynamic = 1 + def applyDynamic = 1 + def applyDynamicNamed = 1 + def updateDynamic = 1 + } + bad2.sel + bad2.sel(1) + bad2.sel(a = 1) + bad2.sel = 1 +} diff --git a/tests/untried/neg/bad-advice.check b/tests/untried/neg/bad-advice.check new file mode 100644 index 000000000000..03b3e4f616ae --- /dev/null +++ b/tests/untried/neg/bad-advice.check @@ -0,0 +1,6 @@ +bad-advice.scala:4: error: pattern type is incompatible with expected type; + found : Bip.type + required: Int + case Bip => true + ^ +one error found diff --git a/tests/untried/neg/bad-advice.flags b/tests/untried/neg/bad-advice.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/bad-advice.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/bad-advice.scala b/tests/untried/neg/bad-advice.scala new file mode 100644 index 000000000000..b1955330d7ed --- /dev/null +++ b/tests/untried/neg/bad-advice.scala @@ -0,0 +1,6 @@ +object Bip +object Test { + def f(x: Int) = x match { + case Bip => true + } +} diff --git a/tests/untried/neg/badtok-1.check b/tests/untried/neg/badtok-1.check new file mode 100644 index 000000000000..b05bc6016154 --- /dev/null +++ b/tests/untried/neg/badtok-1.check @@ -0,0 +1,7 @@ +badtok-1.scala:2: error: unclosed character literal +'42' +^ +badtok-1.scala:2: error: unclosed character literal +'42' + ^ +two errors found diff --git a/tests/untried/neg/badtok-1.scala b/tests/untried/neg/badtok-1.scala new file mode 100644 index 000000000000..706e794946a7 --- /dev/null +++ b/tests/untried/neg/badtok-1.scala @@ -0,0 +1,2 @@ +// bug 989 +'42' diff --git a/tests/untried/neg/badtok-2.check b/tests/untried/neg/badtok-2.check new file mode 100644 index 000000000000..e6861c240763 --- /dev/null +++ b/tests/untried/neg/badtok-2.check @@ -0,0 +1,4 @@ +badtok-2.scala:3: error: unclosed quoted identifier +`x +^ +one error found diff --git a/tests/untried/neg/badtok-2.scala b/tests/untried/neg/badtok-2.scala new file mode 100644 index 000000000000..4d1ba1b2ccb9 --- /dev/null +++ b/tests/untried/neg/badtok-2.scala @@ -0,0 +1,3 @@ +//bug 990 +object Test { +`x diff --git a/tests/untried/neg/badtok-3.check b/tests/untried/neg/badtok-3.check new file mode 100644 index 000000000000..aee4f6f4db4d --- /dev/null +++ b/tests/untried/neg/badtok-3.check @@ -0,0 +1,4 @@ +badtok-3.scala:2: error: input ended while parsing XML + } + ^ +catch-all.scala:4: warning: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning. + try { "warn" } catch { case x => } + ^ +catch-all.scala:6: warning: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning. + try { "warn" } catch { case _: RuntimeException => ; case x => } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/catch-all.flags b/tests/untried/neg/catch-all.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/catch-all.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/catch-all.scala b/tests/untried/neg/catch-all.scala new file mode 100644 index 000000000000..c05be7704441 --- /dev/null +++ b/tests/untried/neg/catch-all.scala @@ -0,0 +1,31 @@ +object CatchAll { + try { "warn" } catch { case _ => } + + try { "warn" } catch { case x => } + + try { "warn" } catch { case _: RuntimeException => ; case x => } + + val t = T + + try { "okay" } catch { case T => } + + try { "okay" } catch { case `t` => } + + try { "okay" } catch { case x @ T => } + + try { "okay" } catch { case x @ `t` => } + + try { "okay" } catch { case _: Throwable => } + + try { "okay" } catch { case _: Exception => } + + try { "okay" } catch { case okay: Throwable => } + + try { "okay" } catch { case okay: Exception => } + + try { "okay" } catch { case _ if "".isEmpty => } + + "okay" match { case _ => "" } +} + +object T extends Throwable diff --git a/tests/untried/neg/check-dead.check b/tests/untried/neg/check-dead.check new file mode 100644 index 000000000000..2150a942bf89 --- /dev/null +++ b/tests/untried/neg/check-dead.check @@ -0,0 +1,15 @@ +check-dead.scala:7: warning: dead code following this construct + def z1 = y1(throw new Exception) // should warn + ^ +check-dead.scala:10: warning: dead code following this construct + def z2 = y2(throw new Exception) // should warn + ^ +check-dead.scala:29: warning: dead code following this construct + throw new Exception // should warn + ^ +check-dead.scala:33: warning: dead code following this construct + throw new Exception // should warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/check-dead.flags b/tests/untried/neg/check-dead.flags new file mode 100644 index 000000000000..c7d406c649e8 --- /dev/null +++ b/tests/untried/neg/check-dead.flags @@ -0,0 +1 @@ +-Ywarn-dead-code -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/check-dead.scala b/tests/untried/neg/check-dead.scala new file mode 100644 index 000000000000..2d5bccb21d00 --- /dev/null +++ b/tests/untried/neg/check-dead.scala @@ -0,0 +1,37 @@ +object Other { + def oops(msg: String = "xxx"): Nothing = throw new Exception(msg) // should not warn +} + +class NoDeads { + def y1(arg: Any) = println("foo") + def z1 = y1(throw new Exception) // should warn + + def y2[T](arg: T) = println("foo") + def z2 = y2(throw new Exception) // should warn + + def y3[T](arg: => T) = println("foo") + def z3 = y3(throw new Exception) // should not warn: by name arg + + def nowarn1 = synchronized { throw new Exception } // should not warn: synchronized should be by name + + def nowarn2: Int = synchronized { // should not warn + val i = 10 + 2 + return i + } + def nowarn3: Int = synchronized { // should not warn + val i = 10 + 2 + i + } + + def nowarn4: String = Other.oops("don't warn about me") // should not warn + + def yeswarn1 = synchronized { + throw new Exception // should warn + 5 * 5 + } + def yeswarn2: Int = synchronized { + throw new Exception // should warn + return 5 + } +} + diff --git a/tests/untried/neg/checksensible.check b/tests/untried/neg/checksensible.check new file mode 100644 index 000000000000..e5f1a38d96b8 --- /dev/null +++ b/tests/untried/neg/checksensible.check @@ -0,0 +1,102 @@ +checksensible.scala:13: warning: comparing a fresh object using `eq' will always yield false + (new AnyRef) eq (new AnyRef) + ^ +checksensible.scala:14: warning: comparing a fresh object using `ne' will always yield true + (new AnyRef) ne (new AnyRef) + ^ +checksensible.scala:15: warning: comparing a fresh object using `eq' will always yield false + Shmoopie eq (new AnyRef) + ^ +checksensible.scala:16: warning: comparing a fresh object using `eq' will always yield false + (Shmoopie: AnyRef) eq (new AnyRef) + ^ +checksensible.scala:17: warning: comparing a fresh object using `eq' will always yield false + (new AnyRef) eq Shmoopie + ^ +checksensible.scala:18: warning: comparing a fresh object using `eq' will always yield false + (new AnyRef) eq null + ^ +checksensible.scala:19: warning: comparing a fresh object using `eq' will always yield false + null eq new AnyRef + ^ +checksensible.scala:26: warning: comparing values of types Unit and Int using `==' will always yield false + (c = 1) == 0 + ^ +checksensible.scala:27: warning: comparing values of types Int and Unit using `==' will always yield false + 0 == (c = 1) + ^ +checksensible.scala:29: warning: comparing values of types Int and String using `==' will always yield false + 1 == "abc" + ^ +checksensible.scala:33: warning: comparing values of types Some[Int] and Int using `==' will always yield false + Some(1) == 1 // as above + ^ +checksensible.scala:38: warning: comparing a fresh object using `==' will always yield false + new AnyRef == 1 + ^ +checksensible.scala:41: warning: comparing values of types Int and Boolean using `==' will always yield false + 1 == (new java.lang.Boolean(true)) + ^ +checksensible.scala:43: warning: comparing values of types Int and Boolean using `!=' will always yield true + 1 != true + ^ +checksensible.scala:44: warning: comparing values of types Unit and Boolean using `==' will always yield false + () == true + ^ +checksensible.scala:45: warning: comparing values of types Unit and Unit using `==' will always yield true + () == () + ^ +checksensible.scala:46: warning: comparing values of types Unit and Unit using `==' will always yield true + () == println + ^ +checksensible.scala:47: warning: comparing values of types Unit and scala.runtime.BoxedUnit using `==' will always yield true + () == scala.runtime.BoxedUnit.UNIT // these should warn for always being true/false + ^ +checksensible.scala:48: warning: comparing values of types scala.runtime.BoxedUnit and Unit using `!=' will always yield false + scala.runtime.BoxedUnit.UNIT != () + ^ +checksensible.scala:51: warning: comparing values of types Int and Unit using `!=' will always yield true + (1 != println) + ^ +checksensible.scala:52: warning: comparing values of types Int and Symbol using `!=' will always yield true + (1 != 'sym) + ^ +checksensible.scala:58: warning: comparing a fresh object using `==' will always yield false + ((x: Int) => x + 1) == null + ^ +checksensible.scala:59: warning: comparing a fresh object using `==' will always yield false + Bep == ((_: Int) + 1) + ^ +checksensible.scala:61: warning: comparing a fresh object using `==' will always yield false + new Object == new Object + ^ +checksensible.scala:62: warning: comparing a fresh object using `==' will always yield false + new Object == "abc" + ^ +checksensible.scala:63: warning: comparing a fresh object using `!=' will always yield true + new Exception() != new Exception() + ^ +checksensible.scala:66: warning: comparing values of types Int and Null using `==' will always yield false + if (foo.length == null) "plante" else "plante pas" + ^ +checksensible.scala:71: warning: comparing values of types Bip and Bop using `==' will always yield false + (x1 == x2) + ^ +checksensible.scala:81: warning: comparing values of types EqEqRefTest.this.C3 and EqEqRefTest.this.Z1 using `==' will always yield false + c3 == z1 + ^ +checksensible.scala:82: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `==' will always yield false + z1 == c3 + ^ +checksensible.scala:83: warning: comparing values of types EqEqRefTest.this.Z1 and EqEqRefTest.this.C3 using `!=' will always yield true + z1 != c3 + ^ +checksensible.scala:84: warning: comparing values of types EqEqRefTest.this.C3 and String using `!=' will always yield true + c3 != "abc" + ^ +checksensible.scala:95: warning: comparing values of types Unit and Int using `!=' will always yield true + while ((c = in.read) != -1) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +33 warnings found +one error found diff --git a/tests/untried/neg/checksensible.flags b/tests/untried/neg/checksensible.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/checksensible.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/checksensible.scala b/tests/untried/neg/checksensible.scala new file mode 100644 index 000000000000..b6083f75e4ab --- /dev/null +++ b/tests/untried/neg/checksensible.scala @@ -0,0 +1,100 @@ +final class Bip { def <=(other: Bop) = true } +final class Bop { } +object Bep { } + +final class Zing { + def !=(other: Zing) = false +} + +// 7 warnings +class RefEqTest { + object Shmoopie + + (new AnyRef) eq (new AnyRef) + (new AnyRef) ne (new AnyRef) + Shmoopie eq (new AnyRef) + (Shmoopie: AnyRef) eq (new AnyRef) + (new AnyRef) eq Shmoopie + (new AnyRef) eq null + null eq new AnyRef +} + +// 13 warnings +class EqEqValTest { + var c = 0 + + (c = 1) == 0 + 0 == (c = 1) + + 1 == "abc" + 1 == ("abc": Any) // doesn't warn because an Any may be a boxed Int + 1 == (1: Any) // as above + "abc" == 1 // warns because the lub of String and Int is Any + Some(1) == 1 // as above + + true == new java.lang.Boolean(true) // none of these should warn + new java.lang.Boolean(true) == true + + new AnyRef == 1 + 1 == new AnyRef // doesn't warn because it could be... + 1 == (new java.lang.Integer(1)) // ...something like this + 1 == (new java.lang.Boolean(true)) + + 1 != true + () == true + () == () + () == println + () == scala.runtime.BoxedUnit.UNIT // these should warn for always being true/false + scala.runtime.BoxedUnit.UNIT != () + (scala.runtime.BoxedUnit.UNIT: java.io.Serializable) != () // shouldn't warn + + (1 != println) + (1 != 'sym) +} + +// 12 warnings +class EqEqRefTest { + val ref = new Bop + ((x: Int) => x + 1) == null + Bep == ((_: Int) + 1) + + new Object == new Object + new Object == "abc" + new Exception() != new Exception() + + val foo: Array[String] = Array("1","2","3") + if (foo.length == null) "plante" else "plante pas" + + // final classes with default equals + val x1 = new Bip + val x2 = new Bop + (x1 == x2) + + class C1 { } + class C2 extends C1 { } + final class Z1 extends C2 { } + final class C3 extends C2 { def !=(other: Z1) = false } + val z1 = new Z1 + val c3 = new C3 + + // these should always warn + c3 == z1 + z1 == c3 + z1 != c3 + c3 != "abc" + // this should warn when feeling chatty + c3 != z1 + + // non-warners + (null: AnyRef) == (null: AnyRef) + (x1 <= x2) + + def main(args: Array[String]) = { + val in = new java.io.FileInputStream(args(0)) + var c = 0 + while ((c = in.read) != -1) + print(c.toChar) + + in.close + } +} diff --git a/tests/untried/neg/checksensibleUnit.check b/tests/untried/neg/checksensibleUnit.check new file mode 100644 index 000000000000..7fed4e558aaa --- /dev/null +++ b/tests/untried/neg/checksensibleUnit.check @@ -0,0 +1,7 @@ +checksensibleUnit.scala:3: error: value > is not a member of Unit + println((c = 1) > 0) + ^ +checksensibleUnit.scala:4: error: value <= is not a member of Unit + println((c = 1) <= 0) + ^ +two errors found diff --git a/tests/untried/neg/checksensibleUnit.scala b/tests/untried/neg/checksensibleUnit.scala new file mode 100644 index 000000000000..11c3b67ea2df --- /dev/null +++ b/tests/untried/neg/checksensibleUnit.scala @@ -0,0 +1,5 @@ +class Test { + var c = 0 + println((c = 1) > 0) + println((c = 1) <= 0) +} diff --git a/tests/untried/neg/choices.check b/tests/untried/neg/choices.check new file mode 100644 index 000000000000..b114394e9609 --- /dev/null +++ b/tests/untried/neg/choices.check @@ -0,0 +1,2 @@ +error: bad options: -Yresolve-term-conflict +one error found diff --git a/tests/untried/neg/choices.flags b/tests/untried/neg/choices.flags new file mode 100644 index 000000000000..9718467d4ca2 --- /dev/null +++ b/tests/untried/neg/choices.flags @@ -0,0 +1 @@ +-Yresolve-term-conflict diff --git a/tests/untried/neg/choices.scala b/tests/untried/neg/choices.scala new file mode 100644 index 000000000000..8827494874cb --- /dev/null +++ b/tests/untried/neg/choices.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + + } +} diff --git a/tests/untried/neg/class-of-double-targs.check b/tests/untried/neg/class-of-double-targs.check new file mode 100644 index 000000000000..f7e2094f9778 --- /dev/null +++ b/tests/untried/neg/class-of-double-targs.check @@ -0,0 +1,4 @@ +class-of-double-targs.scala:2: error: expression of type Class[Int](classOf[scala.Int]) does not take type parameters. + classOf[Int][Int] + ^ +one error found diff --git a/tests/untried/neg/class-of-double-targs.scala b/tests/untried/neg/class-of-double-targs.scala new file mode 100644 index 000000000000..26a2fa838136 --- /dev/null +++ b/tests/untried/neg/class-of-double-targs.scala @@ -0,0 +1,3 @@ +object Test { + classOf[Int][Int] +} diff --git a/tests/untried/neg/classmanifests_new_deprecations.check b/tests/untried/neg/classmanifests_new_deprecations.check new file mode 100644 index 000000000000..fd1e2728c31b --- /dev/null +++ b/tests/untried/neg/classmanifests_new_deprecations.check @@ -0,0 +1,27 @@ +classmanifests_new_deprecations.scala:2: warning: type ClassManifest in object Predef is deprecated: Use `scala.reflect.ClassTag` instead + def cm1[T: ClassManifest] = ??? + ^ +classmanifests_new_deprecations.scala:3: warning: type ClassManifest in object Predef is deprecated: Use `scala.reflect.ClassTag` instead + def cm2[T](implicit evidence$1: ClassManifest[T]) = ??? + ^ +classmanifests_new_deprecations.scala:4: warning: type ClassManifest in object Predef is deprecated: Use `scala.reflect.ClassTag` instead + val cm3: ClassManifest[Int] = null + ^ +classmanifests_new_deprecations.scala:6: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead + def rcm1[T: scala.reflect.ClassManifest] = ??? + ^ +classmanifests_new_deprecations.scala:7: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead + def rcm2[T](implicit evidence$1: scala.reflect.ClassManifest[T]) = ??? + ^ +classmanifests_new_deprecations.scala:8: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead + val rcm3: scala.reflect.ClassManifest[Int] = null + ^ +classmanifests_new_deprecations.scala:10: warning: type ClassManifest in object Predef is deprecated: Use `scala.reflect.ClassTag` instead + type CM[T] = ClassManifest[T] + ^ +classmanifests_new_deprecations.scala:15: warning: type ClassManifest in package reflect is deprecated: Use scala.reflect.ClassTag instead + type RCM[T] = scala.reflect.ClassManifest[T] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/classmanifests_new_deprecations.flags b/tests/untried/neg/classmanifests_new_deprecations.flags new file mode 100644 index 000000000000..c6bfaf1f64a4 --- /dev/null +++ b/tests/untried/neg/classmanifests_new_deprecations.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/tests/untried/neg/classmanifests_new_deprecations.scala b/tests/untried/neg/classmanifests_new_deprecations.scala new file mode 100644 index 000000000000..7aebf011f0b5 --- /dev/null +++ b/tests/untried/neg/classmanifests_new_deprecations.scala @@ -0,0 +1,37 @@ +object Test extends App { + def cm1[T: ClassManifest] = ??? + def cm2[T](implicit evidence$1: ClassManifest[T]) = ??? + val cm3: ClassManifest[Int] = null + + def rcm1[T: scala.reflect.ClassManifest] = ??? + def rcm2[T](implicit evidence$1: scala.reflect.ClassManifest[T]) = ??? + val rcm3: scala.reflect.ClassManifest[Int] = null + + type CM[T] = ClassManifest[T] + def acm1[T: CM] = ??? + def acm2[T](implicit evidence$1: CM[T]) = ??? + val acm3: CM[Int] = null + + type RCM[T] = scala.reflect.ClassManifest[T] + def arcm1[T: RCM] = ??? + def arcm2[T](implicit evidence$1: RCM[T]) = ??? + val arcm3: RCM[Int] = null + + def m1[T: Manifest] = ??? + def m2[T](implicit evidence$1: Manifest[T]) = ??? + val m3: Manifest[Int] = null + + def rm1[T: scala.reflect.Manifest] = ??? + def rm2[T](implicit evidence$1: scala.reflect.Manifest[T]) = ??? + val rm3: scala.reflect.Manifest[Int] = null + + type M[T] = Manifest[T] + def am1[T: M] = ??? + def am2[T](implicit evidence$1: M[T]) = ??? + val am3: M[Int] = null + + type RM[T] = scala.reflect.Manifest[T] + def arm1[T: RM] = ??? + def arm2[T](implicit evidence$1: RM[T]) = ??? + val arm3: RM[Int] = null +} diff --git a/tests/untried/neg/classtags_contextbound_a.check b/tests/untried/neg/classtags_contextbound_a.check new file mode 100644 index 000000000000..5edb7f9a5ad1 --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_a.check @@ -0,0 +1,4 @@ +classtags_contextbound_a.scala:2: error: No ClassTag available for T + def foo[T] = Array[T]() + ^ +one error found diff --git a/tests/untried/neg/classtags_contextbound_a.scala b/tests/untried/neg/classtags_contextbound_a.scala new file mode 100644 index 000000000000..77ca0cfd063d --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_a.scala @@ -0,0 +1,4 @@ +object Test extends App { + def foo[T] = Array[T]() + println(foo[Int].getClass) +} diff --git a/tests/untried/neg/classtags_contextbound_b.check b/tests/untried/neg/classtags_contextbound_b.check new file mode 100644 index 000000000000..e17ab8b0d167 --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_b.check @@ -0,0 +1,4 @@ +classtags_contextbound_b.scala:5: error: No ClassTag available for T + def foo[T] = mkArray[T] + ^ +one error found diff --git a/tests/untried/neg/classtags_contextbound_b.scala b/tests/untried/neg/classtags_contextbound_b.scala new file mode 100644 index 000000000000..503dfa5c0300 --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_b.scala @@ -0,0 +1,7 @@ +import scala.reflect.{ClassTag, classTag} + +object Test extends App { + def mkArray[T: ClassTag] = Array[T]() + def foo[T] = mkArray[T] + println(foo[Int].getClass) +} diff --git a/tests/untried/neg/classtags_contextbound_c.check b/tests/untried/neg/classtags_contextbound_c.check new file mode 100644 index 000000000000..e8666f7a10e0 --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_c.check @@ -0,0 +1,4 @@ +classtags_contextbound_c.scala:4: error: No ClassTag available for T + def mkArray[T] = Array[T]() + ^ +one error found diff --git a/tests/untried/neg/classtags_contextbound_c.scala b/tests/untried/neg/classtags_contextbound_c.scala new file mode 100644 index 000000000000..b6b98ca74f96 --- /dev/null +++ b/tests/untried/neg/classtags_contextbound_c.scala @@ -0,0 +1,7 @@ +import scala.reflect.{ClassTag, classTag} + +object Test extends App { + def mkArray[T] = Array[T]() + def foo[T: ClassTag] = mkArray[T] + println(foo[Int].getClass) +} diff --git a/tests/untried/neg/classtags_dont_use_typetags.check b/tests/untried/neg/classtags_dont_use_typetags.check new file mode 100644 index 000000000000..4f728d267de7 --- /dev/null +++ b/tests/untried/neg/classtags_dont_use_typetags.check @@ -0,0 +1,4 @@ +classtags_dont_use_typetags.scala:4: error: No ClassTag available for T + def foo[T: TypeTag] = Array[T]() + ^ +one error found diff --git a/tests/untried/neg/classtags_dont_use_typetags.scala b/tests/untried/neg/classtags_dont_use_typetags.scala new file mode 100644 index 000000000000..3173d83111a5 --- /dev/null +++ b/tests/untried/neg/classtags_dont_use_typetags.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def foo[T: TypeTag] = Array[T]() +} diff --git a/tests/untried/neg/compile-time-only-a.check b/tests/untried/neg/compile-time-only-a.check new file mode 100644 index 000000000000..9bc96f6b9b2e --- /dev/null +++ b/tests/untried/neg/compile-time-only-a.check @@ -0,0 +1,79 @@ +compile-time-only-a.scala:10: error: C3 +@compileTimeOnly("C3") case class C3(x: Int) + ^ +compile-time-only-a.scala:12: error: C4 +@compileTimeOnly("C4") case class C4(x: Int) + ^ +compile-time-only-a.scala:17: error: C5 + implicit class C5(val x: Int) { + ^ +compile-time-only-a.scala:32: error: C1 + new C1() + ^ +compile-time-only-a.scala:36: error: C2 + C2 + ^ +compile-time-only-a.scala:38: error: C3 + new C3(2) + ^ +compile-time-only-a.scala:41: error: C4 + new C4(2) + ^ +compile-time-only-a.scala:45: error: C5 + 2.ext + ^ +compile-time-only-a.scala:46: error: C5 + C5(2) + ^ +compile-time-only-a.scala:49: error: C6.x + val _ = c6.x + ^ +compile-time-only-a.scala:50: error: C6.foo + c6.foo + ^ +compile-time-only-a.scala:51: error: C6.Foo + type Foo = c6.Foo + ^ +compile-time-only-a.scala:52: error: C6.y + c6.y = c6.y + ^ +compile-time-only-a.scala:52: error: C6.y + c6.y = c6.y + ^ +compile-time-only-a.scala:54: error: C7 + val c701: (C7, C7) = ??? + ^ +compile-time-only-a.scala:55: error: C7 + val c702: (C7 => C7) = ??? + ^ +compile-time-only-a.scala:56: error: C7 + val c703: { val x: C7 } = ??? + ^ +compile-time-only-a.scala:57: error: C7 + val c704: AnyRef with C7 = ??? + ^ +compile-time-only-a.scala:60: error: C7 + val c706: C7 Either C7 = ??? + ^ +compile-time-only-a.scala:61: error: C7 + val c707a: List[C7] = ??? + ^ +compile-time-only-a.scala:63: error: C7 + val c708a: T forSome { type T <: C7 } = ??? + ^ +compile-time-only-a.scala:66: error: C8 + val c709: (C8[Int], C8[C7]) = ??? + ^ +compile-time-only-a.scala:67: error: C8 + val c710: (C8[_] => C8[_]) = ??? + ^ +compile-time-only-a.scala:74: error: placebo +class Test { + ^ +compile-time-only-a.scala:75: error: placebo + @placebo def x = (2: @placebo) + ^ +compile-time-only-a.scala:75: error: placebo + @placebo def x = (2: @placebo) + ^ +26 errors found diff --git a/tests/untried/neg/compile-time-only-a.scala b/tests/untried/neg/compile-time-only-a.scala new file mode 100644 index 000000000000..130a3c539f0e --- /dev/null +++ b/tests/untried/neg/compile-time-only-a.scala @@ -0,0 +1,76 @@ +import scala.annotation.compileTimeOnly +import scala.language.existentials + +@compileTimeOnly("C1") class C1 +object C1 + +class C2 +@compileTimeOnly("C2") object C2 + +@compileTimeOnly("C3") case class C3(x: Int) + +@compileTimeOnly("C4") case class C4(x: Int) +object C4 + +object pkg { + @compileTimeOnly("C5") + implicit class C5(val x: Int) { + def ext = ??? + } +} + +class C6(@compileTimeOnly("C6.x") val x: Int) { + @compileTimeOnly("C6.foo") def foo = 2 + @compileTimeOnly("C6.Foo") type Foo = Int + @compileTimeOnly("C6.y") var y = 3 +} + +@compileTimeOnly("C7") class C7 +@compileTimeOnly("C8") class C8[T] + +object Test extends App { + new C1() + C1 + + new C2() + C2 + + new C3(2) + C3(2) + + new C4(2) + C4(2) + + import pkg._ + 2.ext + C5(2) + + val c6 = new C6(2) + val _ = c6.x + c6.foo + type Foo = c6.Foo + c6.y = c6.y + + val c701: (C7, C7) = ??? + val c702: (C7 => C7) = ??? + val c703: { val x: C7 } = ??? + val c704: AnyRef with C7 = ??? + // https://groups.google.com/forum/#!topic/scala-internals/5n07TiCnBZU + // val c705: ({ @compileTimeOnly("C7") type C7[T] = List[T] })#C7[_] = ??? + val c706: C7 Either C7 = ??? + val c707a: List[C7] = ??? + val c707b = List[C7]() + val c708a: T forSome { type T <: C7 } = ??? + // https://groups.google.com/forum/#!topic/scala-internals/5n07TiCnBZU + // val c708b: T forSome { @compileTimeOnly("C7") type T } = ??? + val c709: (C8[Int], C8[C7]) = ??? + val c710: (C8[_] => C8[_]) = ??? +} + +@compileTimeOnly("placebo") +class placebo extends scala.annotation.StaticAnnotation + +@placebo +class Test { + @placebo def x = (2: @placebo) +} diff --git a/tests/untried/neg/compile-time-only-b.check b/tests/untried/neg/compile-time-only-b.check new file mode 100644 index 000000000000..50cdf57fb5d6 --- /dev/null +++ b/tests/untried/neg/compile-time-only-b.check @@ -0,0 +1,13 @@ +compile-time-only-b.scala:9: error: splice must be enclosed within a reify {} block + val ignored1 = expr.splice + ^ +compile-time-only-b.scala:10: error: cannot use value except for signatures of macro implementations + val ignored2 = expr.value + ^ +compile-time-only-b.scala:13: error: splice must be enclosed within a reify {} block + val ignored3 = reify(fortyTwo).splice + ^ +compile-time-only-b.scala:14: error: cannot use value except for signatures of macro implementations + val ignored4 = reify(fortyTwo).value + ^ +four errors found diff --git a/tests/untried/neg/compile-time-only-b.scala b/tests/untried/neg/compile-time-only-b.scala new file mode 100644 index 000000000000..7636fd38db57 --- /dev/null +++ b/tests/untried/neg/compile-time-only-b.scala @@ -0,0 +1,15 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + // HAHA!!! + // no compileTimeOnly errors here, because scalac does constant folding + // the type of reify(42) is Expr[42.type] + // therefore the type of expr.splice is 42.type, which is then constfolded + val expr = reify(42) + val ignored1 = expr.splice + val ignored2 = expr.value + + val fortyTwo = 42 + val ignored3 = reify(fortyTwo).splice + val ignored4 = reify(fortyTwo).value +} diff --git a/tests/untried/neg/constrs.check b/tests/untried/neg/constrs.check new file mode 100644 index 000000000000..4f4a12bc13ed --- /dev/null +++ b/tests/untried/neg/constrs.check @@ -0,0 +1,18 @@ +constrs.scala:6: error: type T is not a member of object test + def this(y: Int)(z: Int)(t: this.T) = { this(this.u + y + z); Console.println(x) } + ^ +constrs.scala:6: error: value u is not a member of object test + def this(y: Int)(z: Int)(t: this.T) = { this(this.u + y + z); Console.println(x) } + ^ +constrs.scala:10: error: called constructor's definition must precede calling constructor's definition + def this() = this("abc") + ^ +constrs.scala:12: error: called constructor's definition must precede calling constructor's definition + def this(x: Boolean) = this(x) + ^ +constrs.scala:16: error: type mismatch; + found : Int(1) + required: a + def this() = this(1) + ^ +5 errors found diff --git a/tests/untried/neg/constrs.scala b/tests/untried/neg/constrs.scala new file mode 100644 index 000000000000..016df098f0f3 --- /dev/null +++ b/tests/untried/neg/constrs.scala @@ -0,0 +1,19 @@ +object test { + + abstract class Test(x: Int) { + type T; + val u = x; + def this(y: Int)(z: Int)(t: this.T) = { this(this.u + y + z); Console.println(x) } + } + + class Foo(x: Int) { + def this() = this("abc") + def this(x: String) = this(1) + def this(x: Boolean) = this(x) + } + + class Bar[a](x: a) { + def this() = this(1) + } + +} diff --git a/tests/untried/neg/constructor-init-order.check b/tests/untried/neg/constructor-init-order.check new file mode 100644 index 000000000000..9ab6ac592313 --- /dev/null +++ b/tests/untried/neg/constructor-init-order.check @@ -0,0 +1,9 @@ +constructor-init-order.scala:7: warning: Reference to uninitialized value baz + val bar1 = baz // warn + ^ +constructor-init-order.scala:17: warning: Reference to uninitialized variable baz + var bar1 = baz // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/constructor-init-order.flags b/tests/untried/neg/constructor-init-order.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/constructor-init-order.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/constructor-init-order.scala b/tests/untried/neg/constructor-init-order.scala new file mode 100644 index 000000000000..fe8fec87adde --- /dev/null +++ b/tests/untried/neg/constructor-init-order.scala @@ -0,0 +1,23 @@ +trait Foo0 { + val quux1: String + val quux2 = quux1 // warning here is "future work" +} + +class Foo1 extends Foo0 { + val bar1 = baz // warn + val bar2 = lazybaz // no warn + val bar3 = defbaz // no warn + val baz = "oops" + lazy val lazybaz = "ok" + def defbaz = "ok" + val quux1 = "oops" +} + +class Foo2 { + var bar1 = baz // warn + var bar2 = lazybaz // no warn + var bar3 = defbaz // no warn + var baz = "oops" + lazy val lazybaz = "ok" + def defbaz = "ok" +} diff --git a/tests/untried/neg/constructor-prefix-error.check b/tests/untried/neg/constructor-prefix-error.check new file mode 100644 index 000000000000..87e948881b32 --- /dev/null +++ b/tests/untried/neg/constructor-prefix-error.check @@ -0,0 +1,4 @@ +constructor-prefix-error.scala:6: error: Outer is not a legal prefix for a constructor + val x = new Outer#Inner + ^ +one error found diff --git a/tests/untried/neg/constructor-prefix-error.scala b/tests/untried/neg/constructor-prefix-error.scala new file mode 100644 index 000000000000..c2accea284f5 --- /dev/null +++ b/tests/untried/neg/constructor-prefix-error.scala @@ -0,0 +1,7 @@ +class Outer { + class Inner +} + +object Test { + val x = new Outer#Inner +} diff --git a/tests/untried/neg/cycle-bounds.check b/tests/untried/neg/cycle-bounds.check new file mode 100644 index 000000000000..d924838aecaa --- /dev/null +++ b/tests/untried/neg/cycle-bounds.check @@ -0,0 +1,4 @@ +cycle-bounds.scala:5: error: illegal cyclic reference involving type T +class NotOk[T <: Comparable[_ <: T]] + ^ +one error found diff --git a/tests/untried/neg/cycle-bounds.flags b/tests/untried/neg/cycle-bounds.flags new file mode 100644 index 000000000000..ca20f55172e9 --- /dev/null +++ b/tests/untried/neg/cycle-bounds.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/untried/neg/cycle-bounds.scala b/tests/untried/neg/cycle-bounds.scala new file mode 100644 index 000000000000..0b43bc703eac --- /dev/null +++ b/tests/untried/neg/cycle-bounds.scala @@ -0,0 +1,5 @@ +// This should be allowed +class Ok[T <: Comparable[_ >: T]] + +// This is (il)legitimately a cyclic reference +class NotOk[T <: Comparable[_ <: T]] diff --git a/tests/untried/neg/cyclics-import.check b/tests/untried/neg/cyclics-import.check new file mode 100644 index 000000000000..be09fca374fe --- /dev/null +++ b/tests/untried/neg/cyclics-import.check @@ -0,0 +1,6 @@ +cyclics-import.scala:1: error: encountered unrecoverable cycle resolving import. +Note: this is often due in part to a class depending on a definition nested within its companion. +If applicable, you may wish to try moving some members into another object. +import User.UserStatus._ + ^ +one error found diff --git a/tests/untried/neg/cyclics-import.scala b/tests/untried/neg/cyclics-import.scala new file mode 100644 index 000000000000..7b510b58e25d --- /dev/null +++ b/tests/untried/neg/cyclics-import.scala @@ -0,0 +1,17 @@ +import User.UserStatus._ + +class User { + var id: Int = 0 + var email: String = null + var password: String = null + var userStatus: UserStatus = null +} + +object User { + object UserStatus extends Enumeration { + type UserStatus = Value + + val Active = Value("1") + val Disabled = Value("2") + } +} diff --git a/tests/untried/neg/cyclics.check b/tests/untried/neg/cyclics.check new file mode 100644 index 000000000000..c240387d2f67 --- /dev/null +++ b/tests/untried/neg/cyclics.check @@ -0,0 +1,10 @@ +cyclics.scala:2: error: illegal cyclic reference involving type A + type A = List[A] + ^ +cyclics.scala:3: error: illegal cyclic reference involving type B + type B[T] = List[B[B[T]]] + ^ +cyclics.scala:5: error: illegal cyclic reference involving type E + type C = I { type E = C } + ^ +three errors found diff --git a/tests/untried/neg/cyclics.scala b/tests/untried/neg/cyclics.scala new file mode 100644 index 000000000000..adfc94e4e54d --- /dev/null +++ b/tests/untried/neg/cyclics.scala @@ -0,0 +1,6 @@ +object test { + type A = List[A] + type B[T] = List[B[B[T]]] + trait I { type E } + type C = I { type E = C } +} diff --git a/tests/untried/neg/dbldef.check b/tests/untried/neg/dbldef.check new file mode 100644 index 000000000000..b896c4cdcf4e --- /dev/null +++ b/tests/untried/neg/dbldef.check @@ -0,0 +1,12 @@ +dbldef.scala:1: error: x is already defined as value x +case class test0(x: Int, x: Float) + ^ +dbldef.scala:1: error: type mismatch; + found : Float + required: Int +case class test0(x: Int, x: Float) + ^ +dbldef.scala:1: error: in class test0, multiple overloaded alternatives of x define default arguments +case class test0(x: Int, x: Float) + ^ +three errors found diff --git a/tests/untried/neg/dbldef.scala b/tests/untried/neg/dbldef.scala new file mode 100644 index 000000000000..c70fb97b2cc8 --- /dev/null +++ b/tests/untried/neg/dbldef.scala @@ -0,0 +1 @@ +case class test0(x: Int, x: Float) diff --git a/tests/untried/neg/deadline-inf-illegal.check b/tests/untried/neg/deadline-inf-illegal.check new file mode 100644 index 000000000000..530d2b2443d4 --- /dev/null +++ b/tests/untried/neg/deadline-inf-illegal.check @@ -0,0 +1,15 @@ +deadline-inf-illegal.scala:5: error: value fromNow is not a member of scala.concurrent.duration.Duration + d.fromNow + ^ +deadline-inf-illegal.scala:6: error: type mismatch; + found : scala.concurrent.duration.Duration + required: scala.concurrent.duration.FiniteDuration + Deadline.now + d + ^ +deadline-inf-illegal.scala:7: error: overloaded method value - with alternatives: + (other: scala.concurrent.duration.Deadline)scala.concurrent.duration.FiniteDuration + (other: scala.concurrent.duration.FiniteDuration)scala.concurrent.duration.Deadline + cannot be applied to (scala.concurrent.duration.Duration) + Deadline.now - d + ^ +three errors found diff --git a/tests/untried/neg/deadline-inf-illegal.scala b/tests/untried/neg/deadline-inf-illegal.scala new file mode 100644 index 000000000000..942cea7014fd --- /dev/null +++ b/tests/untried/neg/deadline-inf-illegal.scala @@ -0,0 +1,8 @@ +import concurrent.duration.{ Deadline, Duration } + +class T { + val d: Duration = Duration.Zero + d.fromNow + Deadline.now + d + Deadline.now - d +} diff --git a/tests/untried/neg/delayed-init-ref.check b/tests/untried/neg/delayed-init-ref.check new file mode 100644 index 000000000000..90bc02796940 --- /dev/null +++ b/tests/untried/neg/delayed-init-ref.check @@ -0,0 +1,16 @@ +delayed-init-ref.scala:17: warning: Selecting value vall from object O, which extends scala.DelayedInit, is likely to yield an uninitialized value + println(O.vall) // warn + ^ +delayed-init-ref.scala:19: warning: Selecting value vall from object O, which extends scala.DelayedInit, is likely to yield an uninitialized value + println(vall) // warn + ^ +delayed-init-ref.scala:28: warning: trait DelayedInit in package scala is deprecated: DelayedInit semantics can be surprising. Support for `App` will continue. +See the release notes for more details: https://github.com/scala/scala/releases/tag/v2.11.0-RC1 +trait Before extends DelayedInit { + ^ +delayed-init-ref.scala:40: warning: Selecting value foo from trait UserContext, which extends scala.DelayedInit, is likely to yield an uninitialized value + println({locally(()); this}.foo) // warn (spurious, but we can't discriminate) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/delayed-init-ref.flags b/tests/untried/neg/delayed-init-ref.flags new file mode 100644 index 000000000000..88a3e4c676eb --- /dev/null +++ b/tests/untried/neg/delayed-init-ref.flags @@ -0,0 +1 @@ +-deprecation -Xlint -Xfatal-warnings diff --git a/tests/untried/neg/delayed-init-ref.scala b/tests/untried/neg/delayed-init-ref.scala new file mode 100644 index 000000000000..f2aa804e28f9 --- /dev/null +++ b/tests/untried/neg/delayed-init-ref.scala @@ -0,0 +1,42 @@ +trait T { + val traitVal = "" +} + +object O extends App with T { + val vall = "" + lazy val lazyy = "" + def deff = "" + + println(vall) // no warn + new { + println(vall) // no warn + } +} + +object Client { + println(O.vall) // warn + import O.vall + println(vall) // warn + + println(O.lazyy) // no warn + println(O.deff) // no warn + println(O.traitVal) // no warn +} + +// Delayed init usage pattern from Specs2 +// See: https://groups.google.com/d/msg/scala-sips/wP6dL8nIAQs/ogjoPE-MSVAJ +trait Before extends DelayedInit { + def before() + override def delayedInit(x: => Unit): Unit = { before; x } +} +object Spec { + trait UserContext extends Before { + def before() = () + val foo = "foo" + } + new UserContext { + println(foo) // no warn + println(this.foo) // no warn + println({locally(()); this}.foo) // warn (spurious, but we can't discriminate) + } +} diff --git a/tests/untried/neg/depmet_1.check b/tests/untried/neg/depmet_1.check new file mode 100644 index 000000000000..7a4f845fd504 --- /dev/null +++ b/tests/untried/neg/depmet_1.check @@ -0,0 +1,10 @@ +depmet_1.scala:2: error: illegal dependent method type: parameter appears in the type of another parameter in the same section or an earlier one + def precise0(y: x.type)(x: String): Unit = {} + ^ +depmet_1.scala:3: error: illegal dependent method type: parameter appears in the type of another parameter in the same section or an earlier one + def precise1(x: String, y: x.type): Unit = {} + ^ +depmet_1.scala:4: error: not found: value y + def precise2[T <: y.type](y: String): Unit = {} + ^ +three errors found diff --git a/tests/untried/neg/depmet_1.scala b/tests/untried/neg/depmet_1.scala new file mode 100644 index 000000000000..9388b2c9a264 --- /dev/null +++ b/tests/untried/neg/depmet_1.scala @@ -0,0 +1,5 @@ +object Test { + def precise0(y: x.type)(x: String): Unit = {} + def precise1(x: String, y: x.type): Unit = {} + def precise2[T <: y.type](y: String): Unit = {} +} diff --git a/tests/untried/neg/divergent-implicit.check b/tests/untried/neg/divergent-implicit.check new file mode 100644 index 000000000000..60d876409f0d --- /dev/null +++ b/tests/untried/neg/divergent-implicit.check @@ -0,0 +1,16 @@ +divergent-implicit.scala:4: error: type mismatch; + found : Int(1) + required: String + val x1: String = 1 + ^ +divergent-implicit.scala:14: error: type mismatch; + found : Test2.Foo + required: Test2.Bar + val x: Bar = new Foo + ^ +divergent-implicit.scala:15: error: type mismatch; + found : Test2.Baz + required: Test2.Bar + val y: Bar = new Baz + ^ +three errors found diff --git a/tests/untried/neg/divergent-implicit.scala b/tests/untried/neg/divergent-implicit.scala new file mode 100644 index 000000000000..4a356d54f780 --- /dev/null +++ b/tests/untried/neg/divergent-implicit.scala @@ -0,0 +1,16 @@ +object Test1 { + implicit def cast[A, B](x: A)(implicit c: A => B): B = c(x) + + val x1: String = 1 + val x2: String = cast[Int, String](1) +} +object Test2 { + class Foo + class Bar + class Baz + implicit def foo2bar(x: Foo)(implicit baz2bar: Baz => Bar): Bar = baz2bar(new Baz) + implicit def baz2bar(x: Baz)(implicit foo2bar: Foo => Bar): Bar = foo2bar(new Foo) + + val x: Bar = new Foo + val y: Bar = new Baz +} diff --git a/tests/untried/neg/dotless-targs.check b/tests/untried/neg/dotless-targs.check new file mode 100644 index 000000000000..4aab939f6141 --- /dev/null +++ b/tests/untried/neg/dotless-targs.check @@ -0,0 +1,4 @@ +dotless-targs.scala:2: error: type application is not allowed for postfix operators + def f1 = "f1" isInstanceOf[String] // not ok + ^ +one error found diff --git a/tests/untried/neg/dotless-targs.scala b/tests/untried/neg/dotless-targs.scala new file mode 100644 index 000000000000..eff63cbec4f9 --- /dev/null +++ b/tests/untried/neg/dotless-targs.scala @@ -0,0 +1,5 @@ +class A { + def f1 = "f1" isInstanceOf[String] // not ok + def f2 = "f2".isInstanceOf[String] // ok + def f3 = "f3" toList // ok +} diff --git a/tests/untried/neg/error_dependentMethodTpeConversionToFunction.check b/tests/untried/neg/error_dependentMethodTpeConversionToFunction.check new file mode 100644 index 000000000000..3496a552c487 --- /dev/null +++ b/tests/untried/neg/error_dependentMethodTpeConversionToFunction.check @@ -0,0 +1,4 @@ +error_dependentMethodTpeConversionToFunction.scala:4: error: method with dependent type (x: AnyRef)x.type cannot be converted to function value + val x: Any => Any = foo + ^ +one error found diff --git a/tests/untried/neg/error_dependentMethodTpeConversionToFunction.scala b/tests/untried/neg/error_dependentMethodTpeConversionToFunction.scala new file mode 100644 index 000000000000..d0c4cb48a8e0 --- /dev/null +++ b/tests/untried/neg/error_dependentMethodTpeConversionToFunction.scala @@ -0,0 +1,5 @@ +// test DependentMethodTpeConversionToFunctionError +object Test { + def foo(x: AnyRef): x.type = x + val x: Any => Any = foo +} diff --git a/tests/untried/neg/error_tooManyArgsPattern.check b/tests/untried/neg/error_tooManyArgsPattern.check new file mode 100644 index 000000000000..ee401ad061ab --- /dev/null +++ b/tests/untried/neg/error_tooManyArgsPattern.check @@ -0,0 +1,4 @@ +error_tooManyArgsPattern.scala:3: error: too many arguments for unapply pattern, maximum = 22 + case List(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) => 7 + ^ +one error found diff --git a/tests/untried/neg/error_tooManyArgsPattern.scala b/tests/untried/neg/error_tooManyArgsPattern.scala new file mode 100644 index 000000000000..d55ba61001f3 --- /dev/null +++ b/tests/untried/neg/error_tooManyArgsPattern.scala @@ -0,0 +1,5 @@ +object Test { + def test(xs: Any) = xs match { // test error message TooManyArgsPatternError + case List(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) => 7 + } +} diff --git a/tests/untried/neg/eta-expand-star-deprecation.check b/tests/untried/neg/eta-expand-star-deprecation.check new file mode 100644 index 000000000000..a79f0df76c5e --- /dev/null +++ b/tests/untried/neg/eta-expand-star-deprecation.check @@ -0,0 +1,4 @@ +warning: -Yeta-expand-keeps-star is deprecated: This flag is scheduled for removal in 2.12. If you have a case where you need this flag then please report a bug. +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/eta-expand-star-deprecation.flags b/tests/untried/neg/eta-expand-star-deprecation.flags new file mode 100644 index 000000000000..5ac8b638e4a0 --- /dev/null +++ b/tests/untried/neg/eta-expand-star-deprecation.flags @@ -0,0 +1 @@ +-Yeta-expand-keeps-star -deprecation -Xfatal-warnings diff --git a/tests/untried/neg/eta-expand-star-deprecation.scala b/tests/untried/neg/eta-expand-star-deprecation.scala new file mode 100644 index 000000000000..574969252245 --- /dev/null +++ b/tests/untried/neg/eta-expand-star-deprecation.scala @@ -0,0 +1,8 @@ +object Test { + def f[T](xs: T*): Unit = () + def g[T] = f[T] _ + + def main(args: Array[String]): Unit = { + g(1, 2) + } +} diff --git a/tests/untried/neg/eta-expand-star.check b/tests/untried/neg/eta-expand-star.check new file mode 100644 index 000000000000..6765d504fc55 --- /dev/null +++ b/tests/untried/neg/eta-expand-star.check @@ -0,0 +1,4 @@ +eta-expand-star.scala:6: error: too many arguments for method apply: (v1: Seq[T])Unit in trait Function1 + g(1, 2) + ^ +one error found diff --git a/tests/untried/neg/eta-expand-star.scala b/tests/untried/neg/eta-expand-star.scala new file mode 100644 index 000000000000..574969252245 --- /dev/null +++ b/tests/untried/neg/eta-expand-star.scala @@ -0,0 +1,8 @@ +object Test { + def f[T](xs: T*): Unit = () + def g[T] = f[T] _ + + def main(args: Array[String]): Unit = { + g(1, 2) + } +} diff --git a/tests/untried/neg/exhausting.check b/tests/untried/neg/exhausting.check new file mode 100644 index 000000000000..619849693cb7 --- /dev/null +++ b/tests/untried/neg/exhausting.check @@ -0,0 +1,27 @@ +exhausting.scala:21: warning: match may not be exhaustive. +It would fail on the following inputs: List(_), List(_, _, _) + def fail1[T](xs: List[T]) = xs match { + ^ +exhausting.scala:27: warning: match may not be exhaustive. +It would fail on the following input: Nil + def fail2[T](xs: List[T]) = xs match { + ^ +exhausting.scala:32: warning: match may not be exhaustive. +It would fail on the following input: List((x: Int forSome x not in (1, 2))) + def fail3a(xs: List[Int]) = xs match { + ^ +exhausting.scala:39: warning: match may not be exhaustive. +It would fail on the following input: Bar3 + def fail3[T](x: Foo[T]) = x match { + ^ +exhausting.scala:47: warning: match may not be exhaustive. +It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2) + def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { + ^ +exhausting.scala:56: warning: match may not be exhaustive. +It would fail on the following inputs: (Bar1, Bar2), (Bar1, Bar3), (Bar2, Bar1), (Bar2, Bar2) + def fail5[T](xx: (Foo[T], Foo[T])) = xx match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/tests/untried/neg/exhausting.flags b/tests/untried/neg/exhausting.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/exhausting.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/exhausting.scala b/tests/untried/neg/exhausting.scala new file mode 100644 index 000000000000..c00569c91d0b --- /dev/null +++ b/tests/untried/neg/exhausting.scala @@ -0,0 +1,61 @@ +object Test { + sealed abstract class Foo[T] + case object Bar1 extends Foo[Int] + case object Bar2 extends Foo[String] + case object Bar3 extends Foo[Any] + + def ex1[T](xs: List[T]) = xs match { + case ys: List[_] => "ok" + } + def ex2[T](xx: (Foo[T], Foo[T])) = xx match { + case (Bar1, Bar1) => () + case (_, Bar1) => () + case (_, Bar3) => () + case (_, Bar2) => () + } + def ex3[T](xx: (Foo[T], Foo[T])) = xx match { + case (_: Foo[_], _: Foo[_]) => () + } + + // fails for: ::(_, Nil), ::(_, ::(_, ::(_, _))), ... + def fail1[T](xs: List[T]) = xs match { + case Nil => "ok" + case x :: y :: Nil => "ok" + } + + // fails for: Nil + def fail2[T](xs: List[T]) = xs match { + case _ :: _ => "ok" + } + + // fails for: ::(, _) + def fail3a(xs: List[Int]) = xs match { + case 1 :: _ => + case 2 :: _ => + case Nil => + } + + // fails for: Bar3 + def fail3[T](x: Foo[T]) = x match { + case Bar1 => "ok" + case Bar2 => "ok" + } + // fails for: (Bar1, Bar2) + // fails for: (Bar1, Bar3) + // fails for: (Bar2, Bar2) + // fails for: (Bar2, Bar1) + def fail4[T <: AnyRef](xx: (Foo[T], Foo[T])) = xx match { + case (Bar1, Bar1) => () + case (Bar2, Bar3) => () + case (Bar3, _) => () + } + // fails for: (Bar1, Bar2) + // fails for: (Bar1, Bar3) + // fails for: (Bar2, Bar1) + // fails for: (Bar2, Bar2) + def fail5[T](xx: (Foo[T], Foo[T])) = xx match { + case (Bar1, Bar1) => () + case (Bar2, Bar3) => () + case (Bar3, _) => () + } +} diff --git a/tests/untried/neg/faculty.check b/tests/untried/neg/faculty.check new file mode 100644 index 000000000000..b1d1d4c9f813 --- /dev/null +++ b/tests/untried/neg/faculty.check @@ -0,0 +1,4 @@ +faculty.scala:3: error: recursive method faculty needs result type + def faculty(x: Int) = if (x == 0) 1 else x * faculty(x - 1) + ^ +one error found diff --git a/tests/untried/neg/faculty.scala b/tests/untried/neg/faculty.scala new file mode 100644 index 000000000000..1f137a48fa80 --- /dev/null +++ b/tests/untried/neg/faculty.scala @@ -0,0 +1,5 @@ +object Test { + + def faculty(x: Int) = if (x == 0) 1 else x * faculty(x - 1) + +} diff --git a/tests/untried/neg/finitary-error.check b/tests/untried/neg/finitary-error.check new file mode 100644 index 000000000000..7bc92058ca8d --- /dev/null +++ b/tests/untried/neg/finitary-error.check @@ -0,0 +1,4 @@ +finitary-error.scala:3: error: class graph is not finitary because type parameter T is expansively recursive +trait C[T] extends A[C[B[T]]] + ^ +one error found diff --git a/tests/untried/neg/finitary-error.scala b/tests/untried/neg/finitary-error.scala new file mode 100644 index 000000000000..a48fcdc70fa3 --- /dev/null +++ b/tests/untried/neg/finitary-error.scala @@ -0,0 +1,3 @@ +trait A[T] +trait B[T] +trait C[T] extends A[C[B[T]]] diff --git a/tests/untried/neg/for-comprehension-old.check b/tests/untried/neg/for-comprehension-old.check new file mode 100644 index 000000000000..1ecaf12af45c --- /dev/null +++ b/tests/untried/neg/for-comprehension-old.check @@ -0,0 +1,26 @@ +for-comprehension-old.scala:3: warning: val keyword in for comprehension is deprecated + for (x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +for-comprehension-old.scala:5: warning: val keyword in for comprehension is deprecated + for (val x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +for-comprehension-old.scala:8: warning: val keyword in for comprehension is deprecated + for (z <- 1 to 2 ; x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +for-comprehension-old.scala:10: warning: val keyword in for comprehension is deprecated + for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +for-comprehension-old.scala:4: error: val in for comprehension must be followed by assignment + for (val x <- 1 to 5 ; y = x) yield x+y // fail + ^ +for-comprehension-old.scala:5: error: val in for comprehension must be followed by assignment + for (val x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +for-comprehension-old.scala:9: error: val in for comprehension must be followed by assignment + for (z <- 1 to 2 ; val x <- 1 to 5 ; y = x) yield x+y // fail + ^ +for-comprehension-old.scala:10: error: val in for comprehension must be followed by assignment + for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail + ^ +four warnings found +four errors found diff --git a/tests/untried/neg/for-comprehension-old.flags b/tests/untried/neg/for-comprehension-old.flags new file mode 100644 index 000000000000..dcc59ebe32ef --- /dev/null +++ b/tests/untried/neg/for-comprehension-old.flags @@ -0,0 +1 @@ +-deprecation diff --git a/tests/untried/neg/for-comprehension-old.scala b/tests/untried/neg/for-comprehension-old.scala new file mode 100644 index 000000000000..10ae363bde7d --- /dev/null +++ b/tests/untried/neg/for-comprehension-old.scala @@ -0,0 +1,11 @@ +class A { + for (x <- 1 to 5 ; y = x) yield x+y // ok + for (x <- 1 to 5 ; val y = x) yield x+y // fail + for (val x <- 1 to 5 ; y = x) yield x+y // fail + for (val x <- 1 to 5 ; val y = x) yield x+y // fail + + for (z <- 1 to 2 ; x <- 1 to 5 ; y = x) yield x+y // ok + for (z <- 1 to 2 ; x <- 1 to 5 ; val y = x) yield x+y // fail + for (z <- 1 to 2 ; val x <- 1 to 5 ; y = x) yield x+y // fail + for (z <- 1 to 2 ; val x <- 1 to 5 ; val y = x) yield x+y // fail +} diff --git a/tests/untried/neg/forgot-interpolator.check b/tests/untried/neg/forgot-interpolator.check new file mode 100644 index 000000000000..8988458982ee --- /dev/null +++ b/tests/untried/neg/forgot-interpolator.check @@ -0,0 +1,27 @@ +forgot-interpolator.scala:4: warning: `$bippy` looks like an interpolated identifier! Did you forget the interpolator? + def f = "Put the $bippy in the $bippy!" // warn 1 + ^ +forgot-interpolator.scala:14: warning: That looks like an interpolated expression! Did you forget the interpolator? + def f = """Put the ${println("bippy")} in the bippy!""" // warn 2 + ^ +forgot-interpolator.scala:30: warning: `$beppo` looks like an interpolated identifier! Did you forget the interpolator? + def f = "$beppo was a marx bros who saw dollars." // warn 3 + ^ +forgot-interpolator.scala:34: warning: `$aleppo` looks like an interpolated identifier! Did you forget the interpolator? + def f = "$aleppo is a pepper and a city." // warn 4 + ^ +forgot-interpolator.scala:47: warning: `$hippo` looks like an interpolated identifier! Did you forget the interpolator? + def h = "$hippo takes an implicit" // warn 6 + ^ +forgot-interpolator.scala:88: warning: `$groucho` looks like an interpolated identifier! Did you forget the interpolator? + def f2 = "I salute $groucho" // warn 7 + ^ +forgot-interpolator.scala:89: warning: `$dingo` looks like an interpolated identifier! Did you forget the interpolator? + def f3 = "I even salute $dingo" // warn 8 + ^ +forgot-interpolator.scala:90: warning: `$calico` looks like an interpolated identifier! Did you forget the interpolator? + def f4 = "I also salute $calico" // warn 9 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/forgot-interpolator.flags b/tests/untried/neg/forgot-interpolator.flags new file mode 100644 index 000000000000..7949c2afa212 --- /dev/null +++ b/tests/untried/neg/forgot-interpolator.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/untried/neg/forgot-interpolator.scala b/tests/untried/neg/forgot-interpolator.scala new file mode 100644 index 000000000000..a53054d89014 --- /dev/null +++ b/tests/untried/neg/forgot-interpolator.scala @@ -0,0 +1,93 @@ +class A { + val bippy = 123 + + def f = "Put the $bippy in the $bippy!" // warn 1 +} + +class B { + val dingus = 123 + + def f = "Put the $bippy in the $bippy!" // no warn +} + +class C { + def f = """Put the ${println("bippy")} in the bippy!""" // warn 2 +} + +package object test { + def aleppo = 9 + def greppo(n: Int) = ??? + def zappos(n: Int)(implicit ord: math.Ordering[Int]) = ??? + def hippo(implicit n: Int) = ??? +} + +package test { + // not sure if overloading is kosher in pkg obj yet + class Doo { + def beppo(i: Int) = 8 * i + def beppo = 8 + class Dah extends Doo { + def f = "$beppo was a marx bros who saw dollars." // warn 3 + } + } + class E { + def f = "$aleppo is a pepper and a city." // warn 4 + def k = s"Just an interpolation of $aleppo" // no warn + } + class Bar { + private def bar = 8 + if (bar > 8) ??? // use it to avoid extra warning + } + class Baz extends Bar { + def f = "$bar is private, shall we warn just in case?" // no longer a warning, private members aren't inherited! + } + class G { + def g = "$greppo takes an arg" // no warn + def z = "$zappos takes an arg too" // no warn + def h = "$hippo takes an implicit" // warn 6 + } + class J { + def j = 8 + class J2 { + def j(i: Int) = 2 * i + def jj = "shadowed $j" // no warn + } + } + import annotation._ + @implicitNotFound("No Z in ${A}") // no warn + class Z[A] +} + + +package inf1 { + import scala.annotation.implicitNotFound + + @implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package inf2 { + @scala.annotation.implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package inf3 { + @scala.annotation.implicitNotFound("Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package curry { + class A { + def bunko()(x: Int): Int = 5 + def groucho(): Int = 5 + def dingo()()()()()(): Int = 5 // kind of nuts this can be evaluated with just 'dingo', but okay + def calico[T1, T2]()()(): Int = 5 // even nutsier + def palomino[T1, T2]()(y: Int = 5)(): Int = 5 // even nutsier + + def f1 = "I was picked up by the $bunko squad" // no warn + def f2 = "I salute $groucho" // warn 7 + def f3 = "I even salute $dingo" // warn 8 + def f4 = "I also salute $calico" // warn 9 + def f5 = "I draw the line at $palomino" // no warn + } +} diff --git a/tests/untried/neg/forward.check b/tests/untried/neg/forward.check new file mode 100644 index 000000000000..252c990370e0 --- /dev/null +++ b/tests/untried/neg/forward.check @@ -0,0 +1,10 @@ +forward.scala:6: error: forward reference extends over definition of value x + def f: Int = x; + ^ +forward.scala:10: error: forward reference extends over definition of value x + def f: Int = g; + ^ +forward.scala:15: error: forward reference extends over definition of variable x + def f: Int = g; + ^ +three errors found diff --git a/tests/untried/neg/forward.scala b/tests/untried/neg/forward.scala new file mode 100644 index 000000000000..d5c0851f09e3 --- /dev/null +++ b/tests/untried/neg/forward.scala @@ -0,0 +1,24 @@ +object Test { + def f: Int = x; + val x: Int = f; + + { + def f: Int = x; + val x: Int = f; + } + { + def f: Int = g; + val x: Int = f; + def g: Int = x; + } + { + def f: Int = g; + var x: Int = f; + def g: Int = x; + } + { + def f: Int = g; + Console.println("foo"); + def g: Int = f; + } +} diff --git a/tests/untried/neg/found-req-variance.check b/tests/untried/neg/found-req-variance.check new file mode 100644 index 000000000000..cc26458ac5e1 --- /dev/null +++ b/tests/untried/neg/found-req-variance.check @@ -0,0 +1,185 @@ +found-req-variance.scala:22: error: type mismatch; + found : Inv[B] + required: Inv[A] +Note: B <: A, but class Inv is invariant in type T. +You may wish to define T as +T instead. (SLS 4.5) + def f2 = Set[Inv[A]]() + new Inv[B] + ^ +found-req-variance.scala:23: error: type mismatch; + found : Inv[C] + required: Inv[A] +Note: C <: A, but class Inv is invariant in type T. +You may wish to define T as +T instead. (SLS 4.5) + def f3 = Set[Inv[A]]() + new Inv[C] + ^ +found-req-variance.scala:24: error: type mismatch; + found : Inv[A] + required: Inv[B] +Note: A >: B, but class Inv is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + def f4 = Set[Inv[B]]() + new Inv[A] + ^ +found-req-variance.scala:26: error: type mismatch; + found : Inv[C] + required: Inv[B] +Note: C <: B, but class Inv is invariant in type T. +You may wish to define T as +T instead. (SLS 4.5) + def f6 = Set[Inv[B]]() + new Inv[C] + ^ +found-req-variance.scala:27: error: type mismatch; + found : Inv[A] + required: Inv[C] +Note: A >: C, but class Inv is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + def f7 = Set[Inv[C]]() + new Inv[A] + ^ +found-req-variance.scala:28: error: type mismatch; + found : Inv[B] + required: Inv[C] +Note: B >: C, but class Inv is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + def f8 = Set[Inv[C]]() + new Inv[B] + ^ +found-req-variance.scala:34: error: type mismatch; + found : MultiInv[A] + required: Multi[A,B,C] +Note: A >: B (and MultiInv[A] <: Multi[A,A,C]), but class Multi is invariant in type Inv. +You may wish to define Inv as -Inv instead. (SLS 4.5) + def g4 = Set[Multi[A, B, C]]() + new MultiInv[A] + ^ +found-req-variance.scala:36: error: type mismatch; + found : MultiInv[C] + required: Multi[A,B,C] +Note: C <: B (and MultiInv[C] <: Multi[A,C,C]), but class Multi is invariant in type Inv. +You may wish to define Inv as +Inv instead. (SLS 4.5) + def g6 = Set[Multi[A, B, C]]() + new MultiInv[C] + ^ +found-req-variance.scala:47: error: type mismatch; + found : FF1[A,A] + required: FF1[B,B] + def ff1 = f[B, B](h[A, A]) // fail + ^ +found-req-variance.scala:48: error: type mismatch; + found : FF1[B,A] + required: FF1[B,B] + def ff2 = f[B, B](h[B, A]) // fail + ^ +found-req-variance.scala:49: error: type mismatch; + found : FF1[C,A] + required: FF1[B,B] + def ff3 = f[B, B](h[C, A]) // fail + ^ +found-req-variance.scala:50: error: type mismatch; + found : FF1[A,B] + required: FF1[B,B] +Note: A >: B, but trait FF1 is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + def ff4 = f[B, B](h[A, B]) // suggest + ^ +found-req-variance.scala:52: error: type mismatch; + found : FF1[C,B] + required: FF1[B,B] +Note: C <: B, but trait FF1 is invariant in type T. +You may wish to define T as +T instead. (SLS 4.5) + def ff6 = f[B, B](h[C, B]) // suggest + ^ +found-req-variance.scala:53: error: type mismatch; + found : FF1[A,C] + required: FF1[B,B] +Note: A >: B, but trait FF1 is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + def ff7 = f[B, B](h[A, C]) // suggest + ^ +found-req-variance.scala:55: error: type mismatch; + found : FF1[C,C] + required: FF1[B,B] +Note: C <: B, but trait FF1 is invariant in type T. +You may wish to define T as +T instead. (SLS 4.5) + def ff9 = f[B, B](h[C, C]) // suggest + ^ +found-req-variance.scala:61: error: type mismatch; + found : FF2[A,A] + required: FF2[B,B] +Note: A >: B, but trait FF2 is invariant in type R. +You may wish to define R as -R instead. (SLS 4.5) + def ff1 = f[B, B](h[A, A]) // suggest + ^ +found-req-variance.scala:62: error: type mismatch; + found : FF2[B,A] + required: FF2[B,B] +Note: A >: B, but trait FF2 is invariant in type R. +You may wish to define R as -R instead. (SLS 4.5) + def ff2 = f[B, B](h[B, A]) // suggest + ^ +found-req-variance.scala:63: error: type mismatch; + found : FF2[C,A] + required: FF2[B,B] + def ff3 = f[B, B](h[C, A]) // fail + ^ +found-req-variance.scala:66: error: type mismatch; + found : FF2[C,B] + required: FF2[B,B] + def ff6 = f[B, B](h[C, B]) // fail + ^ +found-req-variance.scala:67: error: type mismatch; + found : FF2[A,C] + required: FF2[B,B] +Note: C <: B, but trait FF2 is invariant in type R. +You may wish to define R as +R instead. (SLS 4.5) + def ff7 = f[B, B](h[A, C]) // suggest + ^ +found-req-variance.scala:68: error: type mismatch; + found : FF2[B,C] + required: FF2[B,B] +Note: C <: B, but trait FF2 is invariant in type R. +You may wish to define R as +R instead. (SLS 4.5) + def ff8 = f[B, B](h[B, C]) // suggest + ^ +found-req-variance.scala:69: error: type mismatch; + found : FF2[C,C] + required: FF2[B,B] + def ff9 = f[B, B](h[C, C]) // fail + ^ +found-req-variance.scala:86: error: type mismatch; + found : java.util.ArrayList[String] + required: java.util.List[AnyRef] +Note: String <: AnyRef, but Java-defined trait List is invariant in type E. +You may wish to investigate a wildcard type such as `_ <: AnyRef`. (SLS 3.2.10) + def g1 = f[AnyRef](new java.util.ArrayList[String] { }) + ^ +found-req-variance.scala:87: error: type mismatch; + found : scala.math.Ordering[AnyRef] + required: java.util.Comparator[String] +Note: AnyRef >: String, but Java-defined trait Comparator is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: String`. (SLS 3.2.10) + def g2 = g[String](Ordering.fromLessThan[AnyRef](_.toString < _.toString)) + ^ +found-req-variance.scala:94: error: type mismatch; + found : Misc.MyData + required: Misc.Data[AnyVal] +Note: Int <: AnyVal (and Misc.MyData <: Misc.Data[Int]), but class Data is invariant in type A. +You may wish to define A as +A instead. (SLS 4.5) + def f1 = Set[Data[AnyVal]]() + new MyData + ^ +found-req-variance.scala:100: error: type mismatch; + found : Set[String] + required: Set[CharSequence] +Note: String <: CharSequence, but trait Set is invariant in type A. +You may wish to investigate a wildcard type such as `_ <: CharSequence`. (SLS 3.2.10) + foo(s) + ^ +found-req-variance.scala:104: error: type mismatch; + found : Misc.Trippy[String,String,String] + required: Misc.Trippy[Object,Object,Object] +Note: String <: Object, but class Trippy is invariant in type T2. +You may wish to define T2 as +T2 instead. (SLS 4.5) + def g1 = Set[Trippy[AnyRef, AnyRef, AnyRef]]() + new Trippy[String, String, String] + ^ +found-req-variance.scala:105: error: type mismatch; + found : scala.collection.immutable.Map[AnyRef,String] + required: Map[String,String] +Note: AnyRef >: String, but trait Map is invariant in type A. +You may wish to investigate a wildcard type such as `_ >: String`. (SLS 3.2.10) + def g2 = Set[Map[String, String]]() + Map[AnyRef, String]() + ^ +28 errors found diff --git a/tests/untried/neg/found-req-variance.scala b/tests/untried/neg/found-req-variance.scala new file mode 100644 index 000000000000..de460f2d03b3 --- /dev/null +++ b/tests/untried/neg/found-req-variance.scala @@ -0,0 +1,106 @@ +import scala.collection.mutable.ListBuffer + +class A +class B extends A +class C extends B + +trait FF1[T, +R] +trait FF2[-T, R] + +class Inv[T] +class InvA extends Inv[A] +class InvB extends Inv[B] +class InvC extends Inv[C] + +class Multi[+Cov, Inv, -Con] +class MultiCov[+T <: A] extends Multi[T, B, C] +class MultiInv[T] extends Multi[A, T, C] +class MultiCon[-T >: C] extends Multi[A, B, T] + +object Test { + def f1 = Set[Inv[A]]() + new Inv[A] + def f2 = Set[Inv[A]]() + new Inv[B] + def f3 = Set[Inv[A]]() + new Inv[C] + def f4 = Set[Inv[B]]() + new Inv[A] + def f5 = Set[Inv[B]]() + new Inv[B] + def f6 = Set[Inv[B]]() + new Inv[C] + def f7 = Set[Inv[C]]() + new Inv[A] + def f8 = Set[Inv[C]]() + new Inv[B] + def f9 = Set[Inv[C]]() + new Inv[C] + + def g1 = Set[Multi[A, B, C]]() + new MultiCov[A] + def g2 = Set[Multi[A, B, C]]() + new MultiCov[B] + def g3 = Set[Multi[A, B, C]]() + new MultiCov[C] + def g4 = Set[Multi[A, B, C]]() + new MultiInv[A] + def g5 = Set[Multi[A, B, C]]() + new MultiInv[B] + def g6 = Set[Multi[A, B, C]]() + new MultiInv[C] + def g7 = Set[Multi[A, B, C]]() + new MultiCon[A] + def g8 = Set[Multi[A, B, C]]() + new MultiCon[B] + def g9 = Set[Multi[A, B, C]]() + new MultiCon[C] +} + +object Functions { + object Set1 { + def f[T, R](x: FF1[T, R]) = () + def h[T, R] : FF1[T, R] = sys.error("") + + def ff1 = f[B, B](h[A, A]) // fail + def ff2 = f[B, B](h[B, A]) // fail + def ff3 = f[B, B](h[C, A]) // fail + def ff4 = f[B, B](h[A, B]) // suggest + def ff5 = f[B, B](h[B, B]) // ok + def ff6 = f[B, B](h[C, B]) // suggest + def ff7 = f[B, B](h[A, C]) // suggest + def ff8 = f[B, B](h[B, C]) // ok + def ff9 = f[B, B](h[C, C]) // suggest + } + object Set2 { + def f[T, R](x: FF2[T, R]) = () + def h[T, R] : FF2[T, R] = sys.error("") + + def ff1 = f[B, B](h[A, A]) // suggest + def ff2 = f[B, B](h[B, A]) // suggest + def ff3 = f[B, B](h[C, A]) // fail + def ff4 = f[B, B](h[A, B]) // ok + def ff5 = f[B, B](h[B, B]) // ok + def ff6 = f[B, B](h[C, B]) // fail + def ff7 = f[B, B](h[A, C]) // suggest + def ff8 = f[B, B](h[B, C]) // suggest + def ff9 = f[B, B](h[C, C]) // fail + } +} + +// TODO +// object TypeAlias { +// type LL[T] = List[T] +// val LL = List +// +// def f1 = Set[LL[B]]() + LL[A](new A) +// def f2 = Set[LL[B]]() + LL[C](new C) +// } + +object Javas { + def f[T](x: java.util.List[T]) = () + def g[T](x: java.util.Comparator[T]) = () + + def g1 = f[AnyRef](new java.util.ArrayList[String] { }) + def g2 = g[String](Ordering.fromLessThan[AnyRef](_.toString < _.toString)) +} + +object Misc { + // original motivation + class Data[A <: AnyVal] + class MyData extends Data[Int] { } + def f1 = Set[Data[AnyVal]]() + new MyData + + // from stackoverflow + def foo(s: Set[CharSequence]): Unit = () + def f4 = { + val s: Set[String] = Set("Hello", "World"); + foo(s) + } + + class Trippy[+T1, T2, +T3] + def g1 = Set[Trippy[AnyRef, AnyRef, AnyRef]]() + new Trippy[String, String, String] + def g2 = Set[Map[String, String]]() + Map[AnyRef, String]() +} diff --git a/tests/untried/neg/gadts1.check b/tests/untried/neg/gadts1.check new file mode 100644 index 000000000000..9b7ea5556a80 --- /dev/null +++ b/tests/untried/neg/gadts1.check @@ -0,0 +1,9 @@ +gadts1.scala:20: error: Test.Cell[a] does not take parameters + case Cell[a](x: Int) => c.x = 5 + ^ +gadts1.scala:20: error: type mismatch; + found : Int(5) + required: a + case Cell[a](x: Int) => c.x = 5 + ^ +two errors found diff --git a/tests/untried/neg/gadts1.scala b/tests/untried/neg/gadts1.scala new file mode 100644 index 000000000000..08403e6eecb2 --- /dev/null +++ b/tests/untried/neg/gadts1.scala @@ -0,0 +1,33 @@ +object Test{ + +abstract class Number +case class Int(n: scala.Int) extends Number +case class Double(d: scala.Double) extends Number + +trait Term[+a] +case class Cell[a](var x: a) extends Term[a] +case class NumTerm(val n: Number) extends Term[Number] +class IntTerm(n: Int) extends NumTerm(n) with Term[Int] + + +def f[a](t:Term[a], c:Cell[a]): Unit = { + t match { + case NumTerm(n) => c.x = Double(1.0) + } + t match { + // presently testing that this gets past the parser: eventually + // it should actually work. + case Cell[a](x: Int) => c.x = 5 + } +} + + +val x:Term[Number] = NumTerm(Int(5)) + +def main(args: Array[String]): Unit = { + val cell = Cell[Int](Int(6)) + Console.println(cell) + f[Int](new IntTerm(Int(5)), cell) + Console.println(cell) +} +} diff --git a/tests/untried/neg/gadts2-strict.check b/tests/untried/neg/gadts2-strict.check new file mode 100644 index 000000000000..960b35ed2f83 --- /dev/null +++ b/tests/untried/neg/gadts2-strict.check @@ -0,0 +1,6 @@ +gadts2-strict.scala:14: error: type mismatch; + found : Test.MyDouble + required: a + case NumTerm(n) => c.x = MyDouble(1.0) + ^ +one error found diff --git a/tests/untried/neg/gadts2-strict.flags b/tests/untried/neg/gadts2-strict.flags new file mode 100644 index 000000000000..19243266d108 --- /dev/null +++ b/tests/untried/neg/gadts2-strict.flags @@ -0,0 +1 @@ +-Xstrict-inference \ No newline at end of file diff --git a/tests/untried/neg/gadts2-strict.scala b/tests/untried/neg/gadts2-strict.scala new file mode 100644 index 000000000000..0edceca7fb9d --- /dev/null +++ b/tests/untried/neg/gadts2-strict.scala @@ -0,0 +1,26 @@ +// A copy of pos/gadts2, which must fail under -Xstrict-inference. +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/neg/gadts2.check b/tests/untried/neg/gadts2.check new file mode 100644 index 000000000000..dc21f3f52c88 --- /dev/null +++ b/tests/untried/neg/gadts2.check @@ -0,0 +1,6 @@ +gadts2.scala:7: error: type mismatch; + found : String("abc") + required: B + (s1: Super[Any]) match { case Sub(f) => f("abc") } + ^ +one error found diff --git a/tests/untried/neg/gadts2.flags b/tests/untried/neg/gadts2.flags new file mode 100644 index 000000000000..19243266d108 --- /dev/null +++ b/tests/untried/neg/gadts2.flags @@ -0,0 +1 @@ +-Xstrict-inference \ No newline at end of file diff --git a/tests/untried/neg/gadts2.scala b/tests/untried/neg/gadts2.scala new file mode 100644 index 000000000000..156944b8d9d2 --- /dev/null +++ b/tests/untried/neg/gadts2.scala @@ -0,0 +1,12 @@ +trait Super[+A] +case class Sub[B](f: B => B) extends Super[B] + +object Test extends App { + val s1 = Sub((x: Int) => x) + + (s1: Super[Any]) match { case Sub(f) => f("abc") } +} +// java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer +// at scala.runtime.BoxesRunTime.unboxToInt(BoxesRunTime.java:105) +// at Test$$anonfun$1.apply(a.scala:5) +// at Test$.delayedEndpoint$Test$1(a.scala:7) diff --git a/tests/untried/neg/higherkind_novalue.check b/tests/untried/neg/higherkind_novalue.check new file mode 100644 index 000000000000..932f7876b1ff --- /dev/null +++ b/tests/untried/neg/higherkind_novalue.check @@ -0,0 +1,7 @@ +higherkind_novalue.scala:2: error: type m takes type parameters + val x: m // type of kind *->* doesn't classify a value, but a val/def/... can only contain/return a value + ^ +higherkind_novalue.scala:3: error: type m takes type parameters + def y: m + ^ +two errors found diff --git a/tests/untried/neg/higherkind_novalue.scala b/tests/untried/neg/higherkind_novalue.scala new file mode 100644 index 000000000000..9c1480c3b823 --- /dev/null +++ b/tests/untried/neg/higherkind_novalue.scala @@ -0,0 +1,4 @@ +abstract class HigherKind[m[s]] { + val x: m // type of kind *->* doesn't classify a value, but a val/def/... can only contain/return a value + def y: m +} diff --git a/tests/untried/neg/hk-bad-bounds.check b/tests/untried/neg/hk-bad-bounds.check new file mode 100644 index 000000000000..d6293993c141 --- /dev/null +++ b/tests/untried/neg/hk-bad-bounds.check @@ -0,0 +1,4 @@ +hk-bad-bounds.scala:4: error: type arguments [Set] do not conform to class SeqFactory's type parameter bounds [CC[X] <: Seq[X] with scala.collection.generic.GenericTraversableTemplate[X,CC]] + def f(x: Boolean) = if (x) (null: SeqFactory[List]) else (null: SeqFactory[Set]) + ^ +one error found diff --git a/tests/untried/neg/hk-bad-bounds.scala b/tests/untried/neg/hk-bad-bounds.scala new file mode 100644 index 000000000000..0ed0b4c38525 --- /dev/null +++ b/tests/untried/neg/hk-bad-bounds.scala @@ -0,0 +1,5 @@ +import collection.generic.SeqFactory + +class A { + def f(x: Boolean) = if (x) (null: SeqFactory[List]) else (null: SeqFactory[Set]) +} diff --git a/tests/untried/neg/illegal-stmt-start.check b/tests/untried/neg/illegal-stmt-start.check new file mode 100644 index 000000000000..01747524f88d --- /dev/null +++ b/tests/untried/neg/illegal-stmt-start.check @@ -0,0 +1,4 @@ +illegal-stmt-start.scala:3: error: illegal start of statement (no modifiers allowed here) + private def bar {} + ^ +one error found diff --git a/tests/untried/neg/illegal-stmt-start.scala b/tests/untried/neg/illegal-stmt-start.scala new file mode 100644 index 000000000000..48ae0a8b0a2a --- /dev/null +++ b/tests/untried/neg/illegal-stmt-start.scala @@ -0,0 +1,5 @@ +class Test { + def foo { + private def bar {} + } +} \ No newline at end of file diff --git a/tests/untried/neg/imp2.check b/tests/untried/neg/imp2.check new file mode 100644 index 000000000000..999cecf16709 --- /dev/null +++ b/tests/untried/neg/imp2.check @@ -0,0 +1,7 @@ +imp2.scala:18: error: reference to f is ambiguous; +it is imported twice in the same scope by +import b._ +and import a._ + val x = f + ^ +one error found diff --git a/tests/untried/neg/imp2.scala b/tests/untried/neg/imp2.scala new file mode 100644 index 000000000000..9937262188d7 --- /dev/null +++ b/tests/untried/neg/imp2.scala @@ -0,0 +1,19 @@ +abstract class C { + val f: Int +} + +object A extends C { + val f = 1 +} + +object B extends C { + val f = 2 +} + +object Test { + val a: C = A; + val b: C = B; + import a._ + import b._ + val x = f +} diff --git a/tests/untried/neg/implicit-shadow.check b/tests/untried/neg/implicit-shadow.check new file mode 100644 index 000000000000..042fca867a03 --- /dev/null +++ b/tests/untried/neg/implicit-shadow.check @@ -0,0 +1,11 @@ +implicit-shadow.scala:4: is not a valid implicit value for Int(1) => ?{def isEmpty: ?} because: +reference to i2s is ambiguous; +it is imported twice in the same scope by +import C._ +and import B._ + 1.isEmpty + ^ +implicit-shadow.scala:4: error: value isEmpty is not a member of Int + 1.isEmpty + ^ +one error found diff --git a/tests/untried/neg/implicit-shadow.flags b/tests/untried/neg/implicit-shadow.flags new file mode 100644 index 000000000000..44842a9d65c6 --- /dev/null +++ b/tests/untried/neg/implicit-shadow.flags @@ -0,0 +1 @@ +-Xlog-implicits diff --git a/tests/untried/neg/implicit-shadow.scala b/tests/untried/neg/implicit-shadow.scala new file mode 100644 index 000000000000..ec7f70b6d01e --- /dev/null +++ b/tests/untried/neg/implicit-shadow.scala @@ -0,0 +1,13 @@ +object Test { + import B._, C._ + + 1.isEmpty +} + +trait A { + implicit def i2s(i: Int): String = "" +} + +object B extends A + +object C extends A diff --git a/tests/untried/neg/implicits.check b/tests/untried/neg/implicits.check new file mode 100644 index 000000000000..6d61f7f22227 --- /dev/null +++ b/tests/untried/neg/implicits.check @@ -0,0 +1,14 @@ +implicits.scala:38: error: type mismatch; + found : test2.HSome[String,test2.HMap] + required: Int + foo(set) + ^ +implicits.scala:46: error: type mismatch; + found : List[Any] + required: List[Mxml] + children.toList.flatMap ( e => { + ^ +implicits.scala:66: error: could not find implicit value for parameter x: Nothing + foo { + ^ +three errors found diff --git a/tests/untried/neg/implicits.scala b/tests/untried/neg/implicits.scala new file mode 100644 index 000000000000..22633a1f35f4 --- /dev/null +++ b/tests/untried/neg/implicits.scala @@ -0,0 +1,74 @@ +class Pos + +class Super + +object Super { + implicit def pos2int(p: Pos): Int = 0 +} + +object Sub extends Super { + class Plus(x: Any) { + def +(y: String): String = x.toString + y + } + implicit def any2plus(x: Any): Plus = new Plus(x) +} + +object Test { + import Super._ + import Sub._ + val p = new Pos + def f(x: Int): Int = x + f(p+1) +} + +object test2 { + sealed trait HMap { + def +[T](v: T) = HSome(v,this) + } + + final case class HSome[T, L <: HMap](head: T, tail: L) extends HMap + + final object HEmpty extends HMap + + val set = HEmpty + 3 + "3" + implicit def select[T](t: HSome[T,_]) = t.head + implicit def selectTail[L](t: HSome[_,L]) = t.tail + + def foo(x: Int) = 3 + foo(set) +} + +// #2180 +class Mxml { + + private def processChildren( children:Seq[Any] ):List[Mxml] = { + + children.toList.flatMap ( e => { + + e match { + + case s:scala.collection.Traversable[_] => s case a => List(a) + + } + + }) + + } + +} + +// SI-5316 +class Test3 { + def foo(p: => Any)(implicit x: Nothing): Unit = () + + object X + + foo { + val a = 0 + + { + import X._ + a + } + } +} diff --git a/tests/untried/neg/import-precedence.check b/tests/untried/neg/import-precedence.check new file mode 100644 index 000000000000..5f9961105284 --- /dev/null +++ b/tests/untried/neg/import-precedence.check @@ -0,0 +1,19 @@ +import-precedence.scala:18: error: reference to X is ambiguous; +it is imported twice in the same scope by +import uniq1.uniq2._ +and import uniq1.X + object Y { def f = X } + ^ +import-precedence.scala:61: error: reference to X is ambiguous; +it is imported twice in the same scope by +import uniq1.uniq2._ +and import uniq1._ + object Y { def f = X } + ^ +import-precedence.scala:67: error: reference to X is ambiguous; +it is imported twice in the same scope by +import uniq1.uniq2.X +and import uniq1.X + object Y { def f = X } + ^ +three errors found diff --git a/tests/untried/neg/import-precedence.scala b/tests/untried/neg/import-precedence.scala new file mode 100644 index 000000000000..0401635e3264 --- /dev/null +++ b/tests/untried/neg/import-precedence.scala @@ -0,0 +1,68 @@ +package uniq1 { + object X + package uniq2 { + object X + package uniq3 { + object X + package uniq4 { + object X + } + } + } +} + +package p1 { + import uniq1.X + package p2 { + import uniq1.uniq2._ + object Y { def f = X } + } +} + +package p2 { + import uniq1.uniq2._ + package p2 { + import uniq1.X + object Y { def f = X } + } +} + +package p3 { + import uniq1.X + import uniq1.uniq2._ + object Y { def f = X } +} + +package p4 { + import uniq1.uniq2._ + import uniq1.X + object Y { def f = X } +} + +package p5 { + import uniq1.X + package p6 { + import uniq1.uniq2.X + object Y { def f = X } + } +} + +package p6 { + import uniq1._ + package p5 { + import uniq1.uniq2._ + object Y { def f = X } + } +} + +package p7 { + import uniq1._ + import uniq1.uniq2._ + object Y { def f = X } +} + +package p8 { + import uniq1.X + import uniq1.uniq2.X + object Y { def f = X } +} diff --git a/tests/untried/neg/infix-op-positions.check b/tests/untried/neg/infix-op-positions.check new file mode 100644 index 000000000000..1bff9b941a77 --- /dev/null +++ b/tests/untried/neg/infix-op-positions.check @@ -0,0 +1,7 @@ +infix-op-positions.scala:2: error: value -! is not a member of Option[Int] + Option(1) -! "test" // left associative operator + ^ +infix-op-positions.scala:3: error: value -!: is not a member of Option[Int] + "test" -!: Option(1) // right associative operators + ^ +two errors found diff --git a/tests/untried/neg/infix-op-positions.scala b/tests/untried/neg/infix-op-positions.scala new file mode 100644 index 000000000000..16351b0ab37a --- /dev/null +++ b/tests/untried/neg/infix-op-positions.scala @@ -0,0 +1,4 @@ +object Test { + Option(1) -! "test" // left associative operator + "test" -!: Option(1) // right associative operators +} diff --git a/tests/untried/neg/interop_abstypetags_arenot_classmanifests.check b/tests/untried/neg/interop_abstypetags_arenot_classmanifests.check new file mode 100644 index 000000000000..d15e33346cbc --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_classmanifests.check @@ -0,0 +1,4 @@ +interop_abstypetags_arenot_classmanifests.scala:5: error: No ClassManifest available for T. + println(classManifest[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_abstypetags_arenot_classmanifests.scala b/tests/untried/neg/interop_abstypetags_arenot_classmanifests.scala new file mode 100644 index 000000000000..6b05eddf7653 --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_classmanifests.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def weakTypeTagIsnotClassManifest[T: WeakTypeTag] = { + println(classManifest[T]) + } + + weakTypeTagIsnotClassManifest[Int] + weakTypeTagIsnotClassManifest[String] + weakTypeTagIsnotClassManifest[Array[Int]] +} diff --git a/tests/untried/neg/interop_abstypetags_arenot_classtags.check b/tests/untried/neg/interop_abstypetags_arenot_classtags.check new file mode 100644 index 000000000000..3aa7a50b5034 --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_classtags.check @@ -0,0 +1,4 @@ +interop_abstypetags_arenot_classtags.scala:6: error: No ClassTag available for T + println(classTag[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_abstypetags_arenot_classtags.scala b/tests/untried/neg/interop_abstypetags_arenot_classtags.scala new file mode 100644 index 000000000000..7e049bf65582 --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_classtags.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.{ClassTag, classTag} + +object Test extends App { + def weakTypeTagIsnotClassTag[T: WeakTypeTag] = { + println(classTag[T]) + } + + weakTypeTagIsnotClassTag[Int] + weakTypeTagIsnotClassTag[String] + weakTypeTagIsnotClassTag[Array[Int]] +} diff --git a/tests/untried/neg/interop_abstypetags_arenot_manifests.check b/tests/untried/neg/interop_abstypetags_arenot_manifests.check new file mode 100644 index 000000000000..5916b68742b8 --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_manifests.check @@ -0,0 +1,4 @@ +interop_abstypetags_arenot_manifests.scala:5: error: No Manifest available for T. + println(manifest[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_abstypetags_arenot_manifests.scala b/tests/untried/neg/interop_abstypetags_arenot_manifests.scala new file mode 100644 index 000000000000..1f934e0bba2f --- /dev/null +++ b/tests/untried/neg/interop_abstypetags_arenot_manifests.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def weakTypeTagIsnotManifest[T: WeakTypeTag] = { + println(manifest[T]) + } + + weakTypeTagIsnotManifest[Int] + weakTypeTagIsnotManifest[String] + weakTypeTagIsnotManifest[Array[Int]] +} diff --git a/tests/untried/neg/interop_classmanifests_arenot_typetags.check b/tests/untried/neg/interop_classmanifests_arenot_typetags.check new file mode 100644 index 000000000000..db8e57981aad --- /dev/null +++ b/tests/untried/neg/interop_classmanifests_arenot_typetags.check @@ -0,0 +1,4 @@ +interop_classmanifests_arenot_typetags.scala:5: error: No TypeTag available for T + println(implicitly[TypeTag[T]]) + ^ +one error found diff --git a/tests/untried/neg/interop_classmanifests_arenot_typetags.scala b/tests/untried/neg/interop_classmanifests_arenot_typetags.scala new file mode 100644 index 000000000000..b89feaf80aa2 --- /dev/null +++ b/tests/untried/neg/interop_classmanifests_arenot_typetags.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def classManifestIsnotTypeTag[T: ClassManifest] = { + println(implicitly[TypeTag[T]]) + } + + classManifestIsnotTypeTag[Int] + classManifestIsnotTypeTag[String] + classManifestIsnotTypeTag[Array[Int]] +} diff --git a/tests/untried/neg/interop_classtags_arenot_manifests.check b/tests/untried/neg/interop_classtags_arenot_manifests.check new file mode 100644 index 000000000000..fa805b5918b8 --- /dev/null +++ b/tests/untried/neg/interop_classtags_arenot_manifests.check @@ -0,0 +1,4 @@ +interop_classtags_arenot_manifests.scala:5: error: No Manifest available for T. + println(manifest[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_classtags_arenot_manifests.scala b/tests/untried/neg/interop_classtags_arenot_manifests.scala new file mode 100644 index 000000000000..3555118d62dd --- /dev/null +++ b/tests/untried/neg/interop_classtags_arenot_manifests.scala @@ -0,0 +1,11 @@ +import scala.reflect.{ClassTag, classTag} + +object Test extends App { + def classTagIsnotManifest[T: ClassTag] = { + println(manifest[T]) + } + + classTagIsnotManifest[Int] + classTagIsnotManifest[String] + classTagIsnotManifest[Array[Int]] +} diff --git a/tests/untried/neg/interop_typetags_arenot_classmanifests.check b/tests/untried/neg/interop_typetags_arenot_classmanifests.check new file mode 100644 index 000000000000..88fb1647e57b --- /dev/null +++ b/tests/untried/neg/interop_typetags_arenot_classmanifests.check @@ -0,0 +1,4 @@ +interop_typetags_arenot_classmanifests.scala:5: error: No ClassManifest available for T. + println(classManifest[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_typetags_arenot_classmanifests.scala b/tests/untried/neg/interop_typetags_arenot_classmanifests.scala new file mode 100644 index 000000000000..04857aaa6d98 --- /dev/null +++ b/tests/untried/neg/interop_typetags_arenot_classmanifests.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def typeTagIsnotClassManifest[T: TypeTag] = { + println(classManifest[T]) + } + + typeTagIsnotClassManifest[Int] + typeTagIsnotClassManifest[String] + typeTagIsnotClassManifest[Array[Int]] +} diff --git a/tests/untried/neg/interop_typetags_arenot_classtags.check b/tests/untried/neg/interop_typetags_arenot_classtags.check new file mode 100644 index 000000000000..1d1fb15f9ebb --- /dev/null +++ b/tests/untried/neg/interop_typetags_arenot_classtags.check @@ -0,0 +1,4 @@ +interop_typetags_arenot_classtags.scala:6: error: No ClassTag available for T + println(classTag[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_typetags_arenot_classtags.scala b/tests/untried/neg/interop_typetags_arenot_classtags.scala new file mode 100644 index 000000000000..f5bd75fb3362 --- /dev/null +++ b/tests/untried/neg/interop_typetags_arenot_classtags.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.{ClassTag, classTag} + +object Test extends App { + def typeTagIsnotClassTag[T: TypeTag] = { + println(classTag[T]) + } + + typeTagIsnotClassTag[Int] + typeTagIsnotClassTag[String] + typeTagIsnotClassTag[Array[Int]] +} diff --git a/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.check b/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.check new file mode 100644 index 000000000000..ba744a883777 --- /dev/null +++ b/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.check @@ -0,0 +1,6 @@ +interop_typetags_without_classtags_arenot_manifests.scala:6: error: to create a manifest here, it is necessary to interoperate with the type tag `evidence$1` in scope. +however typetag -> manifest conversion requires a class tag for the corresponding type to be present. +to proceed add a class tag to the type `T` (e.g. by introducing a context bound) and recompile. + println(manifest[T]) + ^ +one error found diff --git a/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.scala b/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.scala new file mode 100644 index 000000000000..ec69c1460a78 --- /dev/null +++ b/tests/untried/neg/interop_typetags_without_classtags_arenot_manifests.scala @@ -0,0 +1,12 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.ClassTag + +object Test extends App { + def typeTagWithoutClassTagIsnotManifest[T: TypeTag] = { + println(manifest[T]) + } + + typeTagWithoutClassTagIsnotManifest[Int] + typeTagWithoutClassTagIsnotManifest[String] + typeTagWithoutClassTagIsnotManifest[Array[Int]] +} diff --git a/tests/untried/neg/java-access-neg.check b/tests/untried/neg/java-access-neg.check new file mode 100644 index 000000000000..af2812b579a1 --- /dev/null +++ b/tests/untried/neg/java-access-neg.check @@ -0,0 +1,16 @@ +S2.scala:12: error: method packageAbstract overrides nothing + override private[b] def packageAbstract() = () // fail + ^ +S2.scala:16: error: method packageConcrete overrides nothing + override private[b] def packageConcrete() = () // fail + ^ +S2.scala:36: error: method packageConcrete overrides nothing + override protected[b] def packageConcrete() = () // fail + ^ +S2.scala:47: error: method packageConcrete overrides nothing + override private[a] def packageConcrete() = () // fail + ^ +S2.scala:58: error: method packageConcrete overrides nothing + override def packageConcrete() = () // fail + ^ +5 errors found diff --git a/tests/untried/neg/java-access-neg/J.java b/tests/untried/neg/java-access-neg/J.java new file mode 100644 index 000000000000..b6bc3363a1ad --- /dev/null +++ b/tests/untried/neg/java-access-neg/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/neg/java-access-neg/S2.scala b/tests/untried/neg/java-access-neg/S2.scala new file mode 100644 index 000000000000..b082bb717413 --- /dev/null +++ b/tests/untried/neg/java-access-neg/S2.scala @@ -0,0 +1,61 @@ +package a.b +package c + +import a.b.J + +/** Variations of java-access-pos with us in a nested package. + */ + +/** Declaring "override" all the time. + */ +class S1 extends J { + override private[b] def packageAbstract() = () // fail + override protected[b] def protectedAbstract() = () + override def publicAbstract() = () + + override private[b] def packageConcrete() = () // fail + override protected[b] def protectedConcrete() = () + override def publicConcrete() = () +} + +/** Implementing abstracts. + */ +class S2 extends J { + private[b] def packageAbstract() = () // fail + protected[b] def protectedAbstract() = () + def publicAbstract() = () +} + +/** Widening access. + */ +class S3 extends J { + protected[b] def packageAbstract() = () // fail + protected[b] def protectedAbstract() = () + def publicAbstract() = () + + override protected[b] def packageConcrete() = () // fail + override protected[b] def protectedConcrete() = () + override def publicConcrete() = () +} +/** More widening. + */ +class S4 extends J { + private[a] def packageAbstract() = () // fail + protected[a] def protectedAbstract() = () + def publicAbstract() = () + + override private[a] def packageConcrete() = () // fail + override protected[a] def protectedConcrete() = () + override def publicConcrete() = () +} +/** Yet more widening. + */ +class S5 extends J { + def packageAbstract() = () // fail + def protectedAbstract() = () + def publicAbstract() = () + + override def packageConcrete() = () // fail + override def protectedConcrete() = () + override def publicConcrete() = () +} diff --git a/tests/untried/neg/lazy-override.check b/tests/untried/neg/lazy-override.check new file mode 100644 index 000000000000..793e6b2020fa --- /dev/null +++ b/tests/untried/neg/lazy-override.check @@ -0,0 +1,9 @@ +lazy-override.scala:11: error: overriding value x in class A of type Int; + lazy value x cannot override a concrete non-lazy value + override lazy val x: Int = { print("/*B.x*/"); 3 } + ^ +lazy-override.scala:13: error: overriding lazy value y in class A of type Int; + value y must be declared lazy to override a concrete lazy value + override val y: Int = { print("/*B.y*/"); 3 } + ^ +two errors found diff --git a/tests/untried/neg/lazy-override.scala b/tests/untried/neg/lazy-override.scala new file mode 100644 index 000000000000..f41d7f038bb9 --- /dev/null +++ b/tests/untried/neg/lazy-override.scala @@ -0,0 +1,19 @@ + +/** Test which should fail compilation */ + class A { + val x: Int = { print("/*A.x*/"); 2 } + lazy val y: Int = { print("/*A.y*/"); 2 } + } + + + class B extends A { + // lazy overrides strict val + override lazy val x: Int = { print("/*B.x*/"); 3 } + // strict val overrides lazy + override val y: Int = { print("/*B.y*/"); 3 } + } + + + + + diff --git a/tests/untried/neg/lazyvals.check b/tests/untried/neg/lazyvals.check new file mode 100644 index 000000000000..c4daf9d842bd --- /dev/null +++ b/tests/untried/neg/lazyvals.check @@ -0,0 +1,25 @@ +lazyvals.scala:6: error: lazy values may not be abstract + lazy val t: Int + ^ +lazyvals.scala:9: error: lazy not allowed here. Only vals can be lazy + lazy var p: Int = 100 + ^ +lazyvals.scala:12: error: lazy not allowed here. Only vals can be lazy + lazy def q: Double = 0.0 + ^ +lazyvals.scala:15: error: '=' expected but ';' found. + lazy val t; + ^ +lazyvals.scala:20: error: lazy not allowed here. Only vals can be lazy + lazy trait T {} + ^ +lazyvals.scala:21: error: lazy not allowed here. Only vals can be lazy + lazy class C {} + ^ +lazyvals.scala:22: error: lazy not allowed here. Only vals can be lazy + lazy object O {} + ^ +lazyvals.scala:25: error: lazy modifier not allowed here. Use call-by-name parameters instead + class A(lazy val obj: Object) {} + ^ +8 errors found diff --git a/tests/untried/neg/lazyvals.scala b/tests/untried/neg/lazyvals.scala new file mode 100644 index 000000000000..f92534f50691 --- /dev/null +++ b/tests/untried/neg/lazyvals.scala @@ -0,0 +1,46 @@ + +/** Test which should fail compilation */ +class Lazy { + + // no abstract lazy values + lazy val t: Int + + // no lazy var + lazy var p: Int = 100 + + // no lazy defs + lazy def q: Double = 0.0 + + def foo { + lazy val t; + () + } + + // no trait/class/object can be lazy + lazy trait T {} + lazy class C {} + lazy object O {} + + // no lazy modifiers in class parameters + class A(lazy val obj: Object) {} +} + +object T2 { + class A { + val x: Int = { print("/*A.x*/"); 2 } + lazy val y: Int = { print("/*A.y*/"); 2 } + } + + + class B extends A { + // lazy overrides strict val + override lazy val x: Int = { print("/*B.x*/"); 3 } + // strict val overrides lazy + override val y: Int = { print("/*B.y*/"); 3 } + } +} + + + + + diff --git a/tests/untried/neg/literate_existentials.check b/tests/untried/neg/literate_existentials.check new file mode 100644 index 000000000000..c98f976f795d --- /dev/null +++ b/tests/untried/neg/literate_existentials.check @@ -0,0 +1,4 @@ +literate_existentials.scala:189: error: Cannot prove that Int <:< M forSome { type M <: String }. + implicitly[Int <:< (M forSome { type M >: Nothing <: String })] // fails + ^ +one error found diff --git a/tests/untried/neg/literate_existentials.scala b/tests/untried/neg/literate_existentials.scala new file mode 100644 index 000000000000..8580347bf99e --- /dev/null +++ b/tests/untried/neg/literate_existentials.scala @@ -0,0 +1,224 @@ + +object LiterateExistentials { + +// Let's play with Scala's type system a bit. +// +// From adriaanm, we have the following substitution rule, which allows us to +// determine whether a type is a subtype of an existential in Scala: +// +// +// T <: subst(U) for all i: subst(Li) <: Vi /\ Vi <: subst(Hi) +// -------------------------------------------------------------- +// T <: U forSome {type X1 :> L1 <: H1; ...; type Xn :> Ln <: Hn} +// +// where subst(T) = T.subst(Xi, Vi) // Vi fresh type variables +// +// T is a subtype of some existential if all constraints of the existential hold +// after substituting Vi for the existentially quantified type variables Xi, +// and T is a subtype of the underlying type U with the same substitution applied. +// +// +// Since we are not a formal substitution system, we will actually be using +// this rule 'backward' in order to determine whether it allows us to +// truthfully make claims; In each example, we will start with the proposition +// that a type is a subtype of an existential. Then, we will fit the +// proposition into the form on the bottom rule by creating a set of bindings +// which allow one to be transformed into the other. Next, we will express the +// top of the substitution rule in terms of a series of constraints. We will +// simplify those constraints until simple inspection can determine whether +// they are consistent. From this, we can conclude whether the type system / +// environment admit the top of the substitution rule (and thus, the bottom). If +// they do, we can say that the proposition is true. + + +// In each case, we will also probe the compiler to see whether _it_ thinks that +// the proposition holds, using an uncommented implicitly[_ <:< _] line. + + + + +// Proposition: Nothing :< (A forSome { type A >: String <: Any }) +// +// +// Bindings: +// T := Nothing +// U := A +// X1 := A +// L1 := String +// H1 := Any +// +// We need: +// +// Nothing <: V1 // (U, which is "A", which V1 substituted for all instances of A) +// String <: V1 +// V1 <: Any +// +// Which simplify to: +// V1 >: String <: Any +// +// That's not inconsistent, so we can say that: +// T <: U forSome { type X1 >: L1 <: H1 } +// which means (under our mappings): +// Nothing <: A forSome { type A >: String <: Any } + +// Now to ask the compiler: + + implicitly[Nothing <:< (A forSome { type A >: String <: Any })] + + +// Let's try another: +// +// Proposition: Int :< (M forSome { type M >: String <: Any }) +// +// Bindings: +// T := Int +// U := M +// X1 := M +// L1 := String +// H1 := Any +// +// We need: +// +// Int <: V1 +// String <: V1 +// V1 <: Any +// +// Which simplify to: +// +// V1 >: lub(Int, String) <: Any +// +// V1 >: Any <: Any +// +// We have demonstrated consistency! We can say that: +// T :< (U forSome { type U >: L1 <: H1 }) +// Under our bindings, this is: +// Int :< (M forSome { type M >: String <: Any }) + + implicitly[Int <:< (M forSome { type M >: String <: Any })] + + + +// Now, let's do a more complicated one: +// +// Proposition: (Nothing, List[String]) <: ((A, B) forSome { type A >: String <: AnyRef; type B >: Null <: List[A] }) +// +// Bindings: +// T := (Nothing, List[String]) +// U := (A, B) +// X1 := A +// X2 := B +// L1 := String +// H1 := AnyRef +// L2 := Null +// H2 := List[A] +// +// We need: +// +// (Nothing, List[String]) <: (V1, V2) +// String <: V1 +// V1 <: AnyRef +// Null <: V2 +// V2 <: List[V1] +// +// Of course, we can split the first line to make: +// +// Nothing <: V1 +// List[String]) <: V2 +// String <: V1 +// V1 <: AnyRef +// Null <: V2 +// V2 <: List[V1] +// +// Which reorder to: +// +// Nothing <: V1 +// String <: V1 +// V1 <: AnyRef +// List[String]) <: V2 +// Null <: V2 +// V2 <: List[V1] +// +// Which simplify to: +// +// String <: V1 +// V1 <: AnyRef +// List[String]) <: V2 +// V2 <: List[V1] +// +// String <: V1 +// V1 <: AnyRef +// String <: V1 +// +// V1 >: String <: AnyRef +// +// Consistency demonstrated! We can say that: +// T <: U forSome {type X1 :> L1 <: H1; type X2 :> L2 <: H2} +// meaning: +// (Nothing, List[String]) <: ((A, B) forSome { type A >: String <: AnyRef; type B >: Null <: List[A] }) + + implicitly[ + (Nothing, List[String]) <:< ((A, B) forSome { type A >: String <: AnyRef; type B >: Null <: List[A] }) + ] + + + +// Now let's try one that isn't true: +// +// Proposition: Int :< (M forSome { type M >: Nothing <: String }) +// +// Bindings: +// T := Int +// U := M +// X1 := M +// L1 := Nothing +// H1 := String +// +// We need: +// +// Int <: V1 +// Nothing <: V1 +// V1 <: String +// +// V1 >: Int <: String +// +// Alas! These are inconsistent! There is no supertype of Int that is a +// subtype of String! Our substitution rule does not allow us to claim that our +// proposition is true. +// + + implicitly[Int <:< (M forSome { type M >: Nothing <: String })] // fails +// The preceeding line causes the compiler to generate an error message. + + + +// Let's look at one final example, courtesy of paulp. +// Proposition: String :< X forSome { type X >: Nothing <: String } +// +// Bindings: +// T := String +// U := X +// X1 := X +// L1 := Nothing +// H1 := String +// +// We need: +// +// String <: V1 +// Nothing <: V1 +// V1 <: String +// +// Which simplify to: +// +// String <: V1 +// V1 <: String +// +// V1 >: String <: String +// +// So, we can say: +// T <: U forSome { type X1 >: L1 <: H1 } +// which means: +// String :< X forSome { type X >: Nothing <: String } + + implicitly[String <:< (X forSome { type X >: Nothing <: String })] + +} diff --git a/tests/untried/neg/logImplicits.check b/tests/untried/neg/logImplicits.check new file mode 100644 index 000000000000..270882b71a09 --- /dev/null +++ b/tests/untried/neg/logImplicits.check @@ -0,0 +1,19 @@ +logImplicits.scala:2: applied implicit conversion from xs.type to ?{def size: ?} = implicit def byteArrayOps(xs: Array[Byte]): scala.collection.mutable.ArrayOps[Byte] + def f(xs: Array[Byte]) = xs.size + ^ +logImplicits.scala:7: applied implicit conversion from String("abc") to ?{def map: ?} = implicit def augmentString(x: String): scala.collection.immutable.StringOps + def f = "abc" map (_ + 1) + ^ +logImplicits.scala:15: inferred view from String("abc") to Int = C.this.convert:(p: String("abc"))Int + math.max(122, x: Int) + ^ +logImplicits.scala:19: applied implicit conversion from Int(1) to ?{def ->: ?} = implicit def ArrowAssoc[A](self: A): ArrowAssoc[A] + def f = (1 -> 2) + "c" + ^ +logImplicits.scala:19: applied implicit conversion from (Int, Int) to ?{def +: ?} = implicit def any2stringadd[A](self: A): any2stringadd[A] + def f = (1 -> 2) + "c" + ^ +logImplicits.scala:22: error: class Un needs to be abstract, since method unimplemented is not defined +class Un { + ^ +one error found diff --git a/tests/untried/neg/logImplicits.flags b/tests/untried/neg/logImplicits.flags new file mode 100644 index 000000000000..97e5ae94efe4 --- /dev/null +++ b/tests/untried/neg/logImplicits.flags @@ -0,0 +1 @@ +-Xlog-implicit-conversions \ No newline at end of file diff --git a/tests/untried/neg/logImplicits.scala b/tests/untried/neg/logImplicits.scala new file mode 100644 index 000000000000..ecb4cbb31e5c --- /dev/null +++ b/tests/untried/neg/logImplicits.scala @@ -0,0 +1,25 @@ +class A { + def f(xs: Array[Byte]) = xs.size + def g(xs: Array[Byte]) = xs.length +} + +class B { + def f = "abc" map (_ + 1) +} + +object C { + final val x = "abc" + + implicit def convert(p: x.type): Int = 123 + + math.max(122, x: Int) +} + +class D { + def f = (1 -> 2) + "c" +} + +class Un { + // forcing post-typer failure, since we're only interested in the output from the above + def unimplemented: Int +} diff --git a/tests/untried/neg/lubs.check b/tests/untried/neg/lubs.check new file mode 100644 index 000000000000..affbd4983c40 --- /dev/null +++ b/tests/untried/neg/lubs.check @@ -0,0 +1,21 @@ +lubs.scala:10: error: type mismatch; + found : test1.A[test1.A[Object]] + required: test1.A[test1.A[test1.A[Any]]] + val x3: A[A[A[Any]]] = f + ^ +lubs.scala:11: error: type mismatch; + found : test1.A[test1.A[Object]] + required: test1.A[test1.A[test1.A[test1.A[Any]]]] + val x4: A[A[A[A[Any]]]] = f + ^ +lubs.scala:24: error: type mismatch; + found : test2.A{type T >: test2.C with test2.D <: test2.A} + required: test2.A{type T >: Null <: test2.A{type T >: Null <: test2.A}} + val x3: A { type T >: Null <: A { type T >: Null <: A } } = f + ^ +lubs.scala:25: error: type mismatch; + found : test2.A{type T >: test2.C with test2.D <: test2.A} + required: test2.A{type T >: Null <: test2.A{type T >: Null <: test2.A{type T >: Null <: test2.A}}} + val x4: A { type T >: Null <: A { type T >: Null <: A { type T >: Null <: A } } } = f + ^ +four errors found diff --git a/tests/untried/neg/lubs.scala b/tests/untried/neg/lubs.scala new file mode 100644 index 000000000000..3524fa4d87fa --- /dev/null +++ b/tests/untried/neg/lubs.scala @@ -0,0 +1,26 @@ +object test1 { + abstract class A[+T] + class C extends A[C] + class D extends A[D] + + def f = if(1 == 2) new C else new D + + val x1: A[Any] = f + val x2: A[A[Any]] = f + val x3: A[A[A[Any]]] = f + val x4: A[A[A[A[Any]]]] = f +} + +object test2 { + + abstract class A { type T } + class C extends A { type T = C } + class D extends A { type T = D } + + def f = if (1 == 2) new C else new D + + val x1: A { type T } = f + val x2: A { type T >: Null <: A } = f + val x3: A { type T >: Null <: A { type T >: Null <: A } } = f + val x4: A { type T >: Null <: A { type T >: Null <: A { type T >: Null <: A } } } = f +} diff --git a/tests/untried/neg/macro-abort.check b/tests/untried/neg/macro-abort.check new file mode 100644 index 000000000000..1e58add53319 --- /dev/null +++ b/tests/untried/neg/macro-abort.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: aborted + Macros.abort + ^ +one error found diff --git a/tests/untried/neg/macro-abort/Macros_1.scala b/tests/untried/neg/macro-abort/Macros_1.scala new file mode 100644 index 000000000000..cd2382a6f077 --- /dev/null +++ b/tests/untried/neg/macro-abort/Macros_1.scala @@ -0,0 +1,9 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = { + c.abort(c.enclosingPosition, "aborted") + } + def abort = macro impl +} diff --git a/tests/untried/neg/macro-abort/Test_2.scala b/tests/untried/neg/macro-abort/Test_2.scala new file mode 100644 index 000000000000..9eee0cccaa69 --- /dev/null +++ b/tests/untried/neg/macro-abort/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.abort +} diff --git a/tests/untried/neg/macro-basic-mamdmi.check b/tests/untried/neg/macro-basic-mamdmi.check new file mode 100644 index 000000000000..61df5131ccb2 --- /dev/null +++ b/tests/untried/neg/macro-basic-mamdmi.check @@ -0,0 +1,5 @@ +Impls_Macros_Test_1.scala:33: error: macro implementation not found: quux +(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) + println(foo(2) + Macros.bar(2) * new Macros().quux(4)) + ^ +one error found diff --git a/tests/untried/neg/macro-basic-mamdmi.flags b/tests/untried/neg/macro-basic-mamdmi.flags new file mode 100644 index 000000000000..5e5dd6ce794e --- /dev/null +++ b/tests/untried/neg/macro-basic-mamdmi.flags @@ -0,0 +1 @@ +-language:experimental.macros diff --git a/tests/untried/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala b/tests/untried/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala new file mode 100644 index 000000000000..c059d962eb41 --- /dev/null +++ b/tests/untried/neg/macro-basic-mamdmi/Impls_Macros_Test_1.scala @@ -0,0 +1,34 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr[Int](q"$x + 1") + } + + def bar(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr[Int](q"$x + 2") + } + + def quux(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr[Int](q"$x + 3") + } +} + +object Macros { + object Shmacros { + def foo(x: Int): Int = macro Impls.foo + } + def bar(x: Int): Int = macro Impls.bar +} + +class Macros { + def quux(x: Int): Int = macro Impls.quux +} + +object Test extends App { + import Macros.Shmacros._ + println(foo(2) + Macros.bar(2) * new Macros().quux(4)) +} diff --git a/tests/untried/neg/macro-blackbox-dynamic-materialization.check b/tests/untried/neg/macro-blackbox-dynamic-materialization.check new file mode 100644 index 000000000000..f6c73f7edb69 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-dynamic-materialization.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: I don't like classes that contain integers + println(implicitly[Foo[C1]]) + ^ +one error found diff --git a/tests/untried/neg/macro-blackbox-dynamic-materialization/Macros_1.scala b/tests/untried/neg/macro-blackbox-dynamic-materialization/Macros_1.scala new file mode 100644 index 000000000000..16a379ea5e50 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +trait Foo[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: Foo[T] = null +} + +object Foo extends LowPriority { + implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: Context) = { + import c.universe._ + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" + } +} diff --git a/tests/untried/neg/macro-blackbox-dynamic-materialization/Test_2.scala b/tests/untried/neg/macro-blackbox-dynamic-materialization/Test_2.scala new file mode 100644 index 000000000000..abb5229bd0d9 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-dynamic-materialization/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(implicitly[Foo[C1]]) + println(implicitly[Foo[C2]]) +} diff --git a/tests/untried/neg/macro-blackbox-extractor.check b/tests/untried/neg/macro-blackbox-extractor.check new file mode 100644 index 000000000000..4c53ff19b84d --- /dev/null +++ b/tests/untried/neg/macro-blackbox-extractor.check @@ -0,0 +1,4 @@ +Test_2.scala:3: error: extractor macros can only be whitebox + case Extractor(x) => println(x) + ^ +one error found diff --git a/tests/untried/neg/macro-blackbox-extractor/Macros_1.scala b/tests/untried/neg/macro-blackbox-extractor/Macros_1.scala new file mode 100644 index 000000000000..64b6270b74af --- /dev/null +++ b/tests/untried/neg/macro-blackbox-extractor/Macros_1.scala @@ -0,0 +1,21 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Extractor { + def unapply(x: Int): Any = macro Macros.unapplyImpl +} + +object Macros { + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/macro-blackbox-extractor/Test_2.scala b/tests/untried/neg/macro-blackbox-extractor/Test_2.scala new file mode 100644 index 000000000000..41be6f976713 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-extractor/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + 42 match { + case Extractor(x) => println(x) + } +} diff --git a/tests/untried/neg/macro-blackbox-fundep-materialization.check b/tests/untried/neg/macro-blackbox-fundep-materialization.check new file mode 100644 index 000000000000..3c03064a2ddc --- /dev/null +++ b/tests/untried/neg/macro-blackbox-fundep-materialization.check @@ -0,0 +1,8 @@ +Test_2.scala:7: error: type mismatch; + found : Iso[Test.Foo,(Int, String, Boolean)] + required: Iso[Test.Foo,Nothing] +Note: (Int, String, Boolean) >: Nothing, but trait Iso is invariant in type U. +You may wish to define U as -U instead. (SLS 4.5) + val equiv = foo(Foo(23, "foo", true)) + ^ +one error found diff --git a/tests/untried/neg/macro-blackbox-fundep-materialization.flags b/tests/untried/neg/macro-blackbox-fundep-materialization.flags new file mode 100644 index 000000000000..4c6cdb71e2fa --- /dev/null +++ b/tests/untried/neg/macro-blackbox-fundep-materialization.flags @@ -0,0 +1 @@ +-Xlog-implicits \ No newline at end of file diff --git a/tests/untried/neg/macro-blackbox-fundep-materialization/Macros_1.scala b/tests/untried/neg/macro-blackbox-fundep-materialization/Macros_1.scala new file mode 100644 index 000000000000..8d776388ee8a --- /dev/null +++ b/tests/untried/neg/macro-blackbox-fundep-materialization/Macros_1.scala @@ -0,0 +1,39 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +trait Iso[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +object Iso { + implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: Context): c.Expr[Iso[T, U]] = { + import c.universe._ + import definitions._ + import Flag._ + + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("Iso")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[Iso[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} diff --git a/tests/untried/neg/macro-blackbox-fundep-materialization/Test_2.scala b/tests/untried/neg/macro-blackbox-fundep-materialization/Test_2.scala new file mode 100644 index 000000000000..8b60943cfd8d --- /dev/null +++ b/tests/untried/neg/macro-blackbox-fundep-materialization/Test_2.scala @@ -0,0 +1,12 @@ +// see the comments for macroExpand.onDelayed for an explanation of what's tested here +object Test extends App { + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c) + + { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } +} diff --git a/tests/untried/neg/macro-blackbox-structural.check b/tests/untried/neg/macro-blackbox-structural.check new file mode 100644 index 000000000000..86a218559c64 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-structural.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: value x is not a member of Any + println(Macros.foo.x) + ^ +one error found diff --git a/tests/untried/neg/macro-blackbox-structural/Impls_Macros_1.scala b/tests/untried/neg/macro-blackbox-structural/Impls_Macros_1.scala new file mode 100644 index 000000000000..786a3f45f2d3 --- /dev/null +++ b/tests/untried/neg/macro-blackbox-structural/Impls_Macros_1.scala @@ -0,0 +1,15 @@ +import scala.language.experimental.macros + +object Macros { + def impl(c: scala.reflect.macros.blackbox.Context) = { + import c.universe._ + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } + + def foo: Any = macro impl +} diff --git a/tests/untried/neg/macro-blackbox-structural/Test_2.scala b/tests/untried/neg/macro-blackbox-structural/Test_2.scala new file mode 100644 index 000000000000..e02b4feb427a --- /dev/null +++ b/tests/untried/neg/macro-blackbox-structural/Test_2.scala @@ -0,0 +1,5 @@ +import Macros._ + +object Test extends App { + println(Macros.foo.x) +} diff --git a/tests/untried/neg/macro-bundle-abstract.check b/tests/untried/neg/macro-bundle-abstract.check new file mode 100644 index 000000000000..1e51a00d0524 --- /dev/null +++ b/tests/untried/neg/macro-bundle-abstract.check @@ -0,0 +1,4 @@ +macro-bundle-abstract.scala:10: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def foo = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-abstract.scala b/tests/untried/neg/macro-bundle-abstract.scala new file mode 100644 index 000000000000..db57d5dc9d7c --- /dev/null +++ b/tests/untried/neg/macro-bundle-abstract.scala @@ -0,0 +1,11 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +abstract class Bundle(c: Context) { + def deferred: Int + def impl = ??? +} + +object Macros { + def foo = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-ambiguous.check b/tests/untried/neg/macro-bundle-ambiguous.check new file mode 100644 index 000000000000..84304964557e --- /dev/null +++ b/tests/untried/neg/macro-bundle-ambiguous.check @@ -0,0 +1,5 @@ +macro-bundle-ambiguous.scala:13: error: macro implementation reference is ambiguous: makes sense both as +a macro bundle method reference and a vanilla object method reference + def foo: Unit = macro Macros.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-ambiguous.scala b/tests/untried/neg/macro-bundle-ambiguous.scala new file mode 100644 index 000000000000..72c6a2c30847 --- /dev/null +++ b/tests/untried/neg/macro-bundle-ambiguous.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) = ??? +} + +object Test extends App { + def foo: Unit = macro Macros.impl +} diff --git a/tests/untried/neg/macro-bundle-need-qualifier.check b/tests/untried/neg/macro-bundle-need-qualifier.check new file mode 100644 index 000000000000..6a74ee6aedb6 --- /dev/null +++ b/tests/untried/neg/macro-bundle-need-qualifier.check @@ -0,0 +1,4 @@ +macro-bundle-need-qualifier.scala:10: error: not found: value impl + def foo: Any = macro impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-need-qualifier.scala b/tests/untried/neg/macro-bundle-need-qualifier.scala new file mode 100644 index 000000000000..1edda8081a25 --- /dev/null +++ b/tests/untried/neg/macro-bundle-need-qualifier.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(val c: Context) { + import c.universe._ + def impl = q"()" +} + +object Macros { + def foo: Any = macro impl +} diff --git a/tests/untried/neg/macro-bundle-noncontext.check b/tests/untried/neg/macro-bundle-noncontext.check new file mode 100644 index 000000000000..bb5d0851f592 --- /dev/null +++ b/tests/untried/neg/macro-bundle-noncontext.check @@ -0,0 +1,4 @@ +macro-bundle-noncontext.scala:8: error: not found: value Bundle + def foo = Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-noncontext.scala b/tests/untried/neg/macro-bundle-noncontext.scala new file mode 100644 index 000000000000..b3d7f4464e91 --- /dev/null +++ b/tests/untried/neg/macro-bundle-noncontext.scala @@ -0,0 +1,9 @@ +import scala.language.experimental.macros + +class Bundle { + def impl = ??? +} + +object Macros { + def foo = Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-nonpublic-c.check b/tests/untried/neg/macro-bundle-nonpublic-c.check new file mode 100644 index 000000000000..1dfcee58b743 --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonpublic-c.check @@ -0,0 +1,4 @@ +macro-bundle-nonpublic-c.scala:6: error: private value c escapes its defining scope as part of type Macros.this.c.universe.Literal + def impl = q"()" + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-nonpublic-c.scala b/tests/untried/neg/macro-bundle-nonpublic-c.scala new file mode 100644 index 000000000000..a240787515df --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonpublic-c.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(c: Context) { + import c.universe._ + def impl = q"()" +} + +object Macros { + def foo: Any = macro Macros.impl +} diff --git a/tests/untried/neg/macro-bundle-nonpublic-impl.check b/tests/untried/neg/macro-bundle-nonpublic-impl.check new file mode 100644 index 000000000000..7a4e1516f763 --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonpublic-impl.check @@ -0,0 +1,4 @@ +macro-bundle-nonpublic-impl.scala:10: error: bundle implementation must be public + def foo: Any = macro Macros.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-nonpublic-impl.scala b/tests/untried/neg/macro-bundle-nonpublic-impl.scala new file mode 100644 index 000000000000..1ed17277cc34 --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonpublic-impl.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(val c: Context) { + import c.universe._ + private def impl = q"()" +} + +object Macros { + def foo: Any = macro Macros.impl +} diff --git a/tests/untried/neg/macro-bundle-nonstatic.check b/tests/untried/neg/macro-bundle-nonstatic.check new file mode 100644 index 000000000000..36bccc54db6d --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonstatic.check @@ -0,0 +1,13 @@ +macro-bundle-nonstatic.scala:12: error: value Bundle is not a member of object Module + def foo1 = macro Module.Bundle.impl + ^ +macro-bundle-nonstatic.scala:13: error: value Bundle is not a member of Module + def foo2 = macro new Module().Bundle.impl + ^ +macro-bundle-nonstatic.scala:17: error: macro bundles must be static + def foo = macro Bundle.impl + ^ +macro-bundle-nonstatic.scala:23: error: macro bundles must be static + def foo = macro Bundle.impl + ^ +four errors found diff --git a/tests/untried/neg/macro-bundle-nonstatic.scala b/tests/untried/neg/macro-bundle-nonstatic.scala new file mode 100644 index 000000000000..dfba79660a86 --- /dev/null +++ b/tests/untried/neg/macro-bundle-nonstatic.scala @@ -0,0 +1,36 @@ +import scala.language.experimental.macros +import scala.reflect.macros.whitebox.Context + +class Module { + class Bundle(val c: Context) { + import c.universe._ + def impl = q"()" + } +} + +object Macros1 { + def foo1 = macro Module.Bundle.impl + def foo2 = macro new Module().Bundle.impl +} + +object Macros2 extends Module { + def foo = macro Bundle.impl +} + +object Macros3 { + val module = new Module + import module._ + def foo = macro Bundle.impl +} + +object Module { + class GoodBundle(val c: Context) { + import c.universe._ + def impl = q"()" + } +} + +object Macros4 { + import Module._ + def foo: Unit = macro GoodBundle.impl +} diff --git a/tests/untried/neg/macro-bundle-object.check b/tests/untried/neg/macro-bundle-object.check new file mode 100644 index 000000000000..b8800105f56d --- /dev/null +++ b/tests/untried/neg/macro-bundle-object.check @@ -0,0 +1,8 @@ +macro-bundle-object.scala:10: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : : Nothing +number of parameter sections differ + def foo = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-object.scala b/tests/untried/neg/macro-bundle-object.scala new file mode 100644 index 000000000000..c92571033a8d --- /dev/null +++ b/tests/untried/neg/macro-bundle-object.scala @@ -0,0 +1,11 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Bundle { + val c: Context = ??? + def impl = ??? +} + +object Macros { + def foo = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-overloaded.check b/tests/untried/neg/macro-bundle-overloaded.check new file mode 100644 index 000000000000..499068aaa812 --- /dev/null +++ b/tests/untried/neg/macro-bundle-overloaded.check @@ -0,0 +1,4 @@ +macro-bundle-overloaded.scala:11: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def foo = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-overloaded.scala b/tests/untried/neg/macro-bundle-overloaded.scala new file mode 100644 index 000000000000..c5120b5b5e29 --- /dev/null +++ b/tests/untried/neg/macro-bundle-overloaded.scala @@ -0,0 +1,12 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.{Context => BlackboxContext} +import scala.reflect.macros.whitebox.{Context => WhiteboxContext} + +class Bundle(val c: BlackboxContext) { + def this(c: WhiteboxContext) = this(c: BlackboxContext) + def impl = ??? +} + +object Macros { + def foo = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-polymorphic.check b/tests/untried/neg/macro-bundle-polymorphic.check new file mode 100644 index 000000000000..60a4d59119b4 --- /dev/null +++ b/tests/untried/neg/macro-bundle-polymorphic.check @@ -0,0 +1,19 @@ +macro-bundle-polymorphic.scala:36: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def black1: Any = macro BlackboxBundle1.impl + ^ +macro-bundle-polymorphic.scala:37: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def black2: Any = macro BlackboxBundle2.impl + ^ +macro-bundle-polymorphic.scala:38: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def black3: Any = macro BlackboxBundle3.impl + ^ +macro-bundle-polymorphic.scala:40: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def white1: Any = macro WhiteboxBundle1.impl + ^ +macro-bundle-polymorphic.scala:41: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def white2: Any = macro WhiteboxBundle2.impl + ^ +macro-bundle-polymorphic.scala:42: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def white3: Any = macro WhiteboxBundle3.impl + ^ +6 errors found diff --git a/tests/untried/neg/macro-bundle-polymorphic.scala b/tests/untried/neg/macro-bundle-polymorphic.scala new file mode 100644 index 000000000000..3e7ffe89c7bc --- /dev/null +++ b/tests/untried/neg/macro-bundle-polymorphic.scala @@ -0,0 +1,43 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.{Context => BlackboxContext} +import scala.reflect.macros.whitebox.{Context => WhiteboxContext} + +class BlackboxBundle1[T](val c: BlackboxContext) { + import c.universe._ + def impl = q"()" +} + +class BlackboxBundle2[T <: BlackboxContext](val c: T) { + import c.universe._ + def impl = q"()" +} + +class BlackboxBundle3[T <: BlackboxContext, U <: T](val c: U) { + import c.universe._ + def impl = q"()" +} + +class WhiteboxBundle1[T](val c: WhiteboxContext) { + import c.universe._ + def impl = q"()" +} + +class WhiteboxBundle2[T <: WhiteboxContext](val c: T) { + import c.universe._ + def impl = q"()" +} + +class WhiteboxBundle3[T <: WhiteboxContext, U <: T](val c: U) { + import c.universe._ + def impl = q"()" +} + +object Macros { + def black1: Any = macro BlackboxBundle1.impl + def black2: Any = macro BlackboxBundle2.impl + def black3: Any = macro BlackboxBundle3.impl + + def white1: Any = macro WhiteboxBundle1.impl + def white2: Any = macro WhiteboxBundle2.impl + def white3: Any = macro WhiteboxBundle3.impl +} diff --git a/tests/untried/neg/macro-bundle-priority-bundle.check b/tests/untried/neg/macro-bundle-priority-bundle.check new file mode 100644 index 000000000000..c6cea72ba6e6 --- /dev/null +++ b/tests/untried/neg/macro-bundle-priority-bundle.check @@ -0,0 +1,8 @@ +macro-bundle-priority-bundle.scala:13: error: bundle implementation has incompatible shape: + required: : Macros.this.c.Expr[Unit] + or : : Macros.this.c.Tree + found : (x: Macros.this.c.Tree): Nothing +number of parameter sections differ + def foo: Unit = macro Macros.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-priority-bundle.scala b/tests/untried/neg/macro-bundle-priority-bundle.scala new file mode 100644 index 000000000000..ab9987b8f7f4 --- /dev/null +++ b/tests/untried/neg/macro-bundle-priority-bundle.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)(x: c.Tree) = ??? +} + +object Test extends App { + def foo: Unit = macro Macros.impl +} diff --git a/tests/untried/neg/macro-bundle-priority-nonbundle.check b/tests/untried/neg/macro-bundle-priority-nonbundle.check new file mode 100644 index 000000000000..0d03b5074b18 --- /dev/null +++ b/tests/untried/neg/macro-bundle-priority-nonbundle.check @@ -0,0 +1,8 @@ +macro-bundle-priority-nonbundle.scala:13: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.whitebox.Context): c.Expr[Unit] + or : (c: scala.reflect.macros.whitebox.Context): c.Tree + found : (c: scala.reflect.macros.whitebox.Context)(x: c.Tree): Nothing +number of parameter sections differ + def foo: Unit = macro Macros.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-priority-nonbundle.scala b/tests/untried/neg/macro-bundle-priority-nonbundle.scala new file mode 100644 index 000000000000..0ef5b789ade0 --- /dev/null +++ b/tests/untried/neg/macro-bundle-priority-nonbundle.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Macros(val c: scala.reflect.api.Universe) { + def impl(x: c.Tree) = ??? +} + +object Macros { + def impl(c: Context)(x: c.Tree) = ??? +} + +object Test extends App { + def foo: Unit = macro Macros.impl +} diff --git a/tests/untried/neg/macro-bundle-trait.check b/tests/untried/neg/macro-bundle-trait.check new file mode 100644 index 000000000000..869c67e1e308 --- /dev/null +++ b/tests/untried/neg/macro-bundle-trait.check @@ -0,0 +1,4 @@ +macro-bundle-trait.scala:10: error: not found: value Bundle + def foo = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-trait.scala b/tests/untried/neg/macro-bundle-trait.scala new file mode 100644 index 000000000000..2015508b8049 --- /dev/null +++ b/tests/untried/neg/macro-bundle-trait.scala @@ -0,0 +1,11 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +trait Bundle { + val c: Context = ??? + def impl = ??? +} + +object Macros { + def foo = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-whitebox-use-raw.check b/tests/untried/neg/macro-bundle-whitebox-use-raw.check new file mode 100644 index 000000000000..5792e317a63a --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-raw.check @@ -0,0 +1,17 @@ +Test_2.scala:2: error: value x is not a member of Any + println(ReturnTypeRefinement.foo.x) + ^ +Test_2.scala:7: error: type mismatch; + found : FundepMaterialization[Test.Foo,(Int, String, Boolean)] + required: FundepMaterialization[Test.Foo,Nothing] +Note: (Int, String, Boolean) >: Nothing, but trait FundepMaterialization is invariant in type U. +You may wish to define U as -U instead. (SLS 4.5) + val equiv = foo(Foo(23, "foo", true)) + ^ +Test_2.scala:13: error: I don't like classes that contain integers + println(implicitly[DynamicMaterialization[C1]]) + ^ +Test_2.scala:17: error: extractor macros can only be whitebox + case ExtractorMacro(x) => println(x) + ^ +four errors found diff --git a/tests/untried/neg/macro-bundle-whitebox-use-raw/Macros_1.scala b/tests/untried/neg/macro-bundle-whitebox-use-raw/Macros_1.scala new file mode 100644 index 000000000000..61bf73e481e7 --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-raw/Macros_1.scala @@ -0,0 +1,108 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +// whitebox use case #1: return type refinement + +class ReturnTypeRefinementBundle(val c: Context) { + import c.universe._ + def impl = { + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } +} + +object ReturnTypeRefinement { + def foo: Any = macro ReturnTypeRefinementBundle.impl +} + +// whitebox use case #2: fundep materialization + +trait FundepMaterialization[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +class FundepMaterializationBundle(val c: Context) { + import c.universe._ + import definitions._ + import Flag._ + + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag]: c.Expr[FundepMaterialization[T, U]] = { + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("FundepMaterialization")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[FundepMaterialization[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} + +object FundepMaterialization { + implicit def materializeIso[T, U]: FundepMaterialization[T, U] = macro FundepMaterializationBundle.impl[T, U] +} + +// whitebox use case #3: dynamic materialization + +trait DynamicMaterialization[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: DynamicMaterialization[T] = null +} + +object DynamicMaterialization extends LowPriority { + implicit def moreSpecific[T]: DynamicMaterialization[T] = macro DynamicMaterializationBundle.impl[T] +} + +class DynamicMaterializationBundle(val c: Context) { + import c.universe._ + def impl[T: c.WeakTypeTag] = { + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new DynamicMaterialization[$tpe]{ override def toString = ${tpe.toString} }" + } +} + +// whitebox use case #4: extractor macros + +object ExtractorMacro { + def unapply(x: Int): Any = macro ExtractorBundle.unapplyImpl +} + +class ExtractorBundle(val c: Context) { + import c.universe._ + def unapplyImpl(x: Tree) = { + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/macro-bundle-whitebox-use-raw/Test_2.scala b/tests/untried/neg/macro-bundle-whitebox-use-raw/Test_2.scala new file mode 100644 index 000000000000..995da737cc95 --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-raw/Test_2.scala @@ -0,0 +1,19 @@ +object Test extends App { + println(ReturnTypeRefinement.foo.x) + + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: FundepMaterialization[C, L]): L = iso.to(c) + locally { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } + + println(implicitly[DynamicMaterialization[C1]]) + println(implicitly[DynamicMaterialization[C2]]) + + 42 match { + case ExtractorMacro(x) => println(x) + } +} diff --git a/tests/untried/neg/macro-bundle-whitebox-use-refined.check b/tests/untried/neg/macro-bundle-whitebox-use-refined.check new file mode 100644 index 000000000000..5792e317a63a --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-refined.check @@ -0,0 +1,17 @@ +Test_2.scala:2: error: value x is not a member of Any + println(ReturnTypeRefinement.foo.x) + ^ +Test_2.scala:7: error: type mismatch; + found : FundepMaterialization[Test.Foo,(Int, String, Boolean)] + required: FundepMaterialization[Test.Foo,Nothing] +Note: (Int, String, Boolean) >: Nothing, but trait FundepMaterialization is invariant in type U. +You may wish to define U as -U instead. (SLS 4.5) + val equiv = foo(Foo(23, "foo", true)) + ^ +Test_2.scala:13: error: I don't like classes that contain integers + println(implicitly[DynamicMaterialization[C1]]) + ^ +Test_2.scala:17: error: extractor macros can only be whitebox + case ExtractorMacro(x) => println(x) + ^ +four errors found diff --git a/tests/untried/neg/macro-bundle-whitebox-use-refined/Macros_1.scala b/tests/untried/neg/macro-bundle-whitebox-use-refined/Macros_1.scala new file mode 100644 index 000000000000..186604422135 --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-refined/Macros_1.scala @@ -0,0 +1,108 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +// whitebox use case #1: return type refinement + +class ReturnTypeRefinementBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def impl = { + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } +} + +object ReturnTypeRefinement { + def foo: Any = macro ReturnTypeRefinementBundle.impl +} + +// whitebox use case #2: fundep materialization + +trait FundepMaterialization[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +class FundepMaterializationBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + import definitions._ + import Flag._ + + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag]: c.Expr[FundepMaterialization[T, U]] = { + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("FundepMaterialization")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[FundepMaterialization[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} + +object FundepMaterialization { + implicit def materializeIso[T, U]: FundepMaterialization[T, U] = macro FundepMaterializationBundle.impl[T, U] +} + +// whitebox use case #3: dynamic materialization + +trait DynamicMaterialization[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: DynamicMaterialization[T] = null +} + +object DynamicMaterialization extends LowPriority { + implicit def moreSpecific[T]: DynamicMaterialization[T] = macro DynamicMaterializationBundle.impl[T] +} + +class DynamicMaterializationBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def impl[T: c.WeakTypeTag] = { + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new DynamicMaterialization[$tpe]{ override def toString = ${tpe.toString} }" + } +} + +// whitebox use case #4: extractor macros + +object ExtractorMacro { + def unapply(x: Int): Any = macro ExtractorBundle.unapplyImpl +} + +class ExtractorBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def unapplyImpl(x: Tree) = { + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/macro-bundle-whitebox-use-refined/Test_2.scala b/tests/untried/neg/macro-bundle-whitebox-use-refined/Test_2.scala new file mode 100644 index 000000000000..995da737cc95 --- /dev/null +++ b/tests/untried/neg/macro-bundle-whitebox-use-refined/Test_2.scala @@ -0,0 +1,19 @@ +object Test extends App { + println(ReturnTypeRefinement.foo.x) + + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: FundepMaterialization[C, L]): L = iso.to(c) + locally { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } + + println(implicitly[DynamicMaterialization[C1]]) + println(implicitly[DynamicMaterialization[C2]]) + + 42 match { + case ExtractorMacro(x) => println(x) + } +} diff --git a/tests/untried/neg/macro-bundle-wrongcontext-a.check b/tests/untried/neg/macro-bundle-wrongcontext-a.check new file mode 100644 index 000000000000..10aadb00356e --- /dev/null +++ b/tests/untried/neg/macro-bundle-wrongcontext-a.check @@ -0,0 +1,4 @@ +macro-bundle-wrongcontext-a.scala:12: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def foo: Any = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-wrongcontext-a.scala b/tests/untried/neg/macro-bundle-wrongcontext-a.scala new file mode 100644 index 000000000000..0cfd433159a7 --- /dev/null +++ b/tests/untried/neg/macro-bundle-wrongcontext-a.scala @@ -0,0 +1,13 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +abstract class MyContext extends Context + +class Bundle(val c: MyContext) { + import c.universe._ + def impl = q"()" +} + +object Macros { + def foo: Any = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-bundle-wrongcontext-b.check b/tests/untried/neg/macro-bundle-wrongcontext-b.check new file mode 100644 index 000000000000..e9700d379ed9 --- /dev/null +++ b/tests/untried/neg/macro-bundle-wrongcontext-b.check @@ -0,0 +1,4 @@ +macro-bundle-wrongcontext-b.scala:10: error: macro bundles must be concrete monomorphic classes having a single constructor with a `val c: Context` parameter + def foo: Any = macro Bundle.impl + ^ +one error found diff --git a/tests/untried/neg/macro-bundle-wrongcontext-b.scala b/tests/untried/neg/macro-bundle-wrongcontext-b.scala new file mode 100644 index 000000000000..5f47e46e436b --- /dev/null +++ b/tests/untried/neg/macro-bundle-wrongcontext-b.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox._ +import scala.language.experimental.macros + +class Bundle(val c: Context { type Foo <: Int }) { + import c.universe._ + def impl = q"()" +} + +object Macros { + def foo: Any = macro Bundle.impl +} diff --git a/tests/untried/neg/macro-cyclic.check b/tests/untried/neg/macro-cyclic.check new file mode 100644 index 000000000000..7978ec64a56d --- /dev/null +++ b/tests/untried/neg/macro-cyclic.check @@ -0,0 +1,4 @@ +Impls_Macros_1.scala:5: error: could not find implicit value for parameter e: SourceLocation + c.universe.reify { implicitly[SourceLocation] } + ^ +one error found diff --git a/tests/untried/neg/macro-cyclic.flags b/tests/untried/neg/macro-cyclic.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-cyclic.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-cyclic/Impls_Macros_1.scala b/tests/untried/neg/macro-cyclic/Impls_Macros_1.scala new file mode 100644 index 000000000000..ad6890144d5a --- /dev/null +++ b/tests/untried/neg/macro-cyclic/Impls_Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = { + c.universe.reify { implicitly[SourceLocation] } + } + + implicit def sourceLocation: SourceLocation1 = macro impl +} + +trait SourceLocation { + /** Source location of the outermost call */ + val outer: SourceLocation + + /** The name of the source file */ + val fileName: String + + /** The line number */ + val line: Int + + /** The character offset */ + val charOffset: Int +} + +case class SourceLocation1(val outer: SourceLocation, val fileName: String, val line: Int, val charOffset: Int) extends SourceLocation diff --git a/tests/untried/neg/macro-deprecate-idents.check b/tests/untried/neg/macro-deprecate-idents.check new file mode 100644 index 000000000000..c5902aeea6ef --- /dev/null +++ b/tests/untried/neg/macro-deprecate-idents.check @@ -0,0 +1,67 @@ +macro-deprecate-idents.scala:2: error: macro is now a reserved word; usage as an identifier is disallowed + val macro = ??? + ^ +macro-deprecate-idents.scala:6: error: macro is now a reserved word; usage as an identifier is disallowed + var macro = ??? + ^ +macro-deprecate-idents.scala:10: error: macro is now a reserved word; usage as an identifier is disallowed + type macro = Int + ^ +macro-deprecate-idents.scala:14: error: macro is now a reserved word; usage as an identifier is disallowed + class macro + ^ +macro-deprecate-idents.scala:18: error: macro is now a reserved word; usage as an identifier is disallowed + class macro + ^ +macro-deprecate-idents.scala:22: error: macro is now a reserved word; usage as an identifier is disallowed + object macro + ^ +macro-deprecate-idents.scala:26: error: macro is now a reserved word; usage as an identifier is disallowed + object macro + ^ +macro-deprecate-idents.scala:30: error: macro is now a reserved word; usage as an identifier is disallowed + trait macro + ^ +macro-deprecate-idents.scala:34: error: macro is now a reserved word; usage as an identifier is disallowed + trait macro + ^ +macro-deprecate-idents.scala:37: error: macro is now a reserved word; usage as an identifier is disallowed +package macro { + ^ +macro-deprecate-idents.scala:38: error: macro is now a reserved word; usage as an identifier is disallowed + package macro.bar { + ^ +macro-deprecate-idents.scala:43: error: macro is now a reserved word; usage as an identifier is disallowed + package macro.foo { + ^ +macro-deprecate-idents.scala:48: error: macro is now a reserved word; usage as an identifier is disallowed + val Some(macro) = Some(42) + ^ +macro-deprecate-idents.scala:49: error: macro is now a reserved word; usage as an identifier is disallowed + macro match { + ^ +macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is disallowed + case macro => println(macro) + ^ +macro-deprecate-idents.scala:50: error: macro is now a reserved word; usage as an identifier is disallowed + case macro => println(macro) + ^ +macro-deprecate-idents.scala:55: error: macro is now a reserved word; usage as an identifier is disallowed + def macro = 2 + ^ +macro-deprecate-idents.scala:3: error: '=' expected but '}' found. +} +^ +macro-deprecate-idents.scala:7: error: '=' expected but '}' found. +} +^ +macro-deprecate-idents.scala:42: error: '{' expected but ';' found. +package foo { +^ +macro-deprecate-idents.scala:45: error: '{' expected but '}' found. +} +^ +macro-deprecate-idents.scala:52: error: ')' expected but '}' found. +} +^ +22 errors found diff --git a/tests/untried/neg/macro-deprecate-idents.flags b/tests/untried/neg/macro-deprecate-idents.flags new file mode 100644 index 000000000000..c6bfaf1f64a4 --- /dev/null +++ b/tests/untried/neg/macro-deprecate-idents.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/tests/untried/neg/macro-deprecate-idents.scala b/tests/untried/neg/macro-deprecate-idents.scala new file mode 100644 index 000000000000..eb418053bbcd --- /dev/null +++ b/tests/untried/neg/macro-deprecate-idents.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/neg/macro-divergence-controlled.check b/tests/untried/neg/macro-divergence-controlled.check new file mode 100644 index 000000000000..4876f7cf9653 --- /dev/null +++ b/tests/untried/neg/macro-divergence-controlled.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: could not find implicit value for parameter e: Complex[Foo] + println(implicitly[Complex[Foo]]) + ^ +one error found diff --git a/tests/untried/neg/macro-divergence-controlled/Impls_Macros_1.scala b/tests/untried/neg/macro-divergence-controlled/Impls_Macros_1.scala new file mode 100644 index 000000000000..5c0450326058 --- /dev/null +++ b/tests/untried/neg/macro-divergence-controlled/Impls_Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +trait Complex[T] + +class Foo(val foo: Foo) + +object Complex { + def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = { + import c.universe._ + val tpe = weakTypeOf[T] + for (f <- tpe.decls.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { + val trecur = appliedType(typeOf[Complex[_]], List(f.info)) + if (c.openImplicits.tail.exists(ic => ic.pt =:= trecur)) c.abort(c.enclosingPosition, "diverging implicit expansion. reported by a macro!") + val recur = c.inferImplicitValue(trecur, silent = true) + if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur") + } + c.Expr[Null](q"null") + } + + implicit object ComplexString extends Complex[String] + implicit def genComplex[T]: Complex[T] = macro impl[T] +} diff --git a/tests/untried/neg/macro-divergence-controlled/Test_2.scala b/tests/untried/neg/macro-divergence-controlled/Test_2.scala new file mode 100644 index 000000000000..e06175f306bc --- /dev/null +++ b/tests/untried/neg/macro-divergence-controlled/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + println(implicitly[Complex[Foo]]) +} diff --git a/tests/untried/neg/macro-exception.check b/tests/untried/neg/macro-exception.check new file mode 100644 index 000000000000..dca97aebce70 --- /dev/null +++ b/tests/untried/neg/macro-exception.check @@ -0,0 +1,7 @@ +Test_2.scala:2: error: exception during macro expansion: +java.lang.Exception + at Macros$.impl(Macros_1.scala:6) + + Macros.exception + ^ +one error found diff --git a/tests/untried/neg/macro-exception/Macros_1.scala b/tests/untried/neg/macro-exception/Macros_1.scala new file mode 100644 index 000000000000..cd8e3c844c35 --- /dev/null +++ b/tests/untried/neg/macro-exception/Macros_1.scala @@ -0,0 +1,9 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = { + throw new Exception() + } + def exception = macro impl +} diff --git a/tests/untried/neg/macro-exception/Test_2.scala b/tests/untried/neg/macro-exception/Test_2.scala new file mode 100644 index 000000000000..223ee32c9635 --- /dev/null +++ b/tests/untried/neg/macro-exception/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.exception +} diff --git a/tests/untried/neg/macro-false-deprecation-warning.check b/tests/untried/neg/macro-false-deprecation-warning.check new file mode 100644 index 000000000000..7d56505ec440 --- /dev/null +++ b/tests/untried/neg/macro-false-deprecation-warning.check @@ -0,0 +1,4 @@ +Impls_Macros_1.scala:5: error: illegal start of simple expression +} +^ +one error found diff --git a/tests/untried/neg/macro-false-deprecation-warning.flags b/tests/untried/neg/macro-false-deprecation-warning.flags new file mode 100644 index 000000000000..59af162db6fb --- /dev/null +++ b/tests/untried/neg/macro-false-deprecation-warning.flags @@ -0,0 +1 @@ +-language:experimental.macros -deprecation \ No newline at end of file diff --git a/tests/untried/neg/macro-false-deprecation-warning/Impls_Macros_1.scala b/tests/untried/neg/macro-false-deprecation-warning/Impls_Macros_1.scala new file mode 100644 index 000000000000..a97dfd4ddf11 --- /dev/null +++ b/tests/untried/neg/macro-false-deprecation-warning/Impls_Macros_1.scala @@ -0,0 +1,15 @@ +import scala.reflect.macros.blackbox.Context + +object Helper { + def unapplySeq[T](x: List[T]): Option[Seq[T]] = +} + +object Macros { + def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[List[T]]) = { + c.universe.reify(Helper.unapplySeq(x.splice)) + } + + object UnapplyMacro { + def unapplySeq[T](x: List[T]): Option[Seq[T]] = macro impl[T] + } +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a.check b/tests/untried/neg/macro-incompatible-macro-engine-a.check new file mode 100644 index 000000000000..8ae08bd16415 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a.check @@ -0,0 +1,7 @@ +Test_3.scala:2: error: macro cannot be expanded, because it was compiled by an incompatible macro engine + Macros.foo + ^ +Test_3.scala:3: error: macro cannot be expanded, because it was compiled by an incompatible macro engine + Macros.foo + ^ +two errors found diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.flags b/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.flags new file mode 100644 index 000000000000..966df731d030 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.flags @@ -0,0 +1 @@ +-Xplugin:. \ No newline at end of file diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.scala b/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.scala new file mode 100644 index 000000000000..5b0c1faec774 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a/Macros_2.scala @@ -0,0 +1,7 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = c.universe.Literal(c.universe.Constant(())) + def foo: Unit = macro impl +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a/Plugin_1.scala b/tests/untried/neg/macro-incompatible-macro-engine-a/Plugin_1.scala new file mode 100644 index 000000000000..8e727dae6989 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a/Plugin_1.scala @@ -0,0 +1,35 @@ +package incompatibleMacroEngine + +import scala.tools.nsc.Global +import scala.tools.nsc.plugins.{Plugin => NscPlugin} + +class Plugin(val global: Global) extends NscPlugin { + import global._ + import analyzer._ + + val name = "incompatibleMacroEngine" + val description = "A sample analyzer plugin that crafts a macro impl binding with a non-standard macro engine." + val components = Nil + addMacroPlugin(MacroPlugin) + + object MacroPlugin extends MacroPlugin { + def fixupBinding(tree: Tree) = new Transformer { + override def transform(tree: Tree) = { + tree match { + case Literal(const @ Constant(x)) if tree.tpe == null => tree setType ConstantType(const) + case _ if tree.tpe == null => tree setType NoType + case _ => ; + } + super.transform(tree) + } + }.transform(tree) + + override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = { + val result = standardTypedMacroBody(typer, ddef) + val List(AnnotationInfo(atp, List(Apply(nucleus, _ :: others)), Nil)) = ddef.symbol.annotations + val updatedBinding = Apply(nucleus, Assign(Literal(Constant("macroEngine")), Literal(Constant("vxxx (implemented in the incompatibleMacroEngine plugin)"))) :: others) + ddef.symbol.setAnnotations(List(AnnotationInfo(atp, List(fixupBinding(updatedBinding)), Nil))) + Some(result) + } + } +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a/Test_3.scala b/tests/untried/neg/macro-incompatible-macro-engine-a/Test_3.scala new file mode 100644 index 000000000000..4b6836e516d7 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a/Test_3.scala @@ -0,0 +1,4 @@ +object Test extends App { + Macros.foo + Macros.foo +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-a/scalac-plugin.xml b/tests/untried/neg/macro-incompatible-macro-engine-a/scalac-plugin.xml new file mode 100644 index 000000000000..42b9cdd75dab --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-a/scalac-plugin.xml @@ -0,0 +1,4 @@ + + incompatible-macro-engine + incompatibleMacroEngine.Plugin + \ No newline at end of file diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b.check b/tests/untried/neg/macro-incompatible-macro-engine-b.check new file mode 100644 index 000000000000..2a7510cf865d --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b.check @@ -0,0 +1,7 @@ +Test_3.scala:2: error: macro cannot be expanded, because it was compiled by an incompatible macro engine (internal diagnostic: expected = v7.0 (implemented in Scala 2.11.0-M8), actual = vxxx (implemented in the incompatibleMacroEngine plugin)) + Macros.foo + ^ +Test_3.scala:3: error: macro cannot be expanded, because it was compiled by an incompatible macro engine (internal diagnostic: expected = v7.0 (implemented in Scala 2.11.0-M8), actual = vxxx (implemented in the incompatibleMacroEngine plugin)) + Macros.foo + ^ +two errors found diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b.flags b/tests/untried/neg/macro-incompatible-macro-engine-b.flags new file mode 100644 index 000000000000..037a693bbd81 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b.flags @@ -0,0 +1 @@ +-Ymacro-debug-lite \ No newline at end of file diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.flags b/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.flags new file mode 100644 index 000000000000..966df731d030 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.flags @@ -0,0 +1 @@ +-Xplugin:. \ No newline at end of file diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.scala b/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.scala new file mode 100644 index 000000000000..5b0c1faec774 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b/Macros_2.scala @@ -0,0 +1,7 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = c.universe.Literal(c.universe.Constant(())) + def foo: Unit = macro impl +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b/Plugin_1.scala b/tests/untried/neg/macro-incompatible-macro-engine-b/Plugin_1.scala new file mode 100644 index 000000000000..8e727dae6989 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b/Plugin_1.scala @@ -0,0 +1,35 @@ +package incompatibleMacroEngine + +import scala.tools.nsc.Global +import scala.tools.nsc.plugins.{Plugin => NscPlugin} + +class Plugin(val global: Global) extends NscPlugin { + import global._ + import analyzer._ + + val name = "incompatibleMacroEngine" + val description = "A sample analyzer plugin that crafts a macro impl binding with a non-standard macro engine." + val components = Nil + addMacroPlugin(MacroPlugin) + + object MacroPlugin extends MacroPlugin { + def fixupBinding(tree: Tree) = new Transformer { + override def transform(tree: Tree) = { + tree match { + case Literal(const @ Constant(x)) if tree.tpe == null => tree setType ConstantType(const) + case _ if tree.tpe == null => tree setType NoType + case _ => ; + } + super.transform(tree) + } + }.transform(tree) + + override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = { + val result = standardTypedMacroBody(typer, ddef) + val List(AnnotationInfo(atp, List(Apply(nucleus, _ :: others)), Nil)) = ddef.symbol.annotations + val updatedBinding = Apply(nucleus, Assign(Literal(Constant("macroEngine")), Literal(Constant("vxxx (implemented in the incompatibleMacroEngine plugin)"))) :: others) + ddef.symbol.setAnnotations(List(AnnotationInfo(atp, List(fixupBinding(updatedBinding)), Nil))) + Some(result) + } + } +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b/Test_3.scala b/tests/untried/neg/macro-incompatible-macro-engine-b/Test_3.scala new file mode 100644 index 000000000000..4b6836e516d7 --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b/Test_3.scala @@ -0,0 +1,4 @@ +object Test extends App { + Macros.foo + Macros.foo +} diff --git a/tests/untried/neg/macro-incompatible-macro-engine-b/scalac-plugin.xml b/tests/untried/neg/macro-incompatible-macro-engine-b/scalac-plugin.xml new file mode 100644 index 000000000000..42b9cdd75dab --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-b/scalac-plugin.xml @@ -0,0 +1,4 @@ + + incompatible-macro-engine + incompatibleMacroEngine.Plugin + \ No newline at end of file diff --git a/tests/untried/neg/macro-incompatible-macro-engine-c.check b/tests/untried/neg/macro-incompatible-macro-engine-c.check new file mode 100644 index 000000000000..fb6c59ab7c7e --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-c.check @@ -0,0 +1,4 @@ +macro-incompatible-macro-engine-c.scala:2: error: can't expand macros compiled by previous versions of Scala + MacroLibCompiledByScala210x.foo + ^ +one error found diff --git a/tests/untried/neg/macro-incompatible-macro-engine-c.scala b/tests/untried/neg/macro-incompatible-macro-engine-c.scala new file mode 100644 index 000000000000..75ada5da387c --- /dev/null +++ b/tests/untried/neg/macro-incompatible-macro-engine-c.scala @@ -0,0 +1,3 @@ +object Test extends App { + MacroLibCompiledByScala210x.foo +} diff --git a/tests/untried/neg/macro-invalidimpl.check b/tests/untried/neg/macro-invalidimpl.check new file mode 100644 index 000000000000..ea7d71c667dc --- /dev/null +++ b/tests/untried/neg/macro-invalidimpl.check @@ -0,0 +1,53 @@ +Macros_Test_2.scala:5: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo(x: Any) = macro impls.foo + ^ +Macros_Test_2.scala:10: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo(x: Any) = macro impls.foo + ^ +Macros_Test_2.scala:18: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo(x: Any) = macro Impls3.foo + ^ +Macros_Test_2.scala:22: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo(x: Any) = macro Impls4.foo + ^ +Macros_Test_2.scala:26: error: ambiguous reference to overloaded definition, +both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any])Nothing +match expected type ? + def foo(x: Any) = macro Impls5.foo + ^ +Macros_Test_2.scala:27: error: ambiguous reference to overloaded definition, +both method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any], y: c.Expr[Any])Nothing +and method foo in object Impls5 of type (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any])Nothing +match expected type ? + def foo(x: Any, y: Any) = macro Impls5.foo + ^ +Macros_Test_2.scala:31: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Unit] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(): c.Expr[Unit] +number of parameter sections differ + def foo1 = macro Impls6.fooEmpty + ^ +Macros_Test_2.scala:32: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(): c.Expr[Unit] + or : (c: scala.reflect.macros.blackbox.Context)(): c.Tree + found : (c: scala.reflect.macros.blackbox.Context): c.Expr[Unit] +number of parameter sections differ + def bar1() = macro Impls6.fooNullary + ^ +Macros_Test_2.scala:36: error: type arguments [String] do not conform to method foo's type parameter bounds [U <: Int] + def foo = macro Impls7.foo[String] + ^ +Macros_Test_2.scala:53: error: macro implementation must be public + def foo = macro Impls8.impl + ^ +10 errors found diff --git a/tests/untried/neg/macro-invalidimpl.flags b/tests/untried/neg/macro-invalidimpl.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidimpl.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidimpl/Impls_1.scala b/tests/untried/neg/macro-invalidimpl/Impls_1.scala new file mode 100644 index 000000000000..862c93b5e81b --- /dev/null +++ b/tests/untried/neg/macro-invalidimpl/Impls_1.scala @@ -0,0 +1,39 @@ +import scala.reflect.macros.blackbox.Context + +class Impls1 { + def foo(c: Context)(x: c.Expr[Any]) = ??? +} + +object Impls2 { + def foo(c: Context)(x: c.Expr[Any]) = ??? +} + +trait MacroHelpers { + object Impls4 { + def foo(c: Context)(x: c.Expr[Any]) = x + } +} + +object Impls5 { + def foo(c: Context)(x: c.Expr[Any]) = ??? + def foo(c: Context)(x: c.Expr[Any], y: c.Expr[Any]) = ??? +} + +object Impls6 { + def fooNullary(c: Context) = { + import c.universe._ + c.Expr[Unit](q"""Predef.println("it works")""") + } + + def fooEmpty(c: Context)() = fooNullary(c) +} + +object Impls7 { + def foo[U <: Int](c: Context) = ??? +} + +package foo { + object Impls8 { + private[foo] def impl(c: Context) = ??? + } +} diff --git a/tests/untried/neg/macro-invalidimpl/Macros_Test_2.scala b/tests/untried/neg/macro-invalidimpl/Macros_Test_2.scala new file mode 100644 index 000000000000..44d665ea2671 --- /dev/null +++ b/tests/untried/neg/macro-invalidimpl/Macros_Test_2.scala @@ -0,0 +1,55 @@ +import scala.reflect.macros.blackbox.Context + +object Macros1 { + val impls = new Impls1 + def foo(x: Any) = macro impls.foo +} + +object Macros2 { + val impls = Impls2 + def foo(x: Any) = macro impls.foo +} + +class Macros3 { + object Impls3 { + def foo(c: Context)(x: c.Expr[Any]) = ??? + } + + def foo(x: Any) = macro Impls3.foo +} + +class Macros4 extends MacroHelpers { + def foo(x: Any) = macro Impls4.foo +} + +object Macros5 { + def foo(x: Any) = macro Impls5.foo + def foo(x: Any, y: Any) = macro Impls5.foo +} + +object Macros6 { + def foo1 = macro Impls6.fooEmpty + def bar1() = macro Impls6.fooNullary +} + +object Macros7 { + def foo = macro Impls7.foo[String] +} + +object Test extends App { + println(Macros1.foo(42)) + println(Macros2.foo(42)) + println(new Macros3().foo(42)) + println(new Macros4().foo(42)) + println(Macros5.foo(42)) + println(Macros6.foo1) + println(Macros6.bar1) + println(Macros6.bar1()) + println(Macros7.foo) +} + +package foo { + object Test extends App { + def foo = macro Impls8.impl + } +} diff --git a/tests/untried/neg/macro-invalidret.check b/tests/untried/neg/macro-invalidret.check new file mode 100644 index 000000000000..568cc7c570db --- /dev/null +++ b/tests/untried/neg/macro-invalidret.check @@ -0,0 +1,35 @@ +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Any] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (c: scala.reflect.macros.blackbox.Context): Int +type mismatch for return type: Int does not conform to c.Expr[Any] + def foo1 = macro Impls.foo1 + ^ +Macros_Test_2.scala:3: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Any] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (c: scala.reflect.macros.blackbox.Context): reflect.runtime.universe.Literal +type mismatch for return type: reflect.runtime.universe.Literal does not conform to c.Expr[Any] + def foo2 = macro Impls.foo2 + ^ +Macros_Test_2.scala:6: error: macro defs must have explicitly specified return types + def foo5 = macro Impls.foo5 + ^ +Macros_Test_2.scala:7: warning: macro defs must have explicitly specified return types (inference of Int from macro impl's c.Expr[Int] is deprecated and is going to stop working in 2.12) + def foo6 = macro Impls.foo6 + ^ +Macros_Test_2.scala:14: error: exception during macro expansion: +scala.NotImplementedError: an implementation is missing + at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225) + at Impls$.foo3(Impls_1.scala:7) + + foo3 + ^ +Macros_Test_2.scala:15: error: macro implementation is missing + foo4 + ^ +Macros_Test_2.scala:17: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + foo6 + ^ +two warnings found +5 errors found diff --git a/tests/untried/neg/macro-invalidret.flags b/tests/untried/neg/macro-invalidret.flags new file mode 100644 index 000000000000..946c53ec0e00 --- /dev/null +++ b/tests/untried/neg/macro-invalidret.flags @@ -0,0 +1,3 @@ +-language:experimental.macros +-Xfatal-warnings +-deprecation \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidret/Impls_1.scala b/tests/untried/neg/macro-invalidret/Impls_1.scala new file mode 100644 index 000000000000..434aeef10f00 --- /dev/null +++ b/tests/untried/neg/macro-invalidret/Impls_1.scala @@ -0,0 +1,10 @@ +import scala.reflect.macros.blackbox.Context +import scala.reflect.runtime.{universe => ru} + +object Impls { + def foo1(c: Context) = 2 + def foo2(c: Context) = ru.Literal(ru.Constant(42)) + def foo3(c: Context) = ??? + def foo5(c: Context) = c.universe.Literal(c.universe.Constant(42)) + def foo6(c: Context) = c.Expr[Int](c.universe.Literal(c.universe.Constant(42))) +} diff --git a/tests/untried/neg/macro-invalidret/Macros_Test_2.scala b/tests/untried/neg/macro-invalidret/Macros_Test_2.scala new file mode 100644 index 000000000000..69c9346e02b6 --- /dev/null +++ b/tests/untried/neg/macro-invalidret/Macros_Test_2.scala @@ -0,0 +1,18 @@ +object Macros { + def foo1 = macro Impls.foo1 + def foo2 = macro Impls.foo2 + def foo3 = macro Impls.foo3 + def foo4 = macro ??? + def foo5 = macro Impls.foo5 + def foo6 = macro Impls.foo6 +} + +object Test extends App { + import Macros._ + foo1 + foo2 + foo3 + foo4 + foo5 + foo6 +} diff --git a/tests/untried/neg/macro-invalidshape.check b/tests/untried/neg/macro-invalidshape.check new file mode 100644 index 000000000000..aa694df6d63b --- /dev/null +++ b/tests/untried/neg/macro-invalidshape.check @@ -0,0 +1,20 @@ +Macros_Test_2.scala:2: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo1(x: Any) = macro 2 + ^ +Macros_Test_2.scala:3: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo2(x: Any) = macro Impls.foo(null)(null) + ^ +Macros_Test_2.scala:4: error: missing arguments for method foo in object Impls; +follow this method with `_' if you want to treat it as a partially applied function + def foo3(x: Any) = macro {2; Impls.foo} + ^ +Macros_Test_2.scala:7: error: macro implementation reference has wrong shape. required: +macro [].[[]] or +macro [].[[]] + def foo = macro impl + ^ +four errors found diff --git a/tests/untried/neg/macro-invalidshape.flags b/tests/untried/neg/macro-invalidshape.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidshape.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidshape/Impls_1.scala b/tests/untried/neg/macro-invalidshape/Impls_1.scala new file mode 100644 index 000000000000..acc6b52b7bf0 --- /dev/null +++ b/tests/untried/neg/macro-invalidshape/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Any]) = ??? +} diff --git a/tests/untried/neg/macro-invalidshape/Macros_Test_2.scala b/tests/untried/neg/macro-invalidshape/Macros_Test_2.scala new file mode 100644 index 000000000000..aaeb34253bfd --- /dev/null +++ b/tests/untried/neg/macro-invalidshape/Macros_Test_2.scala @@ -0,0 +1,17 @@ +object Macros { + def foo1(x: Any) = macro 2 + def foo2(x: Any) = macro Impls.foo(null)(null) + def foo3(x: Any) = macro {2; Impls.foo} + { + def impl(c: scala.reflect.macros.blackbox.Context) = { import c.universe._; c.Expr[Unit](q"()") } + def foo = macro impl + foo + } +} + +object Test extends App { + import Macros._ + foo1(42) + foo2(42) + foo3(42) +} diff --git a/tests/untried/neg/macro-invalidsig-params-badtype.check b/tests/untried/neg/macro-invalidsig-params-badtype.check new file mode 100644 index 000000000000..159754c72e2d --- /dev/null +++ b/tests/untried/neg/macro-invalidsig-params-badtype.check @@ -0,0 +1,8 @@ +Impls_Macros_1.scala:8: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(x: Int): Nothing +type mismatch for parameter x: c.Expr[Int] does not conform to Int + def foo(x: Int) = macro Impls.foo + ^ +one error found diff --git a/tests/untried/neg/macro-invalidsig-params-badtype.flags b/tests/untried/neg/macro-invalidsig-params-badtype.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidsig-params-badtype.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala b/tests/untried/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala new file mode 100644 index 000000000000..e549cc9576e8 --- /dev/null +++ b/tests/untried/neg/macro-invalidsig-params-badtype/Impls_Macros_1.scala @@ -0,0 +1,9 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: Int) = ??? +} + +object Macros { + def foo(x: Int) = macro Impls.foo +} diff --git a/tests/untried/neg/macro-invalidsig.check b/tests/untried/neg/macro-invalidsig.check new file mode 100644 index 000000000000..8898ffc3de61 --- /dev/null +++ b/tests/untried/neg/macro-invalidsig.check @@ -0,0 +1,85 @@ +Macros_Test_2.scala:2: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences + def foo[U]: Int = macro Impls1.foo[U] + ^ +Macros_Test_2.scala:6: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : : Nothing +number of parameter sections differ + def foo = macro Impls2.foo + ^ +Macros_Test_2.scala:10: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (c: scala.reflect.api.Universe): Nothing +type mismatch for parameter c: scala.reflect.macros.blackbox.Context does not conform to scala.reflect.api.Universe + def foo = macro Impls3.foo + ^ +Macros_Test_2.scala:14: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (cs: scala.reflect.macros.blackbox.Context*): Nothing +types incompatible for parameter cs: corresponding is not a vararg parameter + def foo = macro Impls4.foo + ^ +Macros_Test_2.scala:18: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Any]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context): Nothing +number of parameter sections differ + def foo(x: Any) = macro Impls5.foo + ^ +Macros_Test_2.scala:22: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences + def foo[U](x: Int) = macro Impls6.foo[T, U] + ^ +Macros_Test_2.scala:26: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int], y: c.Expr[Int]): Nothing +parameter lists have different length, found extra parameter y: c.Expr[Int] + def foo(x: Int) = macro Impls7.foo + ^ +Macros_Test_2.scala:30: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(x: c.universe.Symbol): Nothing +type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Symbol + def foo(x: Int) = macro Impls8.foo + ^ +Macros_Test_2.scala:34: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree, y: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(xs: c.Expr[Int]*): Nothing +parameter lists have different length, required extra parameter y: c.Expr[Int] + def foo(x: Int, y: Int) = macro Impls9.foo + ^ +Macros_Test_2.scala:38: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context)(x: c.Tree, y: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(y: c.Expr[Int], x: c.Expr[Int]): Nothing +parameter names differ: x != y + def foo(x: Int, y: Int) = macro Impls10.foo + ^ +Macros_Test_2.scala:42: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context): c.Expr[Nothing] + or : (c: scala.reflect.macros.blackbox.Context): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(U: c.universe.Type): Nothing +number of parameter sections differ + def foo[U] = macro Impls11.foo[U] + ^ +Macros_Test_2.scala:46: error: type arguments [U] do not conform to method foo's type parameter bounds [U <: String] + def foo[U] = macro Impls12.foo[U] + ^ +Macros_Test_2.scala:50: error: type arguments [U] do not conform to method foo's type parameter bounds [U <: String] + def foo[U <: Int] = macro Impls13.foo[U] + ^ +Macros_Test_2.scala:54: error: macro implementation reference has too few type arguments for method foo: [U](c: scala.reflect.macros.blackbox.Context)(implicit evidence$4: c.WeakTypeTag[U])Nothing + def foo = macro Impls14.foo + ^ +Macros_Test_2.scala:59: error: macro implementation reference has too few type arguments for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$5: c.WeakTypeTag[T], implicit evidence$6: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] + def foo15[V]: Unit = macro Impls15.foo + ^ +Macros_Test_2.scala:60: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.blackbox.Context)(implicit evidence$7: c.WeakTypeTag[T], implicit evidence$8: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] + def foo16[V]: Unit = macro Impls16.foo[V] + ^ +16 errors found diff --git a/tests/untried/neg/macro-invalidsig.flags b/tests/untried/neg/macro-invalidsig.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidsig.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidsig/Impls_1.scala b/tests/untried/neg/macro-invalidsig/Impls_1.scala new file mode 100644 index 000000000000..2816c4ddfb4c --- /dev/null +++ b/tests/untried/neg/macro-invalidsig/Impls_1.scala @@ -0,0 +1,86 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.macros.blackbox.Context + +object Impls1 { + def foo[U: c.WeakTypeTag: Numeric](c: Context) = { import c.universe._; q"42" } +} + +object Impls2 { + def foo = ??? +} + +object Impls3 { + def foo(c: scala.reflect.api.Universe) = ??? +} + +object Impls4 { + def foo(cs: Context*) = ??? +} + +object Impls5 { + def foo(c: Context) = ??? +} + +object Impls6 { + def foo[T, U: c.WeakTypeTag](c: Context)(implicit x: c.Expr[Int]) = { + import c.{prefix => prefix} + import c.universe._ + c.Expr[Unit](q""" + println("invoking foo_targs...") + println("type of prefix is: " + ${prefix.staticType.toString}) + println("U is: " + ${implicitly[c.WeakTypeTag[U]].tpe.toString}) + """) + } +} + +object Impls7 { + def foo(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = ??? +} + +object Impls8 { + def foo(c: Context)(x: c.universe.Symbol) = ??? +} + +object Impls9 { + def foo(c: Context)(xs: c.Expr[Int]*) = ??? +} + +object Impls10 { + def foo(c: Context)(y: c.Expr[Int], x: c.Expr[Int]) = ??? +} + +object Impls11 { + def foo[U](c: Context)(U: c.universe.Type) = ??? +} + +object Impls12 { + def foo[U <: String](c: Context) = ??? +} + +object Impls13 { + def foo[U <: String](c: Context) = ??? +} + +object Impls14 { + def foo[U: c.WeakTypeTag](c: Context) = ??? +} + +object Impls15 { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ + println(implicitly[c.WeakTypeTag[T]]) + println(implicitly[c.WeakTypeTag[U]]) + println(V) + c.Expr[Unit](q"()") + } +} + +object Impls16 { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ + println(implicitly[c.WeakTypeTag[T]]) + println(implicitly[c.WeakTypeTag[U]]) + println(V) + c.Expr[Unit](q"()") + } +} diff --git a/tests/untried/neg/macro-invalidsig/Macros_Test_2.scala b/tests/untried/neg/macro-invalidsig/Macros_Test_2.scala new file mode 100644 index 000000000000..d662a029e19e --- /dev/null +++ b/tests/untried/neg/macro-invalidsig/Macros_Test_2.scala @@ -0,0 +1,83 @@ +object Macros1 { + def foo[U]: Int = macro Impls1.foo[U] +} + +object Macros2 { + def foo = macro Impls2.foo +} + +object Macros3 { + def foo = macro Impls3.foo +} + +object Macros4 { + def foo = macro Impls4.foo +} + +object Macros5 { + def foo(x: Any) = macro Impls5.foo +} + +class Macros6[T] { + def foo[U](x: Int) = macro Impls6.foo[T, U] +} + +object Macros7 { + def foo(x: Int) = macro Impls7.foo +} + +object Macros8 { + def foo(x: Int) = macro Impls8.foo +} + +object Macros9 { + def foo(x: Int, y: Int) = macro Impls9.foo +} + +object Macros10 { + def foo(x: Int, y: Int) = macro Impls10.foo +} + +object Macros11 { + def foo[U] = macro Impls11.foo[U] +} + +object Macros12 { + def foo[U] = macro Impls12.foo[U] +} + +object Macros13 { + def foo[U <: Int] = macro Impls13.foo[U] +} + +object Macros14 { + def foo = macro Impls14.foo +} + +class D[T] { + class C[U] { + def foo15[V]: Unit = macro Impls15.foo + def foo16[V]: Unit = macro Impls16.foo[V] + } +} + +object Test extends App { + println(Macros1.foo[String]) + println(Macros2.foo) + println(Macros3.foo) + println(Macros4.foo) + println(Macros5.foo(42)) + println(new Macros6[Int]().foo[String](42)) + println(Macros7.foo(42)) + println(Macros8.foo) + println(Macros9.foo(4, 2)) + println(Macros10.foo(4, 2)) + println(Macros11.foo[Int]) + println(Macros12.foo[Int]) + println(Macros13.foo[Int]) + println(Macros14.foo) + val outer1 = new D[Int] + val outer2 = new outer1.C[String] + outer2.foo15[Boolean] + outer2.foo16[Boolean] +} diff --git a/tests/untried/neg/macro-invalidusage-badargs.check b/tests/untried/neg/macro-invalidusage-badargs.check new file mode 100644 index 000000000000..4c1115418b57 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badargs.check @@ -0,0 +1,18 @@ +Macros_Test_2.scala:5: error: type mismatch; + found : String("42") + required: Int + foo("42") + ^ +Macros_Test_2.scala:6: error: too few argument lists for macro invocation + foo + ^ +Macros_Test_2.scala:7: error: Int does not take parameters + foo(4)(2) + ^ +Macros_Test_2.scala:8: error: macro applications do not support named and/or default arguments + foo() + ^ +Macros_Test_2.scala:9: error: too many arguments for macro method foo: (x: Int)Int + foo(4, 2) + ^ +5 errors found diff --git a/tests/untried/neg/macro-invalidusage-badargs.flags b/tests/untried/neg/macro-invalidusage-badargs.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badargs.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-badargs/Impls_1.scala b/tests/untried/neg/macro-invalidusage-badargs/Impls_1.scala new file mode 100644 index 000000000000..8765cfbd5f2c --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badargs/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Int]) = x +} diff --git a/tests/untried/neg/macro-invalidusage-badargs/Macros_Test_2.scala b/tests/untried/neg/macro-invalidusage-badargs/Macros_Test_2.scala new file mode 100644 index 000000000000..05ba98730920 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badargs/Macros_Test_2.scala @@ -0,0 +1,10 @@ +object Macros { def foo(x: Int): Int = macro Impls.foo } +import Macros._ + +object Test extends App { + foo("42") + foo + foo(4)(2) + foo() + foo(4, 2) +} diff --git a/tests/untried/neg/macro-invalidusage-badbounds.check b/tests/untried/neg/macro-invalidusage-badbounds.check new file mode 100644 index 000000000000..277f407d3833 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badbounds.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:7: error: type arguments [Int] do not conform to macro method foo's type parameter bounds [U <: String] + foo[Int] + ^ +one error found diff --git a/tests/untried/neg/macro-invalidusage-badbounds.flags b/tests/untried/neg/macro-invalidusage-badbounds.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badbounds.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-badbounds/Impls_1.scala b/tests/untried/neg/macro-invalidusage-badbounds/Impls_1.scala new file mode 100644 index 000000000000..1769da91e1eb --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badbounds/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo[U <: String](c: Context) = { import c.universe._; c.Expr[Unit](q"()") } +} diff --git a/tests/untried/neg/macro-invalidusage-badbounds/Macros_Test_2.scala b/tests/untried/neg/macro-invalidusage-badbounds/Macros_Test_2.scala new file mode 100644 index 000000000000..546bc7accedf --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badbounds/Macros_Test_2.scala @@ -0,0 +1,8 @@ +object Macros { + def foo[U <: String]: Unit = macro Impls.foo[U] +} + +object Test extends App { + import Macros._ + foo[Int] +} diff --git a/tests/untried/neg/macro-invalidusage-badtargs.check b/tests/untried/neg/macro-invalidusage-badtargs.check new file mode 100644 index 000000000000..722ec03765c8 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badtargs.check @@ -0,0 +1,18 @@ +Macros_Test_2.scala:13: error: macro method foo1: (x: Int)Int does not take type parameters. + foo1[String](42) + ^ +Macros_Test_2.scala:14: error: wrong number of type parameters for macro method foo2: [T](x: Int)Int + foo2[String, String](42) + ^ +Macros_Test_2.scala:15: error: wrong number of type parameters for macro method foo3: [T, U](x: Int)Int + foo3[String](42) + ^ +Macros_Test_2.scala:16: error: String takes no type parameters, expected: one + foo4[String](42) + ^ +Macros_Test_2.scala:17: error: kinds of the type arguments (List) do not conform to the expected kinds of the type parameters (type T). +List's type parameters do not match type T's expected parameters: +type A has no type parameters, but type U has one + foo5[List](42) + ^ +5 errors found diff --git a/tests/untried/neg/macro-invalidusage-badtargs.flags b/tests/untried/neg/macro-invalidusage-badtargs.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badtargs.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-badtargs/Impls_1.scala b/tests/untried/neg/macro-invalidusage-badtargs/Impls_1.scala new file mode 100644 index 000000000000..8765cfbd5f2c --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badtargs/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Int]) = x +} diff --git a/tests/untried/neg/macro-invalidusage-badtargs/Macros_Test_2.scala b/tests/untried/neg/macro-invalidusage-badtargs/Macros_Test_2.scala new file mode 100644 index 000000000000..be61c4e8e862 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-badtargs/Macros_Test_2.scala @@ -0,0 +1,18 @@ +import scala.language.higherKinds + +object Macros { + def foo1(x: Int): Int = macro Impls.foo + def foo2[T](x: Int): Int = macro Impls.foo + def foo3[T, U](x: Int): Int = macro Impls.foo + def foo4[T[_]](x: Int): Int = macro Impls.foo + def foo5[T[U[_]]](x: Int): Int = macro Impls.foo +} + +object Test extends App { + import Macros._ + foo1[String](42) + foo2[String, String](42) + foo3[String](42) + foo4[String](42) + foo5[List](42) +} diff --git a/tests/untried/neg/macro-invalidusage-methodvaluesyntax.check b/tests/untried/neg/macro-invalidusage-methodvaluesyntax.check new file mode 100644 index 000000000000..10046b230563 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-methodvaluesyntax.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:6: error: macros cannot be eta-expanded + val firstClassFoo = Macros.foo _ + ^ +one error found diff --git a/tests/untried/neg/macro-invalidusage-methodvaluesyntax.flags b/tests/untried/neg/macro-invalidusage-methodvaluesyntax.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-methodvaluesyntax.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala b/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala new file mode 100644 index 000000000000..5cf284750bf4 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Impls_1.scala @@ -0,0 +1,8 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context) = { + import c.universe._ + c.Expr[Unit](q"""println("it works")""") + } +} diff --git a/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Macros_Test_2.scala b/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Macros_Test_2.scala new file mode 100644 index 000000000000..83bc8dbfe0d2 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-methodvaluesyntax/Macros_Test_2.scala @@ -0,0 +1,8 @@ +object Macros { + def foo: Unit = macro Impls.foo +} + +object Test extends App { + val firstClassFoo = Macros.foo _ + firstClassFoo +} diff --git a/tests/untried/neg/macro-invalidusage-nontypeable.check b/tests/untried/neg/macro-invalidusage-nontypeable.check new file mode 100644 index 000000000000..88e6057e5e66 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-nontypeable.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: not found: value IDoNotExist + Macros.foo + ^ +one error found diff --git a/tests/untried/neg/macro-invalidusage-nontypeable.flags b/tests/untried/neg/macro-invalidusage-nontypeable.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-nontypeable.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala b/tests/untried/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala new file mode 100644 index 000000000000..76d696bf1dd0 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-nontypeable/Impls_Macros_1.scala @@ -0,0 +1,13 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context) = { + import c.universe._ + val body = Ident(TermName("IDoNotExist")) + c.Expr[Int](body) + } +} + +object Macros { + def foo = macro Impls.foo +} diff --git a/tests/untried/neg/macro-invalidusage-nontypeable/Test_2.scala b/tests/untried/neg/macro-invalidusage-nontypeable/Test_2.scala new file mode 100644 index 000000000000..5d19639cddff --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-nontypeable/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.foo +} diff --git a/tests/untried/neg/macro-invalidusage-presuper.check b/tests/untried/neg/macro-invalidusage-presuper.check new file mode 100644 index 000000000000..c0b1ec024805 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-presuper.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:3: error: only concrete field definitions allowed in early object initialization section +class D extends { def x = macro impl } with AnyRef + ^ +one error found diff --git a/tests/untried/neg/macro-invalidusage-presuper.flags b/tests/untried/neg/macro-invalidusage-presuper.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-presuper.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-presuper/Impls_1.scala b/tests/untried/neg/macro-invalidusage-presuper/Impls_1.scala new file mode 100644 index 000000000000..ea98f01fa455 --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-presuper/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def impl(c: Context) = { import c.universe._; c.Expr[Unit](q"()") } +} \ No newline at end of file diff --git a/tests/untried/neg/macro-invalidusage-presuper/Macros_Test_2.scala b/tests/untried/neg/macro-invalidusage-presuper/Macros_Test_2.scala new file mode 100644 index 000000000000..ff46a5915fdb --- /dev/null +++ b/tests/untried/neg/macro-invalidusage-presuper/Macros_Test_2.scala @@ -0,0 +1,3 @@ +import Impls._ + +class D extends { def x = macro impl } with AnyRef \ No newline at end of file diff --git a/tests/untried/neg/macro-noexpand.check b/tests/untried/neg/macro-noexpand.check new file mode 100644 index 000000000000..2c176a99bec0 --- /dev/null +++ b/tests/untried/neg/macro-noexpand.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:7: error: not found: value x + foo(x) + ^ +one error found diff --git a/tests/untried/neg/macro-noexpand.flags b/tests/untried/neg/macro-noexpand.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-noexpand.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-noexpand/Impls_1.scala b/tests/untried/neg/macro-noexpand/Impls_1.scala new file mode 100644 index 000000000000..acc6b52b7bf0 --- /dev/null +++ b/tests/untried/neg/macro-noexpand/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Any]) = ??? +} diff --git a/tests/untried/neg/macro-noexpand/Macros_Test_2.scala b/tests/untried/neg/macro-noexpand/Macros_Test_2.scala new file mode 100644 index 000000000000..fa9745d973c7 --- /dev/null +++ b/tests/untried/neg/macro-noexpand/Macros_Test_2.scala @@ -0,0 +1,8 @@ +object Macros { + def foo(x: Any) = macro Impls.foo +} + +object Test extends App { + import Macros._ + foo(x) +} diff --git a/tests/untried/neg/macro-nontypeablebody.check b/tests/untried/neg/macro-nontypeablebody.check new file mode 100644 index 000000000000..9f5831ab304c --- /dev/null +++ b/tests/untried/neg/macro-nontypeablebody.check @@ -0,0 +1,4 @@ +Macros_Test_2.scala:2: error: value foo2 is not a member of object Impls + def foo(x: Any) = macro Impls.foo2 + ^ +one error found diff --git a/tests/untried/neg/macro-nontypeablebody.flags b/tests/untried/neg/macro-nontypeablebody.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-nontypeablebody.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-nontypeablebody/Impls_1.scala b/tests/untried/neg/macro-nontypeablebody/Impls_1.scala new file mode 100644 index 000000000000..acc6b52b7bf0 --- /dev/null +++ b/tests/untried/neg/macro-nontypeablebody/Impls_1.scala @@ -0,0 +1,5 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo(c: Context)(x: c.Expr[Any]) = ??? +} diff --git a/tests/untried/neg/macro-nontypeablebody/Macros_Test_2.scala b/tests/untried/neg/macro-nontypeablebody/Macros_Test_2.scala new file mode 100644 index 000000000000..5eb037b25de4 --- /dev/null +++ b/tests/untried/neg/macro-nontypeablebody/Macros_Test_2.scala @@ -0,0 +1,8 @@ +object Macros { + def foo(x: Any) = macro Impls.foo2 +} + +object Test extends App { + import Macros._ + foo(42) +} diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.check b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.check new file mode 100644 index 000000000000..6b5d3013bada --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.check @@ -0,0 +1,5 @@ +Impls_Macros_1.scala:12: error: overriding method foo in trait Foo of type (x: Int)Int; + macro method foo cannot be used here - term macros cannot override abstract methods + def foo(x: Int): Int = macro Impls.impl + ^ +one error found diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.flags b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala new file mode 100644 index 000000000000..916b454463b6 --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Impls_Macros_1.scala @@ -0,0 +1,13 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def impl(c: Context)(x: c.Expr[Int]) = x +} + +trait Foo { + def foo(x: Int): Int +} + +object Macros extends Foo { + def foo(x: Int): Int = macro Impls.impl +} diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Test_2.scala b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Test_2.scala new file mode 100644 index 000000000000..8821dc946481 --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-a/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + val designator: Macros.type = Macros + designator.foo(42) +} diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.check b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.check new file mode 100644 index 000000000000..c733555549ae --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.check @@ -0,0 +1,11 @@ +Test_2.scala:3: error: <$anon: C with A> inherits conflicting members: + macro method t in trait C of type ()Unit and + method t in trait A of type ()Unit +(Note: this can be resolved by declaring an override in <$anon: C with A>.) + val c2 = new C with A {} + ^ +Test_2.scala:5: error: overriding macro method t in trait C of type ()Unit; + method t cannot be used here - only term macros can override term macros + val c4 = new C with A { override def t(): Unit = () } + ^ +two errors found diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.flags b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala new file mode 100644 index 000000000000..17827abf7a6c --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Impls_Macros_1.scala @@ -0,0 +1,8 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +trait T { def t(): Unit } +trait A { def t(): Unit = () } + +object Macro { def t(c: Context)(): c.Expr[Unit] = c.universe.reify(()) } +trait C extends T { self: A => override def t(): Unit = macro Macro.t } diff --git a/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala new file mode 100644 index 000000000000..79deae63b725 --- /dev/null +++ b/tests/untried/neg/macro-override-macro-overrides-abstract-method-b/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + val c1 = new A with C {} + val c2 = new C with A {} + val c3 = new C with A { override def t(): Unit = macro Macro.t } + val c4 = new C with A { override def t(): Unit = () } +} diff --git a/tests/untried/neg/macro-override-method-overrides-macro.check b/tests/untried/neg/macro-override-method-overrides-macro.check new file mode 100644 index 000000000000..e396d65ff1a6 --- /dev/null +++ b/tests/untried/neg/macro-override-method-overrides-macro.check @@ -0,0 +1,5 @@ +Macros_Test_2.scala:8: error: overriding macro method foo in class B of type (x: String)Unit; + method foo cannot be used here - only term macros can override term macros + override def foo(x: String): Unit = println("fooDString") + ^ +one error found diff --git a/tests/untried/neg/macro-override-method-overrides-macro.flags b/tests/untried/neg/macro-override-method-overrides-macro.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-override-method-overrides-macro.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-override-method-overrides-macro/Impls_1.scala b/tests/untried/neg/macro-override-method-overrides-macro/Impls_1.scala new file mode 100644 index 000000000000..8d585be67524 --- /dev/null +++ b/tests/untried/neg/macro-override-method-overrides-macro/Impls_1.scala @@ -0,0 +1,14 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def impl(c: Context)(tag: String, x: c.Expr[_]) = { + import c.{prefix => prefix} + import c.universe._ + c.Expr[Unit](q"println($tag, ${prefix.toString}, $x)") + } + + def fooBString(c: Context)(x: c.Expr[_]) = impl(c)("fooBString", x) + def fooBInt(c: Context)(x: c.Expr[_]) = impl(c)("fooBInt", x) + def fooDInt(c: Context)(x: c.Expr[_]) = impl(c)("fooDInt", x) + def fooZString(c: Context)(x: c.Expr[_]) = impl(c)("fooZString", x) +} diff --git a/tests/untried/neg/macro-override-method-overrides-macro/Macros_Test_2.scala b/tests/untried/neg/macro-override-method-overrides-macro/Macros_Test_2.scala new file mode 100644 index 000000000000..d47157766e49 --- /dev/null +++ b/tests/untried/neg/macro-override-method-overrides-macro/Macros_Test_2.scala @@ -0,0 +1,15 @@ +class B { + def foo(x: String): Unit = macro Impls.fooBString + def foo(x: Int): Unit = macro Impls.fooBInt + def foo(x: Boolean): Unit = println("fooBBoolean") +} + +class D extends B { + override def foo(x: String): Unit = println("fooDString") + override def foo(x: Int): Unit = macro Impls.fooDInt +} + +class Z extends D { + override def foo(x: String): Unit = macro Impls.fooZString + override def foo(x: Boolean): Unit = println("fooZBoolean") +} diff --git a/tests/untried/neg/macro-qmarkqmarkqmark.check b/tests/untried/neg/macro-qmarkqmarkqmark.check new file mode 100644 index 000000000000..bc3e25edaf1a --- /dev/null +++ b/tests/untried/neg/macro-qmarkqmarkqmark.check @@ -0,0 +1,13 @@ +macro-qmarkqmarkqmark.scala:5: error: macro implementation is missing + foo1 + ^ +macro-qmarkqmarkqmark.scala:8: error: too few argument lists for macro invocation + foo2 + ^ +macro-qmarkqmarkqmark.scala:9: error: macro implementation is missing + foo2(1) + ^ +macro-qmarkqmarkqmark.scala:12: error: macro implementation is missing + foo3[Int] + ^ +four errors found diff --git a/tests/untried/neg/macro-qmarkqmarkqmark.scala b/tests/untried/neg/macro-qmarkqmarkqmark.scala new file mode 100644 index 000000000000..6c0462ea8010 --- /dev/null +++ b/tests/untried/neg/macro-qmarkqmarkqmark.scala @@ -0,0 +1,13 @@ +import language.experimental.macros + +object Macros { + def foo1 = macro ??? + foo1 + + def foo2(x: Int) = macro ??? + foo2 + foo2(1) + + def foo3[T] = macro ??? + foo3[Int] +} diff --git a/tests/untried/neg/macro-quasiquotes.check b/tests/untried/neg/macro-quasiquotes.check new file mode 100644 index 000000000000..a985aee156e4 --- /dev/null +++ b/tests/untried/neg/macro-quasiquotes.check @@ -0,0 +1,8 @@ +Macros_1.scala:14: error: bundle implementation has incompatible shape: + required: (x: Impls.this.c.Expr[Int]): Impls.this.c.Expr[Unit] + or : (x: Impls.this.c.Tree): Impls.this.c.Tree + found : (x: Impls.this.c.universe.Block): Impls.this.c.Tree +type mismatch for parameter x: Impls.this.c.Expr[Int] does not conform to Impls.this.c.universe.Block + def m3(x: Int): Unit = macro Impls.impl3 + ^ +one error found diff --git a/tests/untried/neg/macro-quasiquotes/Macros_1.scala b/tests/untried/neg/macro-quasiquotes/Macros_1.scala new file mode 100644 index 000000000000..62e7a596bb1d --- /dev/null +++ b/tests/untried/neg/macro-quasiquotes/Macros_1.scala @@ -0,0 +1,15 @@ +import language.experimental.macros +import scala.reflect.macros.blackbox.Context + +class Impls(val c: Context) { + import c.universe._ + def impl1(x: Expr[Int]) = q"println(x)" + def impl2(x: Tree) = q"println(x)" + def impl3(x: Block) = q"println(x)" +} + +object Macros { + def m1(x: Int): Unit = macro Impls.impl1 + def m2(x: Int): Unit = macro Impls.impl2 + def m3(x: Int): Unit = macro Impls.impl3 +} diff --git a/tests/untried/neg/macro-quasiquotes/Test_2.scala b/tests/untried/neg/macro-quasiquotes/Test_2.scala new file mode 100644 index 000000000000..c7b8948d79a5 --- /dev/null +++ b/tests/untried/neg/macro-quasiquotes/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + Macros.m1 + Macros.m2 + Macros.m3 +} diff --git a/tests/untried/neg/macro-reify-splice-splice.check b/tests/untried/neg/macro-reify-splice-splice.check new file mode 100644 index 000000000000..bd1ea7acee0b --- /dev/null +++ b/tests/untried/neg/macro-reify-splice-splice.check @@ -0,0 +1,7 @@ +Macros_1.scala:8: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + { c.universe.reify(c.universe.reify("hello world")) }.splice.splice + ^ +one error found diff --git a/tests/untried/neg/macro-reify-splice-splice.flags b/tests/untried/neg/macro-reify-splice-splice.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/macro-reify-splice-splice.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/macro-reify-splice-splice/Macros_1.scala b/tests/untried/neg/macro-reify-splice-splice/Macros_1.scala new file mode 100644 index 000000000000..4a68fe687b7d --- /dev/null +++ b/tests/untried/neg/macro-reify-splice-splice/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def foo = macro Impls.foo + + object Impls { + def foo(c: Context) = c.universe.reify { + { c.universe.reify(c.universe.reify("hello world")) }.splice.splice + } + } +} diff --git a/tests/untried/neg/macro-reify-splice-splice/Test_2.scala b/tests/untried/neg/macro-reify-splice-splice/Test_2.scala new file mode 100644 index 000000000000..cff569bd81b1 --- /dev/null +++ b/tests/untried/neg/macro-reify-splice-splice/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + println(Macros.foo) +} diff --git a/tests/untried/neg/macro-reify-typetag-hktypeparams-notags.check b/tests/untried/neg/macro-reify-typetag-hktypeparams-notags.check new file mode 100644 index 000000000000..44efaae775c2 --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-hktypeparams-notags.check @@ -0,0 +1,7 @@ +Test.scala:5: error: No TypeTag available for C[T] + println(implicitly[TypeTag[C[T]]]) + ^ +Test.scala:6: error: No TypeTag available for List[C[T]] + println(implicitly[TypeTag[List[C[T]]]]) + ^ +two errors found diff --git a/tests/untried/neg/macro-reify-typetag-hktypeparams-notags/Test.scala b/tests/untried/neg/macro-reify-typetag-hktypeparams-notags/Test.scala new file mode 100644 index 000000000000..09652721cdc1 --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-hktypeparams-notags/Test.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def fooNoTypeTagHK[C[_], T] = { + println(implicitly[TypeTag[C[T]]]) + println(implicitly[TypeTag[List[C[T]]]]) + } + fooNoTypeTagHK[List, Int] +} diff --git a/tests/untried/neg/macro-reify-typetag-typeparams-notags.check b/tests/untried/neg/macro-reify-typetag-typeparams-notags.check new file mode 100644 index 000000000000..7c67b02aa606 --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-typeparams-notags.check @@ -0,0 +1,7 @@ +Test.scala:5: error: No TypeTag available for T + println(implicitly[TypeTag[T]]) + ^ +Test.scala:6: error: No TypeTag available for List[T] + println(implicitly[TypeTag[List[T]]]) + ^ +two errors found diff --git a/tests/untried/neg/macro-reify-typetag-typeparams-notags/Test.scala b/tests/untried/neg/macro-reify-typetag-typeparams-notags/Test.scala new file mode 100644 index 000000000000..504f7327c48b --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-typeparams-notags/Test.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def fooNoTypeTag[T] = { + println(implicitly[TypeTag[T]]) + println(implicitly[TypeTag[List[T]]]) + } + fooNoTypeTag[Int] +} diff --git a/tests/untried/neg/macro-reify-typetag-useabstypetag.check b/tests/untried/neg/macro-reify-typetag-useabstypetag.check new file mode 100644 index 000000000000..7c67b02aa606 --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-useabstypetag.check @@ -0,0 +1,7 @@ +Test.scala:5: error: No TypeTag available for T + println(implicitly[TypeTag[T]]) + ^ +Test.scala:6: error: No TypeTag available for List[T] + println(implicitly[TypeTag[List[T]]]) + ^ +two errors found diff --git a/tests/untried/neg/macro-reify-typetag-useabstypetag/Test.scala b/tests/untried/neg/macro-reify-typetag-useabstypetag/Test.scala new file mode 100644 index 000000000000..95b8dfc99758 --- /dev/null +++ b/tests/untried/neg/macro-reify-typetag-useabstypetag/Test.scala @@ -0,0 +1,9 @@ +import scala.reflect.runtime.universe._ + +object Test extends App { + def fooTypeTag[T: WeakTypeTag] = { + println(implicitly[TypeTag[T]]) + println(implicitly[TypeTag[List[T]]]) + } + fooTypeTag[Int] +} diff --git a/tests/untried/neg/macro-without-xmacros-a.check b/tests/untried/neg/macro-without-xmacros-a.check new file mode 100644 index 000000000000..ec194be3a9ed --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-a.check @@ -0,0 +1,17 @@ +Macros_2.scala:5: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. +This can be achieved by adding the import clause 'import scala.language.experimental.macros' +or by setting the compiler option -language:experimental.macros. +See the Scala docs for value scala.language.experimental.macros for a discussion +why the feature needs to be explicitly enabled. + def foo(x: Int): Int = macro foo_impl + ^ +Macros_2.scala:7: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. + def bar(x: Int): Int = macro bar_impl + ^ +Macros_2.scala:11: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. + def quux(x: Int): Int = macro quux_impl + ^ +three errors found diff --git a/tests/untried/neg/macro-without-xmacros-a/Impls_1.scala b/tests/untried/neg/macro-without-xmacros-a/Impls_1.scala new file mode 100644 index 000000000000..04d5d1ac0f50 --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-a/Impls_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 1") + } + + def bar_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 2") + } + + def quux_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 3") + } +} diff --git a/tests/untried/neg/macro-without-xmacros-a/Macros_2.scala b/tests/untried/neg/macro-without-xmacros-a/Macros_2.scala new file mode 100644 index 000000000000..e32a70ba8d0a --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-a/Macros_2.scala @@ -0,0 +1,12 @@ +import Impls._ + +object Macros { + object Shmacros { + def foo(x: Int): Int = macro foo_impl + } + def bar(x: Int): Int = macro bar_impl +} + +class Macros { + def quux(x: Int): Int = macro quux_impl +} diff --git a/tests/untried/neg/macro-without-xmacros-a/Test_3.scala b/tests/untried/neg/macro-without-xmacros-a/Test_3.scala new file mode 100644 index 000000000000..011eb1f57453 --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-a/Test_3.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros.Shmacros._ + println(foo(2) + Macros.bar(2) * new Macros().quux(4)) +} diff --git a/tests/untried/neg/macro-without-xmacros-b.check b/tests/untried/neg/macro-without-xmacros-b.check new file mode 100644 index 000000000000..c97850f0a97b --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-b.check @@ -0,0 +1,17 @@ +Macros_2.scala:3: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. +This can be achieved by adding the import clause 'import scala.language.experimental.macros' +or by setting the compiler option -language:experimental.macros. +See the Scala docs for value scala.language.experimental.macros for a discussion +why the feature needs to be explicitly enabled. + def foo(x: Int): Int = macro Impls.foo_impl + ^ +Macros_2.scala:5: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. + def bar(x: Int): Int = macro Impls.bar_impl + ^ +Macros_2.scala:9: error: macro definition needs to be enabled +by making the implicit value scala.language.experimental.macros visible. + def quux(x: Int): Int = macro Impls.quux_impl + ^ +three errors found diff --git a/tests/untried/neg/macro-without-xmacros-b/Impls_1.scala b/tests/untried/neg/macro-without-xmacros-b/Impls_1.scala new file mode 100644 index 000000000000..04d5d1ac0f50 --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-b/Impls_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.blackbox.Context + +object Impls { + def foo_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 1") + } + + def bar_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 2") + } + + def quux_impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + c.Expr(q"$x + 3") + } +} diff --git a/tests/untried/neg/macro-without-xmacros-b/Macros_2.scala b/tests/untried/neg/macro-without-xmacros-b/Macros_2.scala new file mode 100644 index 000000000000..120f50abcd4b --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-b/Macros_2.scala @@ -0,0 +1,10 @@ +object Macros { + object Shmacros { + def foo(x: Int): Int = macro Impls.foo_impl + } + def bar(x: Int): Int = macro Impls.bar_impl +} + +class Macros { + def quux(x: Int): Int = macro Impls.quux_impl +} diff --git a/tests/untried/neg/macro-without-xmacros-b/Test_3.scala b/tests/untried/neg/macro-without-xmacros-b/Test_3.scala new file mode 100644 index 000000000000..011eb1f57453 --- /dev/null +++ b/tests/untried/neg/macro-without-xmacros-b/Test_3.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros.Shmacros._ + println(foo(2) + Macros.bar(2) * new Macros().quux(4)) +} diff --git a/tests/untried/neg/main1.check b/tests/untried/neg/main1.check new file mode 100644 index 000000000000..b7451058180c --- /dev/null +++ b/tests/untried/neg/main1.check @@ -0,0 +1,28 @@ +main1.scala:3: warning: Foo has a main method with parameter type Array[String], but foo1.Foo will not be a runnable program. + Reason: companion is a trait, which means no static forwarder can be generated. + + object Foo { // companion is trait + ^ +main1.scala:10: warning: Foo has a main method with parameter type Array[String], but foo2.Foo will not be a runnable program. + Reason: companion contains its own main method, which means no static forwarder can be generated. + + object Foo { // companion has its own main + ^ +main1.scala:22: warning: Foo has a main method with parameter type Array[String], but foo3.Foo will not be a runnable program. + Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated. + + object Foo { // Companion contains main, but not an interfering main. + ^ +main1.scala:31: warning: Foo has a main method with parameter type Array[String], but foo4.Foo will not be a runnable program. + Reason: companion contains its own main method, which means no static forwarder can be generated. + + object Foo extends Foo { // Inherits main from the class + ^ +main1.scala:39: warning: Foo has a main method with parameter type Array[String], but foo5.Foo will not be a runnable program. + Reason: companion contains its own main method, which means no static forwarder can be generated. + + object Foo extends Foo { // Overrides main from the class + ^ +error: No warnings can be incurred under -Xfatal-warnings. +5 warnings found +one error found diff --git a/tests/untried/neg/main1.flags b/tests/untried/neg/main1.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/main1.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/main1.scala b/tests/untried/neg/main1.scala new file mode 100644 index 000000000000..2b5551ac3836 --- /dev/null +++ b/tests/untried/neg/main1.scala @@ -0,0 +1,45 @@ +// negatives +package foo1 { + object Foo { // companion is trait + def main(args: Array[String]): Unit = () + } + trait Foo +} + +package foo2 { + object Foo { // companion has its own main + def main(args: Array[String]): Unit = () + } + class Foo { + def main(args: Array[String]): Unit = () + } +} + +// these should all be made to work, but are negatives for now +// because forwarders need more work. + +package foo3 { + object Foo { // Companion contains main, but not an interfering main. + def main(args: Array[String]): Unit = () + } + class Foo { + def main(args: Int): Unit = () + } +} + +package foo4 { + object Foo extends Foo { // Inherits main from the class + } + class Foo { + def main(args: Array[String]): Unit = () + } +} + +package foo5 { + object Foo extends Foo { // Overrides main from the class + override def main(args: Array[String]): Unit = () + } + class Foo { + def main(args: Array[String]): Unit = () + } +} diff --git a/tests/untried/neg/migration28.check b/tests/untried/neg/migration28.check new file mode 100644 index 000000000000..afb4db62e205 --- /dev/null +++ b/tests/untried/neg/migration28.check @@ -0,0 +1,7 @@ +migration28.scala:4: warning: method scanRight in trait TraversableLike has changed semantics in version 2.9.0: +The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse. + List(1,2,3,4,5).scanRight(0)(_+_) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/migration28.flags b/tests/untried/neg/migration28.flags new file mode 100644 index 000000000000..197b3198c888 --- /dev/null +++ b/tests/untried/neg/migration28.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xmigration diff --git a/tests/untried/neg/migration28.scala b/tests/untried/neg/migration28.scala new file mode 100644 index 000000000000..facc9b36d2f2 --- /dev/null +++ b/tests/untried/neg/migration28.scala @@ -0,0 +1,9 @@ +object Test { + import scala.collection.mutable._ + + List(1,2,3,4,5).scanRight(0)(_+_) + + def main(args: Array[String]): Unit = { + + } +} diff --git a/tests/untried/neg/missing-param-type-tuple.check b/tests/untried/neg/missing-param-type-tuple.check new file mode 100644 index 000000000000..3a4258ff8c5b --- /dev/null +++ b/tests/untried/neg/missing-param-type-tuple.check @@ -0,0 +1,31 @@ +missing-param-type-tuple.scala:3: error: missing parameter type +Note: The expected type requires a one-argument function accepting a 2-Tuple. + Consider a pattern matching anonymous function, `{ case (a, b) => ... }` + val x: ((Int, Int)) => Int = (a, b) => 0 + ^ +missing-param-type-tuple.scala:3: error: missing parameter type + val x: ((Int, Int)) => Int = (a, b) => 0 + ^ +missing-param-type-tuple.scala:5: error: missing parameter type +Note: The expected type requires a one-argument function accepting a 3-Tuple. + Consider a pattern matching anonymous function, `{ case (param1, ..., param3) => ... }` + val y: ((Int, Int, Int)) => Int = (a, b, !!) => 0 + ^ +missing-param-type-tuple.scala:5: error: missing parameter type + val y: ((Int, Int, Int)) => Int = (a, b, !!) => 0 + ^ +missing-param-type-tuple.scala:5: error: missing parameter type + val y: ((Int, Int, Int)) => Int = (a, b, !!) => 0 + ^ +missing-param-type-tuple.scala:7: error: missing parameter type +Note: The expected type requires a one-argument function accepting a 3-Tuple. + Consider a pattern matching anonymous function, `{ case (param1, ..., param3) => ... }` + val z: ((Int, Int, Int)) => Int = (a, NotAVariablePatternName, c) => 0 + ^ +missing-param-type-tuple.scala:7: error: missing parameter type + val z: ((Int, Int, Int)) => Int = (a, NotAVariablePatternName, c) => 0 + ^ +missing-param-type-tuple.scala:7: error: missing parameter type + val z: ((Int, Int, Int)) => Int = (a, NotAVariablePatternName, c) => 0 + ^ +8 errors found diff --git a/tests/untried/neg/missing-param-type-tuple.scala b/tests/untried/neg/missing-param-type-tuple.scala new file mode 100644 index 000000000000..72c0c820346e --- /dev/null +++ b/tests/untried/neg/missing-param-type-tuple.scala @@ -0,0 +1,8 @@ +class C { + + val x: ((Int, Int)) => Int = (a, b) => 0 + + val y: ((Int, Int, Int)) => Int = (a, b, !!) => 0 + + val z: ((Int, Int, Int)) => Int = (a, NotAVariablePatternName, c) => 0 +} diff --git a/tests/untried/neg/mixins.check b/tests/untried/neg/mixins.check new file mode 100644 index 000000000000..f310ca596294 --- /dev/null +++ b/tests/untried/neg/mixins.check @@ -0,0 +1,6 @@ +mixins.scala:9: error: illegal inheritance; superclass C + is not a subclass of the superclass B + of the mixin trait M +class D extends C with M + ^ +one error found diff --git a/tests/untried/neg/mixins.scala b/tests/untried/neg/mixins.scala new file mode 100644 index 000000000000..18b091f17028 --- /dev/null +++ b/tests/untried/neg/mixins.scala @@ -0,0 +1,9 @@ +class A; + +class B extends A + +class C extends A + +trait M extends B + +class D extends C with M diff --git a/tests/untried/neg/multi-array.check b/tests/untried/neg/multi-array.check new file mode 100644 index 000000000000..511caa126fc0 --- /dev/null +++ b/tests/untried/neg/multi-array.check @@ -0,0 +1,4 @@ +multi-array.scala:7: error: too many arguments for constructor Array: (_length: Int)Array[T] + val a: Array[Int] = new Array(10, 10) + ^ +one error found diff --git a/tests/untried/neg/multi-array.flags b/tests/untried/neg/multi-array.flags new file mode 100644 index 000000000000..c36e713ab84b --- /dev/null +++ b/tests/untried/neg/multi-array.flags @@ -0,0 +1 @@ +-deprecation \ No newline at end of file diff --git a/tests/untried/neg/multi-array.scala b/tests/untried/neg/multi-array.scala new file mode 100644 index 000000000000..b04e0fa0b159 --- /dev/null +++ b/tests/untried/neg/multi-array.scala @@ -0,0 +1,14 @@ +/** Multi-dimensional array creation with `new` was removed in 2.10. + * The replacement Array.ofDim[Int](10,10) makes the original mistake + * which was tested here impossible. + * This test will fail now because the constructor doesn't exist anymore. + */ +class Foo { + val a: Array[Int] = new Array(10, 10) +} + +//Before removal of constructor non-unary Array constructors: +/** Check that a multi-dimensional array can't be created + * when the wrong number of arguments w.r.t. to the array's + * type is given. + */ diff --git a/tests/untried/neg/name-lookup-stable.check b/tests/untried/neg/name-lookup-stable.check new file mode 100644 index 000000000000..751df9505e69 --- /dev/null +++ b/tests/untried/neg/name-lookup-stable.check @@ -0,0 +1,11 @@ +name-lookup-stable.scala:15: error: reference to PrimaryKey is ambiguous; +it is both defined in class A and imported subsequently by +import ColumnOption._ + (null: Any) match { case PrimaryKey => } + ^ +name-lookup-stable.scala:17: error: reference to PrimaryKey is ambiguous; +it is both defined in class A and imported subsequently by +import ColumnOption._ + PrimaryKey // was already ambigious in 2.10.3 + ^ +two errors found diff --git a/tests/untried/neg/name-lookup-stable.scala b/tests/untried/neg/name-lookup-stable.scala new file mode 100644 index 000000000000..0d862f06e136 --- /dev/null +++ b/tests/untried/neg/name-lookup-stable.scala @@ -0,0 +1,20 @@ +// This used to compile under 2.10.3 but the ambiguity is now noticed +// in 2.11.x (after a70c8219). I think the new behaviour is correct; +// we shouldn't discard names based on "expected stability" before +// evaluating ambiguity. +object ColumnOption { + object PrimaryKey +} + +class A { + def PrimaryKey: Any = ??? + + { + import ColumnOption._ + + (null: Any) match { case PrimaryKey => } + + PrimaryKey // was already ambigious in 2.10.3 + } +} + diff --git a/tests/untried/neg/names-defaults-neg-ref.check b/tests/untried/neg/names-defaults-neg-ref.check new file mode 100644 index 000000000000..61d66fd32a4f --- /dev/null +++ b/tests/untried/neg/names-defaults-neg-ref.check @@ -0,0 +1,16 @@ +names-defaults-neg-ref.scala:3: error: in <$anon: A2235 with B2235>, multiple overloaded alternatives of method f define default arguments. +The members with defaults are defined in trait B2235 and trait A2235. + new A2235 with B2235 + ^ +names-defaults-neg-ref.scala:7: error: in class A, multiple overloaded alternatives of method foo define default arguments. +class A { + ^ +names-defaults-neg-ref.scala:17: error: in class C, multiple overloaded alternatives of method bar define default arguments. +The members with defaults are defined in class C and class B. +class C extends B { + ^ +names-defaults-neg-ref.scala:21: error: overriding method bar$default$1 in class B of type => String; + method bar$default$1 has incompatible type + def bar(i: Int = 129083) = i + ^ +four errors found diff --git a/tests/untried/neg/names-defaults-neg-ref.scala b/tests/untried/neg/names-defaults-neg-ref.scala new file mode 100644 index 000000000000..17a482799074 --- /dev/null +++ b/tests/untried/neg/names-defaults-neg-ref.scala @@ -0,0 +1,26 @@ +object Test extends App { + // #2235 + new A2235 with B2235 +} + +// only one overloaded alternative is allowed to have defaults +class A { + def foo(a: Int = 0) = a + def foo(b: String = "another") = b +} + +class B { + def foo(a: Int) = a + def bar(u: String = "ldksj") = u +} + +class C extends B { + override def foo(a: Int = 1092) = a + def foo(b: String = "lskdfj") + + def bar(i: Int = 129083) = i +} + +// #2235 +trait A2235 { def f(x: Int = 1) = x } +trait B2235 { def f(x: String = "1") = x } diff --git a/tests/untried/neg/names-defaults-neg-warn.check b/tests/untried/neg/names-defaults-neg-warn.check new file mode 100644 index 000000000000..0f4edef84e55 --- /dev/null +++ b/tests/untried/neg/names-defaults-neg-warn.check @@ -0,0 +1,9 @@ +names-defaults-neg-warn.scala:11: warning: the parameter name s has been deprecated. Use x instead. + deprNam2.f(s = "dlfkj") + ^ +names-defaults-neg-warn.scala:12: warning: the parameter name x has been deprecated. Use s instead. + deprNam2.g(x = "dlkjf") + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/names-defaults-neg-warn.flags b/tests/untried/neg/names-defaults-neg-warn.flags new file mode 100644 index 000000000000..d1b831ea87cd --- /dev/null +++ b/tests/untried/neg/names-defaults-neg-warn.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/names-defaults-neg-warn.scala b/tests/untried/neg/names-defaults-neg-warn.scala new file mode 100644 index 000000000000..c7a2b2f42929 --- /dev/null +++ b/tests/untried/neg/names-defaults-neg-warn.scala @@ -0,0 +1,14 @@ +object Test extends App { + object deprNam2 { + def f(@deprecatedName('s) x: String) = 1 + def f(s: Object) = 2 + + def g(@deprecatedName('x) s: Object) = 3 + def g(s: String) = 4 + } + + deprNam2.f(s = new Object) + deprNam2.f(s = "dlfkj") + deprNam2.g(x = "dlkjf") + deprNam2.g(s = new Object) +} diff --git a/tests/untried/neg/names-defaults-neg.check b/tests/untried/neg/names-defaults-neg.check new file mode 100644 index 000000000000..20ddd55f1fde --- /dev/null +++ b/tests/untried/neg/names-defaults-neg.check @@ -0,0 +1,185 @@ +names-defaults-neg.scala:65: error: not enough arguments for method apply: (a: Int, b: String)(c: Int*)Fact in object Fact. +Unspecified value parameter b. + val fac = Fact(1)(2, 3) + ^ +names-defaults-neg.scala:5: error: type mismatch; + found : String("#") + required: Int + test1(b = 2, a = "#") + ^ +names-defaults-neg.scala:5: error: type mismatch; + found : Int(2) + required: String + test1(b = 2, a = "#") + ^ +names-defaults-neg.scala:8: error: positional after named argument. + test1(b = "(*", 23) + ^ +names-defaults-neg.scala:13: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. + test2(x = 1) + ^ +names-defaults-neg.scala:15: error: not found: value c + test1(c = 0, b = "joke") + ^ +names-defaults-neg.scala:16: error: not found: value m + test7((m = 1)) // named arguments must be top-level assignments + ^ +names-defaults-neg.scala:17: error: not found: value m + test7({m = 1}) + ^ +names-defaults-neg.scala:18: error: not found: value m + test7 { m = 1 } // no named arguments in argument block + ^ +names-defaults-neg.scala:19: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. + test8(x = 1) + ^ +names-defaults-neg.scala:22: error: parameter 'a' is already specified at parameter position 1 + test1(1, a = 2) + ^ +names-defaults-neg.scala:23: error: parameter 'b' is already specified at parameter position 1 + test1(b = 1, b = "2") + ^ +names-defaults-neg.scala:26: error: Int does not take parameters + test3(b = 3, a = 1)(3) + ^ +names-defaults-neg.scala:35: error: ambiguous reference to overloaded definition, +both method f in object t1 of type (b: String, a: Int)String +and method f in object t1 of type (a: Int, b: String)String +match argument types (b: String,a: Int) + t1.f(b = "dkljf", a = 1) + ^ +names-defaults-neg.scala:42: error: ambiguous reference to overloaded definition, +both method f in object t3 of type (a2: Int)(b: Int)String +and method f in object t3 of type (a1: Int)String +match argument types (Int) + t3.f(1) + ^ +names-defaults-neg.scala:43: error: ambiguous reference to overloaded definition, +both method f in object t3 of type (a2: Int)(b: Int)String +and method f in object t3 of type (a1: Int)String +match argument types (Int) + t3.f(1)(2) + ^ +names-defaults-neg.scala:49: error: ambiguous reference to overloaded definition, +both method g in object t7 of type (a: B)String +and method g in object t7 of type (a: C, b: Int*)String +match argument types (C) + t7.g(new C()) // ambigous reference + ^ +names-defaults-neg.scala:53: error: parameter 'b' is already specified at parameter position 2 + test5(a = 1, b = "dkjl", b = "dkj") + ^ +names-defaults-neg.scala:54: error: parameter 'b' is already specified at parameter position 2 + test5(1, "2", b = 3) + ^ +names-defaults-neg.scala:55: error: when using named arguments, the vararg parameter has to be specified exactly once + test5(b = "dlkj") + ^ +names-defaults-neg.scala:61: error: ambiguous reference to overloaded definition, +both method f in object t8 of type (b: String, a: Int)String +and method f in object t8 of type (a: Int, b: Object)String +match argument types (a: Int,b: String) and expected result type Any + println(t8.f(a = 0, b = "1")) // ambigous reference + ^ +names-defaults-neg.scala:69: error: wrong number of arguments for pattern A1(x: Int,y: String) + A1() match { case A1(_) => () } + ^ +names-defaults-neg.scala:76: error: no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])T[T[List[T[X forSome { type X }]]]] exist so that it can be applied to arguments (List[Int]) + --- because --- +argument expression's type is not compatible with formal parameter type; + found : List[Int] + required: ?T[?T[List[?T[X forSome { type X }]]]] +Error occurred in an application involving default arguments. + test4() + ^ +names-defaults-neg.scala:79: error: type mismatch; + found : List[Int] + required: List[List[?]] + def test6[T](x: List[List[T]] = List(1,2)) = x + ^ +names-defaults-neg.scala:82: error: type mismatch; + found : Int + required: String +Error occurred in an application involving default arguments. + new A2[String]() + ^ +names-defaults-neg.scala:86: error: module extending its companion class cannot use default constructor arguments + object C extends C() + ^ +names-defaults-neg.scala:90: error: deprecated parameter name x has to be distinct from any other parameter name (deprecated or not). + def deprNam1(x: Int, @deprecatedName('x) y: String) = 0 + ^ +names-defaults-neg.scala:91: error: deprecated parameter name a has to be distinct from any other parameter name (deprecated or not). + def deprNam2(a: String)(@deprecatedName('a) b: Int) = 1 + ^ +names-defaults-neg.scala:93: warning: the parameter name y has been deprecated. Use b instead. + deprNam3(y = 10, b = 2) + ^ +names-defaults-neg.scala:93: error: parameter 'b' is already specified at parameter position 1 + deprNam3(y = 10, b = 2) + ^ +names-defaults-neg.scala:98: error: unknown parameter name: m + f3818(y = 1, m = 1) + ^ +names-defaults-neg.scala:131: error: reference to var2 is ambiguous; it is both a method parameter and a variable in scope. + delay(var2 = 40) + ^ +names-defaults-neg.scala:134: error: missing parameter type for expanded function ((x$1) => a = x$1) + val taf2: Int => Unit = testAnnFun(a = _, b = get("+")) + ^ +names-defaults-neg.scala:134: error: not found: value a + val taf2: Int => Unit = testAnnFun(a = _, b = get("+")) + ^ +names-defaults-neg.scala:134: error: not found: value get + val taf2: Int => Unit = testAnnFun(a = _, b = get("+")) + ^ +names-defaults-neg.scala:135: error: parameter 'a' is already specified at parameter position 1 + val taf3 = testAnnFun(b = _: String, a = get(8)) + ^ +names-defaults-neg.scala:136: error: missing parameter type for expanded function ((x$3) => testAnnFun(x$3, ((x$4) => b = x$4))) + val taf4: (Int, String) => Unit = testAnnFun(_, b = _) + ^ +names-defaults-neg.scala:136: error: missing parameter type for expanded function ((x$4) => b = x$4) + val taf4: (Int, String) => Unit = testAnnFun(_, b = _) + ^ +names-defaults-neg.scala:136: error: not found: value b + val taf4: (Int, String) => Unit = testAnnFun(_, b = _) + ^ +names-defaults-neg.scala:144: error: variable definition needs type because 'x' is used as a named argument in its body. + def t3 { var x = t.f(x = 1) } + ^ +names-defaults-neg.scala:147: error: variable definition needs type because 'x' is used as a named argument in its body. + object t6 { var x = t.f(x = 1) } + ^ +names-defaults-neg.scala:147: warning: type-checking the invocation of method f checks if the named argument expression 'x = ...' is a valid assignment +in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for x. + object t6 { var x = t.f(x = 1) } + ^ +names-defaults-neg.scala:150: error: variable definition needs type because 'x' is used as a named argument in its body. + class t9 { var x = t.f(x = 1) } + ^ +names-defaults-neg.scala:150: warning: type-checking the invocation of method f checks if the named argument expression 'x = ...' is a valid assignment +in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for x. + class t9 { var x = t.f(x = 1) } + ^ +names-defaults-neg.scala:164: error: variable definition needs type because 'x' is used as a named argument in its body. + def u3 { var x = u.f(x = 1) } + ^ +names-defaults-neg.scala:167: error: variable definition needs type because 'x' is used as a named argument in its body. + def u6 { var x = u.f(x = "32") } + ^ +names-defaults-neg.scala:170: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. + def u9 { var x: Int = u.f(x = 1) } + ^ +names-defaults-neg.scala:177: error: variable definition needs type because 'x' is used as a named argument in its body. + class u15 { var x = u.f(x = 1) } + ^ +names-defaults-neg.scala:177: warning: type-checking the invocation of method f checks if the named argument expression 'x = ...' is a valid assignment +in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for x. + class u15 { var x = u.f(x = 1) } + ^ +names-defaults-neg.scala:180: error: reference to x is ambiguous; it is both a method parameter and a variable in scope. + class u18 { var x: Int = u.f(x = 1) } + ^ +four warnings found +46 errors found diff --git a/tests/untried/neg/names-defaults-neg.flags b/tests/untried/neg/names-defaults-neg.flags new file mode 100644 index 000000000000..dcc59ebe32ef --- /dev/null +++ b/tests/untried/neg/names-defaults-neg.flags @@ -0,0 +1 @@ +-deprecation diff --git a/tests/untried/neg/names-defaults-neg.scala b/tests/untried/neg/names-defaults-neg.scala new file mode 100644 index 000000000000..2f8700ac6b22 --- /dev/null +++ b/tests/untried/neg/names-defaults-neg.scala @@ -0,0 +1,184 @@ +object Test extends App { + // TESTS + + // re-ordering + test1(b = 2, a = "#") + + // mixing named and positional + test1(b = "(*", 23) + + // assignment / names + var x = 0 + var y = 0 + test2(x = 1) + test2(y = 1) + test1(c = 0, b = "joke") + test7((m = 1)) // named arguments must be top-level assignments + test7({m = 1}) + test7 { m = 1 } // no named arguments in argument block + test8(x = 1) + + // argument specified twice + test1(1, a = 2) + test1(b = 1, b = "2") + + // error message when there are too many argument lists (not very nice..) + test3(b = 3, a = 1)(3) + + + + // overloading resolution + object t1 { + def f(a: Int, b: String) = "first" + def f(b: String, a: Int) = "second" + } + t1.f(b = "dkljf", a = 1) + + + object t3 { + def f(a1: Int) = "first" + def f(a2: Int)(b: Int) = "second" + } + t3.f(1) + t3.f(1)(2) + + object t7 { + def g(a: C, b: Int*) = "third" + def g(a: B) = "fourth" + } + t7.g(new C()) // ambigous reference + + // vararg + def test5(a: Int, b: String*) = a + test5(a = 1, b = "dkjl", b = "dkj") + test5(1, "2", b = 3) + test5(b = "dlkj") + + object t8 { + def f(a: Int, b: Object) = "first" + def f(b: String, a: Int) = "second" + } + println(t8.f(a = 0, b = "1")) // ambigous reference + + + // case class copy does not exist if there's a vararg + val fac = Fact(1)(2, 3) + val facc = fac.copy(b = "dlkfj")() + + // no defaults in patterns + A1() match { case A1(_) => () } + + + // return types of default getters + + // definition compiles, but default cannot be used, it doesn't conform + def test4[T[P]](x: T[T[List[T[X forSome { type X }]]]] = List(1,2)) = x + test4() + + // doesn't compile + def test6[T](x: List[List[T]] = List(1,2)) = x + + // correct error message + new A2[String]() + + object t3648 { + class C(val s: String = "") + object C extends C() + } + + // deprecated names + def deprNam1(x: Int, @deprecatedName('x) y: String) = 0 + def deprNam2(a: String)(@deprecatedName('a) b: Int) = 1 + def deprNam3(@deprecatedName('x) a: Int, @deprecatedName('y) b: Int) = a + b + deprNam3(y = 10, b = 2) + + + // t3818 + def f3818(x: Int = 1, y: Int, z: Int = 1) = 0 + f3818(y = 1, m = 1) + + // DEFINITIONS + def test1(a: Int, b: String) = a +": "+ b + def test2(x: Unit) = println("test2") + def test3(a: Int, b: Int) = a + b + def test7(m: Int) = m + def test8[T](x: => T) = println("test8") +} + +class B { + def foo(a: Int) = a + def bar(u: String = "ldksj") = u +} + +class C extends B { + override def foo(a: Int = 1092) = a + def foo(b: String = "lskdfj") + + def bar(i: Int = 129083) = i +} + +case class Fact(a: Int, b: String)(c: Int*) + +case class A1(x: Int = 1, y: String = "2") + +class A2[T](a: T = 1) + + +// anonymous functions +object anfun { + var var2 = 0 + def delay(var2: => Unit): Unit = { var2 } + delay(var2 = 40) + + def testAnnFun(a: Int, b: String) = println(a +": "+ b) + val taf2: Int => Unit = testAnnFun(a = _, b = get("+")) + val taf3 = testAnnFun(b = _: String, a = get(8)) + val taf4: (Int, String) => Unit = testAnnFun(_, b = _) +} + +object t3685 { + object t { def f(x: Int) = x } + + def t1: Unit = { def x = t.f(x = 1) } + def t2: Unit = { val x = t.f(x = 1) } + def t3: Unit = { var x = t.f(x = 1) } + object t4 { def x = t.f(x = 1) } + object t5 { val x = t.f(x = 1) } + object t6 { var x = t.f(x = 1) } + class t7 { def x = t.f(x = 1) } + class t8 { val x = t.f(x = 1) } + class t9 { var x = t.f(x = 1) } + + def t10: Unit = { def x: Int = t.f(x = 1) } + def t11: Unit = { val x: Int = t.f(x = 1) } + def t12: Unit = { var x: Int = t.f(x = 1) } + class t13 { def x: Int = t.f(x = 1) } + class t14 { val x: Int = t.f(x = 1) } + class t15 { var x: Int = t.f(x = 1) } + + + object u { def f[T](x: T) = 100 } + + def u1: Unit = { def x = u.f(x = 1) } + def u2: Unit = { val x = u.f(x = 1) } + def u3: Unit = { var x = u.f(x = 1) } + def u4: Unit = { def x = u.f(x = "23") } + def u5: Unit = { val x = u.f(x = "32") } + def u6: Unit = { var x = u.f(x = "32") } + def u7: Unit = { def x: Int = u.f(x = 1) } + def u8: Unit = { val x: Int = u.f(x = 1) } + def u9: Unit = { var x: Int = u.f(x = 1) } + def u10: Unit = { def x: Int = u.f(x = "32") } + def u11: Unit = { val x: Int = u.f(x = "32") } + def u12: Unit = { var x: Int = u.f(x = "32") } + + class u13 { def x = u.f(x = 1) } + class u14 { val x = u.f(x = 1) } + class u15 { var x = u.f(x = 1) } + class u16 { def x: Int = u.f(x = 1) } + class u17 { val x: Int = u.f(x = 1) } + class u18 { var x: Int = u.f(x = 1) } + class u19 { def x: Int = u.f(x = "32") } + class u20 { val x: Int = u.f(x = "32") } + class u21 { var x: Int = u.f(x = "32") } +} diff --git a/tests/untried/neg/nested-annotation.check b/tests/untried/neg/nested-annotation.check new file mode 100644 index 000000000000..ca263943fefb --- /dev/null +++ b/tests/untried/neg/nested-annotation.check @@ -0,0 +1,10 @@ +nested-annotation.scala:3: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class ComplexAnnotation(val value: Annotation) extends ClassfileAnnotation + ^ +nested-annotation.scala:8: error: nested classfile annotations must be defined in java; found: inline + @ComplexAnnotation(new inline) def bippy(): Int = 1 + ^ +one warning found +one error found diff --git a/tests/untried/neg/nested-annotation.scala b/tests/untried/neg/nested-annotation.scala new file mode 100644 index 000000000000..35c0cd3b75ce --- /dev/null +++ b/tests/untried/neg/nested-annotation.scala @@ -0,0 +1,9 @@ +import annotation._ + +class ComplexAnnotation(val value: Annotation) extends ClassfileAnnotation + +class A { + // It's hard to induce this error because @ComplexAnnotation(@inline) is a parse + // error so it never gets out of the parser, but: + @ComplexAnnotation(new inline) def bippy(): Int = 1 +} diff --git a/tests/untried/neg/nested-fn-print.check b/tests/untried/neg/nested-fn-print.check new file mode 100644 index 000000000000..ea278554d42e --- /dev/null +++ b/tests/untried/neg/nested-fn-print.check @@ -0,0 +1,20 @@ +nested-fn-print.scala:4: error: only classes can have declared but undefined members +(Note that variables need to be initialized to be defined) + var x3: Int => Double + ^ +nested-fn-print.scala:7: error: type mismatch; + found : String("a") + required: Int => (Float => Double) + x1 = "a" + ^ +nested-fn-print.scala:8: error: type mismatch; + found : String("b") + required: (Int => Float) => Double + x2 = "b" + ^ +nested-fn-print.scala:9: error: type mismatch; + found : String("c") + required: Int => Double + x3 = "c" + ^ +four errors found diff --git a/tests/untried/neg/nested-fn-print.scala b/tests/untried/neg/nested-fn-print.scala new file mode 100644 index 000000000000..c599a235aba6 --- /dev/null +++ b/tests/untried/neg/nested-fn-print.scala @@ -0,0 +1,11 @@ +object Test { + var x1: Int => Float => Double = _ + var x2: (Int => Float) => Double = _ + var x3: Int => Double + + def main(args: Array[String]): Unit = { + x1 = "a" + x2 = "b" + x3 = "c" + } +} diff --git a/tests/untried/neg/newpat_unreachable.check b/tests/untried/neg/newpat_unreachable.check new file mode 100644 index 000000000000..4463e2f1a43e --- /dev/null +++ b/tests/untried/neg/newpat_unreachable.check @@ -0,0 +1,35 @@ +newpat_unreachable.scala:6: warning: patterns after a variable pattern cannot match (SLS 8.1.1) +If you intended to match against parameter b of method contrivedExample, you must use backticks, like: case `b` => + case b => println("matched b") + ^ +newpat_unreachable.scala:7: warning: unreachable code due to variable pattern 'b' on line 6 +If you intended to match against parameter c of method contrivedExample, you must use backticks, like: case `c` => + case c => println("matched c") + ^ +newpat_unreachable.scala:8: warning: unreachable code due to variable pattern 'b' on line 6 +If you intended to match against value d in class A, you must use backticks, like: case `d` => + case d => println("matched d") + ^ +newpat_unreachable.scala:9: warning: unreachable code due to variable pattern 'b' on line 6 + case _ => println("matched neither") + ^ +newpat_unreachable.scala:7: warning: unreachable code + case c => println("matched c") + ^ +newpat_unreachable.scala:22: warning: patterns after a variable pattern cannot match (SLS 8.1.1) +If you intended to match against parameter b of method g, you must use backticks, like: case `b` => + case b => 1 + ^ +newpat_unreachable.scala:23: warning: unreachable code due to variable pattern 'b' on line 22 +If you intended to match against parameter c of method h, you must use backticks, like: case `c` => + case c => 2 + ^ +newpat_unreachable.scala:24: warning: unreachable code due to variable pattern 'b' on line 22 + case _ => 3 + ^ +newpat_unreachable.scala:23: warning: unreachable code + case c => 2 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +9 warnings found +one error found diff --git a/tests/untried/neg/newpat_unreachable.flags b/tests/untried/neg/newpat_unreachable.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/newpat_unreachable.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/newpat_unreachable.scala b/tests/untried/neg/newpat_unreachable.scala new file mode 100644 index 000000000000..c9cc85cec69d --- /dev/null +++ b/tests/untried/neg/newpat_unreachable.scala @@ -0,0 +1,29 @@ +object Test { + class A { + val d = 55 + + def contrivedExample[A, B, C](a: A, b: B, c: C): Unit = a match { + case b => println("matched b") + case c => println("matched c") + case d => println("matched d") + case _ => println("matched neither") + } + + def correctExample[A, B, C](a: A, b: B, c: C): Unit = a match { + case `b` => println("matched b") + case `c` => println("matched c") + case `d` => println("matched d") + case _ => println("matched neither") + } + + def f[A](a: A) = { + def g[B](b: B) = { + def h[C](c: C) = a match { + case b => 1 + case c => 2 + case _ => 3 + } + } + } + } +} diff --git a/tests/untried/neg/no-implicit-to-anyref-any-val.check b/tests/untried/neg/no-implicit-to-anyref-any-val.check new file mode 100644 index 000000000000..5953e1bd6d5d --- /dev/null +++ b/tests/untried/neg/no-implicit-to-anyref-any-val.check @@ -0,0 +1,34 @@ +no-implicit-to-anyref-any-val.scala:11: error: the result type of an implicit conversion must be more specific than AnyRef + 1: AnyRef + ^ +no-implicit-to-anyref-any-val.scala:17: error: type mismatch; + found : Any + required: AnyRef + (null: Any): AnyRef + ^ +no-implicit-to-anyref-any-val.scala:21: error: type mismatch; + found : AnyVal + required: AnyRef + (0: AnyVal): AnyRef + ^ +no-implicit-to-anyref-any-val.scala:27: error: type mismatch; + found : Test.AV + required: AnyRef +Note that AV extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + new AV(0): AnyRef + ^ +no-implicit-to-anyref-any-val.scala:30: error: the result type of an implicit conversion must be more specific than AnyVal + "": AnyVal + ^ +no-implicit-to-anyref-any-val.scala:32: error: type mismatch; + found : Object + required: AnyVal +Note that implicit conversions are not applicable because they are ambiguous: + both method ArrowAssoc in object Predef of type [A](self: A)ArrowAssoc[A] + and method Ensuring in object Predef of type [A](self: A)Ensuring[A] + are possible conversion functions from Object to AnyVal + new Object() : AnyVal + ^ +6 errors found diff --git a/tests/untried/neg/no-implicit-to-anyref-any-val.scala b/tests/untried/neg/no-implicit-to-anyref-any-val.scala new file mode 100644 index 000000000000..f5daf541afca --- /dev/null +++ b/tests/untried/neg/no-implicit-to-anyref-any-val.scala @@ -0,0 +1,33 @@ +// Checks that the state of standard implicits in Predef._ and scala._ +// doesn't allow us to unambiguously and implicitly convert AnyVal +// and subtypes to AnyRef. +// +// In the days before value classes, this was precariously held be +// the competing implicits Any => StringAdd and Any => StringFormat. +// Since then, these have both become value classes, but seeing as +// this happened simultaneously, we're still okay. +object Test { + locally { + 1: AnyRef + } + + locally { + // before this test case was added and ContextErrors was tweaked, this + // emitted: "Note that Any extends Any, not AnyRef." + (null: Any): AnyRef + } + + locally { + (0: AnyVal): AnyRef + } + + class AV(val a: Int) extends AnyVal + + locally { + new AV(0): AnyRef + } + + "": AnyVal + + new Object() : AnyVal +} diff --git a/tests/untried/neg/no-predef.check b/tests/untried/neg/no-predef.check new file mode 100644 index 000000000000..a63d8c5ba5c6 --- /dev/null +++ b/tests/untried/neg/no-predef.check @@ -0,0 +1,14 @@ +no-predef.scala:2: error: type mismatch; + found : scala.Long(5L) + required: java.lang.Long + def f1 = 5L: java.lang.Long + ^ +no-predef.scala:3: error: type mismatch; + found : java.lang.Long + required: scala.Long + def f2 = new java.lang.Long(5) : Long + ^ +no-predef.scala:4: error: value map is not a member of String + def f3 = "abc" map (_ + 1) + ^ +three errors found diff --git a/tests/untried/neg/no-predef.flags b/tests/untried/neg/no-predef.flags new file mode 100644 index 000000000000..3abc2d521517 --- /dev/null +++ b/tests/untried/neg/no-predef.flags @@ -0,0 +1 @@ +-Yno-predef \ No newline at end of file diff --git a/tests/untried/neg/no-predef.scala b/tests/untried/neg/no-predef.scala new file mode 100644 index 000000000000..48883d7ba8ac --- /dev/null +++ b/tests/untried/neg/no-predef.scala @@ -0,0 +1,5 @@ +class NoPredef { + def f1 = 5L: java.lang.Long + def f2 = new java.lang.Long(5) : Long + def f3 = "abc" map (_ + 1) +} diff --git a/tests/untried/neg/noMember1.check b/tests/untried/neg/noMember1.check new file mode 100644 index 000000000000..846574bef977 --- /dev/null +++ b/tests/untried/neg/noMember1.check @@ -0,0 +1,5 @@ +noMember1.scala:1: error: object MultiMap is not a member of package scala.collection.mutable +Note: trait MultiMap exists, but it has no companion object. +import scala.collection.mutable.MultiMap._ + ^ +one error found diff --git a/tests/untried/neg/noMember1.scala b/tests/untried/neg/noMember1.scala new file mode 100644 index 000000000000..0aee7bff7f9f --- /dev/null +++ b/tests/untried/neg/noMember1.scala @@ -0,0 +1,3 @@ +import scala.collection.mutable.MultiMap._ + +class A diff --git a/tests/untried/neg/noMember2.check b/tests/untried/neg/noMember2.check new file mode 100644 index 000000000000..f65571bdc900 --- /dev/null +++ b/tests/untried/neg/noMember2.check @@ -0,0 +1,5 @@ +noMember2.scala:2: error: object MultiMap is not a member of package scala.collection.mutable +Note: trait MultiMap exists, but it has no companion object. + val m = scala.collection.mutable.MultiMap(1, 2, 3) + ^ +one error found diff --git a/tests/untried/neg/noMember2.scala b/tests/untried/neg/noMember2.scala new file mode 100644 index 000000000000..bf72d4f4713c --- /dev/null +++ b/tests/untried/neg/noMember2.scala @@ -0,0 +1,3 @@ +object Test { + val m = scala.collection.mutable.MultiMap(1, 2, 3) +} diff --git a/tests/untried/neg/nonlocal-warning.check b/tests/untried/neg/nonlocal-warning.check new file mode 100644 index 000000000000..5202df655a2a --- /dev/null +++ b/tests/untried/neg/nonlocal-warning.check @@ -0,0 +1,9 @@ +nonlocal-warning.scala:4: warning: This catches all Throwables. If this is really intended, use `case x : Throwable` to clear this warning. + catch { case x => 11 } + ^ +nonlocal-warning.scala:2: warning: catch block may intercept non-local return from method foo + def foo(l: List[Int]): Int = { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/nonlocal-warning.flags b/tests/untried/neg/nonlocal-warning.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/nonlocal-warning.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/nonlocal-warning.scala b/tests/untried/neg/nonlocal-warning.scala new file mode 100644 index 000000000000..f908a863029d --- /dev/null +++ b/tests/untried/neg/nonlocal-warning.scala @@ -0,0 +1,18 @@ +class Foo { + def foo(l: List[Int]): Int = { + try l foreach { _ => return 5 } + catch { case x => 11 } + 22 + } + + val pf: PartialFunction[Throwable, Unit] = { + case x if false => () + } + + def bar(l: List[Int]): Int = { + try l foreach { _ => return 5 } + catch pf + finally println() + 22 + } +} diff --git a/tests/untried/neg/nopredefs.check b/tests/untried/neg/nopredefs.check new file mode 100644 index 000000000000..0a0ab34482bd --- /dev/null +++ b/tests/untried/neg/nopredefs.check @@ -0,0 +1,4 @@ +nopredefs.scala:5: error: not found: value Set + val y = Set(3) + ^ +one error found diff --git a/tests/untried/neg/nopredefs.scala b/tests/untried/neg/nopredefs.scala new file mode 100644 index 000000000000..1128b189342a --- /dev/null +++ b/tests/untried/neg/nopredefs.scala @@ -0,0 +1,6 @@ +import Predef.{Set => _, _} + +object Test { + val x = Map(1 -> 2) + val y = Set(3) +} diff --git a/tests/untried/neg/not-a-legal-formal-parameter-tuple.check b/tests/untried/neg/not-a-legal-formal-parameter-tuple.check new file mode 100644 index 000000000000..2b906b8ff355 --- /dev/null +++ b/tests/untried/neg/not-a-legal-formal-parameter-tuple.check @@ -0,0 +1,19 @@ +not-a-legal-formal-parameter-tuple.scala:2: error: not a legal formal parameter. +Note: Tuples cannot be directly destructured in method or function parameters. + Either create a single parameter accepting the Tuple2, + or consider a pattern matching anonymous function: `{ case (a, b) => ... } + val x: ((Int, Int) => Int) = (((a, b)) => a) + ^ +not-a-legal-formal-parameter-tuple.scala:3: error: not a legal formal parameter. +Note: Tuples cannot be directly destructured in method or function parameters. + Either create a single parameter accepting the Tuple2, + or consider a pattern matching anonymous function: `{ case (param1, param2) => ... } + val y: ((Int, Int, Int) => Int) = (((a, !!)) => a) + ^ +not-a-legal-formal-parameter-tuple.scala:4: error: not a legal formal parameter. +Note: Tuples cannot be directly destructured in method or function parameters. + Either create a single parameter accepting the Tuple3, + or consider a pattern matching anonymous function: `{ case (param1, ..., param3) => ... } + val z: ((Int, Int, Int) => Int) = (((a, NotAPatternVariableName, c)) => a) + ^ +three errors found diff --git a/tests/untried/neg/not-a-legal-formal-parameter-tuple.scala b/tests/untried/neg/not-a-legal-formal-parameter-tuple.scala new file mode 100644 index 000000000000..c7a13557df30 --- /dev/null +++ b/tests/untried/neg/not-a-legal-formal-parameter-tuple.scala @@ -0,0 +1,5 @@ +class C { + val x: ((Int, Int) => Int) = (((a, b)) => a) + val y: ((Int, Int, Int) => Int) = (((a, !!)) => a) + val z: ((Int, Int, Int) => Int) = (((a, NotAPatternVariableName, c)) => a) +} diff --git a/tests/untried/neg/not-possible-cause.check b/tests/untried/neg/not-possible-cause.check new file mode 100644 index 000000000000..5c09fa154568 --- /dev/null +++ b/tests/untried/neg/not-possible-cause.check @@ -0,0 +1,9 @@ +not-possible-cause.scala:2: error: type mismatch; + found : a.type (with underlying type A) + required: AnyRef +Note that A is bounded only by Equals, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def foo[A <: Product](a: A) { type X = a.type } + ^ +one error found diff --git a/tests/untried/neg/not-possible-cause.scala b/tests/untried/neg/not-possible-cause.scala new file mode 100644 index 000000000000..6c500b7b8511 --- /dev/null +++ b/tests/untried/neg/not-possible-cause.scala @@ -0,0 +1,3 @@ +object Foo { + def foo[A <: Product](a: A): Unit = { type X = a.type } +} diff --git a/tests/untried/neg/null-unsoundness.check b/tests/untried/neg/null-unsoundness.check new file mode 100644 index 000000000000..bc0b5c996ca1 --- /dev/null +++ b/tests/untried/neg/null-unsoundness.check @@ -0,0 +1,5 @@ +null-unsoundness.scala:8: error: stable identifier required, but A.this.x found. + Note that value x is not stable because its type, A.this.A with A.this.D, is volatile. + var y: x.T = new C("abc") + ^ +one error found diff --git a/tests/untried/neg/null-unsoundness.scala b/tests/untried/neg/null-unsoundness.scala new file mode 100644 index 000000000000..0f8ed5e3140d --- /dev/null +++ b/tests/untried/neg/null-unsoundness.scala @@ -0,0 +1,14 @@ +class B +class C(x: String) extends B + +class A { + type A >: Null + class D { type T >: C <: B } + val x: A with D = null + var y: x.T = new C("abc") +} +object Test extends A with App { + class C { type T = Int; val x = 1 } + type A = C + y = 42 +} diff --git a/tests/untried/neg/nullary-override.check b/tests/untried/neg/nullary-override.check new file mode 100644 index 000000000000..f032f4a6c22b --- /dev/null +++ b/tests/untried/neg/nullary-override.check @@ -0,0 +1,6 @@ +nullary-override.scala:2: warning: non-nullary method overrides nullary method +class B extends A { override def x(): Int = 4 } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/nullary-override.flags b/tests/untried/neg/nullary-override.flags new file mode 100644 index 000000000000..6c1dd108aea5 --- /dev/null +++ b/tests/untried/neg/nullary-override.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xlint \ No newline at end of file diff --git a/tests/untried/neg/nullary-override.scala b/tests/untried/neg/nullary-override.scala new file mode 100644 index 000000000000..3eb4784a0cff --- /dev/null +++ b/tests/untried/neg/nullary-override.scala @@ -0,0 +1,3 @@ +class A { def x: Int = 3 } +class B extends A { override def x(): Int = 4 } + diff --git a/tests/untried/neg/object-not-a-value.check b/tests/untried/neg/object-not-a-value.check new file mode 100644 index 000000000000..613210f27c4d --- /dev/null +++ b/tests/untried/neg/object-not-a-value.check @@ -0,0 +1,4 @@ +object-not-a-value.scala:5: error: object java.util.List is not a value + List(1) map (_ + 1) + ^ +one error found diff --git a/tests/untried/neg/object-not-a-value.scala b/tests/untried/neg/object-not-a-value.scala new file mode 100644 index 000000000000..207b271df22c --- /dev/null +++ b/tests/untried/neg/object-not-a-value.scala @@ -0,0 +1,7 @@ +object Test { + import java.util._ + + def main(args: Array[String]): Unit = { + List(1) map (_ + 1) + } +} diff --git a/tests/untried/neg/overload-msg.check b/tests/untried/neg/overload-msg.check new file mode 100644 index 000000000000..c61ace0dd0a3 --- /dev/null +++ b/tests/untried/neg/overload-msg.check @@ -0,0 +1,13 @@ +overload-msg.scala:3: error: overloaded method value + with alternatives: + (x: Double)Double + (x: Float)Float + (x: Long)Long + (x: scala.Int)scala.Int + (x: Char)scala.Int + (x: Short)scala.Int + (x: Byte)scala.Int + (x: String)String + cannot be applied to (Int(in method f)) + def f[Int](y: Int) = x + y + ^ +one error found diff --git a/tests/untried/neg/overload-msg.scala b/tests/untried/neg/overload-msg.scala new file mode 100644 index 000000000000..8715c156a24f --- /dev/null +++ b/tests/untried/neg/overload-msg.scala @@ -0,0 +1,4 @@ +// type parameter shadows actual type, massive overload error confuses. +class A(x: Int) { + def f[Int](y: Int) = x + y +} diff --git a/tests/untried/neg/overload.check b/tests/untried/neg/overload.check new file mode 100644 index 000000000000..abfabaf3f2b7 --- /dev/null +++ b/tests/untried/neg/overload.check @@ -0,0 +1,7 @@ +overload.scala:10: error: ambiguous reference to overloaded definition, +both method f in class D of type (x: Any)Unit +and method f in class C of type (x: Int)Unit +match argument types (Int) + (new D).f(1) + ^ +one error found diff --git a/tests/untried/neg/overload.scala b/tests/untried/neg/overload.scala new file mode 100644 index 000000000000..3128a39d06b8 --- /dev/null +++ b/tests/untried/neg/overload.scala @@ -0,0 +1,11 @@ +class C { + def f(x: Int): Unit = {} +} + +class D extends C { + def f(x: Any): Unit = {} +} + +object Test { + (new D).f(1) +} diff --git a/tests/untried/neg/overloaded-implicit.check b/tests/untried/neg/overloaded-implicit.check new file mode 100644 index 000000000000..ca0870705d49 --- /dev/null +++ b/tests/untried/neg/overloaded-implicit.check @@ -0,0 +1,9 @@ +overloaded-implicit.scala:2: warning: parameterized overloaded implicit methods are not visible as view bounds + implicit def imp1[T](x: List[T]): Map[T, T] = Map() + ^ +overloaded-implicit.scala:3: warning: parameterized overloaded implicit methods are not visible as view bounds + implicit def imp1[T](x: Set[T]): Map[T, T] = Map() + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/overloaded-implicit.flags b/tests/untried/neg/overloaded-implicit.flags new file mode 100644 index 000000000000..9c1e74e4ef84 --- /dev/null +++ b/tests/untried/neg/overloaded-implicit.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings -Xdev diff --git a/tests/untried/neg/overloaded-implicit.scala b/tests/untried/neg/overloaded-implicit.scala new file mode 100644 index 000000000000..68b1ceaa30b7 --- /dev/null +++ b/tests/untried/neg/overloaded-implicit.scala @@ -0,0 +1,17 @@ +object Test { + implicit def imp1[T](x: List[T]): Map[T, T] = Map() + implicit def imp1[T](x: Set[T]): Map[T, T] = Map() + + def f[T <% Map[Int, Int]](x: T): Double = 1.0d + + // not parameterized, no warning + implicit def imp2(x: List[Int]): String = "a" + implicit def imp2(x: Set[Int]): String = "b" + + def g[T <% String](x: T): Double = 2.0d + + def main(args: Array[String]): Unit = { + // println(f(List(1))) + println(g(List(1))) + } +} diff --git a/tests/untried/neg/overloaded-unapply.check b/tests/untried/neg/overloaded-unapply.check new file mode 100644 index 000000000000..68a826bac2ae --- /dev/null +++ b/tests/untried/neg/overloaded-unapply.check @@ -0,0 +1,14 @@ +overloaded-unapply.scala:18: error: ambiguous reference to overloaded definition, +both method unapply in object List of type [a](xs: List[a])Option[Null] +and method unapply in object List of type [a](xs: List[a])Option[(a, List[a])] +match argument types (List[a]) + case List(x, xs) => 7 + ^ +overloaded-unapply.scala:22: error: cannot resolve overloaded unapply + case List(x, xs) => 7 + ^ +overloaded-unapply.scala:12: error: method unapply is defined twice + conflicting symbols both originated in file 'overloaded-unapply.scala' + def unapply[a](xs: List[a]): Option[Null] = xs match { + ^ +three errors found diff --git a/tests/untried/neg/overloaded-unapply.scala b/tests/untried/neg/overloaded-unapply.scala new file mode 100644 index 000000000000..36909626c1f1 --- /dev/null +++ b/tests/untried/neg/overloaded-unapply.scala @@ -0,0 +1,24 @@ +sealed abstract class List[+a] +private case object Nil extends List[Nothing] +private final case class Cons[+a](head: a, tail: List[a]) +extends List[a] + +object List { + def unapply[a](xs: List[a]): Option[(a, List[a])] = xs match { + case Nil => None + case Cons(x, xs) => Some(x, xs) + } + + def unapply[a](xs: List[a]): Option[Null] = xs match { + case Nil => Some(null) + case Cons(_, _) => None + } + + def foo[a](xs: List[a]) = xs match { + case List(x, xs) => 7 + } + + def bar(xs: Any) = xs match { // test error message OverloadedUnapplyError + case List(x, xs) => 7 + } +} diff --git a/tests/untried/neg/override-object-flag.check b/tests/untried/neg/override-object-flag.check new file mode 100644 index 000000000000..344165138dd3 --- /dev/null +++ b/tests/untried/neg/override-object-flag.check @@ -0,0 +1,5 @@ +override-object-flag.scala:3: error: overriding object Foo in trait A; + object Foo cannot override final member +trait B extends A { override object Foo } + ^ +one error found diff --git a/tests/untried/neg/override-object-flag.scala b/tests/untried/neg/override-object-flag.scala new file mode 100644 index 000000000000..74d00dd44519 --- /dev/null +++ b/tests/untried/neg/override-object-flag.scala @@ -0,0 +1,3 @@ +// no flag enabling it, fail +trait A { object Foo } +trait B extends A { override object Foo } diff --git a/tests/untried/neg/override-object-no.check b/tests/untried/neg/override-object-no.check new file mode 100644 index 000000000000..9cfda80fc379 --- /dev/null +++ b/tests/untried/neg/override-object-no.check @@ -0,0 +1,23 @@ +override-object-no.scala:14: error: overriding object Bar in trait Foo with object Bar in trait Foo2: +an overriding object must conform to the overridden object's class bound; + found : case1.Bippy + required: case1.Bippy with case1.Bippo + override object Bar extends Bippy { // err + ^ +override-object-no.scala:21: error: overriding object Bar in trait Quux1 with object Bar in trait Quux2: +an overriding object must conform to the overridden object's class bound; + found : AnyRef{def g: String} + required: AnyRef{def g: Int} + trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err + ^ +override-object-no.scala:25: error: overriding object Bar in trait Quux3; + object Bar cannot override final member + trait Quux4 extends Quux3 { override object Bar } // err + ^ +override-object-no.scala:43: error: overriding object A in class Foo with object A in class P2: +an overriding object must conform to the overridden object's class bound; + found : case2.Bar[List[String]] + required: case2.Bar[Traversable[String]] + override object A extends Bar[List[String]] // err + ^ +four errors found diff --git a/tests/untried/neg/override-object-no.flags b/tests/untried/neg/override-object-no.flags new file mode 100644 index 000000000000..22e9a95c4ff7 --- /dev/null +++ b/tests/untried/neg/override-object-no.flags @@ -0,0 +1 @@ +-Yoverride-objects \ No newline at end of file diff --git a/tests/untried/neg/override-object-no.scala b/tests/untried/neg/override-object-no.scala new file mode 100644 index 000000000000..745cdb2332a6 --- /dev/null +++ b/tests/untried/neg/override-object-no.scala @@ -0,0 +1,45 @@ +// See also pos/override-object-yes.scala + +package case1 { + // Missing interface in overriding object + class Bippy { def f = 1 } + trait Bippo + + trait Foo { + object Bar extends Bippy with Bippo { override def f = 2 } + def f(x: Bippo) + def g = f(Bar) + } + trait Foo2 extends Foo { + override object Bar extends Bippy { // err + override def f = 3 + } + } + + // type mismatch in member + trait Quux1 { object Bar { def g = 55 } } + trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err + + // still can't override final objects! + trait Quux3 { final object Bar { } } + trait Quux4 extends Quux3 { override object Bar } // err +} + +// type parameter as-seen-from business +package case2 { + // invariance (see pos for the covariant case) + class Bar[T] + + class Foo[T] { + object A extends Bar[T] + } + + class Baz[S] extends Foo[S] { + override object A extends Bar[S] + } + + class P1 extends Foo[Traversable[String]] + class P2 extends P1 { + override object A extends Bar[List[String]] // err + } +} diff --git a/tests/untried/neg/override.check b/tests/untried/neg/override.check new file mode 100644 index 000000000000..8be98bf4d0cd --- /dev/null +++ b/tests/untried/neg/override.check @@ -0,0 +1,5 @@ +override.scala:9: error: overriding type T in trait A with bounds >: Int <: Int; + type T in trait B with bounds >: String <: String has incompatible type + lazy val x : A with B = {println(""); x} + ^ +one error found diff --git a/tests/untried/neg/override.scala b/tests/untried/neg/override.scala new file mode 100755 index 000000000000..79755160619c --- /dev/null +++ b/tests/untried/neg/override.scala @@ -0,0 +1,15 @@ +trait X { + trait A { type T >: Int <: Int } + val x : A + var n : x.T = 3 +} + +trait Y extends X { + trait B { type T >: String <: String } + lazy val x : A with B = {println(""); x} + n = "foo" +} + +object Test extends App { + new Y {} +} diff --git a/tests/untried/neg/parent-inherited-twice-error.check b/tests/untried/neg/parent-inherited-twice-error.check new file mode 100644 index 000000000000..521a6c19d010 --- /dev/null +++ b/tests/untried/neg/parent-inherited-twice-error.check @@ -0,0 +1,7 @@ +parent-inherited-twice-error.scala:2: error: trait A is inherited twice +class B extends A with A + ^ +parent-inherited-twice-error.scala:2: error: trait A is inherited twice +class B extends A with A + ^ +two errors found diff --git a/tests/untried/neg/parent-inherited-twice-error.scala b/tests/untried/neg/parent-inherited-twice-error.scala new file mode 100644 index 000000000000..7b433b98608f --- /dev/null +++ b/tests/untried/neg/parent-inherited-twice-error.scala @@ -0,0 +1,2 @@ +trait A +class B extends A with A diff --git a/tests/untried/neg/parstar.check b/tests/untried/neg/parstar.check new file mode 100644 index 000000000000..108f0f4de8e0 --- /dev/null +++ b/tests/untried/neg/parstar.check @@ -0,0 +1,7 @@ +parstar.scala:8: error: *-parameter must come last + def m(a: A*, b: B ) = a.toArray + ^ +parstar.scala:9: error: *-parameter must come last + def m(a: A*, b: B*) = a.toArray + ^ +two errors found diff --git a/tests/untried/neg/parstar.scala b/tests/untried/neg/parstar.scala new file mode 100644 index 000000000000..dd8d108447e0 --- /dev/null +++ b/tests/untried/neg/parstar.scala @@ -0,0 +1,10 @@ +package test; + +object test { + class A + class B + + def m(a: A, b: B*) = b.toArray + def m(a: A*, b: B ) = a.toArray + def m(a: A*, b: B*) = a.toArray +} diff --git a/tests/untried/neg/pat_unreachable.check b/tests/untried/neg/pat_unreachable.check new file mode 100644 index 000000000000..374ee4e9cf7e --- /dev/null +++ b/tests/untried/neg/pat_unreachable.check @@ -0,0 +1,17 @@ +pat_unreachable.scala:22: warning: patterns after a variable pattern cannot match (SLS 8.1.1) +If you intended to match against parameter b of method contrivedExample, you must use backticks, like: case `b` => + case b => println("matched b") + ^ +pat_unreachable.scala:23: warning: unreachable code due to variable pattern 'b' on line 22 +If you intended to match against parameter c of method contrivedExample, you must use backticks, like: case `c` => + case c => println("matched c") + ^ +pat_unreachable.scala:24: warning: unreachable code due to variable pattern 'b' on line 22 + case _ => println("matched neither") + ^ +pat_unreachable.scala:23: warning: unreachable code + case c => println("matched c") + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/pat_unreachable.flags b/tests/untried/neg/pat_unreachable.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/pat_unreachable.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/pat_unreachable.scala b/tests/untried/neg/pat_unreachable.scala new file mode 100644 index 000000000000..1f402e5212df --- /dev/null +++ b/tests/untried/neg/pat_unreachable.scala @@ -0,0 +1,26 @@ + +object Test extends App { + def unreachable1(xs:Seq[Char]) = xs match { + case Seq(x, y, _*) => x::y::Nil + case Seq(x, y, z, w) => List(z,w) // redundant! + } + def unreachable2(xs:Seq[Char]) = xs match { + case Seq(x, y, _*) => x::y::Nil + case Seq(x, y) => List(x, y) + } + + def not_unreachable(xs:Seq[Char]) = xs match { + case Seq(x, y, _*) => x::y::Nil + case Seq(x) => List(x) + } + def not_unreachable2(xs:Seq[Char]) = xs match { + case Seq(x, y) => x::y::Nil + case Seq(x, y, z, _*) => List(x,y) + } + + def contrivedExample[A, B, C](a: A, b: B, c: C): Unit = a match { + case b => println("matched b") + case c => println("matched c") + case _ => println("matched neither") + } +} diff --git a/tests/untried/neg/patmat-classtag-compound.check b/tests/untried/neg/patmat-classtag-compound.check new file mode 100644 index 000000000000..8a54c935bd76 --- /dev/null +++ b/tests/untried/neg/patmat-classtag-compound.check @@ -0,0 +1,6 @@ +patmat-classtag-compound.scala:12: warning: abstract type pattern A is unchecked since it is eliminated by erasure + case b: A with Bar => true + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/patmat-classtag-compound.flags b/tests/untried/neg/patmat-classtag-compound.flags new file mode 100644 index 000000000000..144ddac9d3d8 --- /dev/null +++ b/tests/untried/neg/patmat-classtag-compound.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings diff --git a/tests/untried/neg/patmat-classtag-compound.scala b/tests/untried/neg/patmat-classtag-compound.scala new file mode 100644 index 000000000000..e2d0df0a02ed --- /dev/null +++ b/tests/untried/neg/patmat-classtag-compound.scala @@ -0,0 +1,17 @@ +object Test extends App{ + trait Bar + trait Foo + // Failed to give an unchecked warning pre: https://github.com/scala/scala/pull/2848 + // + // Features interacting: + // - implicit class tags to enable type patterns on abstract types + // - type tests on compound types. + // + // We could try make these work together, but an unchecked warning is okay for now. + def x[A: reflect.ClassTag](a: Any): Boolean = a match{ + case b: A with Bar => true + case _ => false + } + println(x[Foo](new Bar{})) + println(x[String]("")) +} diff --git a/tests/untried/neg/patmat-type-check.check b/tests/untried/neg/patmat-type-check.check new file mode 100644 index 000000000000..fedac3b746c6 --- /dev/null +++ b/tests/untried/neg/patmat-type-check.check @@ -0,0 +1,46 @@ +patmat-type-check.scala:11: warning: fruitless type test: a value of type Test.Bop4[T] cannot also be a Seq[A] + def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:11: error: pattern type is incompatible with expected type; + found : Seq[A] + required: Test.Bop4[T] + def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:15: warning: fruitless type test: a value of type Test.Bop5[_$1,T1,T2] cannot also be a Seq[A] + def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:15: error: pattern type is incompatible with expected type; + found : Seq[A] + required: Test.Bop5[_$1,T1,T2] where type _$1 + def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:19: warning: fruitless type test: a value of type Test.Bop3[T] cannot also be a Seq[A] + def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:19: error: pattern type is incompatible with expected type; + found : Seq[A] + required: Test.Bop3[T] + def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true } + ^ +patmat-type-check.scala:22: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: String + def f1 = "bob".reverse match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:23: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Array[Char] + def f2 = "bob".toArray match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:27: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Test.Bop2 + def f3(x: Bop2) = x match { case Seq('b', 'o', 'b') => true } // fail + ^ +patmat-type-check.scala:30: error: scrutinee is incompatible with pattern type; + found : Seq[A] + required: Test.Bop3[Char] + def f4[T](x: Bop3[Char]) = x match { case Seq('b', 'o', 'b') => true } // fail + ^ +three warnings found +7 errors found diff --git a/tests/untried/neg/patmat-type-check.scala b/tests/untried/neg/patmat-type-check.scala new file mode 100644 index 000000000000..26d0409fa02f --- /dev/null +++ b/tests/untried/neg/patmat-type-check.scala @@ -0,0 +1,31 @@ +object Test +{ + def s1 = "bob".toList match { case Seq('b', 'o', 'b') => true } // list ok + + // not final, allowed + class Bop + def s2(x: Bop) = x match { case Seq('b', 'o', 'b') => true } + + // covariance, allowed + final class Bop4[+T] + def s3[T](x: Bop4[T]) = x match { case Seq('b', 'o', 'b') => true } + + // contravariance, allowed + final class Bop5[T, U, -V] + def s4[T1, T2](x: Bop5[_, T1, T2]) = x match { case Seq('b', 'o', 'b') => true } + + // free type parameter, allowed + final class Bop3[T] + def f4[T](x: Bop3[T]) = x match { case Seq('b', 'o', 'b') => true } + + // String and Array are final/invariant, disallowed + def f1 = "bob".reverse match { case Seq('b', 'o', 'b') => true } // fail + def f2 = "bob".toArray match { case Seq('b', 'o', 'b') => true } // fail + + // final, no type parameters, should be disallowed + final class Bop2 + def f3(x: Bop2) = x match { case Seq('b', 'o', 'b') => true } // fail + + // final, invariant type parameter, should be disallowed + def f4[T](x: Bop3[Char]) = x match { case Seq('b', 'o', 'b') => true } // fail +} diff --git a/tests/untried/neg/patmatexhaust.check b/tests/untried/neg/patmatexhaust.check new file mode 100644 index 000000000000..2dad60845107 --- /dev/null +++ b/tests/untried/neg/patmatexhaust.check @@ -0,0 +1,42 @@ +patmatexhaust.scala:7: warning: match may not be exhaustive. +It would fail on the following input: Baz + def ma1(x:Foo) = x match { + ^ +patmatexhaust.scala:11: warning: match may not be exhaustive. +It would fail on the following input: Bar(_) + def ma2(x:Foo) = x match { + ^ +patmatexhaust.scala:23: warning: match may not be exhaustive. +It would fail on the following inputs: (Kult(_), Kult(_)), (Qult(), Qult()) + def ma3(x:Mult) = (x,x) match { // not exhaustive + ^ +patmatexhaust.scala:49: warning: match may not be exhaustive. +It would fail on the following inputs: Gp(), Gu + def ma4(x:Deep) = x match { // missing cases: Gu, Gp + ^ +patmatexhaust.scala:55: warning: unreachable code + case _ if 1 == 0 => + ^ +patmatexhaust.scala:53: warning: match may not be exhaustive. +It would fail on the following input: Gp() + def ma5(x:Deep) = x match { + ^ +patmatexhaust.scala:75: warning: match may not be exhaustive. +It would fail on the following input: B() + def ma9(x: B) = x match { + ^ +patmatexhaust.scala:100: warning: match may not be exhaustive. +It would fail on the following input: C1() + def ma10(x: C) = x match { // not exhaustive: C1 is not sealed. + ^ +patmatexhaust.scala:114: warning: match may not be exhaustive. +It would fail on the following inputs: D1, D2() + def ma10(x: C) = x match { // not exhaustive: C1 has subclasses. + ^ +patmatexhaust.scala:126: warning: match may not be exhaustive. +It would fail on the following input: C1() + def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. + ^ +error: No warnings can be incurred under -Xfatal-warnings. +10 warnings found +one error found diff --git a/tests/untried/neg/patmatexhaust.flags b/tests/untried/neg/patmatexhaust.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/patmatexhaust.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/patmatexhaust.scala b/tests/untried/neg/patmatexhaust.scala new file mode 100644 index 000000000000..f93719782918 --- /dev/null +++ b/tests/untried/neg/patmatexhaust.scala @@ -0,0 +1,131 @@ +class TestSealedExhaustive { // compile only + sealed abstract class Foo + + case class Bar(x:Int) extends Foo + case object Baz extends Foo + + def ma1(x:Foo) = x match { + case Bar(_) => // not exhaustive + } + + def ma2(x:Foo) = x match { + case Baz => // not exhaustive + } + + sealed abstract class Mult + case class Kult(s:Mult) extends Mult + case class Qult() extends Mult + + def ma33(x:Kult) = x match { // exhaustive + case Kult(_) => // exhaustive + } + + def ma3(x:Mult) = (x,x) match { // not exhaustive + case (Kult(_), Qult()) => // Kult missing + //case (Kult(_), Kult(_)) => + case (Qult(), Kult(_)) => // Qult missing + //case (Qult(), Qult()) => + } + + def ma3u(x:Mult) = ((x,x) : @unchecked) match { // not exhaustive, but not checked! + case (Kult(_), Qult()) => + case (Qult(), Kult(_)) => + } + + sealed abstract class Deep + + case object Ga extends Deep + sealed class Gp extends Deep + case object Gu extends Gp + + def zma3(x:Deep) = x match { // exhaustive! + case _ => + } + def zma4(x:Deep) = x match { // exhaustive! + case Ga => + case _ => + } + + def ma4(x:Deep) = x match { // missing cases: Gu, Gp + case Ga => + } + + def ma5(x:Deep) = x match { + case Gu => + case _ if 1 == 0 => + case Ga => + } + + def ma6() = List(1,2) match { // give up + case List(1,2) => + case x :: xs => + } + + def ma7() = List(1,2) match { //exhaustive + case 1::2::Nil => + case _ => + } + + sealed class B + case class B1() extends B + case object B2 extends B + def ma8(x: B) = x match { + case _: B => true + } + def ma9(x: B) = x match { + case B1() => true // missing B, which is not abstract so must be included + case B2 => true + } + + object ob1 { + sealed abstract class C + sealed abstract class C1 extends C + object C2 extends C + case class C3() extends C + case object C4 extends C + + def ma10(x: C) = x match { // exhaustive: abstract sealed C1 is dead end. + case C3() => true + case C2 | C4 => true + } + } + + object ob2 { + sealed abstract class C + abstract class C1 extends C + object C2 extends C + case class C3() extends C + case object C4 extends C + + def ma10(x: C) = x match { // not exhaustive: C1 is not sealed. + case C3() => true + case C2 | C4 => true + } + } + object ob3 { + sealed abstract class C + sealed abstract class C1 extends C + object D1 extends C1 + case class D2() extends C1 + object C2 extends C + case class C3() extends C + case object C4 extends C + + def ma10(x: C) = x match { // not exhaustive: C1 has subclasses. + case C3() => true + case C2 | C4 => true + } + } + object ob4 { + sealed abstract class C + sealed class C1 extends C + object C2 extends C + case class C3() extends C + case object C4 extends C + + def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. + case C3() => true + case C2 | C4 => true + } + } +} diff --git a/tests/untried/neg/patternalts.check b/tests/untried/neg/patternalts.check new file mode 100644 index 000000000000..9bec9a001ae5 --- /dev/null +++ b/tests/untried/neg/patternalts.check @@ -0,0 +1,4 @@ +patternalts.scala:3: error: illegal variable in pattern alternative + case List(x) | List() => Console.println(x) + ^ +one error found diff --git a/tests/untried/neg/patternalts.scala b/tests/untried/neg/patternalts.scala new file mode 100644 index 000000000000..539df43201cb --- /dev/null +++ b/tests/untried/neg/patternalts.scala @@ -0,0 +1,5 @@ +object Test { + List(1) match { + case List(x) | List() => Console.println(x) + } +} diff --git a/tests/untried/neg/permanent-blindness.check b/tests/untried/neg/permanent-blindness.check new file mode 100644 index 000000000000..cdde201ef642 --- /dev/null +++ b/tests/untried/neg/permanent-blindness.check @@ -0,0 +1,12 @@ +permanent-blindness.scala:10: warning: imported `Bippy' is permanently hidden by definition of class Bippy in package bar + import foo.{ Bippy, Bop, Dingus } + ^ +permanent-blindness.scala:10: warning: imported `Bop' is permanently hidden by definition of object Bop in package bar + import foo.{ Bippy, Bop, Dingus } + ^ +permanent-blindness.scala:10: warning: imported `Dingus' is permanently hidden by definition of object Dingus in package bar + import foo.{ Bippy, Bop, Dingus } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/permanent-blindness.flags b/tests/untried/neg/permanent-blindness.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/permanent-blindness.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/permanent-blindness.scala b/tests/untried/neg/permanent-blindness.scala new file mode 100644 index 000000000000..bb57e36fc000 --- /dev/null +++ b/tests/untried/neg/permanent-blindness.scala @@ -0,0 +1,22 @@ +package foo { + class Bippy + object Bop { + def fff = 5 + } + object Dingus +} + +package bar { + import foo.{ Bippy, Bop, Dingus } + + class Bippy + object Bop + object Dingus + + + class Ding { + def fff = 5 + + def g = new Bippy + } +} diff --git a/tests/untried/neg/predef-masking.check b/tests/untried/neg/predef-masking.check new file mode 100644 index 000000000000..79e4dece8aa8 --- /dev/null +++ b/tests/untried/neg/predef-masking.check @@ -0,0 +1,4 @@ +predef-masking.scala:7: error: value + is not a member of type parameter T + def f[T](x: T) = x + 5 + ^ +one error found diff --git a/tests/untried/neg/predef-masking.scala b/tests/untried/neg/predef-masking.scala new file mode 100644 index 000000000000..67b69aa1699b --- /dev/null +++ b/tests/untried/neg/predef-masking.scala @@ -0,0 +1,21 @@ +// Testing predef masking +import Predef.{ any2stringadd => _, _ } + +object StringPlusConfusion { + // Would love to do something about this error message, but by the + // time we get our hands on it the context is lost. + def f[T](x: T) = x + 5 + + // After we block out any2stringadd, the error is: + // + // work/a.scala:7: error: value + is not a member of type parameter T + // def f[T](x: T) = x + 5 + // ^ + // Normally, it is: + // + // work/a.scala:7: error: type mismatch; + // found : Int(5) + // required: String + // def f[T](x: T) = x + 5 + // ^ +} diff --git a/tests/untried/neg/primitive-sigs-1.check b/tests/untried/neg/primitive-sigs-1.check new file mode 100644 index 000000000000..77dc457a499c --- /dev/null +++ b/tests/untried/neg/primitive-sigs-1.check @@ -0,0 +1,6 @@ +B.scala:3: error: type mismatch; + found : Bippy + required: AC[Integer] + J.f(new Bippy()) + ^ +one error found diff --git a/tests/untried/neg/primitive-sigs-1/A.scala b/tests/untried/neg/primitive-sigs-1/A.scala new file mode 100644 index 000000000000..007a64c8f1de --- /dev/null +++ b/tests/untried/neg/primitive-sigs-1/A.scala @@ -0,0 +1,9 @@ +// scala: the signature in the abstract class will use the +// upper bound as return type, which for us will be Integer +// since primitives can't appear in bounds. +abstract class AC[T <: Int] { + def f(): T +} +class Bippy extends AC[Int] { + def f(): Int = 5 +} diff --git a/tests/untried/neg/primitive-sigs-1/B.scala b/tests/untried/neg/primitive-sigs-1/B.scala new file mode 100644 index 000000000000..0958bcda57da --- /dev/null +++ b/tests/untried/neg/primitive-sigs-1/B.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]): Unit = { + J.f(new Bippy()) + } +} diff --git a/tests/untried/neg/primitive-sigs-1/J.java b/tests/untried/neg/primitive-sigs-1/J.java new file mode 100644 index 000000000000..2e43b8330c0a --- /dev/null +++ b/tests/untried/neg/primitive-sigs-1/J.java @@ -0,0 +1,8 @@ +// java: often the java or scala compiler will save us from +// the untruth in the signature, but not always. +public class J { + public static Integer f(AC x) { return x.f(); } + public static void main(String[] args) { + f(new Bippy()); + } +} diff --git a/tests/untried/neg/protected-constructors.check b/tests/untried/neg/protected-constructors.check new file mode 100644 index 000000000000..f44d7db9b982 --- /dev/null +++ b/tests/untried/neg/protected-constructors.check @@ -0,0 +1,22 @@ +protected-constructors.scala:17: error: too many arguments for constructor Foo1: ()dingus.Foo1 + val foo1 = new Foo1("abc") + ^ +protected-constructors.scala:18: error: constructor Foo2 in class Foo2 cannot be accessed in object P + Access to protected constructor Foo2 not permitted because + enclosing object P in package hungus is not a subclass of + class Foo2 in package dingus where target is defined + val foo2 = new Foo2("abc") + ^ +protected-constructors.scala:19: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding + Access to protected class Foo3 not permitted because + enclosing object P in package hungus is not a subclass of + object Ding in package dingus where target is defined + val foo3 = new Ding.Foo3("abc") + ^ +protected-constructors.scala:15: error: class Foo3 in object Ding cannot be accessed in object dingus.Ding + Access to protected class Foo3 not permitted because + enclosing object P in package hungus is not a subclass of + object Ding in package dingus where target is defined + class Bar3 extends Ding.Foo3("abc") + ^ +four errors found diff --git a/tests/untried/neg/protected-constructors.scala b/tests/untried/neg/protected-constructors.scala new file mode 100644 index 000000000000..2838caf09c83 --- /dev/null +++ b/tests/untried/neg/protected-constructors.scala @@ -0,0 +1,21 @@ +package dingus { + class Foo1() { protected def this(name: String) = this() } + class Foo2 protected (name: String) { } + object Ding { + protected class Foo3(name: String) { } + } +} + +package hungus { + import dingus._ + + object P { + class Bar1 extends Foo1("abc") + class Bar2 extends Foo2("abc") + class Bar3 extends Ding.Foo3("abc") + + val foo1 = new Foo1("abc") + val foo2 = new Foo2("abc") + val foo3 = new Ding.Foo3("abc") + } +} diff --git a/tests/untried/neg/protected-static-fail.check b/tests/untried/neg/protected-static-fail.check new file mode 100644 index 000000000000..9f0bc92e7dc7 --- /dev/null +++ b/tests/untried/neg/protected-static-fail.check @@ -0,0 +1,16 @@ +S.scala:5: error: method f in object J cannot be accessed in object bippy.J + J.f() + ^ +S.scala:6: error: method f1 in object S1 cannot be accessed in object bippy.S1 + Access to protected method f1 not permitted because + enclosing object Test in package bippy is not a subclass of + object S1 in package bippy where target is defined + S1.f1() + ^ +S.scala:8: error: method f2 in class S2 cannot be accessed in bippy.S2 + Access to protected method f2 not permitted because + enclosing object Test in package bippy is not a subclass of + class S2 in package bippy where target is defined + x.f2() + ^ +three errors found diff --git a/tests/untried/neg/protected-static-fail/J.java b/tests/untried/neg/protected-static-fail/J.java new file mode 100644 index 000000000000..c340800d7f1f --- /dev/null +++ b/tests/untried/neg/protected-static-fail/J.java @@ -0,0 +1,7 @@ +package bippy; + +public class J { + private static String f() { + return "hi mom"; + } +} \ No newline at end of file diff --git a/tests/untried/neg/protected-static-fail/S.scala b/tests/untried/neg/protected-static-fail/S.scala new file mode 100644 index 000000000000..f9dd89d9d098 --- /dev/null +++ b/tests/untried/neg/protected-static-fail/S.scala @@ -0,0 +1,10 @@ +package bippy + +object Test { + def main(args: Array[String]): Unit = { + J.f() + S1.f1() + val x = new S2 + x.f2() + } +} diff --git a/tests/untried/neg/protected-static-fail/S0.scala b/tests/untried/neg/protected-static-fail/S0.scala new file mode 100644 index 000000000000..93a7bd91a892 --- /dev/null +++ b/tests/untried/neg/protected-static-fail/S0.scala @@ -0,0 +1,9 @@ +package bippy + +object S1 { + protected def f1() = "hi mom" +} + +class S2 { + protected def f2() = "hi mom" +} diff --git a/tests/untried/neg/qualifying-class-error-1.check b/tests/untried/neg/qualifying-class-error-1.check new file mode 100644 index 000000000000..c70db9ba6018 --- /dev/null +++ b/tests/untried/neg/qualifying-class-error-1.check @@ -0,0 +1,4 @@ +qualifying-class-error-1.scala:2: error: this can be used only in a class, object, or template +class B extends A(this.getClass.getName.length) + ^ +one error found diff --git a/tests/untried/neg/qualifying-class-error-1.scala b/tests/untried/neg/qualifying-class-error-1.scala new file mode 100644 index 000000000000..09152fe04ca4 --- /dev/null +++ b/tests/untried/neg/qualifying-class-error-1.scala @@ -0,0 +1,2 @@ +class A(val i:Int) +class B extends A(this.getClass.getName.length) diff --git a/tests/untried/neg/qualifying-class-error-2.check b/tests/untried/neg/qualifying-class-error-2.check new file mode 100644 index 000000000000..50c275968563 --- /dev/null +++ b/tests/untried/neg/qualifying-class-error-2.check @@ -0,0 +1,4 @@ +qualifying-class-error-2.scala:9: error: A is not an enclosing class + protected[A] def f() {} + ^ +one error found diff --git a/tests/untried/neg/qualifying-class-error-2.scala b/tests/untried/neg/qualifying-class-error-2.scala new file mode 100644 index 000000000000..9b80e1030f2c --- /dev/null +++ b/tests/untried/neg/qualifying-class-error-2.scala @@ -0,0 +1,11 @@ +package A { + trait X { + protected[A] def f() + } +} + +package B { + class Y extends A.X { + protected[A] def f(): Unit = {} + } +} diff --git a/tests/untried/neg/quasiquotes-syntax-error-position.check b/tests/untried/neg/quasiquotes-syntax-error-position.check new file mode 100644 index 000000000000..9fd6ce041761 --- /dev/null +++ b/tests/untried/neg/quasiquotes-syntax-error-position.check @@ -0,0 +1,47 @@ +quasiquotes-syntax-error-position.scala:5: error: '=' expected but identifier found. + q"def $a f" + ^ +quasiquotes-syntax-error-position.scala:6: error: illegal start of simple expression + q"$a(" + ^ +quasiquotes-syntax-error-position.scala:7: error: '}' expected but end of quote found. + q"class $t { def foo = $a" + ^ +quasiquotes-syntax-error-position.scala:8: error: '.' expected but unquotee found. + q"import $t $t" + ^ +quasiquotes-syntax-error-position.scala:9: error: '{' expected but end of quote found. + q"package p" + ^ +quasiquotes-syntax-error-position.scala:10: error: ';' expected but '@' found. + q"foo@$a" + ^ +quasiquotes-syntax-error-position.scala:11: error: case classes without a parameter list are not allowed; +use either case objects or case classes with an explicit `()' as a parameter list. + q"case class A" + ^ +quasiquotes-syntax-error-position.scala:12: error: identifier expected but ']' found. + tq"$t => $t $t]" + ^ +quasiquotes-syntax-error-position.scala:13: error: end of quote expected but 'case' found. + cq"pattern => body ; case pattern2 =>" + ^ +quasiquotes-syntax-error-position.scala:14: error: ')' expected but end of quote found. + pq"$a(bar" + ^ +quasiquotes-syntax-error-position.scala:15: error: ':' expected but ')' found. + q"def foo(x)" + ^ +quasiquotes-syntax-error-position.scala:16: error: illegal start of simple expression + q"$a(])" + ^ +quasiquotes-syntax-error-position.scala:17: error: in XML literal: '>' expected instead of '$' + q"foo bar " + ^ +quasiquotes-syntax-error-position.scala:19: error: ';' expected but '<:' found. + q"val $x: $x <: $x" + ^ +quasiquotes-syntax-error-position.scala:20: error: '=' expected but '.' found. + q"def f ( $x ) . $x" + ^ +15 errors found diff --git a/tests/untried/neg/quasiquotes-syntax-error-position.scala b/tests/untried/neg/quasiquotes-syntax-error-position.scala new file mode 100644 index 000000000000..823fe9a551a0 --- /dev/null +++ b/tests/untried/neg/quasiquotes-syntax-error-position.scala @@ -0,0 +1,21 @@ +import scala.reflect.runtime.universe._ +object test extends App { + val a = TermName("a") + val t = TypeName("t") + q"def $a f" + q"$a(" + q"class $t { def foo = $a" + q"import $t $t" + q"package p" + q"foo@$a" + q"case class A" + tq"$t => $t $t]" + cq"pattern => body ; case pattern2 =>" + pq"$a(bar" + q"def foo(x)" + q"$a(])" + q"foo bar " + val x = q"x" + q"val $x: $x <: $x" + q"def f ( $x ) . $x" +} diff --git a/tests/untried/neg/quasiquotes-unliftable-not-found.check b/tests/untried/neg/quasiquotes-unliftable-not-found.check new file mode 100644 index 000000000000..5594aa1b1573 --- /dev/null +++ b/tests/untried/neg/quasiquotes-unliftable-not-found.check @@ -0,0 +1,4 @@ +quasiquotes-unliftable-not-found.scala:4: error: Can't find reflect.runtime.universe.Unliftable[Test.C], consider providing it + val q"${c: C}" = q"()" + ^ +one error found diff --git a/tests/untried/neg/quasiquotes-unliftable-not-found.scala b/tests/untried/neg/quasiquotes-unliftable-not-found.scala new file mode 100644 index 000000000000..b2a1ccb47d75 --- /dev/null +++ b/tests/untried/neg/quasiquotes-unliftable-not-found.scala @@ -0,0 +1,5 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + class C + val q"${c: C}" = q"()" +} diff --git a/tests/untried/neg/raw-types-stubs.check b/tests/untried/neg/raw-types-stubs.check new file mode 100644 index 000000000000..f1b26a23b755 --- /dev/null +++ b/tests/untried/neg/raw-types-stubs.check @@ -0,0 +1,11 @@ +S_3.scala:1: error: class Sub needs to be abstract, since: +it has 2 unimplemented members. +/** As seen from class Sub, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def raw(x$1: M_1[_ <: String]): Unit = ??? + def raw(x$1: Any): Unit = ??? + +class Sub extends Raw_2 { } + ^ +one error found diff --git a/tests/untried/neg/raw-types-stubs/M_1.java b/tests/untried/neg/raw-types-stubs/M_1.java new file mode 100644 index 000000000000..6ea0d2e59380 --- /dev/null +++ b/tests/untried/neg/raw-types-stubs/M_1.java @@ -0,0 +1,3 @@ +public class M_1 { } + + diff --git a/tests/untried/neg/raw-types-stubs/Raw_2.java b/tests/untried/neg/raw-types-stubs/Raw_2.java new file mode 100644 index 000000000000..eff7df790ef2 --- /dev/null +++ b/tests/untried/neg/raw-types-stubs/Raw_2.java @@ -0,0 +1,4 @@ +public abstract class Raw_2 { + public abstract void raw(Object list); + public abstract void raw(M_1 list); +} diff --git a/tests/untried/neg/raw-types-stubs/S_3.scala b/tests/untried/neg/raw-types-stubs/S_3.scala new file mode 100644 index 000000000000..618eedc88827 --- /dev/null +++ b/tests/untried/neg/raw-types-stubs/S_3.scala @@ -0,0 +1 @@ +class Sub extends Raw_2 { } diff --git a/tests/untried/neg/reassignment.check b/tests/untried/neg/reassignment.check new file mode 100644 index 000000000000..f0effd1459df --- /dev/null +++ b/tests/untried/neg/reassignment.check @@ -0,0 +1,13 @@ +reassignment.scala:2: error: not found: value x + x = 5 + ^ +reassignment.scala:3: error: not found: value y + y := 45 + ^ +reassignment.scala:4: error: not found: value y + y += 45 + ^ +reassignment.scala:6: error: reassignment to val + z = 51 + ^ +four errors found diff --git a/tests/untried/neg/reassignment.scala b/tests/untried/neg/reassignment.scala new file mode 100644 index 000000000000..afb3542009ae --- /dev/null +++ b/tests/untried/neg/reassignment.scala @@ -0,0 +1,7 @@ +class A { + x = 5 + y := 45 + y += 45 + val z = 50 + z = 51 +} diff --git a/tests/untried/neg/reflection-names-neg.check b/tests/untried/neg/reflection-names-neg.check new file mode 100644 index 000000000000..f941ec8dc1b2 --- /dev/null +++ b/tests/untried/neg/reflection-names-neg.check @@ -0,0 +1,13 @@ +reflection-names-neg.scala:5: error: type mismatch; + found : String("abc") + required: reflect.runtime.universe.Name +Note that implicit conversions are not applicable because they are ambiguous: + both method stringToTermName in trait Names of type (s: String)reflect.runtime.universe.TermName + and method stringToTypeName in trait Names of type (s: String)reflect.runtime.universe.TypeName + are possible conversion functions from String("abc") to reflect.runtime.universe.Name + val x2 = ("abc": Name) drop 1 // error + ^ +reflection-names-neg.scala:5: error: value drop is not a member of reflect.runtime.universe.Name + val x2 = ("abc": Name) drop 1 // error + ^ +two errors found diff --git a/tests/untried/neg/reflection-names-neg.scala b/tests/untried/neg/reflection-names-neg.scala new file mode 100644 index 000000000000..7283d16db975 --- /dev/null +++ b/tests/untried/neg/reflection-names-neg.scala @@ -0,0 +1,6 @@ +import scala.reflect.runtime.universe._ + +object Test { + val x1 = "abc" drop 1 // "bc": String + val x2 = ("abc": Name) drop 1 // error +} diff --git a/tests/untried/neg/reify_ann2b.check b/tests/untried/neg/reify_ann2b.check new file mode 100644 index 000000000000..d32bedaf8f4b --- /dev/null +++ b/tests/untried/neg/reify_ann2b.check @@ -0,0 +1,4 @@ +reify_ann2b.scala:9: error: inner classes cannot be classfile annotations + class ann(bar: String) extends annotation.ClassfileAnnotation + ^ +one error found diff --git a/tests/untried/neg/reify_ann2b.scala b/tests/untried/neg/reify_ann2b.scala new file mode 100644 index 000000000000..974d5daf5c10 --- /dev/null +++ b/tests/untried/neg/reify_ann2b.scala @@ -0,0 +1,28 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + // test 1: reify + val tree = reify{ + class ann(bar: String) extends annotation.ClassfileAnnotation + + @ann(bar="1a") @ann(bar="1b") class C[@ann(bar="2a") @ann(bar="2b") T](@ann(bar="3a") @ann(bar="3b") x: T @ann(bar="4a") @ann(bar="4b")) { + @ann(bar="5a") @ann(bar="5b") def f(x: Int @ann(bar="6a") @ann(bar="6b")) = { + @ann(bar="7a") @ann(bar="7b") val r = (x + 3): @ann(bar="8a") @ann(bar="8b") + val s = 4: Int @ann(bar="9a") @ann(bar="9b") + r + s + } + } + }.tree + println(tree.toString) + + // test 2: import and typecheck + val toolbox = cm.mkToolBox() + val ttree = toolbox.typeCheck(tree) + println(ttree.toString) + + // test 3: import and compile + toolbox.eval(tree) +} diff --git a/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.check b/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.check new file mode 100644 index 000000000000..75b7555b01d4 --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.check @@ -0,0 +1,7 @@ +reify_metalevel_breach_+0_refers_to_1.scala:10: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + inner.splice + ^ +one error found diff --git a/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.scala b/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.scala new file mode 100644 index 000000000000..409a03e235d4 --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_+0_refers_to_1.scala @@ -0,0 +1,16 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val code = reify{ + val x = 2 + val inner = reify{x} + inner.splice + }; + + val toolbox = cm.mkToolBox() + val evaluated = toolbox.eval(code.tree) + println("evaluated = " + evaluated) +} diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.check b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.check new file mode 100644 index 000000000000..ca5556db022e --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.check @@ -0,0 +1,7 @@ +reify_metalevel_breach_-1_refers_to_0_a.scala:9: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + val code = reify{outer.splice.splice} + ^ +one error found diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.scala b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.scala new file mode 100644 index 000000000000..297db6b72e0c --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_a.scala @@ -0,0 +1,14 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val x = 2 + val outer = reify{reify{x}} + val code = reify{outer.splice.splice} + + val toolbox = cm.mkToolBox() + val evaluated = toolbox.eval(code.tree) + println("evaluated = " + evaluated) +} diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.check b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.check new file mode 100644 index 000000000000..e34cb1ac1e7b --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.check @@ -0,0 +1,7 @@ +reify_metalevel_breach_-1_refers_to_0_b.scala:12: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + }.splice + ^ +one error found diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.scala b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.scala new file mode 100644 index 000000000000..aab0778f6224 --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_0_b.scala @@ -0,0 +1,18 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val x = 2 + val code = reify{ + { + val inner = reify{reify{x}} + inner.splice + }.splice + } + + val toolbox = cm.mkToolBox() + val evaluated = toolbox.eval(code.tree) + println("evaluated = " + evaluated) +} diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.check b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.check new file mode 100644 index 000000000000..90b0e8dac636 --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.check @@ -0,0 +1,7 @@ +reify_metalevel_breach_-1_refers_to_1.scala:10: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + inner.splice.splice + ^ +one error found diff --git a/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.scala b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.scala new file mode 100644 index 000000000000..806caf5c6fd7 --- /dev/null +++ b/tests/untried/neg/reify_metalevel_breach_-1_refers_to_1.scala @@ -0,0 +1,16 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val code = reify{ + val x = 2 + val inner = reify{reify{x}} + inner.splice.splice + }; + + val toolbox = cm.mkToolBox() + val evaluated = toolbox.eval(code.tree) + println("evaluated = " + evaluated) +} diff --git a/tests/untried/neg/reify_nested_inner_refers_to_local.check b/tests/untried/neg/reify_nested_inner_refers_to_local.check new file mode 100644 index 000000000000..68689b18d008 --- /dev/null +++ b/tests/untried/neg/reify_nested_inner_refers_to_local.check @@ -0,0 +1,7 @@ +reify_nested_inner_refers_to_local.scala:9: error: the splice cannot be resolved statically, which means there is a cross-stage evaluation involved. +cross-stage evaluations need to be invoked explicitly, so we're showing you this error. +if you're sure this is not an oversight, add scala-compiler.jar to the classpath, +import `scala.tools.reflect.Eval` and call `.eval` instead. + reify{x}.splice + ^ +one error found diff --git a/tests/untried/neg/reify_nested_inner_refers_to_local.scala b/tests/untried/neg/reify_nested_inner_refers_to_local.scala new file mode 100644 index 000000000000..526aba72394e --- /dev/null +++ b/tests/untried/neg/reify_nested_inner_refers_to_local.scala @@ -0,0 +1,15 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val code = reify{ + val x = 2 + reify{x}.splice + }; + + val toolbox = cm.mkToolBox() + val evaluated = toolbox.eval(code.tree) + println("evaluated = " + evaluated) +} diff --git a/tests/untried/neg/run-gadts-strict.check b/tests/untried/neg/run-gadts-strict.check new file mode 100644 index 000000000000..b4d36c462990 --- /dev/null +++ b/tests/untried/neg/run-gadts-strict.check @@ -0,0 +1,21 @@ +run-gadts-strict.scala:12: error: type mismatch; + found : n.type (with underlying type Int) + required: T + case Lit(n) => n + ^ +run-gadts-strict.scala:13: error: type mismatch; + found : Int + required: T + case Succ(u) => eval(u) + 1 + ^ +run-gadts-strict.scala:14: error: type mismatch; + found : Boolean + required: T + case IsZero(u) => eval(u) == 0 + ^ +run-gadts-strict.scala:15: error: type mismatch; + found : T(in class If) + required: T(in method eval) + case If(c, u1, u2) => eval(if (eval(c)) u1 else u2) + ^ +four errors found diff --git a/tests/untried/neg/run-gadts-strict.flags b/tests/untried/neg/run-gadts-strict.flags new file mode 100644 index 000000000000..19243266d108 --- /dev/null +++ b/tests/untried/neg/run-gadts-strict.flags @@ -0,0 +1 @@ +-Xstrict-inference \ No newline at end of file diff --git a/tests/untried/neg/run-gadts-strict.scala b/tests/untried/neg/run-gadts-strict.scala new file mode 100644 index 000000000000..041d10d4bd30 --- /dev/null +++ b/tests/untried/neg/run-gadts-strict.scala @@ -0,0 +1,18 @@ +// A copy of run/gadts.scala, which must fail under -Xstrict-inference. +abstract class Term[T] +case class Lit(x: Int) extends Term[Int] +case class Succ(t: Term[Int]) extends Term[Int] +case class IsZero(t: Term[Int]) extends Term[Boolean] +case class If[T](c: Term[Boolean], + t1: Term[T], + t2: Term[T]) extends Term[T] + +object Test extends App { + def eval[T](t: Term[T]): T = t match { + case Lit(n) => n + case Succ(u) => eval(u) + 1 + case IsZero(u) => eval(u) == 0 + case If(c, u1, u2) => eval(if (eval(c)) u1 else u2) + } + println(eval(If(IsZero(Lit(1)), Lit(41), Succ(Lit(41))))) +} diff --git a/tests/untried/neg/sabin2.check b/tests/untried/neg/sabin2.check new file mode 100644 index 000000000000..8a093610696e --- /dev/null +++ b/tests/untried/neg/sabin2.check @@ -0,0 +1,6 @@ +sabin2.scala:22: error: type mismatch; + found : Test.Base#T + required: _7.T where val _7: Test.Base + a.set(b.get()) // Error + ^ +one error found diff --git a/tests/untried/neg/sabin2.scala b/tests/untried/neg/sabin2.scala new file mode 100644 index 000000000000..24a4e511a6d0 --- /dev/null +++ b/tests/untried/neg/sabin2.scala @@ -0,0 +1,23 @@ +object Test extends App + { + abstract class Base { + type T + var x: T = _ + class Inner { + def set(y: T) = x = y + def get() = x + def print() = println("Hello world") + } + } + + object IntBase extends Base { type T = Int } + object StringBase extends Base { type T = String } + + val a : Base#Inner = new IntBase.Inner + val b : Base#Inner = new StringBase.Inner + + a.print() // OK + b.print() // OK + + a.set(b.get()) // Error + } diff --git a/tests/untried/neg/saferJavaConversions.check b/tests/untried/neg/saferJavaConversions.check new file mode 100644 index 000000000000..0e53d2c4379b --- /dev/null +++ b/tests/untried/neg/saferJavaConversions.check @@ -0,0 +1,6 @@ +saferJavaConversions.scala:13: error: type mismatch; + found : String("a") + required: Foo + val v = map.get("a") // now this is a type error + ^ +one error found diff --git a/tests/untried/neg/saferJavaConversions.scala b/tests/untried/neg/saferJavaConversions.scala new file mode 100644 index 000000000000..f0611204e6b5 --- /dev/null +++ b/tests/untried/neg/saferJavaConversions.scala @@ -0,0 +1,20 @@ + +case class Foo(s: String) + +object Test { + def f1 = { + import scala.collection.JavaConversions._ + val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b") + val v = map.get("a") // should be a type error, actually returns null + } + def f2 = { + import scala.collection.convert.wrapAsScala._ + val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b") + val v = map.get("a") // now this is a type error + } + def f3 = { + import scala.collection.convert.wrapAsJava._ + val map: Map[Foo, String] = Map(Foo("a") -> "a", Foo("b") -> "b") + val v = map.get("a") + } +} diff --git a/tests/untried/neg/saito.check b/tests/untried/neg/saito.check new file mode 100644 index 000000000000..061a45b76ec4 --- /dev/null +++ b/tests/untried/neg/saito.check @@ -0,0 +1,4 @@ +saito.scala:10: error: class A cannot be instantiated because it does not conform to its self-type A with B + val a: A = new A; // should not be allowed + ^ +one error found diff --git a/tests/untried/neg/saito.scala b/tests/untried/neg/saito.scala new file mode 100644 index 000000000000..b4fcd598e440 --- /dev/null +++ b/tests/untried/neg/saito.scala @@ -0,0 +1,14 @@ +class B {} +class A { self: B => + def m(): B = { + this + } +} + +object Exec{ + def main(args: Array[String]): Unit = { + val a: A = new A; // should not be allowed + val b: B = a.m(); + } +} + diff --git a/tests/untried/neg/sammy_restrictions.check b/tests/untried/neg/sammy_restrictions.check new file mode 100644 index 000000000000..8cc49f9aa92a --- /dev/null +++ b/tests/untried/neg/sammy_restrictions.check @@ -0,0 +1,49 @@ +sammy_restrictions.scala:31: error: type mismatch; + found : () => Int + required: NoAbstract + (() => 0) : NoAbstract + ^ +sammy_restrictions.scala:32: error: type mismatch; + found : Int => Int + required: TwoAbstract + ((x: Int) => 0): TwoAbstract + ^ +sammy_restrictions.scala:34: error: class type required but DerivedOneAbstract with OneAbstract found + ((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here. + ^ +sammy_restrictions.scala:35: error: type mismatch; + found : Int => Int + required: NoEmptyConstructor + ((x: Int) => 0): NoEmptyConstructor + ^ +sammy_restrictions.scala:37: error: type mismatch; + found : Int => Int + required: OneEmptySecondaryConstructor + ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call. + ^ +sammy_restrictions.scala:38: error: type mismatch; + found : Int => Int + required: MultipleConstructorLists + ((x: Int) => 0): MultipleConstructorLists + ^ +sammy_restrictions.scala:39: error: type mismatch; + found : Int => Int + required: MultipleMethodLists + ((x: Int) => 0): MultipleMethodLists + ^ +sammy_restrictions.scala:40: error: type mismatch; + found : Int => Int + required: ImplicitConstructorParam + ((x: Int) => 0): ImplicitConstructorParam + ^ +sammy_restrictions.scala:41: error: type mismatch; + found : Int => Int + required: ImplicitMethodParam + ((x: Int) => 0): ImplicitMethodParam + ^ +sammy_restrictions.scala:44: error: type mismatch; + found : Int => Int + required: PolyMethod + ((x: Int) => 0): PolyMethod + ^ +10 errors found diff --git a/tests/untried/neg/sammy_restrictions.flags b/tests/untried/neg/sammy_restrictions.flags new file mode 100644 index 000000000000..48fd867160ba --- /dev/null +++ b/tests/untried/neg/sammy_restrictions.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/neg/sammy_restrictions.scala b/tests/untried/neg/sammy_restrictions.scala new file mode 100644 index 000000000000..5f1a04cd206e --- /dev/null +++ b/tests/untried/neg/sammy_restrictions.scala @@ -0,0 +1,45 @@ +class NoAbstract + +class TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int } + +class Base // check that the super class constructor isn't considered. +class NoEmptyConstructor(a: Int) extends Base { def this(a: String) = this(0); def ap(a: Int): Int } + +class OneEmptyConstructor() { def this(a: Int) = this(); def ap(a: Int): Int } + +class OneEmptySecondaryConstructor(a: Int) { def this() = this(0); def ap(a: Int): Int } + +class MultipleConstructorLists()() { def ap(a: Int): Int } + +class MultipleMethodLists()() { def ap(a: Int)(): Int } + +class ImplicitConstructorParam()(implicit a: String) { def ap(a: Int): Int } + +class ImplicitMethodParam() { def ap(a: Int)(implicit b: String): Int } + +class PolyClass[T] { def ap(a: T): T } + +class PolyMethod { def ap[T](a: T): T } + +class OneAbstract { def ap(a: Any): Any } +class DerivedOneAbstract extends OneAbstract + +object Test { + implicit val s: String = "" + type NonClassType = DerivedOneAbstract with OneAbstract + + (() => 0) : NoAbstract + ((x: Int) => 0): TwoAbstract + ((x: Int) => 0): DerivedOneAbstract // okay + ((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here. + ((x: Int) => 0): NoEmptyConstructor + ((x: Int) => 0): OneEmptyConstructor // okay + ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call. + ((x: Int) => 0): MultipleConstructorLists + ((x: Int) => 0): MultipleMethodLists + ((x: Int) => 0): ImplicitConstructorParam + ((x: Int) => 0): ImplicitMethodParam + + ((x: Int) => 0): PolyClass[Int] // okay + ((x: Int) => 0): PolyMethod +} diff --git a/tests/untried/neg/sammy_wrong_arity.check b/tests/untried/neg/sammy_wrong_arity.check new file mode 100644 index 000000000000..af547a201dbe --- /dev/null +++ b/tests/untried/neg/sammy_wrong_arity.check @@ -0,0 +1,52 @@ +sammy_wrong_arity.scala:6: error: type mismatch; + found : () => Int + required: T1 + (() => 0): T1 + ^ +sammy_wrong_arity.scala:7: error: type mismatch; + found : Any => Int + required: T2 + ((x: Any) => 0): T2 + ^ +sammy_wrong_arity.scala:9: error: type mismatch; + found : Any => Int + required: T0 + ((x: Any) => 0): T0 + ^ +sammy_wrong_arity.scala:10: error: type mismatch; + found : Any => Int + required: T2 + ((x: Any) => 0): T2 + ^ +sammy_wrong_arity.scala:12: error: type mismatch; + found : (Any, Any) => Int + required: T0 + ((x: Any, y: Any) => 0): T0 + ^ +sammy_wrong_arity.scala:13: error: type mismatch; + found : (Any, Any) => Int + required: T1 + ((x: Any, y: Any) => 0): T1 + ^ +sammy_wrong_arity.scala:15: error: missing parameter type + ((x) => 0): T2 + ^ +sammy_wrong_arity.scala:17: error: missing parameter type + ((x) => 0): T0 + ^ +sammy_wrong_arity.scala:18: error: missing parameter type + ((x) => 0): T2 + ^ +sammy_wrong_arity.scala:20: error: missing parameter type + ((x, y) => 0): T0 + ^ +sammy_wrong_arity.scala:20: error: missing parameter type + ((x, y) => 0): T0 + ^ +sammy_wrong_arity.scala:21: error: missing parameter type + ((x, y) => 0): T1 + ^ +sammy_wrong_arity.scala:21: error: missing parameter type + ((x, y) => 0): T1 + ^ +13 errors found diff --git a/tests/untried/neg/sammy_wrong_arity.flags b/tests/untried/neg/sammy_wrong_arity.flags new file mode 100644 index 000000000000..48fd867160ba --- /dev/null +++ b/tests/untried/neg/sammy_wrong_arity.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/tests/untried/neg/sammy_wrong_arity.scala b/tests/untried/neg/sammy_wrong_arity.scala new file mode 100644 index 000000000000..d03d266a0ba8 --- /dev/null +++ b/tests/untried/neg/sammy_wrong_arity.scala @@ -0,0 +1,22 @@ +trait T0 { def ap(): Int } +trait T1 { def ap(a: Any): Int } +trait T2 { def ap(a: Any, b: Any): Int } + +class Test { + (() => 0): T1 + ((x: Any) => 0): T2 + + ((x: Any) => 0): T0 + ((x: Any) => 0): T2 + + ((x: Any, y: Any) => 0): T0 + ((x: Any, y: Any) => 0): T1 + + ((x) => 0): T2 + + ((x) => 0): T0 + ((x) => 0): T2 + + ((x, y) => 0): T0 + ((x, y) => 0): T1 +} diff --git a/tests/untried/neg/scopes.check b/tests/untried/neg/scopes.check new file mode 100644 index 000000000000..f8e8c3758a36 --- /dev/null +++ b/tests/untried/neg/scopes.check @@ -0,0 +1,26 @@ +scopes.scala:3: error: t is already defined as type t + type t = Float + ^ +scopes.scala:5: error: x is already defined as value x + val x: Float = .0f; + ^ +scopes.scala:8: error: y is already defined as value y + val y: Float = .0f + ^ +scopes.scala:6: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + { + ^ +scopes.scala:11: error: x is already defined as value x + def f1(x: Int, x: Float) = x + ^ +scopes.scala:12: error: y is already defined as value y + def f2(x: Int)(y: Int, y: Float) = x + y + ^ +scopes.scala:13: error: x is already defined as value x + val closure = (x: Int, x: Float) => x + ^ +scopes.scala:15: error: x is already defined as value x + case x::x => x + ^ +one warning found +7 errors found diff --git a/tests/untried/neg/scopes.scala b/tests/untried/neg/scopes.scala new file mode 100644 index 000000000000..660e826619cd --- /dev/null +++ b/tests/untried/neg/scopes.scala @@ -0,0 +1,18 @@ +object test1 { + type t = Int + type t = Float + val x: Int = 0 + val x: Float = .0f; + { + val y: Int = 0 + val y: Float = .0f + () + } + def f1(x: Int, x: Float) = x + def f2(x: Int)(y: Int, y: Float) = x + y + val closure = (x: Int, x: Float) => x + List() match { + case x::x => x + case Nil => Nil + } +} diff --git a/tests/untried/neg/sealed-final-neg.check b/tests/untried/neg/sealed-final-neg.check new file mode 100644 index 000000000000..500d23f49a33 --- /dev/null +++ b/tests/untried/neg/sealed-final-neg.check @@ -0,0 +1,4 @@ +sealed-final-neg.scala:41: error: expected class or object definition +"Due to SI-6142 this emits no warnings, so we'll just break it until that's fixed." +^ +one error found diff --git a/tests/untried/neg/sealed-final-neg.flags b/tests/untried/neg/sealed-final-neg.flags new file mode 100644 index 000000000000..cfabf7a5b451 --- /dev/null +++ b/tests/untried/neg/sealed-final-neg.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Yinline-warnings -optimise \ No newline at end of file diff --git a/tests/untried/neg/sealed-final-neg.scala b/tests/untried/neg/sealed-final-neg.scala new file mode 100644 index 000000000000..bc25330e13cc --- /dev/null +++ b/tests/untried/neg/sealed-final-neg.scala @@ -0,0 +1,41 @@ +package neg1 { + 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 + final class Baz3 extends Foo { + override def bar(x: Int) = x - 1 + } + + object Test { + // bar can't be inlined - it is overridden in Baz3 + def f = Foo.mkFoo() bar 10 + } +} + +package neg2 { + 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 + class Baz3 extends Foo { + override def bar(x: Int) = x - 1 + } + + object Test { + // bar can't be inlined - Baz3 is not final + def f = Foo.mkFoo() bar 10 + } +} + +"Due to SI-6142 this emits no warnings, so we'll just break it until that's fixed." diff --git a/tests/untried/neg/sealed-java-enums.check b/tests/untried/neg/sealed-java-enums.check new file mode 100644 index 000000000000..a3c39ec5cdac --- /dev/null +++ b/tests/untried/neg/sealed-java-enums.check @@ -0,0 +1,7 @@ +sealed-java-enums.scala:5: warning: match may not be exhaustive. +It would fail on the following inputs: BLOCKED, TERMINATED, TIMED_WAITING + def f(state: State) = state match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/sealed-java-enums.flags b/tests/untried/neg/sealed-java-enums.flags new file mode 100644 index 000000000000..e709c6591866 --- /dev/null +++ b/tests/untried/neg/sealed-java-enums.flags @@ -0,0 +1 @@ +-Xexperimental -Xfatal-warnings diff --git a/tests/untried/neg/sealed-java-enums.scala b/tests/untried/neg/sealed-java-enums.scala new file mode 100644 index 000000000000..2daf93f3088d --- /dev/null +++ b/tests/untried/neg/sealed-java-enums.scala @@ -0,0 +1,10 @@ +import java.lang.Thread.State +import java.lang.Thread.State._ + +object Test { + def f(state: State) = state match { + case NEW | WAITING => true + case RUNNABLE => false + // and I forget the rest + } +} diff --git a/tests/untried/neg/sensitive.check b/tests/untried/neg/sensitive.check new file mode 100644 index 000000000000..32d988ec97b0 --- /dev/null +++ b/tests/untried/neg/sensitive.check @@ -0,0 +1,4 @@ +sensitive.scala:17: error: constructor Sensitive in class Sensitive cannot be accessed in object Attacker + val y = new Sensitive() + ^ +one error found diff --git a/tests/untried/neg/sensitive.scala b/tests/untried/neg/sensitive.scala new file mode 100644 index 000000000000..a084a0a8ca6d --- /dev/null +++ b/tests/untried/neg/sensitive.scala @@ -0,0 +1,18 @@ +class Certificate{} + +object Admin extends Certificate; + +class SecurityViolationException extends Exception + +object Sensitive { + def makeSensitive(credentials: Certificate): Sensitive = + if (credentials == Admin) new Sensitive() + else throw new SecurityViolationException +} +class Sensitive private () { +} + +object Attacker { + val x = Sensitive.makeSensitive(null) + val y = new Sensitive() +} diff --git a/tests/untried/neg/sensitive2.check b/tests/untried/neg/sensitive2.check new file mode 100644 index 000000000000..19152fe18846 --- /dev/null +++ b/tests/untried/neg/sensitive2.check @@ -0,0 +1,10 @@ +sensitive2.scala:6: error: type mismatch; + found : String("abc") + required: Test.Foo[_] +Note that implicit conversions are not applicable because they are ambiguous: + both method foo1 in object Test of type [A](a: A)Test.Foo[A] + and method foo2 in object Test of type (a: Any)Test.Foo[String] + are possible conversion functions from String("abc") to Test.Foo[_] + val a: Foo[_] = "abc" + ^ +one error found diff --git a/tests/untried/neg/sensitive2.scala b/tests/untried/neg/sensitive2.scala new file mode 100644 index 000000000000..e0cf515bd078 --- /dev/null +++ b/tests/untried/neg/sensitive2.scala @@ -0,0 +1,8 @@ +object Test { + class Foo[A](z: A) + implicit def foo1[A](a: A): Foo[A] = new Foo(a) + implicit def foo2(a: Any): Foo[String] = new Foo("123") + + val a: Foo[_] = "abc" + +} diff --git a/tests/untried/neg/serialversionuid-not-const.check b/tests/untried/neg/serialversionuid-not-const.check new file mode 100644 index 000000000000..9c383d97adf4 --- /dev/null +++ b/tests/untried/neg/serialversionuid-not-const.check @@ -0,0 +1,10 @@ +serialversionuid-not-const.scala:1: error: annotation argument needs to be a constant; found: 13L.toLong +@SerialVersionUID(13l.toLong) class C1 extends Serializable + ^ +serialversionuid-not-const.scala:3: error: annotation argument needs to be a constant; found: 13.asInstanceOf[Long] +@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable + ^ +serialversionuid-not-const.scala:4: error: annotation argument needs to be a constant; found: Test.bippy +@SerialVersionUID(Test.bippy) class C4 extends Serializable + ^ +three errors found diff --git a/tests/untried/neg/serialversionuid-not-const.scala b/tests/untried/neg/serialversionuid-not-const.scala new file mode 100644 index 000000000000..f0e3ef4e7e7e --- /dev/null +++ b/tests/untried/neg/serialversionuid-not-const.scala @@ -0,0 +1,16 @@ +@SerialVersionUID(13l.toLong) class C1 extends Serializable +@SerialVersionUID(13l) class C2 extends Serializable +@SerialVersionUID(13.asInstanceOf[Long]) class C3 extends Serializable +@SerialVersionUID(Test.bippy) class C4 extends Serializable + +object Test { + val bippy = 13L + + def show(c: Class[_]) = println(java.io.ObjectStreamClass.lookup(c).getSerialVersionUID) + def main(args: Array[String]): Unit = { + show(classOf[C1]) + show(classOf[C2]) + show(classOf[C3]) + show(classOf[C4]) + } +} diff --git a/tests/untried/neg/spec-overrides.check b/tests/untried/neg/spec-overrides.check new file mode 100644 index 000000000000..639186af4078 --- /dev/null +++ b/tests/untried/neg/spec-overrides.check @@ -0,0 +1,7 @@ +spec-overrides.scala:8: error: Type parameter has to be specialized at least for the same types as in the overridden method. Missing types: Int + override def a[@specialized(Double) T](t: T): List[T] = Nil + ^ +spec-overrides.scala:12: error: Type parameter has to be specialized at least for the same types as in the overridden method. Missing types: Int + override def a[T](t: T): List[T] = Nil + ^ +two errors found diff --git a/tests/untried/neg/spec-overrides.scala b/tests/untried/neg/spec-overrides.scala new file mode 100644 index 000000000000..713ce27bd327 --- /dev/null +++ b/tests/untried/neg/spec-overrides.scala @@ -0,0 +1,26 @@ +class P { + def a[@specialized(Int) T](t: T): List[T] = List(t) +} +class FX extends P { + override def a[@specialized(Int) T](t: T): List[T] = Nil +} +class FX1 extends P { + override def a[@specialized(Double) T](t: T): List[T] = Nil +} + +class FX2 extends P { + override def a[T](t: T): List[T] = Nil +} + +object Test extends App { + val fx = new FX + val p = new P + + println(fx.a(3)) + println((fx: P).a(3)) + println((fx: P).a(3.0)) + + + // val d = new Derived[Int] + // println((d: Base[Int]).m(10)) +} diff --git a/tests/untried/neg/specification-scopes.check b/tests/untried/neg/specification-scopes.check new file mode 100644 index 000000000000..ab986135e54b --- /dev/null +++ b/tests/untried/neg/specification-scopes.check @@ -0,0 +1,12 @@ +P_2.scala:14: error: reference to x is ambiguous; +it is both defined in object C and imported subsequently by +import Q.X._ + println("L14: "+x) // reference to 'x' is ambiguous here + ^ +P_2.scala:19: error: reference to y is ambiguous; +it is imported twice in the same scope by +import P.X._ +and import X.y + println("L19: "+y) // reference to 'y' is ambiguous here + ^ +two errors found diff --git a/tests/untried/neg/specification-scopes/P_1.scala b/tests/untried/neg/specification-scopes/P_1.scala new file mode 100644 index 000000000000..3b11f1167d6c --- /dev/null +++ b/tests/untried/neg/specification-scopes/P_1.scala @@ -0,0 +1,6 @@ +package P { + object X { val x = 1; val y = 2; } +} +package Q { + object X { val x = true; val y = "" } +} diff --git a/tests/untried/neg/specification-scopes/P_2.scala b/tests/untried/neg/specification-scopes/P_2.scala new file mode 100644 index 000000000000..d59f82e90da6 --- /dev/null +++ b/tests/untried/neg/specification-scopes/P_2.scala @@ -0,0 +1,21 @@ +package P { // 'X' bound by package clause + import Console._ // 'println' bound by wildcard import + object A { + println("L4: "+X) // 'X' refers to 'P.X' here + object B { + import Q._ // 'X' bound by wildcard import + println("L7: "+X) // 'X' refers to 'Q.X' here + import X._ // 'x' and 'y' bound by wildcard import + println("L8: "+x) // 'x' refers to 'Q.X.x' here + object C { + val x = 3 // 'x' bound by local definition + println("L12: "+x); // 'x' refers to constant '3' here + { import Q.X._ // 'x' and 'y' bound by wildcard + println("L14: "+x) // reference to 'x' is ambiguous here + import X.y // 'y' bound by explicit import + println("L16: "+y); // 'y' refers to 'Q.X.y' here + { val x = "abc" // 'x' bound by local definition + import P.X._ // 'x' and 'y' bound by wildcard + println("L19: "+y) // reference to 'y' is ambiguous here + println("L20: "+x) // 'x' refers to string ''abc'' here +}}}}}} diff --git a/tests/untried/neg/stmt-expr-discard.check b/tests/untried/neg/stmt-expr-discard.check new file mode 100644 index 000000000000..1207e6da5080 --- /dev/null +++ b/tests/untried/neg/stmt-expr-discard.check @@ -0,0 +1,9 @@ +stmt-expr-discard.scala:3: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + + 2 + ^ +stmt-expr-discard.scala:4: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + - 4 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/stmt-expr-discard.flags b/tests/untried/neg/stmt-expr-discard.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/stmt-expr-discard.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/stmt-expr-discard.scala b/tests/untried/neg/stmt-expr-discard.scala new file mode 100644 index 000000000000..e60c8546259c --- /dev/null +++ b/tests/untried/neg/stmt-expr-discard.scala @@ -0,0 +1,5 @@ +class A { + def f = 1 + + 2 + - 4 +} diff --git a/tests/untried/neg/stringinterpolation_macro-neg.check b/tests/untried/neg/stringinterpolation_macro-neg.check new file mode 100644 index 000000000000..703846ad620a --- /dev/null +++ b/tests/untried/neg/stringinterpolation_macro-neg.check @@ -0,0 +1,172 @@ +stringinterpolation_macro-neg.scala:13: error: there are no parts + new StringContext().f() + ^ +stringinterpolation_macro-neg.scala:14: error: too few arguments for interpolated string + new StringContext("", " is ", "%2d years old").f(s) + ^ +stringinterpolation_macro-neg.scala:15: error: too many arguments for interpolated string + new StringContext("", " is ", "%2d years old").f(s, d, d) + ^ +stringinterpolation_macro-neg.scala:16: error: too few arguments for interpolated string + new StringContext("", "").f() + ^ +stringinterpolation_macro-neg.scala:19: error: type mismatch; + found : String + required: Boolean + f"$s%b" + ^ +stringinterpolation_macro-neg.scala:20: error: type mismatch; + found : String + required: Char + f"$s%c" + ^ +stringinterpolation_macro-neg.scala:21: error: type mismatch; + found : Double + required: Char + f"$f%c" + ^ +stringinterpolation_macro-neg.scala:22: error: type mismatch; + found : String + required: Int + f"$s%x" + ^ +stringinterpolation_macro-neg.scala:23: error: type mismatch; + found : Boolean + required: Int + f"$b%d" + ^ +stringinterpolation_macro-neg.scala:24: error: type mismatch; + found : String + required: Int + f"$s%d" + ^ +stringinterpolation_macro-neg.scala:25: error: type mismatch; + found : Double + required: Int + f"$f%o" + ^ +stringinterpolation_macro-neg.scala:26: error: type mismatch; + found : String + required: Double + f"$s%e" + ^ +stringinterpolation_macro-neg.scala:27: error: type mismatch; + found : Boolean + required: Double + f"$b%f" + ^ +stringinterpolation_macro-neg.scala:32: error: type mismatch; + found : String + required: Int +Note that implicit conversions are not applicable because they are ambiguous: + both value strToInt2 of type String => Int + and value strToInt1 of type String => Int + are possible conversion functions from String to Int + f"$s%d" + ^ +stringinterpolation_macro-neg.scala:35: error: illegal conversion character 'i' + f"$s%i" + ^ +stringinterpolation_macro-neg.scala:38: error: Illegal flag '+' + f"$s%+ 0,(s" + ^ +stringinterpolation_macro-neg.scala:38: error: Illegal flag ' ' + f"$s%+ 0,(s" + ^ +stringinterpolation_macro-neg.scala:38: error: Illegal flag '0' + f"$s%+ 0,(s" + ^ +stringinterpolation_macro-neg.scala:38: error: Illegal flag ',' + f"$s%+ 0,(s" + ^ +stringinterpolation_macro-neg.scala:38: error: Illegal flag '(' + f"$s%+ 0,(s" + ^ +stringinterpolation_macro-neg.scala:39: error: Only '-' allowed for c conversion + f"$c%#+ 0,(c" + ^ +stringinterpolation_macro-neg.scala:40: error: # not allowed for d conversion + f"$d%#d" + ^ +stringinterpolation_macro-neg.scala:41: error: ',' only allowed for d conversion of integral types + f"$d%,x" + ^ +stringinterpolation_macro-neg.scala:42: error: only use '+' for BigInt conversions to o, x, X + f"$d%+ (x" + ^ +stringinterpolation_macro-neg.scala:42: error: only use ' ' for BigInt conversions to o, x, X + f"$d%+ (x" + ^ +stringinterpolation_macro-neg.scala:42: error: only use '(' for BigInt conversions to o, x, X + f"$d%+ (x" + ^ +stringinterpolation_macro-neg.scala:43: error: ',' not allowed for a, A + f"$f%,(a" + ^ +stringinterpolation_macro-neg.scala:43: error: '(' not allowed for a, A + f"$f%,(a" + ^ +stringinterpolation_macro-neg.scala:44: error: Only '-' allowed for date/time conversions + f"$t%#+ 0,(tT" + ^ +stringinterpolation_macro-neg.scala:47: error: precision not allowed + f"$c%.2c" + ^ +stringinterpolation_macro-neg.scala:48: error: precision not allowed + f"$d%.2d" + ^ +stringinterpolation_macro-neg.scala:49: error: precision not allowed + f"%.2%" + ^ +stringinterpolation_macro-neg.scala:50: error: precision not allowed + f"%.2n" + ^ +stringinterpolation_macro-neg.scala:51: error: precision not allowed + f"$f%.2a" + ^ +stringinterpolation_macro-neg.scala:52: error: precision not allowed + f"$t%.2tT" + ^ +stringinterpolation_macro-neg.scala:55: error: No last arg + f"% 1 + implicit val strToInt2 = (s: String) => 2 + f"$s%d" + } + + f"$s%i" + + // 3) flag mismatches + f"$s%+ 0,(s" + f"$c%#+ 0,(c" + f"$d%#d" + f"$d%,x" + f"$d%+ (x" + f"$f%,(a" + f"$t%#+ 0,(tT" + + // 4) bad precisions + f"$c%.2c" + f"$d%.2d" + f"%.2%" + f"%.2n" + f"$f%.2a" + f"$t%.2tT" + + // 5) bad indexes + f"%: Null <: Object](x: A): Object; val x: A }) = x.m[Tata](x.x) //fail + ^ +structural.scala:11: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def f2[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: B): Object; val x: B }) = x.m[Tata](x.x) //fail + ^ +structural.scala:12: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def f3[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: C): Object; val x: C }) = x.m[Tata](x.x) //fail + ^ +structural.scala:13: error: Parameter type in structural refinement may not refer to a type member of that refinement + def f4[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: D): Object; val x: D }) = x.m[Tata](x.x) //fail + ^ +structural.scala:42: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + type Summable[T] = { def +(v : T) : T } + ^ +structural.scala:46: error: Parameter type in structural refinement may not refer to the type of that refinement (self type) + type S1 = { def f(p: this.type): Unit } + ^ +structural.scala:49: error: Parameter type in structural refinement may not refer to a type member of that refinement + type S2 = { type T; def f(p: T): Unit } + ^ +structural.scala:52: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def s3[U >: Null <: Object](p: { def f(p: U): Unit; def u: U }) = () + ^ +9 errors found diff --git a/tests/untried/neg/structural.scala b/tests/untried/neg/structural.scala new file mode 100644 index 000000000000..d78339931788 --- /dev/null +++ b/tests/untried/neg/structural.scala @@ -0,0 +1,54 @@ +object Test extends App { + + def f(x: { type D; def m: D }): Null = null + + class Tata + + abstract class Toto[A <: Object] { + type B <: Object + + def f1[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: A): Object; val x: A }) = x.m[Tata](x.x) //fail + def f2[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: B): Object; val x: B }) = x.m[Tata](x.x) //fail + def f3[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: C): Object; val x: C }) = x.m[Tata](x.x) //fail + def f4[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: D): Object; val x: D }) = x.m[Tata](x.x) //fail + def f5[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: E): Object; val x: Tata }) = x.m[Tata](x.x) //suceed + + def f6[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: Object): A }) = x.m[Tata](null) //suceed + def f7[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: Object): B }) = x.m[Tata](null) //suceed + def f8[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: Object): C }) = x.m[Tata](null) //suceed + def f9[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: Object): D }) = x.m[Tata](null) //fail + def f0[C <: Object](x: Object{ type D <: Object; def m[E >: Null <: Object](x: Object): E }) = x.m[Tata](null) //suceed + + } + + val tata = new Tata + val toto = new Toto[Tata] { + type B = Tata + } + + //toto.f1[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Tata): Object = null; val x = tata }) + //toto.f2[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Tata): Object = null; val x = tata }) + //toto.f3[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Tata): Object = null; val x = tata }) + //toto.f4[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: D): Object = null; val x = tata }) + toto.f5[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: E): Object = null; val x: Test.Tata = tata }) + + toto.f6[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Object): Tata = null }) + toto.f7[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Object): Tata = null }) + toto.f8[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Object): Tata = null }) + //toto.f9[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Object): D = null }) + toto.f0[Tata](new Object{ type D = Tata; def m[E >: Null <: Object](x: Object): E = null }) + + /* Bug #1246 */ + type Summable[T] = { def +(v : T) : T } + def sum[T <: Summable[T]](xs : List[T]) = xs.reduceLeft[T](_ + _) + + /* Bug #1004 & #967 */ + type S1 = { def f(p: this.type): Unit } + val s1 = new { def f(p: this.type): Unit = () } + + type S2 = { type T; def f(p: T): Unit } + //val s2: S2 = new { type T = A; def f(p: T): Unit = () } + + def s3[U >: Null <: Object](p: { def f(p: U): Unit; def u: U }) = () + +} diff --git a/tests/untried/neg/suggest-similar.check b/tests/untried/neg/suggest-similar.check new file mode 100644 index 000000000000..057aa8b250fd --- /dev/null +++ b/tests/untried/neg/suggest-similar.check @@ -0,0 +1,10 @@ +suggest-similar.scala:8: error: not found: value flippitx + flippitx = 123 + ^ +suggest-similar.scala:9: error: not found: value identiyt + Nil map identiyt + ^ +suggest-similar.scala:10: error: not found: type Bingus + new Bingus + ^ +three errors found diff --git a/tests/untried/neg/suggest-similar.scala b/tests/untried/neg/suggest-similar.scala new file mode 100644 index 000000000000..ff327478fe10 --- /dev/null +++ b/tests/untried/neg/suggest-similar.scala @@ -0,0 +1,11 @@ +class Dingus +object Dingus { + var flippity = 1 +} +import Dingus._ + +class A { + flippitx = 123 + Nil map identiyt + new Bingus +} diff --git a/tests/untried/neg/super-cast-or-test.check b/tests/untried/neg/super-cast-or-test.check new file mode 100644 index 000000000000..8e5eed62bd31 --- /dev/null +++ b/tests/untried/neg/super-cast-or-test.check @@ -0,0 +1,7 @@ +super-cast-or-test.scala:1: error: super not allowed here: use this.asInstanceOf instead +trait A { def f = super.asInstanceOf[AnyRef] } + ^ +super-cast-or-test.scala:2: error: super not allowed here: use this.isInstanceOf instead +trait B { def g = super.isInstanceOf[AnyRef] } + ^ +two errors found diff --git a/tests/untried/neg/super-cast-or-test.scala b/tests/untried/neg/super-cast-or-test.scala new file mode 100644 index 000000000000..a0f86d808160 --- /dev/null +++ b/tests/untried/neg/super-cast-or-test.scala @@ -0,0 +1,3 @@ +trait A { def f = super.asInstanceOf[AnyRef] } +trait B { def g = super.isInstanceOf[AnyRef] } + diff --git a/tests/untried/neg/switch.check b/tests/untried/neg/switch.check new file mode 100644 index 000000000000..f968d3a4485f --- /dev/null +++ b/tests/untried/neg/switch.check @@ -0,0 +1,9 @@ +switch.scala:38: warning: could not emit switch for @switch annotated match + def fail2(c: Char) = (c: @switch @unchecked) match { + ^ +switch.scala:45: warning: could not emit switch for @switch annotated match + def fail3(c: Char) = (c: @unchecked @switch) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/switch.flags b/tests/untried/neg/switch.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/switch.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/switch.scala b/tests/untried/neg/switch.scala new file mode 100644 index 000000000000..a66ed768fa49 --- /dev/null +++ b/tests/untried/neg/switch.scala @@ -0,0 +1,66 @@ +import scala.annotation.switch + +// this is testing not so much how things ought to be but how they are; +// the test is supposed to start failing if the behavior changes at all. +object Other { + val C1 = 'P' // fails: not final + final val C2 = 'Q' // succeeds: singleton type Char('Q') inferred + final val C3: Char = 'R' // fails: type Char specified + final val C4 = '\u000A' // succeeds like C2 but more unicodey +} + +object Main { + def succ1(c: Char) = (c: @switch) match { + case 'A' | 'B' | 'C' => true + case 'd' => true + case 'f' | 'g' => true + case _ => false + } + + def succ2(c: Char) = (c: @switch) match { + case 'A' | 'B' | 'C' => true + case Other.C2 => true + case Other.C4 => true + case _ => false + } + + // has a guard, but since SI-5830 that's ok + def succ_guard(c: Char) = (c: @switch) match { + case 'A' | 'B' | 'C' => true + case x if x == 'A' => true + case _ => false + } + + // throwing in @unchecked on the next two to make sure + // multiple annotations are processed correctly + + // thinks a val in an object is constant... so naive + def fail2(c: Char) = (c: @switch @unchecked) match { + case 'A' => true + case Other.C1 => true + case _ => false + } + + // more naivete + def fail3(c: Char) = (c: @unchecked @switch) match { + case 'A' => true + case Other.C3 => true + case _ => false + } + + // guard case done correctly + def succ3(c: Char) = (c: @switch) match { + case 'A' | 'B' | 'C' => true + case x => x == 'A' + } + + // some ints just to mix it up a bit + def succ4(x: Int, y: Int) = ((x+y): @switch) match { + case 1 => 5 + case 2 => 10 + case 3 => 20 + case 4 => 50 + case 5|6|7|8 => 100 + case _ => -1 + } +} diff --git a/tests/untried/neg/t0003.check b/tests/untried/neg/t0003.check new file mode 100644 index 000000000000..8bab55db3f4a --- /dev/null +++ b/tests/untried/neg/t0003.check @@ -0,0 +1,6 @@ +t0003.scala:2: error: type mismatch; + found : A => (B => B) + required: A => B + def foo[A, B, C](l: List[A], f: A => B=>B, g: B=>B=>C): List[C] = l map (g compose f) + ^ +one error found diff --git a/tests/untried/neg/t0003.scala b/tests/untried/neg/t0003.scala new file mode 100644 index 000000000000..e41cfa9e9e5f --- /dev/null +++ b/tests/untried/neg/t0003.scala @@ -0,0 +1,3 @@ +object Test { + def foo[A, B, C](l: List[A], f: A => B=>B, g: B=>B=>C): List[C] = l map (g compose f) +} diff --git a/tests/untried/neg/t0015.check b/tests/untried/neg/t0015.check new file mode 100644 index 000000000000..43adc22f7283 --- /dev/null +++ b/tests/untried/neg/t0015.check @@ -0,0 +1,6 @@ +t0015.scala:5: error: type mismatch; + found : () => Nothing + required: Nothing => ? + Nil.map(f _) + ^ +one error found diff --git a/tests/untried/neg/t0015.scala b/tests/untried/neg/t0015.scala new file mode 100644 index 000000000000..225197f95075 --- /dev/null +++ b/tests/untried/neg/t0015.scala @@ -0,0 +1,25 @@ +abstract class Test +{ + def f: Nothing + + Nil.map(f _) +} + +abstract class M +{ self => + + type T + final type selfType = M {type T = self.T} + type actualSelfType >: self.type <: selfType + + + def f[U](x: Any) = {} + + // compiles successfully + //f[Int](self: actualSelfType) + + f[Int](self: selfType) // compiles Ok now was well, because we narrow to singletonType in this situation + + //def g(x: Any) = {} + //g(self: selfType) +} diff --git a/tests/untried/neg/t0117.check b/tests/untried/neg/t0117.check new file mode 100644 index 000000000000..579cf883a7c1 --- /dev/null +++ b/tests/untried/neg/t0117.check @@ -0,0 +1,4 @@ +t0117.scala:2: error: Implementation restriction: traits may not select fields or methods from super[C] where C is a class +trait B extends A { println(super[A].a) } + ^ +one error found diff --git a/tests/untried/neg/t0117.scala b/tests/untried/neg/t0117.scala new file mode 100644 index 000000000000..4cd9ad6ef1ad --- /dev/null +++ b/tests/untried/neg/t0117.scala @@ -0,0 +1,5 @@ +class A { def a = 0 } +trait B extends A { println(super[A].a) } +object Test extends App { + new B {} +} diff --git a/tests/untried/neg/t0152.check b/tests/untried/neg/t0152.check new file mode 100644 index 000000000000..a7909bf14d4d --- /dev/null +++ b/tests/untried/neg/t0152.check @@ -0,0 +1,6 @@ +t0152.scala:10: error: illegal inheritance; + object boom inherits different type instances of class Value: +Value[Int] and Value[String] + object boom extends Value[java.lang.String]("foo") with PlusOne + ^ +one error found diff --git a/tests/untried/neg/t0152.scala b/tests/untried/neg/t0152.scala new file mode 100644 index 000000000000..d86d59e9748b --- /dev/null +++ b/tests/untried/neg/t0152.scala @@ -0,0 +1,13 @@ +class Value[+T](x: T) { + def value = x +} + +trait PlusOne extends Value[Int] { + override def value = super.value + 1 +} + +object Test extends App { + object boom extends Value[java.lang.String]("foo") with PlusOne + + println(boom.value) // class cast exception! +} diff --git a/tests/untried/neg/t0204.check b/tests/untried/neg/t0204.check new file mode 100644 index 000000000000..0f7acfdddecb --- /dev/null +++ b/tests/untried/neg/t0204.check @@ -0,0 +1,4 @@ +t0204.scala:4: error: class type required but Program.A{type T = String} found + trait C extends B + ^ +one error found diff --git a/tests/untried/neg/t0204.scala b/tests/untried/neg/t0204.scala new file mode 100644 index 000000000000..0de9d9d16d1f --- /dev/null +++ b/tests/untried/neg/t0204.scala @@ -0,0 +1,5 @@ +object Program { + trait A { type T } + type B = A { type T = String } + trait C extends B +} diff --git a/tests/untried/neg/t0207.check b/tests/untried/neg/t0207.check new file mode 100644 index 000000000000..ebe6759b36ca --- /dev/null +++ b/tests/untried/neg/t0207.check @@ -0,0 +1,7 @@ +t0207.scala:3: error: type T takes type parameters + type S = (T with T)[A] + ^ +t0207.scala:3: error: type T takes type parameters + type S = (T with T)[A] + ^ +two errors found diff --git a/tests/untried/neg/t0207.scala b/tests/untried/neg/t0207.scala new file mode 100644 index 000000000000..d9df0ca95127 --- /dev/null +++ b/tests/untried/neg/t0207.scala @@ -0,0 +1,4 @@ +trait A { + type T[_] + type S = (T with T)[A] +} diff --git a/tests/untried/neg/t0209.check b/tests/untried/neg/t0209.check new file mode 100644 index 000000000000..1904e58e7ae3 --- /dev/null +++ b/tests/untried/neg/t0209.check @@ -0,0 +1,6 @@ +t0209.scala:15: error: type mismatch; + found : C + required: _1.type where val _1: A + (new B: A).f(new C) + ^ +one error found diff --git a/tests/untried/neg/t0209.scala b/tests/untried/neg/t0209.scala new file mode 100644 index 000000000000..cd9bd975442e --- /dev/null +++ b/tests/untried/neg/t0209.scala @@ -0,0 +1,17 @@ +abstract class A { + def f(x : this.type) : B +} + +class B extends A { + override def f(x : this.type) : B = x +} + +class C extends A { + override def f(x : this.type) : B = null +} + +object Program { + def main(args : Array[String]): Unit = { + (new B: A).f(new C) + } +} diff --git a/tests/untried/neg/t0214.check b/tests/untried/neg/t0214.check new file mode 100644 index 000000000000..30bb0488cf4f --- /dev/null +++ b/tests/untried/neg/t0214.check @@ -0,0 +1,4 @@ +t0214.scala:3: error: missing parameter type + a2p(x => x._1,(2,3)) + ^ +one error found diff --git a/tests/untried/neg/t0214.scala b/tests/untried/neg/t0214.scala new file mode 100644 index 000000000000..bdc42bfd7832 --- /dev/null +++ b/tests/untried/neg/t0214.scala @@ -0,0 +1,4 @@ +object Test { + def a2p[a,b,c](f:((a,b))=>c,v:(a,b)):c = f(v) + a2p(x => x._1,(2,3)) +} diff --git a/tests/untried/neg/t0218.check b/tests/untried/neg/t0218.check new file mode 100644 index 000000000000..a22583d23bd4 --- /dev/null +++ b/tests/untried/neg/t0218.check @@ -0,0 +1,4 @@ +t0218.scala:10: error: class type required but APQ.this.P found + List(new PP) + ^ +one error found diff --git a/tests/untried/neg/t0218.scala b/tests/untried/neg/t0218.scala new file mode 100644 index 000000000000..319be82a7a65 --- /dev/null +++ b/tests/untried/neg/t0218.scala @@ -0,0 +1,12 @@ +trait APQ { + class Placement { + } + + type P <: Placement + + type PP = P + + def pq(numQueens: Int, numRows: Int) : List[Placement] = { + List(new PP) + } +} diff --git a/tests/untried/neg/t0226.check b/tests/untried/neg/t0226.check new file mode 100644 index 000000000000..247f1f2443a7 --- /dev/null +++ b/tests/untried/neg/t0226.check @@ -0,0 +1,10 @@ +t0226.scala:5: error: not found: type A1 + (implicit _1: Foo[List[A1]], _2: Foo[A2]): Foo[Tuple2[List[A1], A2]] = + ^ +t0226.scala:5: error: not found: type A1 + (implicit _1: Foo[List[A1]], _2: Foo[A2]): Foo[Tuple2[List[A1], A2]] = + ^ +t0226.scala:8: error: could not find implicit value for parameter rep: Test.this.Foo[((List[Char], Int), (scala.collection.immutable.Nil.type, Int))] + foo(((List('b'), 3), (Nil, 4))) + ^ +three errors found diff --git a/tests/untried/neg/t0226.scala b/tests/untried/neg/t0226.scala new file mode 100644 index 000000000000..beca3cd6454b --- /dev/null +++ b/tests/untried/neg/t0226.scala @@ -0,0 +1,9 @@ +class Test { + def foo[A](x: A)(implicit rep: Foo[A]): Foo[A] = rep + abstract class Foo[A] + implicit def list2Foo[List[A1], A2] + (implicit _1: Foo[List[A1]], _2: Foo[A2]): Foo[Tuple2[List[A1], A2]] = + null //dummy + + foo(((List('b'), 3), (Nil, 4))) +} diff --git a/tests/untried/neg/t0259.check b/tests/untried/neg/t0259.check new file mode 100644 index 000000000000..8c15d984196e --- /dev/null +++ b/tests/untried/neg/t0259.check @@ -0,0 +1,7 @@ +t0259.scala:4: error: double definition: +constructor TestCase3: (groups: (String, Int)*)test.TestCase3 at line 3 and +constructor TestCase3: (groups: String*)test.TestCase3 at line 4 +have same type after erasure: (groups: Seq)test.TestCase3 + def this( groups: String*) = this() + ^ +one error found diff --git a/tests/untried/neg/t0259.scala b/tests/untried/neg/t0259.scala new file mode 100644 index 000000000000..29aef701124d --- /dev/null +++ b/tests/untried/neg/t0259.scala @@ -0,0 +1,6 @@ +package test; +class TestCase3() { + def this( groups: (String, Int)*) = this() + def this( groups: String*) = this() +} +object Main extends TestCase3 with App diff --git a/tests/untried/neg/t0345.check b/tests/untried/neg/t0345.check new file mode 100644 index 000000000000..1e55d01cd1ce --- /dev/null +++ b/tests/untried/neg/t0345.check @@ -0,0 +1,4 @@ +t0345.scala:2: error: object creation impossible, since method cons in trait Lizt of type (a: Nothing)Unit is not defined + val empty = new Lizt[Nothing] { + ^ +one error found diff --git a/tests/untried/neg/t0345.scala b/tests/untried/neg/t0345.scala new file mode 100644 index 000000000000..15b941bc414b --- /dev/null +++ b/tests/untried/neg/t0345.scala @@ -0,0 +1,15 @@ +object Lizt { + val empty = new Lizt[Nothing] { + def cons[A](a : A): Unit = {} + } +} + +trait Lizt[A] { + def cons(a : A) : Unit +} +class Test { + abstract class C[A] {} + val c = new C[Int] { + def f[A](x: A): Unit = {} + } + } diff --git a/tests/untried/neg/t0351.check b/tests/untried/neg/t0351.check new file mode 100644 index 000000000000..ce10605eca04 --- /dev/null +++ b/tests/untried/neg/t0351.check @@ -0,0 +1,4 @@ +t0351.scala:2: error: no by-name parameter type allowed here + def identity[T](x : => T) : (=> T) + ^ +one error found diff --git a/tests/untried/neg/t0351.scala b/tests/untried/neg/t0351.scala new file mode 100644 index 000000000000..665bd89da4b4 --- /dev/null +++ b/tests/untried/neg/t0351.scala @@ -0,0 +1,3 @@ +abstract class Foo { + def identity[T](x : => T) : (=> T) +} diff --git a/tests/untried/neg/t0418.check b/tests/untried/neg/t0418.check new file mode 100644 index 000000000000..b95f8e4e1bcd --- /dev/null +++ b/tests/untried/neg/t0418.check @@ -0,0 +1,4 @@ +t0418.scala:2: error: not found: value Foo12340771 + null match { case Foo12340771.Bar(x) => x } + ^ +one error found diff --git a/tests/untried/neg/t0418.scala b/tests/untried/neg/t0418.scala new file mode 100644 index 000000000000..67007010d4e8 --- /dev/null +++ b/tests/untried/neg/t0418.scala @@ -0,0 +1,3 @@ +object Test { + null match { case Foo12340771.Bar(x) => x } +} diff --git a/tests/untried/neg/t0503.check b/tests/untried/neg/t0503.check new file mode 100644 index 000000000000..51e5bbeda6f7 --- /dev/null +++ b/tests/untried/neg/t0503.check @@ -0,0 +1,7 @@ +t0503.scala:1: error: expected class or object definition +val x = new { } with { } +^ +t0503.scala:3: error: expected class or object definition +val y = new { } with A +^ +two errors found diff --git a/tests/untried/neg/t0503.scala b/tests/untried/neg/t0503.scala new file mode 100644 index 000000000000..322e1ad132d7 --- /dev/null +++ b/tests/untried/neg/t0503.scala @@ -0,0 +1,3 @@ +val x = new { } with { } +trait A +val y = new { } with A diff --git a/tests/untried/neg/t0513.check b/tests/untried/neg/t0513.check new file mode 100644 index 000000000000..edc0c9ab67c3 --- /dev/null +++ b/tests/untried/neg/t0513.check @@ -0,0 +1,7 @@ +t0513.scala:5: error: type arguments [Nothing,Int] do not conform to class Y's type parameter bounds [T1,T2 <: T1] + val test2 = Test[Y[Nothing, Int]] // No error + ^ +t0513.scala:5: error: type arguments [Nothing,Int] do not conform to class Y's type parameter bounds [T1,T2 <: T1] + val test2 = Test[Y[Nothing, Int]] // No error + ^ +two errors found diff --git a/tests/untried/neg/t0513.scala b/tests/untried/neg/t0513.scala new file mode 100644 index 000000000000..0193483cab86 --- /dev/null +++ b/tests/untried/neg/t0513.scala @@ -0,0 +1,6 @@ +object Test { + case class Y[T1, T2 <: T1]() + //val test = Y[Nothing, Int] // Compiler error + case class Test[T]() + val test2 = Test[Y[Nothing, Int]] // No error +} diff --git a/tests/untried/neg/t0528neg.check b/tests/untried/neg/t0528neg.check new file mode 100644 index 000000000000..c8c3ab422f78 --- /dev/null +++ b/tests/untried/neg/t0528neg.check @@ -0,0 +1,4 @@ +t0528neg.scala:2: error: covariant type A occurs in invariant position in type => Array[T forSome { type T <: A }] of method toArray + def toArray: Array[T forSome {type T <: A}] + ^ +one error found diff --git a/tests/untried/neg/t0528neg.scala b/tests/untried/neg/t0528neg.scala new file mode 100644 index 000000000000..d19bdac73008 --- /dev/null +++ b/tests/untried/neg/t0528neg.scala @@ -0,0 +1,15 @@ +trait Sequ[+A] { + def toArray: Array[T forSome {type T <: A}] +} + +class RichStr extends Sequ[Char] { + // override to a primitive array + def toArray: Array[Char] = new Array[Char](10) +} + +object Foo extends App { + val x: RichStr = new RichStr + + println(x.toArray) // call directly + println((x: Sequ[Char]).toArray) // calling through the bridge misses unboxing +} diff --git a/tests/untried/neg/t0565.check b/tests/untried/neg/t0565.check new file mode 100644 index 000000000000..98e61a250352 --- /dev/null +++ b/tests/untried/neg/t0565.check @@ -0,0 +1,4 @@ +t0565.scala:8: error: Parameter type in structural refinement may not refer to a type member of that refinement + def z (w : T) : T } = + ^ +one error found diff --git a/tests/untried/neg/t0565.scala b/tests/untried/neg/t0565.scala new file mode 100644 index 000000000000..53059a4e009b --- /dev/null +++ b/tests/untried/neg/t0565.scala @@ -0,0 +1,22 @@ +object Test extends App { + + class MacGuffin + + object A { + var x : { type T >: Null <: AnyRef; + val y : T; + def z (w : T) : T } = + new { type T = String; + val y = "foo"; + def z (w : String) = w + "bar" } + lazy val u = { println("u evaluated"); x } + def foo (v : => u.type#T) : u.type#T = { + x = new { type T = MacGuffin; + val y = new MacGuffin; + def z (w : MacGuffin) = w } + u.z(v) + } + } + + A.foo(A.u.y) +} diff --git a/tests/untried/neg/t0590.check b/tests/untried/neg/t0590.check new file mode 100644 index 000000000000..a3ef70c6cdf8 --- /dev/null +++ b/tests/untried/neg/t0590.check @@ -0,0 +1,6 @@ +t0590.scala:2: error: type mismatch; + found : Null(null) + required: T + implicit def foo[T] : T = null + ^ +one error found diff --git a/tests/untried/neg/t0590.scala b/tests/untried/neg/t0590.scala new file mode 100644 index 000000000000..3416ade35586 --- /dev/null +++ b/tests/untried/neg/t0590.scala @@ -0,0 +1,3 @@ +object Test { + implicit def foo[T] : T = null +} diff --git a/tests/untried/neg/t0606.check b/tests/untried/neg/t0606.check new file mode 100644 index 000000000000..fb83fca74437 --- /dev/null +++ b/tests/untried/neg/t0606.check @@ -0,0 +1,4 @@ +t0606.scala:5: error: private value db escapes its defining scope as part of type Foo.this.db.Info + val info = new db.Info + ^ +one error found diff --git a/tests/untried/neg/t0606.scala b/tests/untried/neg/t0606.scala new file mode 100644 index 000000000000..e76ea810e5cb --- /dev/null +++ b/tests/untried/neg/t0606.scala @@ -0,0 +1,6 @@ +class Database { + class Info +} +class Foo(db : Database) { + val info = new db.Info +} diff --git a/tests/untried/neg/t0673.check b/tests/untried/neg/t0673.check new file mode 100644 index 000000000000..fd27afc23fff --- /dev/null +++ b/tests/untried/neg/t0673.check @@ -0,0 +1,4 @@ +Test.scala:2: error: object JavaClass.InnerClass is not a value + val x = JavaClass.InnerClass + ^ +one error found diff --git a/tests/untried/neg/t0673/JavaClass.java b/tests/untried/neg/t0673/JavaClass.java new file mode 100644 index 000000000000..e469e134837e --- /dev/null +++ b/tests/untried/neg/t0673/JavaClass.java @@ -0,0 +1,3 @@ +public class JavaClass { + public static class InnerClass {} +} diff --git a/tests/untried/neg/t0673/Test.scala b/tests/untried/neg/t0673/Test.scala new file mode 100644 index 000000000000..43b97887e41e --- /dev/null +++ b/tests/untried/neg/t0673/Test.scala @@ -0,0 +1,3 @@ +object Test { + val x = JavaClass.InnerClass +} diff --git a/tests/untried/neg/t0699.check b/tests/untried/neg/t0699.check new file mode 100644 index 000000000000..c944da8c105a --- /dev/null +++ b/tests/untried/neg/t0699.check @@ -0,0 +1,10 @@ +B.scala:2: error: illegal inheritance from sealed trait T + trait T1 extends A.T + ^ +B.scala:3: error: illegal inheritance from sealed class C + trait T2 extends A.C + ^ +B.scala:4: error: illegal inheritance from sealed class C + class C1 extends A.C + ^ +three errors found diff --git a/tests/untried/neg/t0699/A.scala b/tests/untried/neg/t0699/A.scala new file mode 100644 index 000000000000..a75ebbd252fc --- /dev/null +++ b/tests/untried/neg/t0699/A.scala @@ -0,0 +1,4 @@ +object A { + sealed trait T + sealed class C +} diff --git a/tests/untried/neg/t0699/B.scala b/tests/untried/neg/t0699/B.scala new file mode 100644 index 000000000000..d27ad16eeb44 --- /dev/null +++ b/tests/untried/neg/t0699/B.scala @@ -0,0 +1,5 @@ +object B { + trait T1 extends A.T + trait T2 extends A.C + class C1 extends A.C +} diff --git a/tests/untried/neg/t0764.check b/tests/untried/neg/t0764.check new file mode 100644 index 000000000000..0c7cff1e1e65 --- /dev/null +++ b/tests/untried/neg/t0764.check @@ -0,0 +1,7 @@ +t0764.scala:13: error: type mismatch; + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + new Main[AType]( (value: AType).prepend ) + ^ +one error found diff --git a/tests/untried/neg/t0764.scala b/tests/untried/neg/t0764.scala new file mode 100644 index 000000000000..7ee76feabd1e --- /dev/null +++ b/tests/untried/neg/t0764.scala @@ -0,0 +1,45 @@ +class Top[A] { + type AType = A +} + +trait Node { outer => + type T <: Node + def prepend = new Node { type T = outer.type } +} + +class Main[NextType <: Node](value: Node { type T = NextType }) + extends Top[Node { type T = NextType }] { + + new Main[AType]( (value: AType).prepend ) +} + +/* we've been back-and-forth on this one -- see PRs on SI-8177 for the reasoning +I think it should compile and that the following error is due to broken =:= on existentials + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + +I claim (omitting the forSome for brevity, even though the premature skolemization is probably the issue) +_1.type =:= Main.this.AType +because +(1) _1.type <:< Main.this.AType and (2) Main.this.AType <:< _1.type +(1), because: +_1.type <:< Node{type T = NextType} (because skolemization and _1's upper bound) +(2), because: +Node{type T = NextType} <:< _1.type forSome val _1: Node{type T = NextType} +because: +Node{type T = NextType} <:< T forSome {type T <: Node{type T = NextType} with Singleton} +because +Node{type T = NextType} <:< Node{type T = NextType} with Singleton + +hmmm.. might the with Singleton be throwing a wrench in our existential house? + +Behold the equivalent program which type checks without the fix for SI-8177. +(Expand type alias, convert type member to type param; +note the covariance to encode subtyping on type members.) + +class Node[+T <: Node[_]] { def prepend = new Node[this.type] } +class Main[NextType <: Node[_]](value: Node[NextType]) { + new Main(value.prepend) +} +*/ diff --git a/tests/untried/neg/t0764b.check b/tests/untried/neg/t0764b.check new file mode 100644 index 000000000000..4040954e7c2d --- /dev/null +++ b/tests/untried/neg/t0764b.check @@ -0,0 +1,47 @@ +t0764b.scala:27: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764..type} + required: p1.t0764.NodeAlias[p1.t0764.NodeAlias[A]] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:28: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764..type} + required: p1.t0764.NodeAlias[p1.t0764.Node{type T = A}] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:34: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764..type} + required: p1.t0764.Node{type T = p1.t0764.NodeAlias[A]} + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:35: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764..type} + required: p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:51: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764..type} + required: p2.t0764.NodeAlias[p2.t0764.NodeAlias[A]] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:52: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764..type} + required: p2.t0764.NodeAlias[p2.t0764.Node{type T = A}] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:58: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764..type} + required: p2.t0764.Node{type T = p2.t0764.NodeAlias[A]} + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:59: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764..type} + required: p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +8 errors found diff --git a/tests/untried/neg/t0764b.scala b/tests/untried/neg/t0764b.scala new file mode 100644 index 000000000000..14c623c67ad2 --- /dev/null +++ b/tests/untried/neg/t0764b.scala @@ -0,0 +1,63 @@ +// see neg/t0764 why this should probably be a pos/ test -- alas something's wrong with existential subtyping (?) + +// In all cases when calling "prepend" the receiver 'v' +// has static type NodeAlias[A] or (equivalently) Node { type T = A }. +// Since prepend explicitly returns the singleton type of the receiver, +// the return type of prepend in all cases is "v.type", and so the call +// to "new Main" can be parameterized with any of the following, in order +// of decreasing specificity with a tie for second place: +// +// new Main[v.type](v.prepend) +// new Main[NodeAlias[A]](v.prepend) +// new Main[Node { type T = A }](v.prepend) +// new Main(v.prepend) + +// the `fail` comments below denote what didn't compile before SI-8177 fixed all of them + +package p1 { + object t0764 { + type NodeAlias[A] = Node { type T = A } + trait Node { outer => + type T <: Node + def prepend: Node { type T = outer.type } = ??? + } + + class Main1[A <: Node](v: NodeAlias[A]) { + private[this] def f1 = new Main1(v.prepend) // fail + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main1[v.type](v.prepend) // ok + } + + class Main2[A <: Node](v: Node { type T = A }) { + private[this] def f1 = new Main2(v.prepend) // fail + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main2[v.type](v.prepend) // ok + } + } +} + +package p2 { + object t0764 { + type NodeAlias[A] = Node { type T = A } + trait Node { outer => + type T <: Node + def prepend: NodeAlias[outer.type] = ??? + } + + class Main1[A <: Node](v: NodeAlias[A]) { + private[this] def f1 = new Main1(v.prepend) // ok! <<========== WOT + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main1[v.type](v.prepend) // ok + } + + class Main2[A <: Node](v: Node { type T = A }) { + private[this] def f1 = new Main2(v.prepend) // fail + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + private[this] def f4 = new Main2[v.type](v.prepend) // ok + } + } +} diff --git a/tests/untried/neg/t0816.check b/tests/untried/neg/t0816.check new file mode 100644 index 000000000000..48f37c141492 --- /dev/null +++ b/tests/untried/neg/t0816.check @@ -0,0 +1,4 @@ +t0816.scala:5: error: case class Ctest has case ancestor Btest, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes. +case class Ctest(override val data: String) extends Btest(data, true) + ^ +one error found diff --git a/tests/untried/neg/t0816.scala b/tests/untried/neg/t0816.scala new file mode 100644 index 000000000000..0128a0ad7282 --- /dev/null +++ b/tests/untried/neg/t0816.scala @@ -0,0 +1,12 @@ +abstract class Atest(val data: String) + +case class Btest(override val data: String, val b: Boolean) extends Atest(data) + +case class Ctest(override val data: String) extends Btest(data, true) + +class testCaseClass { + def test(x: Atest) = x match { + case Ctest(data) => Console.println("C") + case Btest(data, b) => Console.println("B") + } +} diff --git a/tests/untried/neg/t0842.check b/tests/untried/neg/t0842.check new file mode 100644 index 000000000000..3351aa1174ce --- /dev/null +++ b/tests/untried/neg/t0842.check @@ -0,0 +1,4 @@ +t0842.scala:1: error: A.this.type does not take type parameters +trait A[T] { def m: this.type[T] = this } + ^ +one error found diff --git a/tests/untried/neg/t0842.scala b/tests/untried/neg/t0842.scala new file mode 100644 index 000000000000..f32c2ba26d71 --- /dev/null +++ b/tests/untried/neg/t0842.scala @@ -0,0 +1 @@ +trait A[T] { def m: this.type[T] = this } diff --git a/tests/untried/neg/t0899.check b/tests/untried/neg/t0899.check new file mode 100644 index 000000000000..8b71be8e0c95 --- /dev/null +++ b/tests/untried/neg/t0899.check @@ -0,0 +1,10 @@ +t0899.scala:9: error: super may be not be used on value o + override val o = "Ha! " + super.o + ^ +t0899.scala:11: error: super may be not be used on variable v + super.v = "aa" + ^ +t0899.scala:12: error: super may be not be used on variable v + println(super.v) + ^ +three errors found diff --git a/tests/untried/neg/t0899.scala b/tests/untried/neg/t0899.scala new file mode 100644 index 000000000000..817dc19eb4ce --- /dev/null +++ b/tests/untried/neg/t0899.scala @@ -0,0 +1,13 @@ +class Top { + val o = "Hi there!" + var v = "Hi there!" + type T + val x: T +} + +class Bot extends Top { + override val o = "Ha! " + super.o + val y: super.T = x + super.v = "aa" + println(super.v) +} diff --git a/tests/untried/neg/t0903.check b/tests/untried/neg/t0903.check new file mode 100644 index 000000000000..2dd05cd3eec3 --- /dev/null +++ b/tests/untried/neg/t0903.check @@ -0,0 +1,7 @@ +t0903.scala:3: error: value += is not a member of Int + x += 1 + ^ +t0903.scala:4: error: reassignment to val + x = 2 + ^ +two errors found diff --git a/tests/untried/neg/t0903.scala b/tests/untried/neg/t0903.scala new file mode 100644 index 000000000000..cf8abce97a92 --- /dev/null +++ b/tests/untried/neg/t0903.scala @@ -0,0 +1,5 @@ +object Test { + val x = 1 + x += 1 + x = 2 +} diff --git a/tests/untried/neg/t1009.check b/tests/untried/neg/t1009.check new file mode 100644 index 000000000000..5c9978b73712 --- /dev/null +++ b/tests/untried/neg/t1009.check @@ -0,0 +1,4 @@ +t1009.scala:2: error: empty quoted identifier + def `` = "fish" + ^ +one error found diff --git a/tests/untried/neg/t1009.scala b/tests/untried/neg/t1009.scala new file mode 100644 index 000000000000..a260397d2807 --- /dev/null +++ b/tests/untried/neg/t1009.scala @@ -0,0 +1,3 @@ +object Foo extends App{ + def `` = "fish" +} diff --git a/tests/untried/neg/t1010.check b/tests/untried/neg/t1010.check new file mode 100644 index 000000000000..2cc8f9d9860b --- /dev/null +++ b/tests/untried/neg/t1010.check @@ -0,0 +1,6 @@ +t1010.scala:14: error: type mismatch; + found : MailBox#Message + required: _3.in.Message where val _3: Actor + unstable.send(msg) // in.Message becomes unstable.Message, but that's ok since Message is a concrete type member + ^ +one error found diff --git a/tests/untried/neg/t1010.scala b/tests/untried/neg/t1010.scala new file mode 100644 index 000000000000..fd142978ecd6 --- /dev/null +++ b/tests/untried/neg/t1010.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): Nothing = + unstable.send(msg) // in.Message becomes unstable.Message, but that's ok since Message is a concrete type member +} diff --git a/tests/untried/neg/t1033.check b/tests/untried/neg/t1033.check new file mode 100644 index 000000000000..16e799264bbf --- /dev/null +++ b/tests/untried/neg/t1033.check @@ -0,0 +1,4 @@ +t1033.scala:5: error: return outside method definition + return 10 + ^ +one error found diff --git a/tests/untried/neg/t1033.scala b/tests/untried/neg/t1033.scala new file mode 100644 index 000000000000..28af01d5cb18 --- /dev/null +++ b/tests/untried/neg/t1033.scala @@ -0,0 +1,13 @@ +object A { + def f :Int = { + class B { + println("B") + return 10 + } + new B + 20 + } + def main(args: Array[String]): Unit = { + f + } +} diff --git a/tests/untried/neg/t1038.check b/tests/untried/neg/t1038.check new file mode 100644 index 000000000000..b191b89ad124 --- /dev/null +++ b/tests/untried/neg/t1038.check @@ -0,0 +1,5 @@ +t1038.scala:4: error: not enough arguments for constructor X: (x: Int)X. +Unspecified value parameter x. + val a = new X + ^ +one error found diff --git a/tests/untried/neg/t1038.scala b/tests/untried/neg/t1038.scala new file mode 100644 index 000000000000..367022965b99 --- /dev/null +++ b/tests/untried/neg/t1038.scala @@ -0,0 +1,8 @@ +class X(x : Int) + +object Y { + val a = new X + import a._ + implicit val b : Int = 1 + implicit val c = 2 +} diff --git a/tests/untried/neg/t1041.check b/tests/untried/neg/t1041.check new file mode 100644 index 000000000000..d82f3a8586be --- /dev/null +++ b/tests/untried/neg/t1041.check @@ -0,0 +1,6 @@ +t1041.scala:3: error: type mismatch; + found : Int(1) + required: List[Int] + case 1 => 4 + ^ +one error found diff --git a/tests/untried/neg/t1041.scala b/tests/untried/neg/t1041.scala new file mode 100644 index 000000000000..a5895c68a98e --- /dev/null +++ b/tests/untried/neg/t1041.scala @@ -0,0 +1,6 @@ +object test { + (1 :: 2 :: Nil) match { + case 1 => 4 + case _ => 0 + } +} diff --git a/tests/untried/neg/t1049.check b/tests/untried/neg/t1049.check new file mode 100644 index 000000000000..4a63cb175dcb --- /dev/null +++ b/tests/untried/neg/t1049.check @@ -0,0 +1,4 @@ +t1049.scala:6: error: not found: value a + case a : a.MapTo => + ^ +one error found diff --git a/tests/untried/neg/t1049.scala b/tests/untried/neg/t1049.scala new file mode 100644 index 000000000000..2f59ed3c09e4 --- /dev/null +++ b/tests/untried/neg/t1049.scala @@ -0,0 +1,9 @@ +class J { + type tttt[a, b] <: _root_.scala.collection.mutable.Map[a, b] + + def r(aa : tttt[String, String]) = { + 0 match { + case a : a.MapTo => + } + } +} diff --git a/tests/untried/neg/t1106.check b/tests/untried/neg/t1106.check new file mode 100644 index 000000000000..f81d0c60258b --- /dev/null +++ b/tests/untried/neg/t1106.check @@ -0,0 +1,7 @@ +t1106.scala:2: error: expected class or object definition +val p = new Par[String] +^ +t1106.scala:5: error: expected class or object definition +new Foo[p.type](p) // crashes compiler +^ +two errors found diff --git a/tests/untried/neg/t1106.scala b/tests/untried/neg/t1106.scala new file mode 100644 index 000000000000..a218eee7a1cd --- /dev/null +++ b/tests/untried/neg/t1106.scala @@ -0,0 +1,5 @@ +class Par[S] +val p = new Par[String] +class Foo[T[x]<:Par[x]](t: T[String]) + +new Foo[p.type](p) // crashes compiler diff --git a/tests/untried/neg/t1112.check b/tests/untried/neg/t1112.check new file mode 100644 index 000000000000..5e3821b1535f --- /dev/null +++ b/tests/untried/neg/t1112.check @@ -0,0 +1,4 @@ +t1112.scala:12: error: too many arguments for method call: (p: Int)(f: => Test.this.Type1)Unit + call(0,() => System.out.println("here we are")) + ^ +one error found diff --git a/tests/untried/neg/t1112.scala b/tests/untried/neg/t1112.scala new file mode 100644 index 000000000000..1a88629faf37 --- /dev/null +++ b/tests/untried/neg/t1112.scala @@ -0,0 +1,14 @@ +// checks that error doesn't crash the compiler +// (due to isFunctionType normalizing Type1 to a function type, +// but then the code that used that test not using the normalized type for further operations) +class Test { + type Type1 = () => Unit + + def call(p: Int)(f: => Type1) = { + f() + } + + def run = { + call(0,() => System.out.println("here we are")) + } +} diff --git a/tests/untried/neg/t112706A.check b/tests/untried/neg/t112706A.check new file mode 100644 index 000000000000..ad403ab13452 --- /dev/null +++ b/tests/untried/neg/t112706A.check @@ -0,0 +1,6 @@ +t112706A.scala:5: error: constructor cannot be instantiated to expected type; + found : (T1, T2) + required: String + case Tuple2(node,_) => + ^ +one error found diff --git a/tests/untried/neg/t112706A.scala b/tests/untried/neg/t112706A.scala new file mode 100644 index 000000000000..11304720bc32 --- /dev/null +++ b/tests/untried/neg/t112706A.scala @@ -0,0 +1,8 @@ +package test; +trait Test { + def foo(p : List[Tuple2[String,String]]) = { + for (t <- p) t._1 match { + case Tuple2(node,_) => + } + } +} diff --git a/tests/untried/neg/t1163.check b/tests/untried/neg/t1163.check new file mode 100644 index 000000000000..69e6b7ac4a4d --- /dev/null +++ b/tests/untried/neg/t1163.check @@ -0,0 +1,7 @@ +t1163.scala:2: error: overriding method foo in trait Sub of type => Sub; + method foo in trait Super of type => Super has incompatible type; + (Note that method foo in trait Sub of type => Sub is abstract, + and is therefore overridden by concrete method foo in trait Super of type => Super) +trait Sub extends Super { override def foo: Sub } + ^ +one error found diff --git a/tests/untried/neg/t1163.scala b/tests/untried/neg/t1163.scala new file mode 100644 index 000000000000..caf5747f9e1f --- /dev/null +++ b/tests/untried/neg/t1163.scala @@ -0,0 +1,2 @@ +trait Super { def foo: Super = new Super {} } +trait Sub extends Super { override def foo: Sub } diff --git a/tests/untried/neg/t1168.check b/tests/untried/neg/t1168.check new file mode 100644 index 000000000000..d9b754774fa5 --- /dev/null +++ b/tests/untried/neg/t1168.check @@ -0,0 +1,4 @@ +t1168.scala:6: error: Names of vals or vars may not end in `_=' + val r_= = 4 + ^ +one error found diff --git a/tests/untried/neg/t1168.scala b/tests/untried/neg/t1168.scala new file mode 100644 index 000000000000..85f2dc90d293 --- /dev/null +++ b/tests/untried/neg/t1168.scala @@ -0,0 +1,7 @@ +class tor { + def r_= = 4 +} + +class child extends tor { + val r_= = 4 +} diff --git a/tests/untried/neg/t1181.check b/tests/untried/neg/t1181.check new file mode 100644 index 000000000000..13b73d5381c7 --- /dev/null +++ b/tests/untried/neg/t1181.check @@ -0,0 +1,10 @@ +t1181.scala:8: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + case (Nil, Nil) => map + ^ +t1181.scala:9: error: type mismatch; + found : scala.collection.immutable.Map[Symbol,Symbol] + required: Symbol + _ => buildMap(map.updated(keyList.head, valueList.head), keyList.tail, valueList.tail) + ^ +one warning found +one error found diff --git a/tests/untried/neg/t1181.scala b/tests/untried/neg/t1181.scala new file mode 100644 index 000000000000..5e5fceacc8ee --- /dev/null +++ b/tests/untried/neg/t1181.scala @@ -0,0 +1,12 @@ +package test + +import scala.collection.immutable.Map + +class CompilerTest(val valueList: List[Symbol]) { + def buildMap(map: Map[Symbol, Symbol], keyList: List[Symbol], valueList: List[Symbol]): Map[Symbol, Symbol] = { + (keyList, valueList) match { + case (Nil, Nil) => map + _ => buildMap(map.updated(keyList.head, valueList.head), keyList.tail, valueList.tail) + } + } +} diff --git a/tests/untried/neg/t1183.check b/tests/untried/neg/t1183.check new file mode 100644 index 000000000000..c402829c701b --- /dev/null +++ b/tests/untried/neg/t1183.check @@ -0,0 +1,17 @@ +t1183.scala:6: error: name clash: class Foo defines object Baz +and its companion object Foo also defines class Baz + object Baz + ^ +t1183.scala:7: error: name clash: class Foo defines class Bam +and its companion object Foo also defines object Bam + class Bam + ^ +t1183.scala:8: error: name clash: class Foo defines object Bar +and its companion object Foo also defines class Bar + object Bar + ^ +t1183.scala:9: error: name clash: class Foo defines class Bar +and its companion object Foo also defines class Bar + case class Bar(i:Int) + ^ +four errors found diff --git a/tests/untried/neg/t1183.scala b/tests/untried/neg/t1183.scala new file mode 100644 index 000000000000..23868ab40102 --- /dev/null +++ b/tests/untried/neg/t1183.scala @@ -0,0 +1,34 @@ +// bug 1183 from in the old tracker, not in Trac + +object Test { + + class Foo(j:Int) { + object Baz + class Bam + object Bar + case class Bar(i:Int) + } + + + class Test717 { + val foo1 = new Foo(1) + + def runTest() = { + val res = (foo1.Bar(2):Any) match { + case foo1.Bar(2) => true // (1) + } + require(res) + } + } + + // (2) + object Foo { + class Bar(val x : String) + class Baz + object Bam + object Bar + + def unapply(s : String) : Option[Bar] = Some(new Bar(s)) + } + +} diff --git a/tests/untried/neg/t1215.check b/tests/untried/neg/t1215.check new file mode 100644 index 000000000000..1f9dd6bf387e --- /dev/null +++ b/tests/untried/neg/t1215.check @@ -0,0 +1,4 @@ +t1215.scala:2: error: value += is not a member of Int + val x = 1 += 1 + ^ +one error found diff --git a/tests/untried/neg/t1215.scala b/tests/untried/neg/t1215.scala new file mode 100644 index 000000000000..0e994d06e2fd --- /dev/null +++ b/tests/untried/neg/t1215.scala @@ -0,0 +1,3 @@ +object Test { + val x = 1 += 1 +} diff --git a/tests/untried/neg/t1224.check b/tests/untried/neg/t1224.check new file mode 100644 index 000000000000..ab8a6f11308c --- /dev/null +++ b/tests/untried/neg/t1224.check @@ -0,0 +1,4 @@ +t1224.scala:4: error: lower bound C[A.this.T] does not conform to upper bound C[C[A.this.T]] + type T >: C[T] <: C[C[T]] + ^ +one error found diff --git a/tests/untried/neg/t1224.flags b/tests/untried/neg/t1224.flags new file mode 100644 index 000000000000..ca20f55172e9 --- /dev/null +++ b/tests/untried/neg/t1224.flags @@ -0,0 +1 @@ +-Ybreak-cycles diff --git a/tests/untried/neg/t1224.scala b/tests/untried/neg/t1224.scala new file mode 100644 index 000000000000..35e01fa379ae --- /dev/null +++ b/tests/untried/neg/t1224.scala @@ -0,0 +1,5 @@ +trait C[T] {} + +abstract class A { + type T >: C[T] <: C[C[T]] +} diff --git a/tests/untried/neg/t1241.check b/tests/untried/neg/t1241.check new file mode 100644 index 000000000000..e1ccf4172fa3 --- /dev/null +++ b/tests/untried/neg/t1241.check @@ -0,0 +1,4 @@ +t1241.scala:5: error: class type required but AnyRef{def hello(): Unit} found + val x4 = new T { def hello() { println("4") } } // error! + ^ +one error found diff --git a/tests/untried/neg/t1241.scala b/tests/untried/neg/t1241.scala new file mode 100644 index 000000000000..1956d1678abb --- /dev/null +++ b/tests/untried/neg/t1241.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 = new T { def hello(): Unit = { println("4") } } // error! + x4.hello() + // more.. +} diff --git a/tests/untried/neg/t1275.check b/tests/untried/neg/t1275.check new file mode 100644 index 000000000000..a930e25ab345 --- /dev/null +++ b/tests/untried/neg/t1275.check @@ -0,0 +1,6 @@ +t1275.scala:11: error: type mismatch; + found : xs.MyType[a] + required: s + = xs f + ^ +one error found diff --git a/tests/untried/neg/t1275.scala b/tests/untried/neg/t1275.scala new file mode 100644 index 000000000000..d7513bf0983f --- /dev/null +++ b/tests/untried/neg/t1275.scala @@ -0,0 +1,15 @@ +object Test { + trait Seq[+t] { + type MyType[+t] <: Seq[t] + + def f: MyType[t] + } + + // illegal abstract type member refinement: changes the arity of MyType + // the error is pretty strange, since the compiler forms the illegal type xs.MyType[a] anyway + def span[a, s <: Seq[a] { type MyType/*look ma, no type parameters!*/ <: s } ](xs: s): s + = xs f +// ^ +// found : xs.MyType[a] +// required: s +} diff --git a/tests/untried/neg/t1286.check b/tests/untried/neg/t1286.check new file mode 100644 index 000000000000..912709613cf3 --- /dev/null +++ b/tests/untried/neg/t1286.check @@ -0,0 +1,5 @@ +b.scala:1: error: Companions 'trait Foo' and 'object Foo' must be defined in same file: + Found in t1286/a.scala and t1286/b.scala +object Foo extends Foo { + ^ +one error found diff --git a/tests/untried/neg/t1286/a.scala b/tests/untried/neg/t1286/a.scala new file mode 100644 index 000000000000..85ffe3bb5847 --- /dev/null +++ b/tests/untried/neg/t1286/a.scala @@ -0,0 +1,3 @@ +trait Foo { + def jump = Foo.x +} diff --git a/tests/untried/neg/t1286/b.scala b/tests/untried/neg/t1286/b.scala new file mode 100644 index 000000000000..48f3b440c29e --- /dev/null +++ b/tests/untried/neg/t1286/b.scala @@ -0,0 +1,3 @@ +object Foo extends Foo { + val x = "x" +} diff --git a/tests/untried/neg/t1355.check b/tests/untried/neg/t1355.check new file mode 100644 index 000000000000..f9786e927181 --- /dev/null +++ b/tests/untried/neg/t1355.check @@ -0,0 +1,4 @@ +t1355.scala:1: error: type arguments [A[T]] do not conform to trait A's type parameter bounds [T <: A[A[T]]] +trait A[T <: A[A[T]]] + ^ +one error found diff --git a/tests/untried/neg/t1355.scala b/tests/untried/neg/t1355.scala new file mode 100644 index 000000000000..3abb3c70ced8 --- /dev/null +++ b/tests/untried/neg/t1355.scala @@ -0,0 +1 @@ +trait A[T <: A[A[T]]] diff --git a/tests/untried/neg/t1364.check b/tests/untried/neg/t1364.check new file mode 100644 index 000000000000..cb8803abdcd9 --- /dev/null +++ b/tests/untried/neg/t1364.check @@ -0,0 +1,5 @@ +t1364.scala:9: error: overriding type T in trait A with bounds <: AnyRef{type S[-U]}; + type T has incompatible type + type T = { type S[U] = U } + ^ +one error found diff --git a/tests/untried/neg/t1364.scala b/tests/untried/neg/t1364.scala new file mode 100644 index 000000000000..dbc7dcf99c6d --- /dev/null +++ b/tests/untried/neg/t1364.scala @@ -0,0 +1,15 @@ +trait A { + type T <: { type S[-U] } + val x : T + def y : x.S[AnyRef] + def z : x.S[String] = y +} + +object B extends A { + type T = { type S[U] = U } + val x : T = null + def y : x.S[AnyRef] = new AnyRef + def t : String = z +} + +// println(B.t) diff --git a/tests/untried/neg/t1371.check b/tests/untried/neg/t1371.check new file mode 100644 index 000000000000..f2e9ffebe825 --- /dev/null +++ b/tests/untried/neg/t1371.check @@ -0,0 +1,4 @@ +t1371.scala:1: error: unbound wildcard type +trait A[T <: (_)] + ^ +one error found diff --git a/tests/untried/neg/t1371.scala b/tests/untried/neg/t1371.scala new file mode 100644 index 000000000000..4ad84a9d5c85 --- /dev/null +++ b/tests/untried/neg/t1371.scala @@ -0,0 +1,2 @@ +trait A[T <: (_)] + diff --git a/tests/untried/neg/t1422.check b/tests/untried/neg/t1422.check new file mode 100644 index 000000000000..362d7ef36bf6 --- /dev/null +++ b/tests/untried/neg/t1422.check @@ -0,0 +1,7 @@ +t1422.scala:1: error: private[this] not allowed for case class parameters +case class A(private[this] val foo:String) { } + ^ +t1422.scala:1: error: value foo in class A cannot be accessed in A +case class A(private[this] val foo:String) { } + ^ +two errors found diff --git a/tests/untried/neg/t1422.scala b/tests/untried/neg/t1422.scala new file mode 100644 index 000000000000..af308244cd1b --- /dev/null +++ b/tests/untried/neg/t1422.scala @@ -0,0 +1 @@ +case class A(private[this] val foo:String) { } diff --git a/tests/untried/neg/t1431.check b/tests/untried/neg/t1431.check new file mode 100644 index 000000000000..a17ba732435f --- /dev/null +++ b/tests/untried/neg/t1431.check @@ -0,0 +1,4 @@ +t1431.scala:8: error: class type required but X#Factory found + def fun[X<:MyTrait with Singleton]() = new X#Factory().value + ^ +one error found diff --git a/tests/untried/neg/t1431.scala b/tests/untried/neg/t1431.scala new file mode 100644 index 000000000000..aff1dbc01452 --- /dev/null +++ b/tests/untried/neg/t1431.scala @@ -0,0 +1,10 @@ +object Bug_New { + trait MyTrait { + type Alpha + def the_value : Alpha + class Factory() {def value : Alpha = the_value} + } + + def fun[X<:MyTrait with Singleton]() = new X#Factory().value +} + diff --git a/tests/untried/neg/t1432.check b/tests/untried/neg/t1432.check new file mode 100644 index 000000000000..e41f3453fec5 --- /dev/null +++ b/tests/untried/neg/t1432.check @@ -0,0 +1,8 @@ +t1432.scala:12: error: type mismatch; + found : (Int, Bug_NoUnique.Alias2[Bug_NoUnique.Wrap[Unit]] => Double) + (which expands to) (Int, Bug_NoUnique.Wrap[Bug_NoUnique.Wrap[Unit]] => Double) + required: Bug_NoUnique.TypeCon[Unit] + (which expands to) (Int, Unit => Double) + def test(x : TypeCon[Wrap[Unit]]) : TypeCon[Unit] = wrap(x) + ^ +one error found diff --git a/tests/untried/neg/t1432.scala b/tests/untried/neg/t1432.scala new file mode 100644 index 000000000000..bdf23312800a --- /dev/null +++ b/tests/untried/neg/t1432.scala @@ -0,0 +1,14 @@ +object Bug_NoUnique { + + type TypeCon[Env] = (Int, Env=>Double) + + case class Wrap[E](parent:E) {} + + type Alias2[E] = Wrap[E] + + def wrap[E,A,Y](v : (A,E=>Y)) : (A,Alias2[E]=>Y) = + throw new Error("Body here") + + def test(x : TypeCon[Wrap[Unit]]) : TypeCon[Unit] = wrap(x) +} + diff --git a/tests/untried/neg/t1477.check b/tests/untried/neg/t1477.check new file mode 100644 index 000000000000..72bffa327061 --- /dev/null +++ b/tests/untried/neg/t1477.check @@ -0,0 +1,5 @@ +t1477.scala:13: error: overriding type V in trait C with bounds <: Middle.this.D; + type V is a volatile type; cannot override a type with non-volatile upper bound + type V <: (D with U) + ^ +one error found diff --git a/tests/untried/neg/t1477.scala b/tests/untried/neg/t1477.scala new file mode 100644 index 000000000000..a9a6d678ca5f --- /dev/null +++ b/tests/untried/neg/t1477.scala @@ -0,0 +1,25 @@ +object Test extends App { + trait A + trait B extends A + + trait C { + type U + trait D { type T >: B <: A } + type V <: D + val y: V#T = new B { } + } + + trait Middle extends C { + type V <: (D with U) + } + + class D extends Middle { + trait E + trait F { type T = E } + type U = F + def frob(arg : E) : E = arg + frob(y) + } + + new D +} diff --git a/tests/untried/neg/t1503.check b/tests/untried/neg/t1503.check new file mode 100644 index 000000000000..7adeea20f3f5 --- /dev/null +++ b/tests/untried/neg/t1503.check @@ -0,0 +1,8 @@ +t1503.scala:7: warning: The value matched by Whatever is bound to n, which may be used under the +unsound assumption that it has type Whatever.type, whereas we can only safely +count on it having type Any, as the pattern is matched using `==` (see SI-1503). + def matchWhateverCCE(x: Any) = x match { case n @ Whatever => n } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t1503.flags b/tests/untried/neg/t1503.flags new file mode 100644 index 000000000000..e93641e9319e --- /dev/null +++ b/tests/untried/neg/t1503.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t1503.scala b/tests/untried/neg/t1503.scala new file mode 100644 index 000000000000..e17248575343 --- /dev/null +++ b/tests/untried/neg/t1503.scala @@ -0,0 +1,8 @@ +object Whatever { + override def equals(x: Any) = true +} + +class Test { + // when left to its own devices, and not under -Xfuture, the return type is Whatever.type + def matchWhateverCCE(x: Any) = x match { case n @ Whatever => n } +} diff --git a/tests/untried/neg/t1523.check b/tests/untried/neg/t1523.check new file mode 100644 index 000000000000..d2489f2602a6 --- /dev/null +++ b/tests/untried/neg/t1523.check @@ -0,0 +1,4 @@ +t1523.scala:4: error: too many arguments for method bug: (x: Any)Any + def go() = bug("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a") + ^ +one error found diff --git a/tests/untried/neg/t1523.scala b/tests/untried/neg/t1523.scala new file mode 100644 index 000000000000..219fb0c0604f --- /dev/null +++ b/tests/untried/neg/t1523.scala @@ -0,0 +1,5 @@ +object test { + def bug(x: Any) = x + + def go() = bug("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a") +} diff --git a/tests/untried/neg/t1548.check b/tests/untried/neg/t1548.check new file mode 100644 index 000000000000..7f5a3f44e2a2 --- /dev/null +++ b/tests/untried/neg/t1548.check @@ -0,0 +1,4 @@ +S.scala:2: error: method defaultMethod overrides nothing + override def defaultMethod = "Boo!" + ^ +one error found diff --git a/tests/untried/neg/t1548/J.java b/tests/untried/neg/t1548/J.java new file mode 100644 index 000000000000..01dd56d34895 --- /dev/null +++ b/tests/untried/neg/t1548/J.java @@ -0,0 +1,12 @@ +package javapkg; + +public class J { + + String defaultMethod() { + return "foo"; + } + + public String toString() { + return "JavaClass: "+defaultMethod(); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t1548/S.scala b/tests/untried/neg/t1548/S.scala new file mode 100644 index 000000000000..086b78029d4c --- /dev/null +++ b/tests/untried/neg/t1548/S.scala @@ -0,0 +1,3 @@ +class ScalaClass extends javapkg.J { + override def defaultMethod = "Boo!" +} diff --git a/tests/untried/neg/t1623.check b/tests/untried/neg/t1623.check new file mode 100644 index 000000000000..251039ad30c3 --- /dev/null +++ b/tests/untried/neg/t1623.check @@ -0,0 +1,4 @@ +t1623.scala:11: error: class BImpl cannot be instantiated because it does not conform to its self-type test.BImpl with test.A + val b = new BImpl + ^ +one error found diff --git a/tests/untried/neg/t1623.scala b/tests/untried/neg/t1623.scala new file mode 100644 index 000000000000..f5189aa4ca2f --- /dev/null +++ b/tests/untried/neg/t1623.scala @@ -0,0 +1,12 @@ +package test + +trait A +trait B + +class BImpl extends B { + this: A => +} + +object Test2 extends App { + val b = new BImpl +} diff --git a/tests/untried/neg/t1672b.check b/tests/untried/neg/t1672b.check new file mode 100644 index 000000000000..60ccf771742d --- /dev/null +++ b/tests/untried/neg/t1672b.check @@ -0,0 +1,16 @@ +t1672b.scala:3: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position + def bar : Nothing = { + ^ +t1672b.scala:14: error: could not optimize @tailrec annotated method baz: it contains a recursive call not in tail position + def baz : Nothing = { + ^ +t1672b.scala:29: error: could not optimize @tailrec annotated method boz: it contains a recursive call not in tail position + case _: Throwable => boz; ??? + ^ +t1672b.scala:34: error: could not optimize @tailrec annotated method bez: it contains a recursive call not in tail position + def bez : Nothing = { + ^ +t1672b.scala:46: error: could not optimize @tailrec annotated method bar: it contains a recursive call not in tail position + else 1 + (try { + ^ +5 errors found diff --git a/tests/untried/neg/t1672b.scala b/tests/untried/neg/t1672b.scala new file mode 100644 index 000000000000..0ccdd036337c --- /dev/null +++ b/tests/untried/neg/t1672b.scala @@ -0,0 +1,52 @@ +object Test { + @annotation.tailrec + def bar : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => bar + } finally { + bar + } + } + + @annotation.tailrec + def baz : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => baz + } finally { + ??? + } + } + + @annotation.tailrec + def boz : Nothing = { + try { + throw new RuntimeException + } catch { + case _: Throwable => boz; ??? + } + } + + @annotation.tailrec + def bez : Nothing = { + try { + bez + } finally { + ??? + } + } + + // the `liftedTree` local method will prevent a tail call here. + @annotation.tailrec + def bar(i : Int) : Int = { + if (i == 0) 0 + else 1 + (try { + throw new RuntimeException + } catch { + case _: Throwable => bar(i - 1) + }) + } +} diff --git a/tests/untried/neg/t1701.check b/tests/untried/neg/t1701.check new file mode 100644 index 000000000000..d603e62e5a6a --- /dev/null +++ b/tests/untried/neg/t1701.check @@ -0,0 +1,4 @@ +t1701.scala:1: error: Cloneable does not take type parameters +class A extends java.lang.Cloneable[String, Option, Int] + ^ +one error found diff --git a/tests/untried/neg/t1701.scala b/tests/untried/neg/t1701.scala new file mode 100644 index 000000000000..7cd6ff9953be --- /dev/null +++ b/tests/untried/neg/t1701.scala @@ -0,0 +1 @@ +class A extends java.lang.Cloneable[String, Option, Int] diff --git a/tests/untried/neg/t1705.check b/tests/untried/neg/t1705.check new file mode 100644 index 000000000000..7f75bd0fb5bb --- /dev/null +++ b/tests/untried/neg/t1705.check @@ -0,0 +1,7 @@ +t1705.scala:9: error: can't existentially abstract over parameterized type this.T[Z] + val c = new C{ + ^ +t1705.scala:14: error: can't existentially abstract over parameterized type C[String] + val x1 = { + ^ +two errors found diff --git a/tests/untried/neg/t1705.scala b/tests/untried/neg/t1705.scala new file mode 100644 index 000000000000..fabdca0ec6e9 --- /dev/null +++ b/tests/untried/neg/t1705.scala @@ -0,0 +1,35 @@ +package trials +object crashing { + trait C { + abstract class T[A] { + def f[Z] (a:T[Z]) : T[A] + } + } + abstract class Thing { + val c = new C{ + class T[A](a:A) { + def f[Z](t:T[Z]) = new T(a) + } + } + val x1 = { + class C[T] { val x: T } + new C[String] + } + } +} +/* + +Infinite loop in Typer.addLocals. Printing all calls to it: + +addLocals: Unit +addLocals: this.T[A] +addLocals: java.lang.Object with crashing.C{ ... } +addLocals: >: Nothing <: java.lang.Object with crashing.C{type T[A] <: java.lang.Object with ScalaObject{def f[Z](this.T[Z]): this.T[A]}} +addLocals: >: Nothing <: java.lang.Object with ScalaObject{def f[Z](this.T[Z]): this.T[Z]} +addLocals: >: Nothing <: java.lang.Object with ScalaObject{def f[Z](this.T[Z]): this.T[Z]} +addLocals: >: Nothing <: java.lang.Object with ScalaObject{def f[Z](this.T[Z]): this.T[Z]} +[...] +* + C { type T[A] <: { def f[Z]: T[Z] => T[A] } } + +*/ diff --git a/tests/untried/neg/t1838.check b/tests/untried/neg/t1838.check new file mode 100644 index 000000000000..a476158c7b1e --- /dev/null +++ b/tests/untried/neg/t1838.check @@ -0,0 +1,7 @@ +t1838.scala:6: error: `sealed' modifier can be used only for classes + sealed val v = 0 + ^ +t1838.scala:5: error: `sealed' modifier can be used only for classes + sealed def f = 0 + ^ +two errors found diff --git a/tests/untried/neg/t1838.scala b/tests/untried/neg/t1838.scala new file mode 100644 index 000000000000..36eeb4050aa3 --- /dev/null +++ b/tests/untried/neg/t1838.scala @@ -0,0 +1,7 @@ +package test + +class A { + sealed class B + sealed def f = 0 + sealed val v = 0 +} diff --git a/tests/untried/neg/t1845.check b/tests/untried/neg/t1845.check new file mode 100644 index 000000000000..a6c82f565987 --- /dev/null +++ b/tests/untried/neg/t1845.check @@ -0,0 +1,6 @@ +t1845.scala:6: error: encountered unrecoverable cycle resolving import. +Note: this is often due in part to a class depending on a definition nested within its companion. +If applicable, you may wish to try moving some members into another object. + import lexical._ + ^ +one error found diff --git a/tests/untried/neg/t1845.scala b/tests/untried/neg/t1845.scala new file mode 100644 index 000000000000..4d3966484ded --- /dev/null +++ b/tests/untried/neg/t1845.scala @@ -0,0 +1,10 @@ +class Tokens { abstract class Token } +trait TokenParsers { val lexical: Tokens } + + +class MyTokenParsers extends TokenParsers { + import lexical._ + + + val lexical = new Tokens +} diff --git a/tests/untried/neg/t1872.check b/tests/untried/neg/t1872.check new file mode 100644 index 000000000000..c5dc2a808077 --- /dev/null +++ b/tests/untried/neg/t1872.check @@ -0,0 +1,8 @@ +t1872.scala:3: warning: fruitless type test: a value of type Int cannot also be a scala.util.Random + def f(x: Int) = x.isInstanceOf[util.Random] + ^ +t1872.scala:3: error: isInstanceOf cannot test if value types are references. + def f(x: Int) = x.isInstanceOf[util.Random] + ^ +one warning found +one error found diff --git a/tests/untried/neg/t1872.scala b/tests/untried/neg/t1872.scala new file mode 100644 index 000000000000..f3c26530489f --- /dev/null +++ b/tests/untried/neg/t1872.scala @@ -0,0 +1,4 @@ +class A { + // a true result here would necessitate profound soul searching + def f(x: Int) = x.isInstanceOf[util.Random] +} diff --git a/tests/untried/neg/t1878.check b/tests/untried/neg/t1878.check new file mode 100644 index 000000000000..5814375515ce --- /dev/null +++ b/tests/untried/neg/t1878.check @@ -0,0 +1,7 @@ +t1878.scala:3: error: bad simple pattern: bad use of _* (a sequence pattern must be the last pattern) + val err1 = "" match { case Seq(f @ _*, ',') => f } + ^ +t1878.scala:9: error: bad simple pattern: bad use of _* (a sequence pattern must be the last pattern) + val List(List(_*, arg2), _) = List(List(1,2,3), List(4,5,6)) + ^ +two errors found diff --git a/tests/untried/neg/t1878.scala b/tests/untried/neg/t1878.scala new file mode 100644 index 000000000000..b29186afc093 --- /dev/null +++ b/tests/untried/neg/t1878.scala @@ -0,0 +1,17 @@ +object Test extends App { + // illegal + val err1 = "" match { case Seq(f @ _*, ',') => f } + + // no error + val List(List(arg1, _*), _) = List(List(1,2,3), List(4,5,6)) + + // illegal + val List(List(_*, arg2), _) = List(List(1,2,3), List(4,5,6)) + + /* see t1878-typer.scala + // illegal - bug #1764 + null match { + case

{ _* }

=> + } + */ +} diff --git a/tests/untried/neg/t1909-object.check b/tests/untried/neg/t1909-object.check new file mode 100644 index 000000000000..401c1f7ebf72 --- /dev/null +++ b/tests/untried/neg/t1909-object.check @@ -0,0 +1,4 @@ +t1909-object.scala:4: error: !!! SI-1909 Unable to STATICally lift object InnerTrouble$1, which is defined in the self- or super-constructor call of class Kaboom. A VerifyError is likely. + object InnerTrouble + ^ +one error found diff --git a/tests/untried/neg/t1909-object.flags b/tests/untried/neg/t1909-object.flags new file mode 100644 index 000000000000..eb8b40661b27 --- /dev/null +++ b/tests/untried/neg/t1909-object.flags @@ -0,0 +1 @@ +-Xdev -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t1909-object.scala b/tests/untried/neg/t1909-object.scala new file mode 100644 index 000000000000..5bb58419b987 --- /dev/null +++ b/tests/untried/neg/t1909-object.scala @@ -0,0 +1,12 @@ +class Kaboom(a: Any) { + def this() = { + this({ + object InnerTrouble + InnerTrouble + }) + } +} + +object Test extends App { + new Kaboom() +} diff --git a/tests/untried/neg/t1909b.check b/tests/untried/neg/t1909b.check new file mode 100644 index 000000000000..9a683643ae9a --- /dev/null +++ b/tests/untried/neg/t1909b.check @@ -0,0 +1,4 @@ +t1909b.scala:4: error: this can be used only in a class, object, or template + def bar() = this.z + 5 + ^ +one error found diff --git a/tests/untried/neg/t1909b.scala b/tests/untried/neg/t1909b.scala new file mode 100644 index 000000000000..637fa9619805 --- /dev/null +++ b/tests/untried/neg/t1909b.scala @@ -0,0 +1,7 @@ +class Ticket1909 (x: Int) { + var z = 12 + def this() = this({ + def bar() = this.z + 5 + bar + }) +} diff --git a/tests/untried/neg/t1960.check b/tests/untried/neg/t1960.check new file mode 100644 index 000000000000..5238141c4ee4 --- /dev/null +++ b/tests/untried/neg/t1960.check @@ -0,0 +1,4 @@ +t1960.scala:5: error: parameter 'p' requires field but conflicts with method p in trait TBase +class Aclass (p: Int) extends TBase { def g() { f(p) } } + ^ +one error found diff --git a/tests/untried/neg/t1960.scala b/tests/untried/neg/t1960.scala new file mode 100644 index 000000000000..ad9a96011fd6 --- /dev/null +++ b/tests/untried/neg/t1960.scala @@ -0,0 +1,5 @@ +object ClassFormatErrorExample extends App { new Aclass(1) } + +trait TBase { var p:Int = 0; def f(p1: Int): Unit = {} } + +class Aclass (p: Int) extends TBase { def g(): Unit = { f(p) } } diff --git a/tests/untried/neg/t1980.check b/tests/untried/neg/t1980.check new file mode 100644 index 000000000000..2fa27fa462d1 --- /dev/null +++ b/tests/untried/neg/t1980.check @@ -0,0 +1,12 @@ +t1980.scala:2: warning: by-name parameters will be evaluated eagerly when called as a right-associative infix operator. For more details, see SI-1980. + def op1_:(x: => Any) = () // warn + ^ +t1980.scala:3: warning: by-name parameters will be evaluated eagerly when called as a right-associative infix operator. For more details, see SI-1980. + def op2_:(x: Any, y: => Any) = () // warn + ^ +t1980.scala:4: warning: by-name parameters will be evaluated eagerly when called as a right-associative infix operator. For more details, see SI-1980. + def op3_:(x: Any, y: => Any)(a: Any) = () // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t1980.flags b/tests/untried/neg/t1980.flags new file mode 100644 index 000000000000..7949c2afa212 --- /dev/null +++ b/tests/untried/neg/t1980.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/untried/neg/t1980.scala b/tests/untried/neg/t1980.scala new file mode 100644 index 000000000000..132865e694b2 --- /dev/null +++ b/tests/untried/neg/t1980.scala @@ -0,0 +1,9 @@ +object Test { + def op1_:(x: => Any) = () // warn + def op2_:(x: Any, y: => Any) = () // warn + def op3_:(x: Any, y: => Any)(a: Any) = () // warn + + def op4() = () // no warn + def op5(x: => Any) = () // no warn + def op6_:(x: Any)(a: => Any) = () // no warn +} diff --git a/tests/untried/neg/t200.check b/tests/untried/neg/t200.check new file mode 100644 index 000000000000..b6b1a3226720 --- /dev/null +++ b/tests/untried/neg/t200.check @@ -0,0 +1,5 @@ +t200.scala:7: error: method foo is defined twice + conflicting symbols both originated in file 't200.scala' + def foo: Int; + ^ +one error found diff --git a/tests/untried/neg/t200.scala b/tests/untried/neg/t200.scala new file mode 100644 index 000000000000..692fe368e2f4 --- /dev/null +++ b/tests/untried/neg/t200.scala @@ -0,0 +1,8 @@ +trait X { + def foo: Int; +} + +trait Y extends X { + def foo: String; + def foo: Int; +} diff --git a/tests/untried/neg/t2031.check b/tests/untried/neg/t2031.check new file mode 100644 index 000000000000..74aa6c9c0b1c --- /dev/null +++ b/tests/untried/neg/t2031.check @@ -0,0 +1,6 @@ +t2031.scala:8: error: polymorphic expression cannot be instantiated to expected type; + found : [A]scala.collection.mutable.Builder[A,scala.collection.immutable.TreeSet[A]] + required: scala.collection.generic.CanBuildFrom[scala.collection.immutable.TreeSet[Int],Int,?] + res0.map(x => x)(TreeSet.newBuilder) + ^ +one error found diff --git a/tests/untried/neg/t2031.scala b/tests/untried/neg/t2031.scala new file mode 100644 index 000000000000..fde7a603fa60 --- /dev/null +++ b/tests/untried/neg/t2031.scala @@ -0,0 +1,9 @@ +import scala.collection.immutable._ + +object Test extends App { + val res0 = TreeSet(1, 2, 3) + + //res0.map(x => x)(TreeSet.newBuilder[Int]) + + res0.map(x => x)(TreeSet.newBuilder) +} diff --git a/tests/untried/neg/t2066.check b/tests/untried/neg/t2066.check new file mode 100644 index 000000000000..efade87e2615 --- /dev/null +++ b/tests/untried/neg/t2066.check @@ -0,0 +1,21 @@ +t2066.scala:6: error: overriding method f in trait A1 of type [T[_]]=> Unit; + method f has incompatible type + override def f[T[+_]] = () + ^ +t2066.scala:10: error: overriding method f in trait A1 of type [T[_]]=> Unit; + method f has incompatible type + override def f[T[-_]] = () + ^ +t2066.scala:23: error: overriding method f in trait A2 of type [T[+_]]=> Unit; + method f has incompatible type + override def f[T[-_]] = () + ^ +t2066.scala:45: error: overriding method f in trait A4 of type [T[X[+_]]]=> Unit; + method f has incompatible type + override def f[T[X[_]]] = () + ^ +t2066.scala:53: error: overriding method f in trait A5 of type [T[X[-_]]]=> Unit; + method f has incompatible type + override def f[T[X[_]]] = () + ^ +5 errors found diff --git a/tests/untried/neg/t2066.scala b/tests/untried/neg/t2066.scala new file mode 100644 index 000000000000..7f15d39c67fa --- /dev/null +++ b/tests/untried/neg/t2066.scala @@ -0,0 +1,70 @@ +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/neg/t2066b.check b/tests/untried/neg/t2066b.check new file mode 100644 index 000000000000..097c44fef337 --- /dev/null +++ b/tests/untried/neg/t2066b.check @@ -0,0 +1,5 @@ +t2066b.scala:7: error: overriding method f in trait A of type [T[_]](x: T[Int])T[Any]; + method f has incompatible type + def f[T[+_]](x : T[Int]) : T[Any] = x + ^ +one error found diff --git a/tests/untried/neg/t2066b.scala b/tests/untried/neg/t2066b.scala new file mode 100644 index 000000000000..2f8ffde1446a --- /dev/null +++ b/tests/untried/neg/t2066b.scala @@ -0,0 +1,16 @@ +object Test extends App { + trait A { + def f[T[_]](x : T[Int]) : T[Any] + } + + class B extends A { + def f[T[+_]](x : T[Int]) : T[Any] = x + } + + class P[Y](var y : Y) + + val p = new P(1) + val palias = (new B():A).f[P](p) + palias.y = "hello" + val z: Int = p.y +} diff --git a/tests/untried/neg/t2070.check b/tests/untried/neg/t2070.check new file mode 100644 index 000000000000..ef1d08f7b74d --- /dev/null +++ b/tests/untried/neg/t2070.check @@ -0,0 +1,6 @@ +t2070.scala:8: error: The kind of trait T does not conform to the expected kind of type T[X] in trait A. +t2070.B.T's type parameters do not match type T's expected parameters: +type X (in object B) has one type parameter, but type X (in trait A) has none + trait T[X[_]] + ^ +one error found diff --git a/tests/untried/neg/t2070.scala b/tests/untried/neg/t2070.scala new file mode 100644 index 000000000000..c810568edc52 --- /dev/null +++ b/tests/untried/neg/t2070.scala @@ -0,0 +1,10 @@ +object t2070 { + trait A { + type T[X] + def f(x : T[Int]) = x + } + + object B extends A { + trait T[X[_]] + } +} diff --git a/tests/untried/neg/t2078.check b/tests/untried/neg/t2078.check new file mode 100644 index 000000000000..00bb323a0bac --- /dev/null +++ b/tests/untried/neg/t2078.check @@ -0,0 +1,4 @@ +t2078.scala:2: error: contravariant type S occurs in covariant position in type => AnyRef{val x: S} of value f + val f = new { val x = y } + ^ +one error found diff --git a/tests/untried/neg/t2078.scala b/tests/untried/neg/t2078.scala new file mode 100644 index 000000000000..342ba088c7e8 --- /dev/null +++ b/tests/untried/neg/t2078.scala @@ -0,0 +1,9 @@ +class A[-S](y : S) { + val f = new { val x = y } +} + +object Test extends App { + val a = new A(1) + val b = a : A[Nothing] + println(b.f.x) +} diff --git a/tests/untried/neg/t2102.check b/tests/untried/neg/t2102.check new file mode 100644 index 000000000000..b4f91a53195f --- /dev/null +++ b/tests/untried/neg/t2102.check @@ -0,0 +1,6 @@ +t2102.scala:2: error: type mismatch; + found : java.util.Iterator[Int] + required: scala.collection.Iterator[_] + val x: Iterator[_] = new java.util.ArrayList[Int]().iterator + ^ +one error found diff --git a/tests/untried/neg/t2102.scala b/tests/untried/neg/t2102.scala new file mode 100644 index 000000000000..9c37039039f4 --- /dev/null +++ b/tests/untried/neg/t2102.scala @@ -0,0 +1,3 @@ +object Test { + val x: Iterator[_] = new java.util.ArrayList[Int]().iterator +} diff --git a/tests/untried/neg/t2139.check b/tests/untried/neg/t2139.check new file mode 100644 index 000000000000..e26f2907617f --- /dev/null +++ b/tests/untried/neg/t2139.check @@ -0,0 +1,6 @@ +t2139.scala:13: error: type mismatch; + found : Int(4) + required: Nothing + val z:Int=(u.f _)(4) + ^ +one error found diff --git a/tests/untried/neg/t2139.scala b/tests/untried/neg/t2139.scala new file mode 100644 index 000000000000..316c0d441180 --- /dev/null +++ b/tests/untried/neg/t2139.scala @@ -0,0 +1,15 @@ +/* + NOTE: if inference is changed so that + T is inferred to be Int, rather than Nothing, + the piece of code below will start to compile OK. + In that case, see ticket #2139, and make sure that + the generated code will no longer crash! +*/ +class U { + def f[T](x:T):T=x +} +object H extends App { + val u=new U + val z:Int=(u.f _)(4) + println("done") +} diff --git a/tests/untried/neg/t2144.check b/tests/untried/neg/t2144.check new file mode 100644 index 000000000000..670e188c2a68 --- /dev/null +++ b/tests/untried/neg/t2144.check @@ -0,0 +1,4 @@ +t2144.scala:2: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def foo[A](a: A) = new { def bar(x: A): A = x } + ^ +one error found diff --git a/tests/untried/neg/t2144.scala b/tests/untried/neg/t2144.scala new file mode 100644 index 000000000000..af9a5e166e87 --- /dev/null +++ b/tests/untried/neg/t2144.scala @@ -0,0 +1,3 @@ +object Test { + def foo[A](a: A) = new { def bar(x: A): A = x } +} diff --git a/tests/untried/neg/t2148.check b/tests/untried/neg/t2148.check new file mode 100644 index 000000000000..27b5dce50791 --- /dev/null +++ b/tests/untried/neg/t2148.check @@ -0,0 +1,4 @@ +t2148.scala:9: error: A is not a legal prefix for a constructor + val b = new A with A#A1 + ^ +one error found diff --git a/tests/untried/neg/t2148.scala b/tests/untried/neg/t2148.scala new file mode 100644 index 000000000000..897f1457b3a7 --- /dev/null +++ b/tests/untried/neg/t2148.scala @@ -0,0 +1,10 @@ +class A { + var i = 0 + trait A1 extends A { + i += 1 + } +} + +object Bob { + val b = new A with A#A1 +} diff --git a/tests/untried/neg/t2180.check b/tests/untried/neg/t2180.check new file mode 100644 index 000000000000..addc4cfbb84c --- /dev/null +++ b/tests/untried/neg/t2180.check @@ -0,0 +1,6 @@ +t2180.scala:3: error: type mismatch; + found : List[Any] + required: List[Mxml] + children.toList.flatMap ( e => { + ^ +one error found diff --git a/tests/untried/neg/t2180.scala b/tests/untried/neg/t2180.scala new file mode 100644 index 000000000000..54a9e49c1c15 --- /dev/null +++ b/tests/untried/neg/t2180.scala @@ -0,0 +1,9 @@ +class Mxml { + private def processChildren( children:Seq[Any] ):List[Mxml] = { + children.toList.flatMap ( e => { + e match { + case s:scala.collection.Traversable[_] => s case a => List(a) + } + }) + } +} diff --git a/tests/untried/neg/t2206.check b/tests/untried/neg/t2206.check new file mode 100644 index 000000000000..766f35d93a3f --- /dev/null +++ b/tests/untried/neg/t2206.check @@ -0,0 +1,5 @@ +t2206.scala:10: error: value f is not a member of o.A + Note: implicit method ax is not applicable here because it comes after the application point and it lacks an explicit result type + a.f() + ^ +one error found diff --git a/tests/untried/neg/t2206.scala b/tests/untried/neg/t2206.scala new file mode 100644 index 000000000000..529f5030b5f2 --- /dev/null +++ b/tests/untried/neg/t2206.scala @@ -0,0 +1,15 @@ +object o { + class A + + class AX { + def f(): Unit = { } + } + + import Implicits._ + val a = new A + a.f() + + object Implicits { + implicit def ax(a: A) = new AX + } +} diff --git a/tests/untried/neg/t2208.check b/tests/untried/neg/t2208.check new file mode 100644 index 000000000000..64bb3a77c83b --- /dev/null +++ b/tests/untried/neg/t2208.check @@ -0,0 +1,4 @@ +t2208.scala:7: error: type arguments [Any] do not conform to type Alias's type parameter bounds [X <: Test.A] + class C extends Alias[Any] // not ok, normalisation should check bounds before expanding Alias + ^ +one error found diff --git a/tests/untried/neg/t2208.scala b/tests/untried/neg/t2208.scala new file mode 100644 index 000000000000..53165cc81a8b --- /dev/null +++ b/tests/untried/neg/t2208.scala @@ -0,0 +1,8 @@ +object Test { + class A + + class B[X] + type Alias[X <: A] = B[X] + + class C extends Alias[Any] // not ok, normalisation should check bounds before expanding Alias +} diff --git a/tests/untried/neg/t2213.check b/tests/untried/neg/t2213.check new file mode 100644 index 000000000000..9fb3bb2eb76d --- /dev/null +++ b/tests/untried/neg/t2213.check @@ -0,0 +1,25 @@ +t2213.scala:9: error: class C needs to be abstract, since: +it has 4 unimplemented members. +/** As seen from class C, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def f: Int = ??? + def g: Int = ??? + val x: Int = ??? + val y: Int = ??? + +class C extends A {} + ^ +t2213.scala:11: error: object creation impossible, since: +it has 4 unimplemented members. +/** As seen from object Q, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + def f: Int = ??? + def g: Int = ??? + val x: Int = ??? + val y: Int = ??? + +object Q extends A { } + ^ +two errors found diff --git a/tests/untried/neg/t2213.scala b/tests/untried/neg/t2213.scala new file mode 100644 index 000000000000..61050906f773 --- /dev/null +++ b/tests/untried/neg/t2213.scala @@ -0,0 +1,11 @@ +abstract class A { + def f: Int + def g: Int + + val x: Int + val y: Int +} + +class C extends A {} + +object Q extends A { } diff --git a/tests/untried/neg/t2275a.check b/tests/untried/neg/t2275a.check new file mode 100644 index 000000000000..cd3c868e76c4 --- /dev/null +++ b/tests/untried/neg/t2275a.check @@ -0,0 +1,13 @@ +t2275a.scala:4: error: in XML literal: in XML content, please use '}}' to express '}' + }else{ + ^ +t2275a.scala:3: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed
+
+ ^ +t2275a.scala:4: error: ';' expected but 'else' found. + }else{ + ^ +t2275a.scala:7: error: '}' expected but eof found. +} + ^ +four errors found diff --git a/tests/untried/neg/t2275a.scala b/tests/untried/neg/t2275a.scala new file mode 100644 index 000000000000..7f2b803daa81 --- /dev/null +++ b/tests/untried/neg/t2275a.scala @@ -0,0 +1,7 @@ +object Test { + if(true) { +
+ }else{ + {"louenesee"} + } +} diff --git a/tests/untried/neg/t2275b.check b/tests/untried/neg/t2275b.check new file mode 100644 index 000000000000..43e34cc4d3aa --- /dev/null +++ b/tests/untried/neg/t2275b.check @@ -0,0 +1,10 @@ +t2275b.scala:2: error: in XML literal: in XML content, please use '}}' to express '}' + {
}xx + ^ +t2275b.scala:2: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed
+ {
}xx + ^ +t2275b.scala:3: error: '}' expected but eof found. +} + ^ +three errors found diff --git a/tests/untried/neg/t2275b.scala b/tests/untried/neg/t2275b.scala new file mode 100644 index 000000000000..312cba8d6dcb --- /dev/null +++ b/tests/untried/neg/t2275b.scala @@ -0,0 +1,3 @@ +object Test { + {
}xx +} diff --git a/tests/untried/neg/t2296a.check b/tests/untried/neg/t2296a.check new file mode 100644 index 000000000000..863b8610468e --- /dev/null +++ b/tests/untried/neg/t2296a.check @@ -0,0 +1,5 @@ +S.scala:6: error: Implementation restriction: trait S accesses protected method foo inside a concrete trait method. +Add an accessor in a class extending class J as a workaround. + foo() + ^ +one error found diff --git a/tests/untried/neg/t2296a/J.java b/tests/untried/neg/t2296a/J.java new file mode 100644 index 000000000000..78ff3e980459 --- /dev/null +++ b/tests/untried/neg/t2296a/J.java @@ -0,0 +1,7 @@ +package j; + +public class J { + protected void foo() { + System.out.println("J.foo()"); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t2296a/S.scala b/tests/untried/neg/t2296a/S.scala new file mode 100644 index 000000000000..2b2e6cddaa19 --- /dev/null +++ b/tests/untried/neg/t2296a/S.scala @@ -0,0 +1,18 @@ +package s { + import j.J + + trait S extends J { + def bar(): Unit = { + foo() + } + } + + class SC extends J with S +} + +object Test { + def main(args : Array[String]): Unit = { + (new s.SC).bar() + (new s.S { }).bar() + } +} diff --git a/tests/untried/neg/t2296b.check b/tests/untried/neg/t2296b.check new file mode 100644 index 000000000000..07cc54d5733d --- /dev/null +++ b/tests/untried/neg/t2296b.check @@ -0,0 +1,5 @@ +S_2.scala:6: error: Implementation restriction: trait S accesses protected method foo inside a concrete trait method. +Add an accessor in a class extending class J_1 as a workaround. + foo() + ^ +one error found diff --git a/tests/untried/neg/t2296b/J_1.java b/tests/untried/neg/t2296b/J_1.java new file mode 100644 index 000000000000..4c91d4707376 --- /dev/null +++ b/tests/untried/neg/t2296b/J_1.java @@ -0,0 +1,7 @@ +package j; + +public class J_1 { + protected void foo() { + System.out.println("J.foo()"); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t2296b/S_2.scala b/tests/untried/neg/t2296b/S_2.scala new file mode 100644 index 000000000000..786ba0bfca6e --- /dev/null +++ b/tests/untried/neg/t2296b/S_2.scala @@ -0,0 +1,18 @@ +package s { + import j.J_1 + + trait S extends J_1 { + def bar(): Unit = { + foo() + } + } + + class SC extends J_1 with S +} + +object Test { + def main(args : Array[String]): Unit = { + (new s.SC).bar() + (new s.S { }).bar() + } +} diff --git a/tests/untried/neg/t2316.check b/tests/untried/neg/t2316.check new file mode 100644 index 000000000000..fea174566336 --- /dev/null +++ b/tests/untried/neg/t2316.check @@ -0,0 +1,7 @@ +t2316.scala:28: error: ambiguous implicit values: + both method T1FromT3 in object T1 of type (implicit t3: test.T3)test.T1 + and method T1FromT2 in object T1 of type (implicit t2: test.T2)test.T1 + match expected type test.T1 + val t1 = requireT1 + ^ +one error found diff --git a/tests/untried/neg/t2316.scala b/tests/untried/neg/t2316.scala new file mode 100644 index 000000000000..bf4bb0ec6f46 --- /dev/null +++ b/tests/untried/neg/t2316.scala @@ -0,0 +1,43 @@ +object test { + case class T1(val source: String) + + + object T1 { + implicit def T1FromT2(implicit t2: T2): T1 = T1("implicit def T1FromT2") + implicit def T1FromT3(implicit t3: T3): T1 = T1("implicit def T1FromT3") + } + + trait T2 { + } + + object T2 { + implicit val t2: T2 = new T2 {} + } + + trait T3 + + def requireT1(implicit t1: T1) = t1 + + { + val t1 = requireT1 + assert(t1.source == "implicit def T1FromT2") + } + + { + implicit def t3: T3 = new T3 {} + val t1 = requireT1 + assert(t1.source == "implicit def T1FromT2") + + // Expected a compile error here, but because T1.T1FromT2(T2.t2) was cached as a non-local implicit + // expression for type T1, this is not checked! + // + // (fragment of implicit-cache-error2.scala):26: error: ambiguous implicit values: + // both method T1FromT3 in object T1 of type (implicit t3: this.T3)this.T1 + // and method T1FromT2 in object T1 of type (implicit t2: this.T2)this.T1 + // match expected type this.T1 + // val t1 = requireT1 + // ^ + // one error found + + } +} diff --git a/tests/untried/neg/t2336.check b/tests/untried/neg/t2336.check new file mode 100644 index 000000000000..28acd4d17965 --- /dev/null +++ b/tests/untried/neg/t2336.check @@ -0,0 +1,4 @@ +t2336.scala:6: error: Foo[Int] is not a legal prefix for a constructor + new Foo[Int]#Bar(0) + ^ +one error found diff --git a/tests/untried/neg/t2336.scala b/tests/untried/neg/t2336.scala new file mode 100755 index 000000000000..4cea02b721f0 --- /dev/null +++ b/tests/untried/neg/t2336.scala @@ -0,0 +1,7 @@ +// we get now: t2336.scala:5: error: type Foo[Int] is not a stable prefix +class Foo[A] { + class Bar[B >: A](x: B) extends Foo[B] +} +object bug { + new Foo[Int]#Bar(0) +} diff --git a/tests/untried/neg/t2388.check b/tests/untried/neg/t2388.check new file mode 100644 index 000000000000..3f97608a4db1 --- /dev/null +++ b/tests/untried/neg/t2388.check @@ -0,0 +1,4 @@ +t2388.scala:2: error: recursive method search needs result type + val searchField = new AnyRef { search() } + ^ +one error found diff --git a/tests/untried/neg/t2388.scala b/tests/untried/neg/t2388.scala new file mode 100644 index 000000000000..3634f346f8a7 --- /dev/null +++ b/tests/untried/neg/t2388.scala @@ -0,0 +1,4 @@ +class Foo { + val searchField = new AnyRef { search() } + def search() = searchField +} diff --git a/tests/untried/neg/t2405.check b/tests/untried/neg/t2405.check new file mode 100644 index 000000000000..78360bcc21bd --- /dev/null +++ b/tests/untried/neg/t2405.check @@ -0,0 +1,8 @@ +t2405.scala:6: warning: imported `y' is permanently hidden by definition of method y + import A.{x => y} + ^ +t2405.scala:8: error: could not find implicit value for parameter e: Int + implicitly[Int] + ^ +one warning found +one error found diff --git a/tests/untried/neg/t2405.scala b/tests/untried/neg/t2405.scala new file mode 100644 index 000000000000..6982285b985e --- /dev/null +++ b/tests/untried/neg/t2405.scala @@ -0,0 +1,10 @@ +object A { implicit val x: Int = 1 } + +// Expecting shadowing #1 +object Test2 { + { + import A.{x => y} + def y: Int = 0 + implicitly[Int] + } +} diff --git a/tests/untried/neg/t2416.check b/tests/untried/neg/t2416.check new file mode 100644 index 000000000000..0899ad09d5eb --- /dev/null +++ b/tests/untried/neg/t2416.check @@ -0,0 +1,10 @@ +t2416.scala:3: error: type arguments [Int] do not conform to trait A's type parameter bounds [X <: Double] + def x : A[Int]#B = 10 // no you won't + ^ +t2416.scala:8: error: type arguments [Boolean] do not conform to type B's type parameter bounds [Y <: Double] + def x : A#B[Boolean] = 10 // seriously? + ^ +t2416.scala:13: error: type arguments [String] do not conform to type B's type parameter bounds [Z <: Double] + type C[Z <: A] = Z#B[String] // nuh-uh! + ^ +three errors found diff --git a/tests/untried/neg/t2416.scala b/tests/untried/neg/t2416.scala new file mode 100644 index 000000000000..6fd2ca229492 --- /dev/null +++ b/tests/untried/neg/t2416.scala @@ -0,0 +1,14 @@ +object t2416a { + trait A[X <: Double] { type B = X } + def x : A[Int]#B = 10 // no you won't +} + +object t2416b { + trait A{type B[Y <: Double] = Int} + def x : A#B[Boolean] = 10 // seriously? +} + +object t2416c { + trait A{type B[Z <: Double] = Int} + type C[Z <: A] = Z#B[String] // nuh-uh! +} diff --git a/tests/untried/neg/t2421b.check b/tests/untried/neg/t2421b.check new file mode 100644 index 000000000000..f666a7d9d732 --- /dev/null +++ b/tests/untried/neg/t2421b.check @@ -0,0 +1,4 @@ +t2421b.scala:12: error: could not find implicit value for parameter aa: Test.F[Test.A] + f + ^ +one error found \ No newline at end of file diff --git a/tests/untried/neg/t2421b.scala b/tests/untried/neg/t2421b.scala new file mode 100644 index 000000000000..4e23a74e833d --- /dev/null +++ b/tests/untried/neg/t2421b.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]() + implicit def b[X <: B] = new F[X]() + + f +} + +/* bug: +error: type arguments [Test2.A] do not conform to method b's type parameter bounds [X <: Test2.B] +*/ diff --git a/tests/untried/neg/t2441.check b/tests/untried/neg/t2441.check new file mode 100644 index 000000000000..6eaacd8fd185 --- /dev/null +++ b/tests/untried/neg/t2441.check @@ -0,0 +1,4 @@ +t2441.scala:12: error: private class Y escapes its defining scope as part of type Some[B.Y] + override def f = Some(new B.Y) + ^ +one error found diff --git a/tests/untried/neg/t2441.scala b/tests/untried/neg/t2441.scala new file mode 100644 index 000000000000..6784ebb333c5 --- /dev/null +++ b/tests/untried/neg/t2441.scala @@ -0,0 +1,15 @@ +trait X +trait A { + def f: Option[X] + def g: Option[X] +} +object B { + private class Y extends X { val y = 42 } +} +class B extends A { + private class Bippy + + override def f = Some(new B.Y) + override def g: Option[X] = Some(new B.Y) +} + diff --git a/tests/untried/neg/t2442.check b/tests/untried/neg/t2442.check new file mode 100644 index 000000000000..9ff0b4466149 --- /dev/null +++ b/tests/untried/neg/t2442.check @@ -0,0 +1,11 @@ +t2442.scala:4: warning: match may not be exhaustive. +It would fail on the following input: THREE + def f(e: MyEnum) = e match { + ^ +t2442.scala:11: warning: match may not be exhaustive. +It would fail on the following input: BLUE + def g(e: MySecondEnum) = e match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t2442.flags b/tests/untried/neg/t2442.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t2442.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t2442/MyEnum.java b/tests/untried/neg/t2442/MyEnum.java new file mode 100644 index 000000000000..3ffbbb31b8fb --- /dev/null +++ b/tests/untried/neg/t2442/MyEnum.java @@ -0,0 +1,3 @@ +public enum MyEnum { + ONE, TWO, THREE; +} \ No newline at end of file diff --git a/tests/untried/neg/t2442/MySecondEnum.java b/tests/untried/neg/t2442/MySecondEnum.java new file mode 100644 index 000000000000..0f841286dea1 --- /dev/null +++ b/tests/untried/neg/t2442/MySecondEnum.java @@ -0,0 +1,6 @@ +public enum MySecondEnum { + RED(1), BLUE(2) { public void foo() {} }; + MySecondEnum(int i) {} + + public void foo() {} +} \ No newline at end of file diff --git a/tests/untried/neg/t2442/t2442.scala b/tests/untried/neg/t2442/t2442.scala new file mode 100644 index 000000000000..305c9d624f82 --- /dev/null +++ b/tests/untried/neg/t2442/t2442.scala @@ -0,0 +1,15 @@ +class Test { + import MyEnum._ + + def f(e: MyEnum) = e match { + case ONE => println("one") + case TWO => println("two") + // missing case --> exhaustivity warning! + } + + import MySecondEnum._ + def g(e: MySecondEnum) = e match { + case RED => println("red") + // missing case --> exhaustivity warning! + } +} diff --git a/tests/untried/neg/t2462a.check b/tests/untried/neg/t2462a.check new file mode 100644 index 000000000000..86d74b86d406 --- /dev/null +++ b/tests/untried/neg/t2462a.check @@ -0,0 +1,4 @@ +t2462a.scala:2: error: Cannot construct a collection of type List[String] with elements of type Int based on a collection of type List[Int]. + List(1,2,3).map[Int, List[String]](x => 1) + ^ +one error found diff --git a/tests/untried/neg/t2462a.scala b/tests/untried/neg/t2462a.scala new file mode 100644 index 000000000000..5e49314d53b0 --- /dev/null +++ b/tests/untried/neg/t2462a.scala @@ -0,0 +1,3 @@ +object Test { + List(1,2,3).map[Int, List[String]](x => 1) +} diff --git a/tests/untried/neg/t2462b.check b/tests/untried/neg/t2462b.check new file mode 100644 index 000000000000..b3b8007a93a2 --- /dev/null +++ b/tests/untried/neg/t2462b.check @@ -0,0 +1,11 @@ +t2462b.scala:6: warning: Invalid implicitNotFound message for trait Meh in package test: +The type parameters Too, Elem referenced in the message of the @implicitNotFound annotation are not defined by trait Meh. +trait Meh[-From, +To] + ^ +t2462b.scala:9: warning: Invalid implicitNotFound message for trait Meh2 in package test: +The type parameter Elem referenced in the message of the @implicitNotFound annotation is not defined by trait Meh2. +trait Meh2[-From, +To] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t2462b.flags b/tests/untried/neg/t2462b.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t2462b.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t2462b.scala b/tests/untried/neg/t2462b.scala new file mode 100644 index 000000000000..576db4bd3f33 --- /dev/null +++ b/tests/untried/neg/t2462b.scala @@ -0,0 +1,9 @@ +package test + +import scala.annotation.implicitNotFound + +@implicitNotFound(msg = "Cannot construct a collection of type ${Too} with elements of type ${Elem} based on a collection of type ${From}.") +trait Meh[-From, +To] + +@implicitNotFound(msg = "Cannot construct a collection of type ${To} ${Elem}.") +trait Meh2[-From, +To] diff --git a/tests/untried/neg/t2462c.check b/tests/untried/neg/t2462c.check new file mode 100644 index 000000000000..edeead55d60c --- /dev/null +++ b/tests/untried/neg/t2462c.check @@ -0,0 +1,7 @@ +t2462c.scala:18: error: No C of X$Y + f[X$Y] + ^ +t2462c.scala:24: error: No C of Foo[Int] + f[Foo[Int]] + ^ +two errors found diff --git a/tests/untried/neg/t2462c.flags b/tests/untried/neg/t2462c.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t2462c.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t2462c.scala b/tests/untried/neg/t2462c.scala new file mode 100644 index 000000000000..acf04afba954 --- /dev/null +++ b/tests/untried/neg/t2462c.scala @@ -0,0 +1,25 @@ + +import annotation._ + +@implicitNotFound("No C of ${ A }") +class C[A] + +trait X$Y +/* using the $$ separator for expanded names is unwise +trait X$$Y +trait X$$$Y +trait X$$$$Y + */ + +trait Foo[A] + +class Test { + def f[A: C] = ??? + f[X$Y] +/* using the $$ separator for expanded names is unwise + f[X$$Y] + f[X$$$Y] + f[X$$$$Y] + */ + f[Foo[Int]] +} diff --git a/tests/untried/neg/t2488.check b/tests/untried/neg/t2488.check new file mode 100644 index 000000000000..170dbf88ff19 --- /dev/null +++ b/tests/untried/neg/t2488.check @@ -0,0 +1,31 @@ +t2488.scala:7: error: overloaded method value f with alternatives: + ()Int + (a: Int,b: Int)Int + cannot be applied to (b: Int, Int) + println(c.f(b = 2, 2)) + ^ +t2488.scala:8: error: overloaded method value f with alternatives: + ()Int + (a: Int,b: Int)Int + cannot be applied to (a: Int, c: Int) + println(c.f(a = 2, c = 2)) + ^ +t2488.scala:9: error: overloaded method value f with alternatives: + ()Int + (a: Int,b: Int)Int + cannot be applied to (Int, c: Int) + println(c.f(2, c = 2)) + ^ +t2488.scala:10: error: overloaded method value f with alternatives: + ()Int + (a: Int,b: Int)Int + cannot be applied to (c: Int, Int) + println(c.f(c = 2, 2)) + ^ +t2488.scala:11: error: overloaded method value f with alternatives: + ()Int + (a: Int,b: Int)Int + cannot be applied to (Int) + println(c.f(2)) + ^ +5 errors found diff --git a/tests/untried/neg/t2488.scala b/tests/untried/neg/t2488.scala new file mode 100644 index 000000000000..8db052eec1e4 --- /dev/null +++ b/tests/untried/neg/t2488.scala @@ -0,0 +1,12 @@ +class C { + def f(a:Int, b:Int) = 1 + def f() = 2 +} +object Test extends App { + val c = new C() + println(c.f(b = 2, 2)) + println(c.f(a = 2, c = 2)) + println(c.f(2, c = 2)) + println(c.f(c = 2, 2)) + println(c.f(2)) +} diff --git a/tests/untried/neg/t2494.check b/tests/untried/neg/t2494.check new file mode 100644 index 000000000000..6d43011e248e --- /dev/null +++ b/tests/untried/neg/t2494.check @@ -0,0 +1,4 @@ +t2494.scala:1: error: recursive value a needs type +object A { val a = { println("a = " + a); a = 1} } + ^ +one error found diff --git a/tests/untried/neg/t2494.scala b/tests/untried/neg/t2494.scala new file mode 100755 index 000000000000..71e6bc4bbfce --- /dev/null +++ b/tests/untried/neg/t2494.scala @@ -0,0 +1 @@ +object A { val a = { println("a = " + a); a = 1} } diff --git a/tests/untried/neg/t2641.check b/tests/untried/neg/t2641.check new file mode 100644 index 000000000000..a0a960f0eac6 --- /dev/null +++ b/tests/untried/neg/t2641.check @@ -0,0 +1,7 @@ +t2641.scala:18: error: wrong number of type arguments for ManagedSeq, should be 2 + with TraversableViewLike[A, ManagedSeqStrict[A], ManagedSeq[A]] + ^ +t2641.scala:27: error: value managedIterator is not a member of ManagedSeq[A,Coll] + override def managedIterator = self.managedIterator slice (from, until) + ^ +two errors found diff --git a/tests/untried/neg/t2641.scala b/tests/untried/neg/t2641.scala new file mode 100644 index 000000000000..bc048e039ecf --- /dev/null +++ b/tests/untried/neg/t2641.scala @@ -0,0 +1,30 @@ +import scala.collection._ +import scala.collection.generic._ +import scala.collection.mutable.Builder + + +abstract class ManagedSeqStrict[+A] + extends Traversable[A] + with GenericTraversableTemplate[A, ManagedSeqStrict] +{ + override def companion: GenericCompanion[ManagedSeqStrict] = null + + override def foreach[U](f: A => U): Unit = () +} + +trait ManagedSeq[+A, +Coll] + extends ManagedSeqStrict[A] + with TraversableView[A, ManagedSeqStrict[A]] + with TraversableViewLike[A, ManagedSeqStrict[A], ManagedSeq[A]] +{ self => + + override def underlying = throw new Exception("no underlying") + + //trait Transformed[+B] extends ManagedSeq[B] with super.Transformed[B] + trait Transformed[+B] extends ManagedSeq[B, Coll] with super.Transformed[B] + + trait Sliced extends Transformed[A] with super.Sliced { + override def managedIterator = self.managedIterator slice (from, until) + } + +} diff --git a/tests/untried/neg/t276.check b/tests/untried/neg/t276.check new file mode 100644 index 000000000000..b241953a2256 --- /dev/null +++ b/tests/untried/neg/t276.check @@ -0,0 +1,5 @@ +t276.scala:6: error: overriding type Bar in class Foo, which equals (Int, Int); + class Bar cannot be used here - classes can only override abstract types + class Bar + ^ +one error found diff --git a/tests/untried/neg/t276.scala b/tests/untried/neg/t276.scala new file mode 100644 index 000000000000..dfc8b468df6e --- /dev/null +++ b/tests/untried/neg/t276.scala @@ -0,0 +1,7 @@ +class Foo { + type Bar = (Int, Int) +} + +class FooFoo extends Foo { + class Bar +} diff --git a/tests/untried/neg/t2773.check b/tests/untried/neg/t2773.check new file mode 100644 index 000000000000..a5ffb5fbd572 --- /dev/null +++ b/tests/untried/neg/t2773.check @@ -0,0 +1,7 @@ +t2773.scala:5: error: value x is not a member of C + import c.x + ^ +t2773.scala:6: error: not found: value x + println(x) + ^ +two errors found diff --git a/tests/untried/neg/t2773.scala b/tests/untried/neg/t2773.scala new file mode 100755 index 000000000000..aaa6351c83d4 --- /dev/null +++ b/tests/untried/neg/t2773.scala @@ -0,0 +1,8 @@ +class C(x: Int) { def foo = x } + +object Test { + val c = new C(0) + import c.x + println(x) +} + diff --git a/tests/untried/neg/t2775.check b/tests/untried/neg/t2775.check new file mode 100644 index 000000000000..934a970f2e8d --- /dev/null +++ b/tests/untried/neg/t2775.check @@ -0,0 +1,4 @@ +t2775.scala:1: error: cannot find class tag for element type B.this.T +trait B[S] { type T = S; val c = new Array[T](1) } + ^ +one error found diff --git a/tests/untried/neg/t2775.scala b/tests/untried/neg/t2775.scala new file mode 100644 index 000000000000..9e4f2f606d22 --- /dev/null +++ b/tests/untried/neg/t2775.scala @@ -0,0 +1 @@ +trait B[S] { type T = S; val c = new Array[T](1) } diff --git a/tests/untried/neg/t2779.check b/tests/untried/neg/t2779.check new file mode 100644 index 000000000000..0ab4c50d0f0f --- /dev/null +++ b/tests/untried/neg/t2779.check @@ -0,0 +1,5 @@ +t2779.scala:16: error: method f is defined twice + conflicting symbols both originated in file 't2779.scala' + override def f = List(M1) + ^ +one error found diff --git a/tests/untried/neg/t2779.scala b/tests/untried/neg/t2779.scala new file mode 100755 index 000000000000..d025055aa0f2 --- /dev/null +++ b/tests/untried/neg/t2779.scala @@ -0,0 +1,25 @@ +abstract class M +{ + def f: List[M] = Nil +} + +object M1 extends M + +object M2 extends M +{ + override def f = List(M1) +} + +object M3 extends M +{ + override def f = List(M1) + override def f = List(M1) +} + +object M4 extends M +{ + override def f = List( + M3, + M2 + ) +} diff --git a/tests/untried/neg/t278.check b/tests/untried/neg/t278.check new file mode 100644 index 000000000000..405f7d225c17 --- /dev/null +++ b/tests/untried/neg/t278.check @@ -0,0 +1,11 @@ +t278.scala:5: error: overloaded method value a with alternatives: + => C.this.A => Unit + => () => Unit + does not take type parameters + println(a[A]) + ^ +t278.scala:4: error: method a is defined twice + conflicting symbols both originated in file 't278.scala' + def a = (p:A) => () + ^ +two errors found diff --git a/tests/untried/neg/t278.scala b/tests/untried/neg/t278.scala new file mode 100644 index 000000000000..39a711bb0985 --- /dev/null +++ b/tests/untried/neg/t278.scala @@ -0,0 +1,6 @@ +class C { + class A + def a = () => () + def a = (p:A) => () + println(a[A]) +} diff --git a/tests/untried/neg/t2796.check b/tests/untried/neg/t2796.check new file mode 100644 index 000000000000..22ee35a7e6ba --- /dev/null +++ b/tests/untried/neg/t2796.check @@ -0,0 +1,9 @@ +t2796.scala:11: warning: early type members are deprecated. Move them to the regular body: the semantics are the same. + type X = Int // warn + ^ +t2796.scala:7: warning: Implementation restriction: early definitions in traits are not initialized before the super class is initialized. + val abstractVal = "T1.abstractVal" // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t2796.flags b/tests/untried/neg/t2796.flags new file mode 100644 index 000000000000..d1b831ea87cd --- /dev/null +++ b/tests/untried/neg/t2796.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t2796.scala b/tests/untried/neg/t2796.scala new file mode 100644 index 000000000000..6e1ac852c328 --- /dev/null +++ b/tests/untried/neg/t2796.scala @@ -0,0 +1,27 @@ +trait Base { + val abstractVal: String + final val useAbstractVal = abstractVal +} + +trait T1 extends { + val abstractVal = "T1.abstractVal" // warn +} with Base + +trait T2 extends { + type X = Int // warn +} with Base + +class C1 extends { + val abstractVal = "C1.abstractVal" // okay +} with Base + +object Test { + def main(args: Array[String]): Unit = { + assert(new C1 ().useAbstractVal == "C1.abstractVal") + // This currently fails. a more ambitious approach to this ticket would add $earlyinit$ + // to traits and call it from the right places in the right order. + // + // For now, we'll just issue a warning. + assert(new T1 {}.useAbstractVal == "T1.abstractVal") + } +} diff --git a/tests/untried/neg/t2801.check b/tests/untried/neg/t2801.check new file mode 100644 index 000000000000..25320de5bc4e --- /dev/null +++ b/tests/untried/neg/t2801.check @@ -0,0 +1,6 @@ +t2801.scala:2: error: type mismatch; + found : Null(null) + required: A + def f[A <: AnyRef] = { val a: A = null ; a } + ^ +one error found diff --git a/tests/untried/neg/t2801.scala b/tests/untried/neg/t2801.scala new file mode 100644 index 000000000000..d425f58b56b2 --- /dev/null +++ b/tests/untried/neg/t2801.scala @@ -0,0 +1,3 @@ +object Test { + def f[A <: AnyRef] = { val a: A = null ; a } +} diff --git a/tests/untried/neg/t284.check b/tests/untried/neg/t284.check new file mode 100644 index 000000000000..7c2e9be03ec2 --- /dev/null +++ b/tests/untried/neg/t284.check @@ -0,0 +1,6 @@ +t284.scala:2: warning: Detected apparent refinement of Unit; are you missing an '=' sign? + def f1(a: T): Unit { } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t284.flags b/tests/untried/neg/t284.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t284.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t284.scala b/tests/untried/neg/t284.scala new file mode 100644 index 000000000000..b04fe33c976b --- /dev/null +++ b/tests/untried/neg/t284.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/neg/t2870.check b/tests/untried/neg/t2870.check new file mode 100644 index 000000000000..99522eca651c --- /dev/null +++ b/tests/untried/neg/t2870.check @@ -0,0 +1,9 @@ +t2870.scala:1: error: not found: type Jar +class Jars(jar: Jar) + ^ +t2870.scala:4: error: encountered unrecoverable cycle resolving import. +Note: this is often due in part to a class depending on a definition nested within its companion. +If applicable, you may wish to try moving some members into another object. + import scala.util.Properties.javaClassPath + ^ +two errors found diff --git a/tests/untried/neg/t2870.scala b/tests/untried/neg/t2870.scala new file mode 100755 index 000000000000..4de19242e3d7 --- /dev/null +++ b/tests/untried/neg/t2870.scala @@ -0,0 +1,9 @@ +class Jars(jar: Jar) + +object Jars { + import scala.util.Properties.javaClassPath + + val scala = fromClasspathString(javaClassPath) + + def fromClasspathString(s: String): Jars = null +} diff --git a/tests/untried/neg/t2910.check b/tests/untried/neg/t2910.check new file mode 100644 index 000000000000..44bf1993db70 --- /dev/null +++ b/tests/untried/neg/t2910.check @@ -0,0 +1,16 @@ +t2910.scala:3: error: forward reference extends over definition of value ret + val ret = l.map({ case MyMatch(id) => id }) + ^ +t2910.scala:9: error: forward reference extends over definition of value z + println(s.length) + ^ +t2910.scala:16: error: forward reference extends over definition of value z + x + ^ +t2910.scala:30: error: forward reference extends over definition of value x + lazy val f: Int = x + ^ +t2910.scala:35: error: forward reference extends over definition of variable x + lazy val f: Int = g + ^ +5 errors found diff --git a/tests/untried/neg/t2910.scala b/tests/untried/neg/t2910.scala new file mode 100644 index 000000000000..f2ce3718c99d --- /dev/null +++ b/tests/untried/neg/t2910.scala @@ -0,0 +1,39 @@ +object Junk { + def f(l: List[String]): List[String] = { + val ret = l.map({ case MyMatch(id) => id }) + val MyMatch = "(\\d+)".r + ret + } + + def test2(): Unit = { + println(s.length) + val z = 0 + lazy val s = "abc" + } + + def test4(): Unit = { + lazy val x = { + x + val z = 0 + lazy val x = 12 + z + } + } +} + +// updated forwards.scala for lazy vals +object Test { + lazy val f: Int = x + val x: Int = f + + { + lazy val f: Int = x + val x: Int = f + println(x) + } + { + lazy val f: Int = g + var x: Int = f + lazy val g: Int = x + } +} diff --git a/tests/untried/neg/t2918.check b/tests/untried/neg/t2918.check new file mode 100644 index 000000000000..aae3045e8af7 --- /dev/null +++ b/tests/untried/neg/t2918.check @@ -0,0 +1,10 @@ +t2918.scala:2: error: illegal cyclic reference involving type A + def g[X, A[X] <: A[X]](x: A[X]) = x + ^ +t2918.scala:2: error: cyclic aliasing or subtyping involving type A + def g[X, A[X] <: A[X]](x: A[X]) = x + ^ +t2918.scala:2: error: A does not take type parameters + def g[X, A[X] <: A[X]](x: A[X]) = x + ^ +three errors found diff --git a/tests/untried/neg/t2918.scala b/tests/untried/neg/t2918.scala new file mode 100755 index 000000000000..ff2be39ae0c4 --- /dev/null +++ b/tests/untried/neg/t2918.scala @@ -0,0 +1,3 @@ +object Test { + def g[X, A[X] <: A[X]](x: A[X]) = x +} diff --git a/tests/untried/neg/t2968.check b/tests/untried/neg/t2968.check new file mode 100644 index 000000000000..5d2387f98c21 --- /dev/null +++ b/tests/untried/neg/t2968.check @@ -0,0 +1,10 @@ +t2968.scala:8: error: Missing closing brace `}' assumed here +} // missing brace +^ +t2968.scala:17: error: Missing closing brace `}' assumed here +} // missing brace +^ +t2968.scala:26: error: Missing closing brace `}' assumed here +} // missing brace +^ +three errors found diff --git a/tests/untried/neg/t2968.scala b/tests/untried/neg/t2968.scala new file mode 100644 index 000000000000..41c3a798a5a2 --- /dev/null +++ b/tests/untried/neg/t2968.scala @@ -0,0 +1,26 @@ +object t1 { + case object Const { + } + + class Var + { + +} // missing brace + +object t2 { + case class Const() { + } + + class Var + { + +} // missing brace + +object t3 { + final case class Const() { + } + + class Var + { + +} // missing brace diff --git a/tests/untried/neg/t2968b.check b/tests/untried/neg/t2968b.check new file mode 100644 index 000000000000..36d25a2d1229 --- /dev/null +++ b/tests/untried/neg/t2968b.check @@ -0,0 +1,4 @@ +t2968b.scala:7: error: '}' expected but eof found. +// missing brace + ^ +one error found diff --git a/tests/untried/neg/t2968b.scala b/tests/untried/neg/t2968b.scala new file mode 100644 index 000000000000..422b618aba6a --- /dev/null +++ b/tests/untried/neg/t2968b.scala @@ -0,0 +1,7 @@ +case class Const() +{ +} + +class Var +{ +// missing brace diff --git a/tests/untried/neg/t2973.check b/tests/untried/neg/t2973.check new file mode 100644 index 000000000000..582fe0063dc8 --- /dev/null +++ b/tests/untried/neg/t2973.check @@ -0,0 +1,4 @@ +t2973.scala:1: error: ';' expected but 'package' found. +package foo {} package bar {} + ^ +one error found \ No newline at end of file diff --git a/tests/untried/neg/t2973.scala b/tests/untried/neg/t2973.scala new file mode 100644 index 000000000000..b9d973580a19 --- /dev/null +++ b/tests/untried/neg/t2973.scala @@ -0,0 +1 @@ +package foo {} package bar {} diff --git a/tests/untried/neg/t3006.check b/tests/untried/neg/t3006.check new file mode 100644 index 000000000000..2447eebc9cba --- /dev/null +++ b/tests/untried/neg/t3006.check @@ -0,0 +1,6 @@ +t3006.scala:8: error: type mismatch; + found : String("H") + required: Int + println(A(3) + "H") + ^ +one error found diff --git a/tests/untried/neg/t3006.scala b/tests/untried/neg/t3006.scala new file mode 100755 index 000000000000..a84b69c842f1 --- /dev/null +++ b/tests/untried/neg/t3006.scala @@ -0,0 +1,10 @@ +object Test extends App { + case class A(x: Int); + + class Foo(a: A) { println("Foo created!"); def +(x: Int) = new A(this.a.x + x); } + + implicit def aToFoo(x: A) = new Foo(x); + + println(A(3) + "H") + +} diff --git a/tests/untried/neg/t3015.check b/tests/untried/neg/t3015.check new file mode 100644 index 000000000000..729db844e7f0 --- /dev/null +++ b/tests/untried/neg/t3015.check @@ -0,0 +1,6 @@ +t3015.scala:7: error: scrutinee is incompatible with pattern type; + found : _$1 + required: String + val b(foo) = "foo" + ^ +one error found diff --git a/tests/untried/neg/t3015.scala b/tests/untried/neg/t3015.scala new file mode 100644 index 000000000000..adfa15b388ba --- /dev/null +++ b/tests/untried/neg/t3015.scala @@ -0,0 +1,8 @@ +class UnApp[P] { + def unapply(a: P): Option[P] = Some(a) +} + +object Test extends App { + val b: UnApp[_] = new UnApp[String] + val b(foo) = "foo" +} diff --git a/tests/untried/neg/t3098.check b/tests/untried/neg/t3098.check new file mode 100644 index 000000000000..5343b128f042 --- /dev/null +++ b/tests/untried/neg/t3098.check @@ -0,0 +1,7 @@ +b.scala:3: warning: match may not be exhaustive. +It would fail on the following input: (_ : C) + def f = (null: T) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t3098.flags b/tests/untried/neg/t3098.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t3098.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t3098/a.scala b/tests/untried/neg/t3098/a.scala new file mode 100644 index 000000000000..57a103c7a8c7 --- /dev/null +++ b/tests/untried/neg/t3098/a.scala @@ -0,0 +1,6 @@ +// Traits.scala +sealed trait T + +trait A extends T +trait B extends T +trait C extends T diff --git a/tests/untried/neg/t3098/b.scala b/tests/untried/neg/t3098/b.scala new file mode 100644 index 000000000000..84a1f9f6f471 --- /dev/null +++ b/tests/untried/neg/t3098/b.scala @@ -0,0 +1,8 @@ +// Test.scala +object Test { + def f = (null: T) match { + case _: A => println("A") + case _: B => println("B") + // no C + } +} diff --git a/tests/untried/neg/t3118.check b/tests/untried/neg/t3118.check new file mode 100644 index 000000000000..da00f1c330b2 --- /dev/null +++ b/tests/untried/neg/t3118.check @@ -0,0 +1,7 @@ +t3118.scala:6: error: value C is not a member of O1 + println(x.C()) // should not be accessible + ^ +t3118.scala:7: error: type C is not a member of O1 + println(new x.C) // is correctly not accessible + ^ +two errors found diff --git a/tests/untried/neg/t3118.scala b/tests/untried/neg/t3118.scala new file mode 100644 index 000000000000..9be24c1ed499 --- /dev/null +++ b/tests/untried/neg/t3118.scala @@ -0,0 +1,8 @@ +class O1 { + private[this] case class C() + + val x = new O1 + + println(x.C()) // should not be accessible + println(new x.C) // is correctly not accessible +} diff --git a/tests/untried/neg/t3160ambiguous.check b/tests/untried/neg/t3160ambiguous.check new file mode 100644 index 000000000000..73a0c6d5dbca --- /dev/null +++ b/tests/untried/neg/t3160ambiguous.check @@ -0,0 +1,7 @@ +t3160ambiguous.scala:8: error: reference to List is ambiguous; +it is imported twice in the same scope by +import scala.collection.immutable._ +and import Bippy._ + def f(x: List[Any]): String = ??? // ambiguous, because Bippy.List is accessible + ^ +one error found diff --git a/tests/untried/neg/t3160ambiguous.scala b/tests/untried/neg/t3160ambiguous.scala new file mode 100644 index 000000000000..57745e60d8c6 --- /dev/null +++ b/tests/untried/neg/t3160ambiguous.scala @@ -0,0 +1,15 @@ +object Bippy { + private class List[+T] +} +class Bippy { + import Bippy._ + import scala.collection.immutable._ + + def f(x: List[Any]): String = ??? // ambiguous, because Bippy.List is accessible +} +class Other { + import Bippy._ + import scala.collection.immutable._ + + def f(x: List[Any]): String = ??? // unambiguous, because Bippy.List is inaccessible +} diff --git a/tests/untried/neg/t3189.check b/tests/untried/neg/t3189.check new file mode 100644 index 000000000000..122af564743a --- /dev/null +++ b/tests/untried/neg/t3189.check @@ -0,0 +1,4 @@ +t3189.scala:2: error: bad simple pattern: use _* to match a sequence + val Array(a,b*) = ("": Any) + ^ +one error found diff --git a/tests/untried/neg/t3189.scala b/tests/untried/neg/t3189.scala new file mode 100644 index 000000000000..4ea4bb7581b9 --- /dev/null +++ b/tests/untried/neg/t3189.scala @@ -0,0 +1,3 @@ +object A { + val Array(a,b*) = ("": Any) +} \ No newline at end of file diff --git a/tests/untried/neg/t3209.check b/tests/untried/neg/t3209.check new file mode 100644 index 000000000000..c5a6b1d95dac --- /dev/null +++ b/tests/untried/neg/t3209.check @@ -0,0 +1,4 @@ +t3209.scala:2: error: expected start of definition +package test +^ +one error found diff --git a/tests/untried/neg/t3209.scala b/tests/untried/neg/t3209.scala new file mode 100644 index 000000000000..d893726659ae --- /dev/null +++ b/tests/untried/neg/t3209.scala @@ -0,0 +1,2 @@ +@javax.annotation.Generated(Array("test")) +package test \ No newline at end of file diff --git a/tests/untried/neg/t3222.check b/tests/untried/neg/t3222.check new file mode 100644 index 000000000000..6170827cc96f --- /dev/null +++ b/tests/untried/neg/t3222.check @@ -0,0 +1,13 @@ +t3222.scala:1: error: not found: type B +@throws(classOf[B]) + ^ +t3222.scala:4: error: not found: type D + def foo(@throws(classOf[D]) x: Int) {} + ^ +t3222.scala:3: error: not found: type C + @throws(classOf[C]) + ^ +t3222.scala:6: error: not found: type E + @throws(classOf[E]) + ^ +four errors found diff --git a/tests/untried/neg/t3222.scala b/tests/untried/neg/t3222.scala new file mode 100644 index 000000000000..7918671a93f6 --- /dev/null +++ b/tests/untried/neg/t3222.scala @@ -0,0 +1,9 @@ +@throws(classOf[B]) +class ExceptionTest { + @throws(classOf[C]) + def foo(@throws(classOf[D]) x: Int): Unit = {} + + @throws(classOf[E]) + type t = String +} + diff --git a/tests/untried/neg/t3224.check b/tests/untried/neg/t3224.check new file mode 100644 index 000000000000..69b02c88625a --- /dev/null +++ b/tests/untried/neg/t3224.check @@ -0,0 +1,26 @@ +t3224.scala:30: error: polymorphic expression cannot be instantiated to expected type; + found : [T]Array[T] + required: List[?] + println(Texts textL Array()) + ^ +t3224.scala:34: error: type mismatch; + found : List[Nothing] + required: Array[?] + println(Texts textA List()) + ^ +t3224.scala:35: error: type mismatch; + found : List[Int] + required: Array[?] + println(Texts textA List(1)) + ^ +t3224.scala:36: error: type mismatch; + found : List[Int] + required: Array[?] + println(Texts textA List(1, 1)); + ^ +t3224.scala:48: error: polymorphic expression cannot be instantiated to expected type; + found : [T]Array[T] + required: List[?] + assert(size(Array()) == 0) + ^ +5 errors found diff --git a/tests/untried/neg/t3224.scala b/tests/untried/neg/t3224.scala new file mode 100755 index 000000000000..b7af8a67b525 --- /dev/null +++ b/tests/untried/neg/t3224.scala @@ -0,0 +1,50 @@ +object Texts{ + def textL[T](list: List[T]) = { + list match{ + case List() => "Empty" + case List(_) => "One" + case List(_*) => "Many" + } + } + + def textA[T](array: Array[T]) = { + array match{ + case Array() => "Empty" + case Array(_) => "One" + case Array(_*) => "Many" + } + } +} + +object Test extends App { + { + implicit def array2list[T](array: Array[T]) = { + println(array.toList.size) + array.toList + } + + println(Texts textL List()) + println(Texts textL List(1)) + println(Texts textL List(1, 1)); + + println(Texts textL Array()) + println(Texts textL Array(1)) + println(Texts textL Array(1, 1)) + + println(Texts textA List()) + println(Texts textA List(1)) + println(Texts textA List(1, 1)); + + println(Texts textA Array()) + println(Texts textA Array(1)) + println(Texts textA Array(1, 1)) + } + + { + implicit def array2list[T](array: Array[T]) = array.toList + def size[T](list: List[T]) = list.size + + assert(size(array2list(Array())) == 0) + assert(size(Array()) == 0) + } +} diff --git a/tests/untried/neg/t3234.check b/tests/untried/neg/t3234.check new file mode 100644 index 000000000000..8f0d624ed9f1 --- /dev/null +++ b/tests/untried/neg/t3234.check @@ -0,0 +1,6 @@ +t3234.scala:17: warning: At the end of the day, could not inline @inline-marked method foo3 + println(foo(42) + foo2(11) + foo3(2)) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t3234.flags b/tests/untried/neg/t3234.flags new file mode 100644 index 000000000000..cc3d9fb6f05a --- /dev/null +++ b/tests/untried/neg/t3234.flags @@ -0,0 +1 @@ +-Yinline -Yinline-warnings -Xfatal-warnings diff --git a/tests/untried/neg/t3234.scala b/tests/untried/neg/t3234.scala new file mode 100644 index 000000000000..1f5b18645f95 --- /dev/null +++ b/tests/untried/neg/t3234.scala @@ -0,0 +1,19 @@ +trait Trait1 { + // need more work before this one works + // @inline + def foo2(n: Int) = n*n +} + +trait Trait2 { + @inline def foo3(n: Int) = 1 +} + +class Base extends Trait1 { + @inline def foo(n: Int) = n +} + +object Test extends Base with Trait2 { + def main(args: Array[String]) = { + println(foo(42) + foo2(11) + foo3(2)) + } +} diff --git a/tests/untried/neg/t3240.check b/tests/untried/neg/t3240.check new file mode 100644 index 000000000000..efae682c661b --- /dev/null +++ b/tests/untried/neg/t3240.check @@ -0,0 +1,4 @@ +t3240.scala:3: error: only classes can have declared but undefined members + type t + ^ +one error found diff --git a/tests/untried/neg/t3240.scala b/tests/untried/neg/t3240.scala new file mode 100644 index 000000000000..fdd86d8eae17 --- /dev/null +++ b/tests/untried/neg/t3240.scala @@ -0,0 +1,8 @@ +class A { + val foo = new { + type t + def apply(a: Option[t], defVal: Any) = { + a.getOrElse(defVal).asInstanceOf[t] + } + } +} diff --git a/tests/untried/neg/t3275.check b/tests/untried/neg/t3275.check new file mode 100644 index 000000000000..117c792321e6 --- /dev/null +++ b/tests/untried/neg/t3275.check @@ -0,0 +1,4 @@ +t3275.scala:2: error: @tailrec annotated method contains no recursive calls + @annotation.tailrec def foo() = 5 + ^ +one error found diff --git a/tests/untried/neg/t3275.scala b/tests/untried/neg/t3275.scala new file mode 100644 index 000000000000..18e38a1a97c2 --- /dev/null +++ b/tests/untried/neg/t3275.scala @@ -0,0 +1,3 @@ +object Test { + @annotation.tailrec def foo() = 5 +} diff --git a/tests/untried/neg/t3346b.check b/tests/untried/neg/t3346b.check new file mode 100644 index 000000000000..bcde6d90e46d --- /dev/null +++ b/tests/untried/neg/t3346b.check @@ -0,0 +1,4 @@ +t3346b.scala:14: error: could not find implicit value for evidence parameter of type TC[Any] + val y = foo(1) + ^ +one error found diff --git a/tests/untried/neg/t3346b.scala b/tests/untried/neg/t3346b.scala new file mode 100644 index 000000000000..f28ee8ba340a --- /dev/null +++ b/tests/untried/neg/t3346b.scala @@ -0,0 +1,15 @@ +import scala.language.implicitConversions + +trait T[X] +trait U[X] +trait TC[M[_]] + +object Test extends App { + def foo[M[_]: TC, A](ma: M[A]) = () + implicit val TCofT: TC[T] = new TC[T] {} + implicit def any2T[A](a: A): T[A] = new T[A] {} + implicit def any2U[A](a: A): U[A] = new U[A] {} + + val x = foo[T, Int](1) + val y = foo(1) +} diff --git a/tests/untried/neg/t3346c.check b/tests/untried/neg/t3346c.check new file mode 100644 index 000000000000..575379d009d3 --- /dev/null +++ b/tests/untried/neg/t3346c.check @@ -0,0 +1,4 @@ +t3346c.scala:60: error: value bar is not a member of Either[Int,String] + eii.bar + ^ +one error found diff --git a/tests/untried/neg/t3346c.scala b/tests/untried/neg/t3346c.scala new file mode 100644 index 000000000000..a5ac166b2d4f --- /dev/null +++ b/tests/untried/neg/t3346c.scala @@ -0,0 +1,61 @@ +object Test extends App { + // + // An attempt to workaround SI-2712, foiled by SI-3346 + // + trait TC[M[_]] + + type EitherInt[A] = Either[Int, A] + + implicit object EitherTC extends TC[EitherInt] + + def foo[M[_]: TC, A](ma: M[A]) = () + + val eii: Either[Int, String] = Right("") + + foo[EitherInt, String](eii) + + // This one needs SI-2712 Higher Order Unification + //foo(eii) // not inferred + + // A workaround is to provide a set of implicit conversions that take values + // based on type constructors of various shapes, and search for the + // type class instances. + // + // This is the approach taken by scalaz7. + + trait TCValue[M[_], A] { + implicit def self: M[A] + def M: TC[M] + + // instead of `foo(eii)`, we'll try `eii.foo` + def foo[M[_], A] = () + } + + + implicit def ToTCValue[M[_], A](ma: M[A])(implicit M0: TC[M]) = new TCValue[M, A] { + implicit val M = M0 + val self = ma + } + implicit def ToTCValueBin1[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[A, α]})#λ]): TCValue[({type λ[α] = M[A, α]})#λ, B] = new TCValue[({type λ[α]=M[A, α]})#λ, B] { + implicit val M = M0 + val self = ma + } + implicit def ToTCValueBin2[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[α, B]})#λ]): TCValue[({type λ[α]=M[α, B]})#λ, A] = new TCValue[({type λ[α]=M[α, B]})#λ, A] { + implicit val M = M0 + val self = ma + } + + + ToTCValueBin1(eii).foo + + // as expected, could not find implicit parameter + // ToTCValueBin2(eii).bar + + // error: implicit conversions are not applicable because they are ambiguous, both method ToTCValueBin1 ... and method ToTCValueBin2 + // annoying!! + // https://issues.scala-lang.org/browse/SI-3346 + // + // Works if we remove ToTCValueBin2 + // + eii.bar +} diff --git a/tests/untried/neg/t3346i.check b/tests/untried/neg/t3346i.check new file mode 100644 index 000000000000..cc17ab7ce484 --- /dev/null +++ b/tests/untried/neg/t3346i.check @@ -0,0 +1,7 @@ +t3346i.scala:28: error: value a is not a member of Test.A[T] + (new A).a + ^ +t3346i.scala:29: error: value a is not a member of Test.A[Nothing] + (new A[Nothing]).a + ^ +two errors found diff --git a/tests/untried/neg/t3346i.scala b/tests/untried/neg/t3346i.scala new file mode 100644 index 000000000000..9ad25445379f --- /dev/null +++ b/tests/untried/neg/t3346i.scala @@ -0,0 +1,30 @@ +import scala.language.implicitConversions + +// the classes involved +case class Z[U](a: U) +case class Intermediate[T, U](t: T, u: U) +class Implicit1[T](b: Implicit2[T]) +class Implicit2[T](c: Implicit3[T]) +class Implicit3[T](/* and so on */) + +object Test extends App { + // the base conversion + implicit def convertToZ[T](a: A[T])(implicit b: Implicit1[T]): Z[A[T]] = Z(a) + + // and the implicit chaining, don't you just love it? :D + // implicit1, with one alternative + implicit def implicit1[T <: Intermediate[_, _]](implicit b: Implicit2[T]) = new Implicit1[T](b) + // implicit2, with two alternatives + implicit def implicit2alt1[T <: Intermediate[_ <: String, _]](implicit c: Implicit3[T]) = new Implicit2[T](c) + implicit def implicit2alt2[T <: Intermediate[_ <: Double, _]](implicit c: Implicit3[T]) = new Implicit2[T](c) + // implicit3, with two alternatives + implicit def implicit3alt1[T <: Intermediate[_, _ <: Int]] = new Implicit3[T]() + implicit def implicit3alt2[T <: Intermediate[_ <: Double, _ <: AnyRef],X] = new Implicit3[T]() + + // and our targets + /** conversion here, with constraints */ + class A[T]() + + (new A).a + (new A[Nothing]).a +} diff --git a/tests/untried/neg/t3392.check b/tests/untried/neg/t3392.check new file mode 100644 index 000000000000..842d63eec98e --- /dev/null +++ b/tests/untried/neg/t3392.check @@ -0,0 +1,4 @@ +t3392.scala:9: error: not found: value x + case x@A(x/*<-- refers to the pattern that includes this comment*/.Ex(42)) => + ^ +one error found diff --git a/tests/untried/neg/t3392.scala b/tests/untried/neg/t3392.scala new file mode 100644 index 000000000000..655c2e84a32e --- /dev/null +++ b/tests/untried/neg/t3392.scala @@ -0,0 +1,11 @@ +object Test { + case class A(a: Int) { + object Ex { + def unapply(i: Int): Option[Int] = Some(i) + } + } + + A(42) match { + case x@A(x/*<-- refers to the pattern that includes this comment*/.Ex(42)) => + } +} diff --git a/tests/untried/neg/t3399.check b/tests/untried/neg/t3399.check new file mode 100644 index 000000000000..987da944c6ee --- /dev/null +++ b/tests/untried/neg/t3399.check @@ -0,0 +1,4 @@ +t3399.scala:23: error: Cannot prove that Nats.Add[Nats._1,Nats._1] =:= Nats._1. + implicitly[ Add[_1, _1] =:= _1] + ^ +one error found diff --git a/tests/untried/neg/t3399.scala b/tests/untried/neg/t3399.scala new file mode 100644 index 000000000000..e39e54ac677e --- /dev/null +++ b/tests/untried/neg/t3399.scala @@ -0,0 +1,24 @@ +object Nats { + sealed trait Nat { + // fold right on N, N-1, ..., 1 + type FoldR[Init <: Type, Type, F <: Fold[Nat, Type]] <: Type + } + sealed trait _0 extends Nat { + type FoldR[Init <: Type, Type, F <: Fold[Nat, Type]] = Init + } + sealed trait Succ[N <: Nat] extends Nat { + type FoldR[Init <: Type, Type, F <: Fold[Nat, Type]] = + F#Apply[Succ[N], N#FoldR[Init, Type, F]] + } + + type Add[A <: Nat, B <: Nat] = A#FoldR[B, Nat, Inc] + trait Fold[-Elem, Value] { + type Apply[N <: Elem, Acc <: Value] <: Value + } + type Inc = Fold[Any, Nat] { + type Apply[N <: Any, Acc <: Nat] = Succ[Acc] + } + + type _1 = Succ[_0] + implicitly[ Add[_1, _1] =:= _1] +} diff --git a/tests/untried/neg/t3403.check b/tests/untried/neg/t3403.check new file mode 100644 index 000000000000..e52d140e6a42 --- /dev/null +++ b/tests/untried/neg/t3403.check @@ -0,0 +1,4 @@ +t3403.scala:2: error: implementation limitation: the BeanProperty annotation cannot be used in a type alias or renamed import +class Foo { @bp var bar: Int = 1 } + ^ +one error found diff --git a/tests/untried/neg/t3403.scala b/tests/untried/neg/t3403.scala new file mode 100644 index 000000000000..7cf0c3e0f7fc --- /dev/null +++ b/tests/untried/neg/t3403.scala @@ -0,0 +1,2 @@ +import scala.beans.{BeanProperty => bp} +class Foo { @bp var bar: Int = 1 } diff --git a/tests/untried/neg/t343.check b/tests/untried/neg/t343.check new file mode 100644 index 000000000000..d310b7915fa2 --- /dev/null +++ b/tests/untried/neg/t343.check @@ -0,0 +1,4 @@ +t343.scala:5: error: private class Foo escapes its defining scope as part of type C.this.Foo + def get:Foo = new Foo(); + ^ +one error found diff --git a/tests/untried/neg/t343.scala b/tests/untried/neg/t343.scala new file mode 100644 index 000000000000..ed57d2eef776 --- /dev/null +++ b/tests/untried/neg/t343.scala @@ -0,0 +1,14 @@ +package scalaInner1; + +class C { + private class Foo {} + def get:Foo = new Foo(); +} + + + +object Test { + def main(args:Array[String]) = { + val c = new C().get; + } +} diff --git a/tests/untried/neg/t3453.check b/tests/untried/neg/t3453.check new file mode 100644 index 000000000000..52c948128c72 --- /dev/null +++ b/tests/untried/neg/t3453.check @@ -0,0 +1,21 @@ +t3453.scala:18: error: type mismatch; + found : A + required: B + new A + ^ +t3453.scala:36: error: type mismatch; + found : A + required: B + new A + ^ +t3453.scala:50: error: type mismatch; + found : A + required: B + new A + ^ +t3453.scala:64: error: type mismatch; + found : A + required: B + new A + ^ +four errors found diff --git a/tests/untried/neg/t3453.scala b/tests/untried/neg/t3453.scala new file mode 100644 index 000000000000..af778189408f --- /dev/null +++ b/tests/untried/neg/t3453.scala @@ -0,0 +1,66 @@ +// test shadowing of implicits by synonymous non-implicit symbols +// whether they be inherited, imported (explicitly or using a wildcard) or defined directly +class A +class B + +trait S { + implicit def aToB(a: A): B = new B +} + +class T1 extends S { + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +object O { + implicit def aToB(a: A): B = new B +} + +class T2a { + import O._ + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +class T2b { + import O.aToB + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +class T3 { + implicit def aToB(a: A): B = new B + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} diff --git a/tests/untried/neg/t3481.check b/tests/untried/neg/t3481.check new file mode 100644 index 000000000000..debe07275be6 --- /dev/null +++ b/tests/untried/neg/t3481.check @@ -0,0 +1,29 @@ +t3481.scala:5: error: type mismatch; + found : String("hello") + required: _$1 + f[A[Int]]("hello") + ^ +t3481.scala:11: error: type mismatch; + found : _$2 + required: b.T + (which expands to) _$2 + def f[T <: B[_]](a: T#T, b: T) = b.m(a) + ^ +t3481.scala:12: error: type mismatch; + found : String("Hello") + required: _$2 + f("Hello", new B[Int]) + ^ +t3481.scala:18: error: type mismatch; + found : String("Hello") + required: t3481.ex3.b.T2 + (which expands to) _$3 + b.m("Hello") + ^ +t3481.scala:25: error: type mismatch; + found : String("Hello") + required: t3481.ex4.Test.b.T2 + (which expands to) _$4 + b.m("Hello") + ^ +5 errors found diff --git a/tests/untried/neg/t3481.scala b/tests/untried/neg/t3481.scala new file mode 100644 index 000000000000..6924fdf566f5 --- /dev/null +++ b/tests/untried/neg/t3481.scala @@ -0,0 +1,28 @@ +object t3481 { + object ex1 { + trait A[T] { type B = T } + def f[T <: A[_]](a: T#B) = 1 + f[A[Int]]("hello") + } + + object ex2 { + trait A { type T; def m(t: T) = t.toString } + class B[T2] extends A { type T = T2 } + def f[T <: B[_]](a: T#T, b: T) = b.m(a) + f("Hello", new B[Int]) + } + + object ex3 { + class B[T] { type T2 = T; def m(t: T2) = t.toString } + val b: B[_] = new B[Int] + b.m("Hello") + } + + object ex4 { + abstract class B[T] { type T2 = T; def m(t: T2): Any } + object Test { + val b: B[_] = sys.error("") + b.m("Hello") + } + } +} diff --git a/tests/untried/neg/t3507-old.check b/tests/untried/neg/t3507-old.check new file mode 100644 index 000000000000..b3ac40473e33 --- /dev/null +++ b/tests/untried/neg/t3507-old.check @@ -0,0 +1,4 @@ +t3507-old.scala:13: error: No Manifest available for _1.b.c.type. + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + ^ +one error found diff --git a/tests/untried/neg/t3507-old.scala b/tests/untried/neg/t3507-old.scala new file mode 100644 index 000000000000..5f8f3644b765 --- /dev/null +++ b/tests/untried/neg/t3507-old.scala @@ -0,0 +1,15 @@ +class A { + object b { + object c + } + def m = b.c +} + +object Test { + var a: A = new A // mutable + val c /*: object _1.b.c forSome { val _1: A } */ = a.m // widening using existential + + def mani[T: Manifest](x: T) = () + mani/*[object _1.b.c]*/(c) // kaboom in manifestOfType / TreeGen.mkAttributedQualifier + // --> _1 is not in scope here +} diff --git a/tests/untried/neg/t3604.check b/tests/untried/neg/t3604.check new file mode 100644 index 000000000000..b07c5c9c711e --- /dev/null +++ b/tests/untried/neg/t3604.check @@ -0,0 +1,7 @@ +t3604.scala:3: error: in XML literal: expected closing tag of abbr + + ^ +t3604.scala:3: error: start tag was here: abbr> + + ^ +two errors found diff --git a/tests/untried/neg/t3604.scala b/tests/untried/neg/t3604.scala new file mode 100644 index 000000000000..f890a58e58d0 --- /dev/null +++ b/tests/untried/neg/t3604.scala @@ -0,0 +1,6 @@ +object Main { +
+
+ { "..." } + +} diff --git a/tests/untried/neg/t3614.check b/tests/untried/neg/t3614.check new file mode 100644 index 000000000000..81628ef37f2b --- /dev/null +++ b/tests/untried/neg/t3614.check @@ -0,0 +1,4 @@ +t3614.scala:2: error: only declarations allowed here + def v = new ({ def a=0 }) + ^ +one error found diff --git a/tests/untried/neg/t3614.scala b/tests/untried/neg/t3614.scala new file mode 100644 index 000000000000..70e429440332 --- /dev/null +++ b/tests/untried/neg/t3614.scala @@ -0,0 +1,3 @@ +object t3614 { + def v = new ({ def a=0 }) +} diff --git a/tests/untried/neg/t3649.check b/tests/untried/neg/t3649.check new file mode 100644 index 000000000000..76d68fa3b7a2 --- /dev/null +++ b/tests/untried/neg/t3649.check @@ -0,0 +1,10 @@ +t3649.scala:1: error: C is already defined as (compiler-generated) case class companion object C +object T { class C(s: String = ""); val C = 0 } + ^ +t3649.scala:2: error: C is already defined as (compiler-generated) case class companion object C +object U { class C(val s: String = ""); val C = new C() {} } + ^ +t3649.scala:2: error: not enough arguments for constructor C: (s: String)U.C +object U { class C(val s: String = ""); val C = new C() {} } + ^ +three errors found diff --git a/tests/untried/neg/t3649.scala b/tests/untried/neg/t3649.scala new file mode 100644 index 000000000000..2aaff9610086 --- /dev/null +++ b/tests/untried/neg/t3649.scala @@ -0,0 +1,2 @@ +object T { class C(s: String = ""); val C = 0 } +object U { class C(val s: String = ""); val C = new C() {} } diff --git a/tests/untried/neg/t3653.check b/tests/untried/neg/t3653.check new file mode 100644 index 000000000000..ad68e29fb49b --- /dev/null +++ b/tests/untried/neg/t3653.check @@ -0,0 +1,7 @@ +t3653.scala:3: error: double definition: +def x(i: Int): Int at line 2 and +def x(implicit x: Int): Int at line 3 +have same type after erasure: (i: Int)Int + def x(implicit x: Int) = 5 + ^ +one error found diff --git a/tests/untried/neg/t3653.scala b/tests/untried/neg/t3653.scala new file mode 100644 index 000000000000..0bedc4fdc3ff --- /dev/null +++ b/tests/untried/neg/t3653.scala @@ -0,0 +1,4 @@ +class B { + def x(i: Int) = 3 + def x(implicit x: Int) = 5 +} diff --git a/tests/untried/neg/t3663.check b/tests/untried/neg/t3663.check new file mode 100644 index 000000000000..c4b27ef21110 --- /dev/null +++ b/tests/untried/neg/t3663.check @@ -0,0 +1,4 @@ +main.scala:11: error: variable foo in class PackageProtected cannot be accessed in test.Test + println(t.foo) + ^ +one error found diff --git a/tests/untried/neg/t3663/PackageProtected.java b/tests/untried/neg/t3663/PackageProtected.java new file mode 100644 index 000000000000..f4535a55b469 --- /dev/null +++ b/tests/untried/neg/t3663/PackageProtected.java @@ -0,0 +1,5 @@ +package test; + +class PackageProtected { + int foo; +} diff --git a/tests/untried/neg/t3663/main.scala b/tests/untried/neg/t3663/main.scala new file mode 100644 index 000000000000..a70ee52cf8bd --- /dev/null +++ b/tests/untried/neg/t3663/main.scala @@ -0,0 +1,14 @@ +package test + +final class Test extends PackageProtected { + def bar = foo +} + +package another { + object Main { + def bug(t: Test): Unit = { + // Can always be replicated. + println(t.foo) + } + } +} diff --git a/tests/untried/neg/t3683a.check b/tests/untried/neg/t3683a.check new file mode 100644 index 000000000000..6386265ebc55 --- /dev/null +++ b/tests/untried/neg/t3683a.check @@ -0,0 +1,7 @@ +t3683a.scala:14: warning: match may not be exhaustive. +It would fail on the following input: XX() + w match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t3683a.flags b/tests/untried/neg/t3683a.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t3683a.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t3683a.scala b/tests/untried/neg/t3683a.scala new file mode 100644 index 000000000000..ac1b6265cf3a --- /dev/null +++ b/tests/untried/neg/t3683a.scala @@ -0,0 +1,20 @@ +sealed trait Foo +sealed trait Bar extends Foo +sealed trait W[T >: Bar <: Foo] +case class X() extends W[Foo] +case class XX() extends W[Bar] +case class Y() extends W[Bar] +case class Z[T >: Bar <: Foo]( + z1: W[T] +) extends W[T] + +object Main { + // should warn for not including XX() + def f1(w: W[Bar]): Int = { + w match { + // case XX() => 2 + case Y() => 1 + case Z(z) => f1(z) + } + } +} diff --git a/tests/untried/neg/t3683b.check b/tests/untried/neg/t3683b.check new file mode 100644 index 000000000000..6e3369241bba --- /dev/null +++ b/tests/untried/neg/t3683b.check @@ -0,0 +1,8 @@ +t3683b.scala:15: error: constructor cannot be instantiated to expected type; + found : X + required: W[Bar] +Note: Foo >: Bar (and X <: W[Foo]), but trait W is invariant in type T. +You may wish to define T as -T instead. (SLS 4.5) + case X() => 1 + ^ +one error found diff --git a/tests/untried/neg/t3683b.scala b/tests/untried/neg/t3683b.scala new file mode 100644 index 000000000000..1c361ed2d3b0 --- /dev/null +++ b/tests/untried/neg/t3683b.scala @@ -0,0 +1,21 @@ +sealed trait Foo +sealed trait Bar extends Foo +sealed trait W[T >: Bar <: Foo] +case class X() extends W[Foo] +case class XX() extends W[Bar] +case class Y() extends W[Bar] +case class Z[T >: Bar <: Foo]( + z1: W[T] +) extends W[T] + +object Main { + // should fail for including X() + def f1(w: W[Bar]): Int = { + w match { + case X() => 1 + case XX() => 2 + case Y() => 1 + case Z(z) => f1(z) + } + } +} diff --git a/tests/untried/neg/t3691.check b/tests/untried/neg/t3691.check new file mode 100644 index 000000000000..6a7e13049a03 --- /dev/null +++ b/tests/untried/neg/t3691.check @@ -0,0 +1,16 @@ +t3691.scala:4: error: type mismatch; + found : Test.A[String] + required: AnyRef{type A[x]} + val b = (new A[String]{}): { type A[x] } // not ok + ^ +t3691.scala:5: error: type mismatch; + found : Test.A[String] + required: AnyRef{type A} + val c = (new A[String]{}): { type A } // not ok + ^ +t3691.scala:7: error: type mismatch; + found : AnyRef{type A = String} + required: AnyRef{type A[X]} + val x = (new { type A = String }): { type A[X] } // not ok + ^ +three errors found diff --git a/tests/untried/neg/t3691.scala b/tests/untried/neg/t3691.scala new file mode 100644 index 000000000000..c1daa4918970 --- /dev/null +++ b/tests/untried/neg/t3691.scala @@ -0,0 +1,11 @@ +object Test { + trait A[X] { type A[x <: X] = x } + val a = (new A[String]{}): { type A[x <: String] } // ok + val b = (new A[String]{}): { type A[x] } // not ok + val c = (new A[String]{}): { type A } // not ok + + val x = (new { type A = String }): { type A[X] } // not ok +//a: AnyRef{type A[X]} + + identity[x.A[Any]] _ +} diff --git a/tests/untried/neg/t3692-new.check b/tests/untried/neg/t3692-new.check new file mode 100644 index 000000000000..bb8692f3ca9d --- /dev/null +++ b/tests/untried/neg/t3692-new.check @@ -0,0 +1,19 @@ +t3692-new.scala:14: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[Int,Int] (the underlying of Map[Int,Int]) is unchecked since it is eliminated by erasure + case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] + ^ +t3692-new.scala:15: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[Int,V] (the underlying of Map[Int,V]) is unchecked since it is eliminated by erasure + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + ^ +t3692-new.scala:16: warning: non-variable type argument Int in type pattern scala.collection.immutable.Map[T,Int] (the underlying of Map[T,Int]) is unchecked since it is eliminated by erasure + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + ^ +t3692-new.scala:15: warning: unreachable code + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + ^ +t3692-new.scala:4: warning: Tester has a main method with parameter type Array[String], but Tester will not be a runnable program. + Reason: main method must have exact signature (Array[String])Unit +object Tester { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +5 warnings found +one error found diff --git a/tests/untried/neg/t3692-new.flags b/tests/untried/neg/t3692-new.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t3692-new.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t3692-new.scala b/tests/untried/neg/t3692-new.scala new file mode 100644 index 000000000000..6ecf4acb8512 --- /dev/null +++ b/tests/untried/neg/t3692-new.scala @@ -0,0 +1,20 @@ +import scala.reflect.{ClassTag, classTag} +import java.lang.Integer + +object Tester { + def main(args: Array[String]) = { + val map = Map("John" -> 1, "Josh" -> 2) + new Tester().toJavaMap(map) + } +} + +class Tester { + private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: ClassTag[T], m2: ClassTag[V]): java.util.Map[_, _] = { + map match { + case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + case _ => new java.util.HashMap[T, V] + } + } +} diff --git a/tests/untried/neg/t3714-neg.check b/tests/untried/neg/t3714-neg.check new file mode 100644 index 000000000000..4f297169686f --- /dev/null +++ b/tests/untried/neg/t3714-neg.check @@ -0,0 +1,13 @@ +t3714-neg.scala:17: error: value break in class BreakImpl cannot be accessed in BreakImpl + Access to protected value break not permitted because + enclosing object Test is not a subclass of + class BreakImpl where target is defined + case b: BreakImpl => b.break + ^ +t3714-neg.scala:25: error: value break in class BreakImpl cannot be accessed in BreakImpl + Access to protected value break not permitted because + enclosing object Test is not a subclass of + class BreakImpl where target is defined + case b: BreakImpl => b.break + ^ +two errors found diff --git a/tests/untried/neg/t3714-neg.scala b/tests/untried/neg/t3714-neg.scala new file mode 100644 index 000000000000..72518de148fd --- /dev/null +++ b/tests/untried/neg/t3714-neg.scala @@ -0,0 +1,41 @@ +// this is a slight negative twist on run/t3714.scala. +trait Break { + protected val break: Int; +} + +class BreakImpl(protected val break: Int) extends Break { } +object BreakImpl { + def apply(x: Int): Break = new BreakImpl(x) + def unapply(x: Any) = x match { + case x: BreakImpl => Some(x.break) + case _ => None + } +} + +object Test { + def f1(x: Break) = x match { + case b: BreakImpl => b.break + case b => -1 + } + def f2(x: Break) = x match { + case BreakImpl(x) => x + case _ => -1 + } + def f3(x: Any) = x match { + case b: BreakImpl => b.break + case b => -1 + } + def f4(x: Any) = x match { + case BreakImpl(x) => x + case _ => -1 + } + + def main(args: Array[String]): Unit = { + val break = BreakImpl(22) + assert(f1(break) == 22) + assert(f2(break) == 22) + assert(f3(break) == 22) + assert(f4(break) == 22) + } +} + diff --git a/tests/untried/neg/t3736.check b/tests/untried/neg/t3736.check new file mode 100644 index 000000000000..7a20f6c08b7c --- /dev/null +++ b/tests/untried/neg/t3736.check @@ -0,0 +1,16 @@ +t3736.scala:4: error: super not allowed here: use this.isInstanceOf instead + def f2 = super.isInstanceOf[String] + ^ +t3736.scala:5: error: super not allowed here: use this.asInstanceOf instead + def f3 = super.asInstanceOf[AnyRef] + ^ +t3736.scala:6: error: super not allowed here: use this.== instead + def f4 = super.==(new AnyRef) + ^ +t3736.scala:7: error: super not allowed here: use this.!= instead + def f5 = super.!=(new AnyRef) + ^ +t3736.scala:8: error: super not allowed here: use this.## instead + def f6 = super.## + ^ +5 errors found diff --git a/tests/untried/neg/t3736.scala b/tests/untried/neg/t3736.scala new file mode 100644 index 000000000000..cf0920912a47 --- /dev/null +++ b/tests/untried/neg/t3736.scala @@ -0,0 +1,34 @@ +object Test { + class A { + def f1 = super.toString + def f2 = super.isInstanceOf[String] + def f3 = super.asInstanceOf[AnyRef] + def f4 = super.==(new AnyRef) + def f5 = super.!=(new AnyRef) + def f6 = super.## + } + + // Ill-advised overloads to be sure... + class B { + def ##(x: String) = true + def ==(x1: String, xs: List[_]) = true + def !=(x1: String, xs: List[_]) = true + } + + class C extends B { + override def ##(x: String) = super.##(x) + override def ==(x1: String, xs: List[_]) = super.==(x1, xs) + override def !=(x1: String, xs: List[_]) = super.!=(x1, xs) + } + + def main(args: Array[String]): Unit = { + val x = new A + x.f1 + x.f2 + x.f3 + x.f4 + x.f5 + x.f6 + } +} + diff --git a/tests/untried/neg/t3757.check b/tests/untried/neg/t3757.check new file mode 100644 index 000000000000..1507df8c4f40 --- /dev/null +++ b/tests/untried/neg/t3757.check @@ -0,0 +1,4 @@ +B.scala:4: error: method foo overrides nothing + override def foo = "B" + ^ +one error found diff --git a/tests/untried/neg/t3757/A.java b/tests/untried/neg/t3757/A.java new file mode 100644 index 000000000000..37da86fe1588 --- /dev/null +++ b/tests/untried/neg/t3757/A.java @@ -0,0 +1,5 @@ +package a; + +public abstract class A { + abstract String foo(); // package protected! +} \ No newline at end of file diff --git a/tests/untried/neg/t3757/B.scala b/tests/untried/neg/t3757/B.scala new file mode 100644 index 000000000000..e899f51e768b --- /dev/null +++ b/tests/untried/neg/t3757/B.scala @@ -0,0 +1,5 @@ +package b + +class B extends a.A { + override def foo = "B" +} diff --git a/tests/untried/neg/t3761-overload-byname.check b/tests/untried/neg/t3761-overload-byname.check new file mode 100644 index 000000000000..ae7d21dfa6b3 --- /dev/null +++ b/tests/untried/neg/t3761-overload-byname.check @@ -0,0 +1,13 @@ +t3761-overload-byname.scala:9: error: ambiguous reference to overloaded definition, +both method m1 in object t of type (x: => Int, s: Object)Int +and method m1 in object t of type (x: => AnyVal, s: String)Int +match argument types (Int,String) + m1(1, "") + ^ +t3761-overload-byname.scala:11: error: ambiguous reference to overloaded definition, +both method m2 in object t of type (x: => Int, s: Object)Int +and method m2 in object t of type (x: => Any, s: String)Int +match argument types (Int,String) + m2(1, "") + ^ +two errors found diff --git a/tests/untried/neg/t3761-overload-byname.scala b/tests/untried/neg/t3761-overload-byname.scala new file mode 100644 index 000000000000..5b9a381b9392 --- /dev/null +++ b/tests/untried/neg/t3761-overload-byname.scala @@ -0,0 +1,13 @@ +object t { + def m1(x: => AnyVal, s: String) = 0 + def m1(x: => Int, s: Object) = 1 + + def m2(x: => Any, s: String) = 0 + def m2(x: => Int, s: Object) = 1 + + + m1(1, "") + m1(1d, "") + m2(1, "") + m2("", "") +} diff --git a/tests/untried/neg/t3769.check b/tests/untried/neg/t3769.check new file mode 100644 index 000000000000..40ccf05ff3f0 --- /dev/null +++ b/tests/untried/neg/t3769.check @@ -0,0 +1,7 @@ +t3769.scala:2: error: in XML literal: expected closing tag of a + val x = {"text"} + ^ +t3769.scala:2: error: start tag was here: a> + val x = {"text"} + ^ +two errors found diff --git a/tests/untried/neg/t3769.scala b/tests/untried/neg/t3769.scala new file mode 100644 index 000000000000..0132b59edfa0 --- /dev/null +++ b/tests/untried/neg/t3769.scala @@ -0,0 +1,3 @@ +object Test { + val x = {"text"} +} diff --git a/tests/untried/neg/t3776.check b/tests/untried/neg/t3776.check new file mode 100644 index 000000000000..0dfe129596d4 --- /dev/null +++ b/tests/untried/neg/t3776.check @@ -0,0 +1,4 @@ +t3776.scala:8: error: value someOperation is not a member of _$1 + def parsedAs[T](v: T) = MyParser.parse(pattern, a).get someOperation v + ^ +one error found diff --git a/tests/untried/neg/t3776.scala b/tests/untried/neg/t3776.scala new file mode 100644 index 000000000000..e24b2fea6382 --- /dev/null +++ b/tests/untried/neg/t3776.scala @@ -0,0 +1,10 @@ +object MyParser { + implicit def literal(s: String): Parser[String] = ??? + trait Parser[+T] + def parse[T](p: Parser[T], in: java.lang.CharSequence): Option[T] = ??? +} +object Test { + class ParsedAs(a: String) (implicit pattern: MyParser.Parser[_]) { + def parsedAs[T](v: T) = MyParser.parse(pattern, a).get someOperation v + } +} diff --git a/tests/untried/neg/t3816.check b/tests/untried/neg/t3816.check new file mode 100644 index 000000000000..40621f89622b --- /dev/null +++ b/tests/untried/neg/t3816.check @@ -0,0 +1,7 @@ +t3816.scala:30: error: stable identifier required, but `syncID` found. + case Some( `syncID` ) => + ^ +t3816.scala:38: error: stable identifier required, but Test.this.foo found. + case Some( `foo` ) => + ^ +two errors found diff --git a/tests/untried/neg/t3816.scala b/tests/untried/neg/t3816.scala new file mode 100644 index 000000000000..0eadbcf8f10f --- /dev/null +++ b/tests/untried/neg/t3816.scala @@ -0,0 +1,42 @@ +class B { + def ::(a: List[Int]): Unit = { + a match { + case x::xs => + case _ => + } + } +} + +object Test { + def testSuccess1( x: Any ) = { + val stable = 2 + x match { + case Some( `stable` ) => + case _ => + } + } + + val bar = 3 + def testSuccess2( x: Any ) = { + x match { + case Some( `bar` ) => + case _ => + } + } + + def testFail1( x: Any ) = { + var syncID = 0 + x match { + case Some( `syncID` ) => + case _ => + } + } + + var foo = 0 + def testFail2( x: Any ) = { + x match { + case Some( `foo` ) => + case _ => + } + } +} diff --git a/tests/untried/neg/t3836.check b/tests/untried/neg/t3836.check new file mode 100644 index 000000000000..ff2fc36ae9a4 --- /dev/null +++ b/tests/untried/neg/t3836.check @@ -0,0 +1,13 @@ +t3836.scala:17: error: reference to IOException is ambiguous; +it is imported twice in the same scope by +import foo.bar._ +and import java.io._ + def f = new IOException // genuinely different + ^ +t3836.scala:26: error: reference to Bippy is ambiguous; +it is imported twice in the same scope by +import baz._ +and import bar._ + def f: Bippy[Int] = ??? + ^ +two errors found diff --git a/tests/untried/neg/t3836.scala b/tests/untried/neg/t3836.scala new file mode 100644 index 000000000000..a68f6e172f94 --- /dev/null +++ b/tests/untried/neg/t3836.scala @@ -0,0 +1,28 @@ +package foo + +package object bar { + type IOException = Object + type Bippy[T] = List[T] +} + +package object baz { + type Bippy[+T] = List[T] +} + +package baz { + import java.io._ + import foo.bar._ + + object Test { + def f = new IOException // genuinely different + } +} + +package baz2 { + import bar._ + import baz._ + + object Test2 { + def f: Bippy[Int] = ??? + } +} diff --git a/tests/untried/neg/t3854.check b/tests/untried/neg/t3854.check new file mode 100644 index 000000000000..c478481a6fba --- /dev/null +++ b/tests/untried/neg/t3854.check @@ -0,0 +1,5 @@ +t3854.scala:1: error: class Bar needs to be abstract, since method foo in trait Foo of type [G[_]](implicit n: N[G,F])X[F] is not defined +(Note that N[G,F] does not match M[G]) +class Bar[F[_]] extends Foo[F] { + ^ +one error found diff --git a/tests/untried/neg/t3854.scala b/tests/untried/neg/t3854.scala new file mode 100644 index 000000000000..e8db76c0a51f --- /dev/null +++ b/tests/untried/neg/t3854.scala @@ -0,0 +1,15 @@ +class Bar[F[_]] extends Foo[F] { + def foo[G[_[_], _]](implicit M: M[G]): X[({type λ[α] = G[F, α] })#λ] = null +} +// vim: set ts=4 sw=4 et: + +trait M[F[_[_], _]] +trait N[F[_], G[_]] + +trait X[F[_]] { + def apply[A]: F[A] +} + +trait Foo[F[_]] { + def foo[G[_]](implicit n: N[G, F]): X[F] +} diff --git a/tests/untried/neg/t3871.check b/tests/untried/neg/t3871.check new file mode 100644 index 000000000000..b920357ee694 --- /dev/null +++ b/tests/untried/neg/t3871.check @@ -0,0 +1,7 @@ +t3871.scala:4: error: variable foo in class Sub2 cannot be accessed in Sub2 + Access to protected method foo not permitted because + enclosing class Base is not a subclass of + class Sub2 where target is defined + s.foo = true + ^ +one error found diff --git a/tests/untried/neg/t3871.scala b/tests/untried/neg/t3871.scala new file mode 100644 index 000000000000..fc459867dfba --- /dev/null +++ b/tests/untried/neg/t3871.scala @@ -0,0 +1,11 @@ +class Base { + def mkNew() = { + val s = new Sub2 + s.foo = true + s + } +} + +class Sub2 extends Base { + protected var foo = false +} diff --git a/tests/untried/neg/t3871b.check b/tests/untried/neg/t3871b.check new file mode 100644 index 000000000000..6ab5ddfaf11a --- /dev/null +++ b/tests/untried/neg/t3871b.check @@ -0,0 +1,97 @@ +t3871b.scala:61: error: not found: value protOT + protOT // not allowed + ^ +t3871b.scala:77: error: method prot in class A cannot be accessed in E.this.A + Access to protected method prot not permitted because + prefix type E.this.A does not conform to + class B in class E where the access take place + a.prot // not allowed, prefix type `A` does not conform to `B` + ^ +t3871b.scala:79: error: value protT is not a member of E.this.B + b.protT // not allowed + ^ +t3871b.scala:80: error: value protT is not a member of E.this.C + c.protT // not allowed + ^ +t3871b.scala:81: error: value protT is not a member of E.this.A + a.protT // not allowed + ^ +t3871b.scala:91: error: method prot in class A cannot be accessed in E.this.A + Access to protected method prot not permitted because + prefix type E.this.A does not conform to + object B in class E where the access take place + a.prot // not allowed + ^ +t3871b.scala:93: error: value protT is not a member of E.this.B + b.protT // not allowed + ^ +t3871b.scala:94: error: value protT is not a member of E.this.C + c.protT // not allowed + ^ +t3871b.scala:95: error: value protT is not a member of E.this.A + a.protT // not allowed + ^ +t3871b.scala:102: error: method prot in class A cannot be accessed in E.this.B + Access to protected method prot not permitted because + enclosing class Z in class E is not a subclass of + class A in class E where target is defined + b.prot // not allowed + ^ +t3871b.scala:103: error: method prot in class A cannot be accessed in E.this.C + Access to protected method prot not permitted because + enclosing class Z in class E is not a subclass of + class A in class E where target is defined + c.prot // not allowed + ^ +t3871b.scala:104: error: method prot in class A cannot be accessed in E.this.A + Access to protected method prot not permitted because + enclosing class Z in class E is not a subclass of + class A in class E where target is defined + a.prot // not allowed + ^ +t3871b.scala:109: error: value protT is not a member of E.this.B + b.protT // not allowed + ^ +t3871b.scala:110: error: value protT is not a member of E.this.C + c.protT // not allowed + ^ +t3871b.scala:111: error: value protT is not a member of E.this.A + a.protT // not allowed + ^ +t3871b.scala:120: error: method prot in class A cannot be accessed in Other.this.e.B + Access to protected method prot not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + b.prot // not allowed + ^ +t3871b.scala:121: error: method prot in class A cannot be accessed in Other.this.e.C + Access to protected method prot not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + c.prot // not allowed + ^ +t3871b.scala:122: error: method prot in class A cannot be accessed in Other.this.e.A + Access to protected method prot not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + a.prot // not allowed + ^ +t3871b.scala:123: error: method protE in class A cannot be accessed in Other.this.e.B + Access to protected method protE not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + b.protE // not allowed + ^ +t3871b.scala:124: error: method protE in class A cannot be accessed in Other.this.e.A + Access to protected method protE not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + a.protE // not allowed + ^ +t3871b.scala:125: error: method protE in class A cannot be accessed in Other.this.e.C + Access to protected method protE not permitted because + enclosing class Other is not a subclass of + class A in class E where target is defined + c.protE // not allowed + ^ +21 errors found diff --git a/tests/untried/neg/t3871b.scala b/tests/untried/neg/t3871b.scala new file mode 100644 index 000000000000..b490b7789ade --- /dev/null +++ b/tests/untried/neg/t3871b.scala @@ -0,0 +1,127 @@ +/** + +The protected modifier applies to class member definitions. Protected members of a class can be accessed from within + + 0a. the companion module of any of those classes + +A protected identifier x may be used as a member name in a selection r.x only +if one of the following applies: + 1a. The access is within the template defining the member, or, + if a qualification C is given, + 1b. inside the package C, or + 1c. the class C , or its companion module, or + 2. r is one of the reserved words this and super, or + 3. r’s type conforms to a type-instance of the class which contains the access. + + 4. A different form of qualification is protected[this]. A member M marked with this + modifier is called object-protected; it can be accessed only from within the object + in which it is defined. That is, a selection p.M is only legal if the prefix is this + or O.this, for some class O enclosing the reference. In addition, the restrictions + for unqualified protected apply. +*/ + +object E { + val e = new E + import e._ + def n(a: A, b: B, c: C) = { + b.protE // 1c + c.protE // 1c + a.protE // 1c + A.protOE // 1c + } +} + +class E { + object A { + protected def protO = 2 + protected[E] def protOE = 3 + protected[this] def protOT = 3 + } + class A { + protected def prot = 2 + protected[E] def protE = 3 + protected[this] def protT = 4 + + // 1a + prot; protE; protT + def foo = {prot; protE; protT} + new { prot; protE } + def this(a: Any) = {this(); prot; protE; protT} + object B extends A { + A.this.prot + A.this.protE + A.this.protT + } + + import A._ + // 0a + protO + // 3 + protOE + protOT // not allowed + } + + class B extends A { + // 1b + this.prot; this.protE; + super.prot; super.protE; + + // 4 + this.protT + // 4 !!! "or the super keyword" + super.protT + + def n(a: A, b: B, c: C) = { + b.prot // 3 + c.prot // 3 + a.prot // not allowed, prefix type `A` does not conform to `B` + + b.protT // not allowed + c.protT // not allowed + a.protT // not allowed + } + } + object B { + def n(a: A, b: B, c: C) = { + b.prot // 3 !!! + c.prot // 3 !!! + // Wording of 3 seems insufficient, missing: + // "... (if the access is from a class), or + // the type instance of companion class (if the access is from a module)" + a.prot // not allowed + + b.protT // not allowed + c.protT // not allowed + a.protT // not allowed + } + } + class C extends B + + class Z { + def n(a: A, b: B, c: C) = { + b.prot // not allowed + c.prot // not allowed + a.prot // not allowed + b.protE // 2 + a.protE // 2 + c.protE // 2 + + b.protT // not allowed + c.protT // not allowed + a.protT // not allowed + } + } +} + +class Other { + val e = new E + import e._ + def n(a: A, b: B, c: C) = { + b.prot // not allowed + c.prot // not allowed + a.prot // not allowed + b.protE // not allowed + a.protE // not allowed + c.protE // not allowed + } +} diff --git a/tests/untried/neg/t3873.check b/tests/untried/neg/t3873.check new file mode 100644 index 000000000000..f9f413aeafd4 --- /dev/null +++ b/tests/untried/neg/t3873.check @@ -0,0 +1,6 @@ +t3873.scala:11: error: type mismatch; + found : Test.a.B + required: a.B where val a: A + wrongf(new A)(a.b) // should not compile + ^ +one error found diff --git a/tests/untried/neg/t3873.scala b/tests/untried/neg/t3873.scala new file mode 100644 index 000000000000..bf57999554a5 --- /dev/null +++ b/tests/untried/neg/t3873.scala @@ -0,0 +1,12 @@ +class A { + class B + def b: B = new B +} + +object Test { + def wrongf(a: A)(b: a.B): a.B = b + + val a = new A + wrongf(a)(a.b) + wrongf(new A)(a.b) // should not compile +} diff --git a/tests/untried/neg/t3909.check b/tests/untried/neg/t3909.check new file mode 100644 index 000000000000..7da0195607a4 --- /dev/null +++ b/tests/untried/neg/t3909.check @@ -0,0 +1,4 @@ +t3909.scala:1: error: in object DO, multiple overloaded alternatives of m1 define default arguments +object DO { + ^ +one error found diff --git a/tests/untried/neg/t3909.scala b/tests/untried/neg/t3909.scala new file mode 100644 index 000000000000..758dc70fd48a --- /dev/null +++ b/tests/untried/neg/t3909.scala @@ -0,0 +1,12 @@ +object DO { + class Extras { } + object Extras { val defaultValue = new Extras } + + def m1(str: String, extraStuff: Extras = Extras.defaultValue): Int = str.length + def m1(i: Int, extraStuff: Extras = Extras.defaultValue): Int = 2 * i + + def main(args: Array[String]): Unit = { + val m1s = m1("foo") + val m1i = m1(42) + } +} diff --git a/tests/untried/neg/t391.check b/tests/untried/neg/t391.check new file mode 100644 index 000000000000..879d9af71fe1 --- /dev/null +++ b/tests/untried/neg/t391.check @@ -0,0 +1,13 @@ +t391.scala:2: error: identifier expected but 'def' found. + def fun1(def x: Int): Int = x; // the "def x" is illegal + ^ +t391.scala:4: error: ':' expected but '}' found. +} +^ +t391.scala:6: error: identifier expected but 'def' found. +class E(def x: Int); // the "def x" is illegal + ^ +t391.scala:6: error: ':' expected but eof found. +class E(def x: Int); // the "def x" is illegal + ^ +four errors found diff --git a/tests/untried/neg/t391.scala b/tests/untried/neg/t391.scala new file mode 100644 index 000000000000..08c083baa58d --- /dev/null +++ b/tests/untried/neg/t391.scala @@ -0,0 +1,6 @@ +trait C { + def fun1(def x: Int): Int = x; // the "def x" is illegal + def fun2(val x: Int): Int = x; // the "val x" is illegal +} + +class E(def x: Int); // the "def x" is illegal diff --git a/tests/untried/neg/t3913.check b/tests/untried/neg/t3913.check new file mode 100644 index 000000000000..d85e5c5bea18 --- /dev/null +++ b/tests/untried/neg/t3913.check @@ -0,0 +1,4 @@ +t3913.scala:2: error: super constructor cannot be passed a self reference unless parameter is declared by-name +object LimboStage extends Stage( Set( LimboStage )) + ^ +one error found diff --git a/tests/untried/neg/t3913.scala b/tests/untried/neg/t3913.scala new file mode 100644 index 000000000000..a5408fe02517 --- /dev/null +++ b/tests/untried/neg/t3913.scala @@ -0,0 +1,8 @@ +class Stage( val transits: Set[ Stage ]) +object LimboStage extends Stage( Set( LimboStage )) + +object Test { + def main( args: Array[ String ]): Unit = { + val x = LimboStage + } +} diff --git a/tests/untried/neg/t3934.check b/tests/untried/neg/t3934.check new file mode 100644 index 000000000000..8b06799f0dd3 --- /dev/null +++ b/tests/untried/neg/t3934.check @@ -0,0 +1,13 @@ +t3934.scala:15: error: method f2 in class J cannot be accessed in test.J + Access to protected method f2 not permitted because + enclosing class S1 in package nest is not a subclass of + class J in package test where target is defined + def g2(x: J) = x.f2() + ^ +t3934.scala:20: error: method f2 in class J cannot be accessed in test.J + Access to protected method f2 not permitted because + prefix type test.J does not conform to + class S2 in package nest where the access take place + def g2(x: J) = x.f2() + ^ +two errors found diff --git a/tests/untried/neg/t3934.scala b/tests/untried/neg/t3934.scala new file mode 100644 index 000000000000..46e9088af3c7 --- /dev/null +++ b/tests/untried/neg/t3934.scala @@ -0,0 +1,23 @@ +package test { + +class J { + def f1(): Int = { return 5; } + protected def f2(): Int = { return 5; } +} + +} + +package test { +package nest { + +class S1 { + def g1(x: J) = x.f1() + def g2(x: J) = x.f2() +} + +class S2 extends J { + def g1(x: J) = x.f1() + def g2(x: J) = x.f2() +} + +}} diff --git a/tests/untried/neg/t3971.check b/tests/untried/neg/t3971.check new file mode 100644 index 000000000000..8685119876ec --- /dev/null +++ b/tests/untried/neg/t3971.check @@ -0,0 +1,21 @@ +t3971.scala:6: error: type mismatch; + found : Int + required: String + f(g("abc")("def")) // g returns Int, needs String + ^ +t3971.scala:7: error: type mismatch; + found : Int(5) + required: String + f(5) + ^ +t3971.scala:8: error: type mismatch; + found : Int + required: String + f(h("abc")) + ^ +t3971.scala:11: error: type mismatch; + found : Boolean + required: String + ({"ab".reverse; "ba".equals})(0): String + ^ +four errors found diff --git a/tests/untried/neg/t3971.scala b/tests/untried/neg/t3971.scala new file mode 100644 index 000000000000..35f64fde0cf8 --- /dev/null +++ b/tests/untried/neg/t3971.scala @@ -0,0 +1,12 @@ +class A { + def f(x: String) = x + def g(x: String)(y: String): Int = x.length + y.length + def h(x: String) = x.length + + f(g("abc")("def")) // g returns Int, needs String + f(5) + f(h("abc")) + + // a perverse piece of code from a perverse coder + ({"ab".reverse; "ba".equals})(0): String +} diff --git a/tests/untried/neg/t3977.check b/tests/untried/neg/t3977.check new file mode 100644 index 000000000000..72335a092610 --- /dev/null +++ b/tests/untried/neg/t3977.check @@ -0,0 +1,4 @@ +t3977.scala:12: error: could not find implicit value for parameter w: False#If[E] + new NoNull + ^ +one error found diff --git a/tests/untried/neg/t3977.scala b/tests/untried/neg/t3977.scala new file mode 100644 index 000000000000..11a8cdba4b00 --- /dev/null +++ b/tests/untried/neg/t3977.scala @@ -0,0 +1,13 @@ +trait Bool { + type If[T] +} + +trait False extends Bool { + type If[F] = F +} + +class Field[E, N <: Bool](implicit val w: N#If[E]) { + type NoNull = Field[E, False] + + new NoNull +} diff --git a/tests/untried/neg/t3987.check b/tests/untried/neg/t3987.check new file mode 100644 index 000000000000..a9f7912b778b --- /dev/null +++ b/tests/untried/neg/t3987.check @@ -0,0 +1,7 @@ +t3987.scala:11: error: type mismatch; + found : Gox + required: Test.GoxZed + (which expands to) t#Zed forSome { type t <: Gox } + val y: GoxZed = x + ^ +one error found diff --git a/tests/untried/neg/t3987.scala b/tests/untried/neg/t3987.scala new file mode 100644 index 000000000000..1226d8022831 --- /dev/null +++ b/tests/untried/neg/t3987.scala @@ -0,0 +1,13 @@ +class Gox { + object Zed { } + class Zed { } +} + +object Test { + type GoxZed = t#Zed forSome { type t <: Gox } + + def main(args: Array[String]): Unit = { + val x = new Gox + val y: GoxZed = x + } +} diff --git a/tests/untried/neg/t3995.check b/tests/untried/neg/t3995.check new file mode 100644 index 000000000000..00ecf4ca5b6e --- /dev/null +++ b/tests/untried/neg/t3995.check @@ -0,0 +1,6 @@ +t3995.scala:31: error: type mismatch; + found : String("") + required: _1.F0 where val _1: Lift + (new Lift).apply("") + ^ +one error found diff --git a/tests/untried/neg/t3995.scala b/tests/untried/neg/t3995.scala new file mode 100644 index 000000000000..be169639db29 --- /dev/null +++ b/tests/untried/neg/t3995.scala @@ -0,0 +1,32 @@ +class Lift { + def apply(f: F0): Unit = {} + + class F0 + object F0 { + implicit def f2f0(fn: String): F0 = ??? + } +} + +object Test { + val l = new Lift + val f = "" + + "": l.F0 // okay + + l.apply("") // okay + + { + val l = new Lift + l.apply("") // okay + } + + // fails trying to mkAttributedQualifier for pre = Skolem(_1 <: Lift with Singletom).F0 + // should this even have shown up in `companionImplicitMap`? It says that: + // + // "@return For those parts that refer to classes with companion objects that + // can be accessed with unambiguous stable prefixes, the implicits infos + // which are members of these companion objects." + // + // The skolem is stable, but it doen't seem much good to us + (new Lift).apply("") +} diff --git a/tests/untried/neg/t4044.check b/tests/untried/neg/t4044.check new file mode 100644 index 000000000000..0e1ea4f51d37 --- /dev/null +++ b/tests/untried/neg/t4044.check @@ -0,0 +1,14 @@ +t4044.scala:9: error: AnyRef takes no type parameters, expected: one + M[AnyRef] // error, (AnyRef :: *) not kind-conformant to (N :: * -> * -> *) + ^ +t4044.scala:11: error: kinds of the type arguments (Test.A) do not conform to the expected kinds of the type parameters (type N). +Test.A's type parameters do not match type N's expected parameters: +type _ has no type parameters, but type O has one + M[A] // error, (A :: (* -> *) not kind-conformant to (N :: * -> * -> *) + ^ +t4044.scala:15: error: kinds of the type arguments (Test.C) do not conform to the expected kinds of the type parameters (type N). +Test.C's type parameters do not match type N's expected parameters: +type _ has one type parameter, but type _ has none + M[C] // error, (C :: (* -> * -> * -> *) not kind-conformant to (N :: * -> * -> *) + ^ +three errors found diff --git a/tests/untried/neg/t4044.scala b/tests/untried/neg/t4044.scala new file mode 100644 index 000000000000..eeb1d11ac968 --- /dev/null +++ b/tests/untried/neg/t4044.scala @@ -0,0 +1,16 @@ +object Test { + def M[N[O[_]]] = () + type A[_] = Any + type B[_[_]] = Any + type C[_[_[_]]] = Any + + M[Any] // okay, Any is kind overloaded. + + M[AnyRef] // error, (AnyRef :: *) not kind-conformant to (N :: * -> * -> *) + + M[A] // error, (A :: (* -> *) not kind-conformant to (N :: * -> * -> *) + + M[B] // okay, (B :: (* -> * -> *) is kind-conformant to (N :: * -> * -> *) + + M[C] // error, (C :: (* -> * -> * -> *) not kind-conformant to (N :: * -> * -> *) +} diff --git a/tests/untried/neg/t4064.check b/tests/untried/neg/t4064.check new file mode 100644 index 000000000000..0d0e20ded13f --- /dev/null +++ b/tests/untried/neg/t4064.check @@ -0,0 +1,4 @@ +t4064.scala:4: error: value FALSE is not a member of object Boolean + new Foo[Boolean](Boolean.FALSE) + ^ +one error found diff --git a/tests/untried/neg/t4064.scala b/tests/untried/neg/t4064.scala new file mode 100644 index 000000000000..f8cb7848a1d0 --- /dev/null +++ b/tests/untried/neg/t4064.scala @@ -0,0 +1,5 @@ +class Foo[T](v: T) {} + +object Test { + new Foo[Boolean](Boolean.FALSE) +} diff --git a/tests/untried/neg/t4069.check b/tests/untried/neg/t4069.check new file mode 100644 index 000000000000..08e937bdfe2a --- /dev/null +++ b/tests/untried/neg/t4069.check @@ -0,0 +1,16 @@ +t4069.scala:7: error: unexpected end of input: possible missing '}' in XML block + case 2 => + ^ +t4069.scala:6: error: Missing closing brace `}' assumed here + + ^ +t4069.scala:9: error: in XML literal: in XML content, please use '}}' to express '}' + } + ^ +t4069.scala:4: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed
+
+ ^ +t4069.scala:10: error: '}' expected but eof found. +} + ^ +5 errors found diff --git a/tests/untried/neg/t4069.scala b/tests/untried/neg/t4069.scala new file mode 100644 index 000000000000..80df6ec16dfa --- /dev/null +++ b/tests/untried/neg/t4069.scala @@ -0,0 +1,10 @@ +object ParserBug { + 1 match { + case 1 => +
+ { 1 match { case 1 => "1"; case 2 => "2" } +
+ case 2 => +
+ } +} \ No newline at end of file diff --git a/tests/untried/neg/t4079.check b/tests/untried/neg/t4079.check new file mode 100644 index 000000000000..f4c956c44588 --- /dev/null +++ b/tests/untried/neg/t4079.check @@ -0,0 +1,4 @@ +t4079_2.scala:2: error: could not find implicit value for parameter f: Functor[List] + Cat.compose[List,Option].Functor + ^ +one error found diff --git a/tests/untried/neg/t4079/t4079_1.scala b/tests/untried/neg/t4079/t4079_1.scala new file mode 100644 index 000000000000..cbae8647888b --- /dev/null +++ b/tests/untried/neg/t4079/t4079_1.scala @@ -0,0 +1,33 @@ +trait Functor[F[_]] { + def map[A,B](fa: F[A], f: A => B): F[B] +} + +trait ComposeT[F[_],G[_]] { + type Apply[A] = F[G[A]] +} + +case class Compose[F[_],G[_]]() { + def Functor(implicit f: Functor[F], g: Functor[G]): Functor[ComposeT[F,G]#Apply] = + new Functor[ComposeT[F,G]#Apply] { + def map[A,B](c: ComposeT[F,G]#Apply[A], h: A => B) = + f.map(c, (x:G[A]) => g.map(x,h)) + } +} + +object Cat { + def compose[F[_],G[_]] = Compose[F,G]() +} + +object Functors { + implicit val List = new Functor[List] { + def map[A,B](fa: List[A], f: A => B): List[B] = fa map f + } + implicit val Option = new Functor[Option] { + def map[A,B](fa: Option[A], f: A => B): Option[B] = fa map f + } +} + +object Main { + import Functors._ + val cf = Cat.compose[List,Option].Functor +} diff --git a/tests/untried/neg/t4079/t4079_2.scala b/tests/untried/neg/t4079/t4079_2.scala new file mode 100644 index 000000000000..9069f0ab4e83 --- /dev/null +++ b/tests/untried/neg/t4079/t4079_2.scala @@ -0,0 +1,3 @@ +object Test { + Cat.compose[List,Option].Functor +} diff --git a/tests/untried/neg/t409.check b/tests/untried/neg/t409.check new file mode 100644 index 000000000000..0edc0d03cd99 --- /dev/null +++ b/tests/untried/neg/t409.check @@ -0,0 +1,4 @@ +t409.scala:6: error: class Case1 needs to be a trait to be mixed in +class Toto extends Expr with Case1(12); + ^ +one error found diff --git a/tests/untried/neg/t409.scala b/tests/untried/neg/t409.scala new file mode 100644 index 000000000000..5dac2fdaa413 --- /dev/null +++ b/tests/untried/neg/t409.scala @@ -0,0 +1,18 @@ +abstract class Expr; +case class Case1(x: Int) extends Expr; +case class Case2(x: Int) extends Expr; +case class Case3(x: Int) extends Expr; + +class Toto extends Expr with Case1(12); + +object Main { + def f(x: Expr): Int = x match { + case Case1(x) => x + case Case2(x) => x + case Case3(x) => x + } + + def main(args: Array[String]): Unit = { + Console.println(f(new Toto)); + } +} diff --git a/tests/untried/neg/t4091.check b/tests/untried/neg/t4091.check new file mode 100644 index 000000000000..2fdd07fd4d6a --- /dev/null +++ b/tests/untried/neg/t4091.check @@ -0,0 +1,4 @@ +t4091.scala:1: error: expected start of definition +private a + ^ +one error found diff --git a/tests/untried/neg/t4091.scala b/tests/untried/neg/t4091.scala new file mode 100644 index 000000000000..7df116d5b51d --- /dev/null +++ b/tests/untried/neg/t4091.scala @@ -0,0 +1,2 @@ +private a +class b diff --git a/tests/untried/neg/t4098.check b/tests/untried/neg/t4098.check new file mode 100644 index 000000000000..232c082ec91f --- /dev/null +++ b/tests/untried/neg/t4098.check @@ -0,0 +1,13 @@ +t4098.scala:3: error: forward reference not allowed from self constructor invocation + this(b) + ^ +t4098.scala:8: error: forward reference not allowed from self constructor invocation + this(b) + ^ +t4098.scala:13: error: forward reference not allowed from self constructor invocation + this(b) + ^ +t4098.scala:18: error: forward reference not allowed from self constructor invocation + this(b) + ^ +four errors found diff --git a/tests/untried/neg/t4098.scala b/tests/untried/neg/t4098.scala new file mode 100644 index 000000000000..2e6d167646a1 --- /dev/null +++ b/tests/untried/neg/t4098.scala @@ -0,0 +1,22 @@ +class A(a: Any) { + def this() = { + this(b) + def b = new {} + } + + def this(x: Int) = { + this(b) + lazy val b = new {} + } + + def this(x: Int, y: Int) = { + this(b) + val b = new {} + } + + def this(x: Int, y: Int, z: Int) = { + this(b) + println(".") + def b = new {} + } +} diff --git a/tests/untried/neg/t412.check b/tests/untried/neg/t412.check new file mode 100644 index 000000000000..9cb467e85411 --- /dev/null +++ b/tests/untried/neg/t412.check @@ -0,0 +1,5 @@ +t412.scala:11: error: stable identifier required, but A.this.c found. + Note that value c is not stable because its type, A.this.CX with A.this.C2, is volatile. + def castA(x: c.T): T2 = x; + ^ +one error found diff --git a/tests/untried/neg/t412.scala b/tests/untried/neg/t412.scala new file mode 100644 index 000000000000..54cd90da1ce0 --- /dev/null +++ b/tests/untried/neg/t412.scala @@ -0,0 +1,31 @@ +object Magic { + + abstract class A[T1,T2]() { + trait C { type T; } + trait C1 extends C { type T = T1; } + trait C2 extends C { type T <: T2; } + + type CX >: Null; + val c: CX with C2 = null; + + def castA(x: c.T): T2 = x; + } + + class B[T1,T2] extends A[T1,T2]() { + type CX = C1; + + def castB(x: T1): T2 = castA(x); + } + + def cast[T1,T2](v: T1): T2 = + new B[T1,T2]().castB(v) + +} + +object Test { + + def main(args: Array[String]): Unit = { + Magic.cast[String,Exception]("xyz").printStackTrace(); + } + +} diff --git a/tests/untried/neg/t4134.check b/tests/untried/neg/t4134.check new file mode 100644 index 000000000000..35a1820b0a6d --- /dev/null +++ b/tests/untried/neg/t4134.check @@ -0,0 +1,4 @@ +t4134.scala:22: error: Member method f of mixin trait T2 is missing a concrete super implementation. +class Konkret extends T3 + ^ +one error found diff --git a/tests/untried/neg/t4134.scala b/tests/untried/neg/t4134.scala new file mode 100644 index 000000000000..18f813dd1d36 --- /dev/null +++ b/tests/untried/neg/t4134.scala @@ -0,0 +1,30 @@ + + + +trait T1 { + def f: String +} + +trait T2 extends T1 { + abstract override def f: String = "goo" + def something = super.f // So the "abstract override" is needed +} + +trait Q1 { + def f: String = "bippy" +} + +//trait T3 extends Q1 with T2 { +trait T3 extends T2 with Q1 { + abstract override def f: String = super[Q1].f + " " + super[T2].f + " hoo" +} + +class Konkret extends T3 + +object Test { + def main(args: Array[String]): Unit = { + val k = new Konkret + println(k.f) + println(k.something) + } +} diff --git a/tests/untried/neg/t4137.check b/tests/untried/neg/t4137.check new file mode 100644 index 000000000000..9767bdb1ce64 --- /dev/null +++ b/tests/untried/neg/t4137.check @@ -0,0 +1,9 @@ +t4137.scala:9: error: overriding type EPC in trait A, which equals [X1]C[X1]; + type EPC has incompatible type + override type EPC = C[T] + ^ +t4137.scala:10: error: overriding type EPC2 in trait A, which equals [X1]C[X1]; + type EPC2 has incompatible type + override type EPC2[X1 <: String] = C[X1] + ^ +two errors found diff --git a/tests/untried/neg/t4137.scala b/tests/untried/neg/t4137.scala new file mode 100644 index 000000000000..60de6de70175 --- /dev/null +++ b/tests/untried/neg/t4137.scala @@ -0,0 +1,11 @@ +trait C[T] + +trait A[T] { + type EPC[X1] = C[X1] + type EPC2[X1] = C[X1] +} + +trait B[T] extends A[T] { + override type EPC = C[T] + override type EPC2[X1 <: String] = C[X1] +} diff --git a/tests/untried/neg/t414.check b/tests/untried/neg/t414.check new file mode 100644 index 000000000000..30211eef8ed4 --- /dev/null +++ b/tests/untried/neg/t414.check @@ -0,0 +1,12 @@ +t414.scala:5: error: pattern type is incompatible with expected type; + found : Empty.type + required: IntMap[a] +Note: if you intended to match against the class, try `case Empty()` + case Empty => + ^ +t414.scala:7: error: type mismatch; + found : Unit + required: a + case _ => + ^ +two errors found diff --git a/tests/untried/neg/t414.scala b/tests/untried/neg/t414.scala new file mode 100644 index 000000000000..86646d13c242 --- /dev/null +++ b/tests/untried/neg/t414.scala @@ -0,0 +1,10 @@ +case class Empty[a]() extends IntMap[a]; +case class Node[a](left: IntMap[a], keyVal: Tuple2[Int, a], right: IntMap[a]) extends IntMap[a]; +abstract class IntMap[a] { + def lookup(key: Int): a = this match { + case Empty => + sys.error("clef inexistante") + case _ => + }; + +}; diff --git a/tests/untried/neg/t4158.check b/tests/untried/neg/t4158.check new file mode 100644 index 000000000000..af281c52cdd8 --- /dev/null +++ b/tests/untried/neg/t4158.check @@ -0,0 +1,7 @@ +t4158.scala:3: error: an expression of type Null is ineligible for implicit conversion + var y = null: Int + ^ +t4158.scala:2: error: an expression of type Null is ineligible for implicit conversion + var x: Int = null + ^ +two errors found diff --git a/tests/untried/neg/t4158.scala b/tests/untried/neg/t4158.scala new file mode 100644 index 000000000000..be3dc4398bc5 --- /dev/null +++ b/tests/untried/neg/t4158.scala @@ -0,0 +1,4 @@ +class A { + var x: Int = null + var y = null: Int +} diff --git a/tests/untried/neg/t4163.check b/tests/untried/neg/t4163.check new file mode 100644 index 000000000000..47bc78d31cbe --- /dev/null +++ b/tests/untried/neg/t4163.check @@ -0,0 +1,7 @@ +t4163.scala:4: error: '<-' expected but '=' found. + x = 3 + ^ +t4163.scala:5: error: illegal start of simple expression + y <- 0 to 100 +^ +two errors found diff --git a/tests/untried/neg/t4163.scala b/tests/untried/neg/t4163.scala new file mode 100644 index 000000000000..44686731d158 --- /dev/null +++ b/tests/untried/neg/t4163.scala @@ -0,0 +1,8 @@ +class Bug { + val z = ( + for { + x = 3 + y <- 0 to 100 + } yield y + ).toArray +} diff --git a/tests/untried/neg/t4166.check b/tests/untried/neg/t4166.check new file mode 100644 index 000000000000..10b77d841abc --- /dev/null +++ b/tests/untried/neg/t4166.check @@ -0,0 +1,4 @@ +t4166.scala:3: error: super constructor arguments cannot reference unconstructed `this` +class Demo extends Base(new { Demo.this.toString }) { + ^ +one error found diff --git a/tests/untried/neg/t4166.scala b/tests/untried/neg/t4166.scala new file mode 100644 index 000000000000..a2ee0671abe7 --- /dev/null +++ b/tests/untried/neg/t4166.scala @@ -0,0 +1,11 @@ +class Base(a: Any) + +class Demo extends Base(new { Demo.this.toString }) { + val x: Any = () +} + + +class Demo2 extends Base(new { this.toString }) { + val x: Any = () +} + diff --git a/tests/untried/neg/t4174.check b/tests/untried/neg/t4174.check new file mode 100644 index 000000000000..914fcff76e0f --- /dev/null +++ b/tests/untried/neg/t4174.check @@ -0,0 +1,4 @@ +t4174.scala:7: error: method bar overrides nothing + foo(new C { override def bar = 1 }) + ^ +one error found diff --git a/tests/untried/neg/t4174.scala b/tests/untried/neg/t4174.scala new file mode 100644 index 000000000000..b4a5ab29da61 --- /dev/null +++ b/tests/untried/neg/t4174.scala @@ -0,0 +1,9 @@ +class C + +object Test { + def foo(c: C) = 0 + + def main(args: Array[String]): Unit = { + foo(new C { override def bar = 1 }) + } +} diff --git a/tests/untried/neg/t418.check b/tests/untried/neg/t418.check new file mode 100644 index 000000000000..1b99717b8214 --- /dev/null +++ b/tests/untried/neg/t418.check @@ -0,0 +1,4 @@ +t418.scala:2: error: not found: value Foo12340771 + null match { case Foo12340771.Bar(x) => x } + ^ +one error found diff --git a/tests/untried/neg/t418.scala b/tests/untried/neg/t418.scala new file mode 100644 index 000000000000..67007010d4e8 --- /dev/null +++ b/tests/untried/neg/t418.scala @@ -0,0 +1,3 @@ +object Test { + null match { case Foo12340771.Bar(x) => x } +} diff --git a/tests/untried/neg/t4196.check b/tests/untried/neg/t4196.check new file mode 100644 index 000000000000..a0586819e94d --- /dev/null +++ b/tests/untried/neg/t4196.check @@ -0,0 +1,4 @@ +t4196.scala:5: error: Some[String] does not take parameters + }.apply("first param") ("spurious param") + ^ +one error found diff --git a/tests/untried/neg/t4196.scala b/tests/untried/neg/t4196.scala new file mode 100644 index 000000000000..a0ad4db72a50 --- /dev/null +++ b/tests/untried/neg/t4196.scala @@ -0,0 +1,6 @@ +object Weird { + { (s: String) => + val foo = Some(s); // to illustrate that vals are printed in the error + foo + }.apply("first param") ("spurious param") +} diff --git a/tests/untried/neg/t421.check b/tests/untried/neg/t421.check new file mode 100644 index 000000000000..dc5fa425acdc --- /dev/null +++ b/tests/untried/neg/t421.check @@ -0,0 +1,4 @@ +t421.scala:5: error: star patterns must correspond with varargs parameters + case Bar("foo",_*) => sys.error("huh?"); + ^ +one error found diff --git a/tests/untried/neg/t421.scala b/tests/untried/neg/t421.scala new file mode 100644 index 000000000000..9a327be89613 --- /dev/null +++ b/tests/untried/neg/t421.scala @@ -0,0 +1,8 @@ +object foo { + case class Bar(a:String, b:AnyRef, c:String*); + + Bar("foo","meets","bar") match { + case Bar("foo",_*) => sys.error("huh?"); + } + +} diff --git a/tests/untried/neg/t4217.check b/tests/untried/neg/t4217.check new file mode 100644 index 000000000000..6c49ec335424 --- /dev/null +++ b/tests/untried/neg/t4217.check @@ -0,0 +1,4 @@ +t4217.scala:2: error: 'case' expected but '}' found. + 42 match { } + ^ +one error found diff --git a/tests/untried/neg/t4217.scala b/tests/untried/neg/t4217.scala new file mode 100644 index 000000000000..0817df2cb79f --- /dev/null +++ b/tests/untried/neg/t4217.scala @@ -0,0 +1,3 @@ +object A extends App { + 42 match { } +} diff --git a/tests/untried/neg/t4221.check b/tests/untried/neg/t4221.check new file mode 100644 index 000000000000..46c2d10a988d --- /dev/null +++ b/tests/untried/neg/t4221.check @@ -0,0 +1,6 @@ +t4221.scala:8: error: type mismatch; + found : Unit + required: Wrapper[S] + def wrap[S <: Cl#Sub[S]](v: S): Wrapper[S] = { + ^ +one error found diff --git a/tests/untried/neg/t4221.scala b/tests/untried/neg/t4221.scala new file mode 100644 index 000000000000..0a8b8add1860 --- /dev/null +++ b/tests/untried/neg/t4221.scala @@ -0,0 +1,10 @@ +class Cl { + class Sub[TheSub <: Sub[TheSub]] +} + +case class Wrapper[T](v: T) + +object O { + def wrap[S <: Cl#Sub[S]](v: S): Wrapper[S] = { + } +} diff --git a/tests/untried/neg/t425.check b/tests/untried/neg/t425.check new file mode 100644 index 000000000000..77ea0c5a4b44 --- /dev/null +++ b/tests/untried/neg/t425.check @@ -0,0 +1,4 @@ +t425.scala:3: error: case class B has case ancestor Temp.A, but case-to-case inheritance is prohibited. To overcome this limitation, use extractors to pattern match on non-leaf nodes. + case class B(override val x: Int, y: Double) extends A(x) + ^ +one error found diff --git a/tests/untried/neg/t425.scala b/tests/untried/neg/t425.scala new file mode 100644 index 000000000000..e50c50ac35e8 --- /dev/null +++ b/tests/untried/neg/t425.scala @@ -0,0 +1,11 @@ +object Temp{ + case class A(x: Int) + case class B(override val x: Int, y: Double) extends A(x) + + val b: A = B(5, 3.3) + b match { + case B(x, y) => Console.println(y) + case A(x) => Console.println(x) + } +} + diff --git a/tests/untried/neg/t4270.check b/tests/untried/neg/t4270.check new file mode 100644 index 000000000000..cfe0a93e005c --- /dev/null +++ b/tests/untried/neg/t4270.check @@ -0,0 +1,4 @@ +t4270.scala:5: error: could not find implicit value for parameter e: Int + implicitly[Int] + ^ +one error found diff --git a/tests/untried/neg/t4270.scala b/tests/untried/neg/t4270.scala new file mode 100644 index 000000000000..2c7c71d8c2f7 --- /dev/null +++ b/tests/untried/neg/t4270.scala @@ -0,0 +1,6 @@ +object Test1 { + object A { implicit val x: Int = 1 } + import A.x + def x: Int = 0 + implicitly[Int] +} diff --git a/tests/untried/neg/t4271.check b/tests/untried/neg/t4271.check new file mode 100644 index 000000000000..91d9fbcfa197 --- /dev/null +++ b/tests/untried/neg/t4271.check @@ -0,0 +1,10 @@ +t4271.scala:9: error: value to is not a member of Int + 3 to 5 + ^ +t4271.scala:10: error: value ensuring is not a member of Int + 5 ensuring true + ^ +t4271.scala:11: error: value -> is not a member of Int + 3 -> 5 + ^ +three errors found diff --git a/tests/untried/neg/t4271.scala b/tests/untried/neg/t4271.scala new file mode 100644 index 000000000000..46ae3ad9ec90 --- /dev/null +++ b/tests/untried/neg/t4271.scala @@ -0,0 +1,12 @@ +object foo { + object Donotuseme + implicit def Ensuring[A](x: A) = Donotuseme + implicit def doubleWrapper(x: Int) = Donotuseme + implicit def floatWrapper(x: Int) = Donotuseme + implicit def intWrapper(x: Int) = Donotuseme + implicit def longWrapper(x: Int) = Donotuseme + implicit def ArrowAssoc[A](x: A) = Donotuseme + 3 to 5 + 5 ensuring true + 3 -> 5 +} diff --git a/tests/untried/neg/t4283b.check b/tests/untried/neg/t4283b.check new file mode 100644 index 000000000000..30d03a310dd5 --- /dev/null +++ b/tests/untried/neg/t4283b.check @@ -0,0 +1,4 @@ +Test.scala:2: error: Unable to access method f in class AbstractFoo with a super reference. + override def f(): Int = super.f() + ^ +one error found diff --git a/tests/untried/neg/t4283b/AbstractFoo.java b/tests/untried/neg/t4283b/AbstractFoo.java new file mode 100644 index 000000000000..7abcd5e76b54 --- /dev/null +++ b/tests/untried/neg/t4283b/AbstractFoo.java @@ -0,0 +1,5 @@ +package test; + +/* package private */ class AbstractFoo { + public int f() { return 2; } +} diff --git a/tests/untried/neg/t4283b/ScalaBipp.scala b/tests/untried/neg/t4283b/ScalaBipp.scala new file mode 100644 index 000000000000..36dea9f4de17 --- /dev/null +++ b/tests/untried/neg/t4283b/ScalaBipp.scala @@ -0,0 +1,5 @@ +package test + +class ScalaBipp extends AbstractFoo { + def make: Option[ScalaBipp] = Option(this) +} diff --git a/tests/untried/neg/t4283b/Test.scala b/tests/untried/neg/t4283b/Test.scala new file mode 100644 index 000000000000..0dc5636ff884 --- /dev/null +++ b/tests/untried/neg/t4283b/Test.scala @@ -0,0 +1,3 @@ +object Derived extends test.ScalaBipp { + override def f(): Int = super.f() +} diff --git a/tests/untried/neg/t4302.check b/tests/untried/neg/t4302.check new file mode 100644 index 000000000000..ea4872927679 --- /dev/null +++ b/tests/untried/neg/t4302.check @@ -0,0 +1,6 @@ +t4302.scala:2: warning: abstract type T is unchecked since it is eliminated by erasure + def hasMatch[T](x: AnyRef) = x.isInstanceOf[T] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t4302.flags b/tests/untried/neg/t4302.flags new file mode 100644 index 000000000000..779916d58f80 --- /dev/null +++ b/tests/untried/neg/t4302.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t4302.scala b/tests/untried/neg/t4302.scala new file mode 100644 index 000000000000..53565f05c247 --- /dev/null +++ b/tests/untried/neg/t4302.scala @@ -0,0 +1,3 @@ +object Test { + def hasMatch[T](x: AnyRef) = x.isInstanceOf[T] +} diff --git a/tests/untried/neg/t4417.check b/tests/untried/neg/t4417.check new file mode 100644 index 000000000000..dbd0f1df460d --- /dev/null +++ b/tests/untried/neg/t4417.check @@ -0,0 +1,7 @@ +t4417.scala:11: error: constructor Pixel$mcD$sp in class Pixel$mcD$sp cannot be accessed in object Pixel + Access to protected constructor Pixel$mcD$sp not permitted because + enclosing object Pixel is not a subclass of + class Pixel$mcD$sp where target is defined + def apply(v: Double): Pixel1d = new Pixel1d(v) + ^ +one error found diff --git a/tests/untried/neg/t4417.scala b/tests/untried/neg/t4417.scala new file mode 100644 index 000000000000..3f6ddc81537c --- /dev/null +++ b/tests/untried/neg/t4417.scala @@ -0,0 +1,17 @@ + + + + +class Pixel[@specialized T] protected (var v: T) + + +object Pixel { + type Pixel1d = Pixel[Double] + + def apply(v: Double): Pixel1d = new Pixel1d(v) +} + + + + + diff --git a/tests/untried/neg/t4419.check b/tests/untried/neg/t4419.check new file mode 100644 index 000000000000..a53e0c95da91 --- /dev/null +++ b/tests/untried/neg/t4419.check @@ -0,0 +1,4 @@ +t4419.scala:2: error: forward reference extends over definition of value b + { val b = a; val a = 1 ; println(a) } + ^ +one error found diff --git a/tests/untried/neg/t4419.scala b/tests/untried/neg/t4419.scala new file mode 100644 index 000000000000..161593f9bbf6 --- /dev/null +++ b/tests/untried/neg/t4419.scala @@ -0,0 +1,3 @@ +class A { + { val b = a; val a = 1 ; println(a) } +} diff --git a/tests/untried/neg/t4425.check b/tests/untried/neg/t4425.check new file mode 100644 index 000000000000..00006c08f0c6 --- /dev/null +++ b/tests/untried/neg/t4425.check @@ -0,0 +1,13 @@ +t4425.scala:3: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: Int)(y: Option[Int]): None.type exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + 42 match { case _ X _ => () } + ^ +t4425.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: Int)(y: Int): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + 42 match { case _ X _ => () } + ^ +t4425.scala:13: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Some[(Int, Int)] exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + "" match { case _ X _ => () } + ^ +three errors found diff --git a/tests/untried/neg/t4425.flags b/tests/untried/neg/t4425.flags new file mode 100644 index 000000000000..1182725e8633 --- /dev/null +++ b/tests/untried/neg/t4425.flags @@ -0,0 +1 @@ +-optimize \ No newline at end of file diff --git a/tests/untried/neg/t4425.scala b/tests/untried/neg/t4425.scala new file mode 100644 index 000000000000..8feedc20f424 --- /dev/null +++ b/tests/untried/neg/t4425.scala @@ -0,0 +1,14 @@ +object Foo { + object X { def unapply(x : Int)(y : Option[Int] = None) = None } + 42 match { case _ X _ => () } +} + +object Foo2 { + object X { def unapply(x : Int)(y: Int) = Some((2,2)) } + 42 match { case _ X _ => () } +} + +object Foo3 { + object X { def unapply(x : String)(y: String) = Some((2,2)) } + "" match { case _ X _ => () } +} diff --git a/tests/untried/neg/t4425b.check b/tests/untried/neg/t4425b.check new file mode 100644 index 000000000000..8418b4fd1275 --- /dev/null +++ b/tests/untried/neg/t4425b.check @@ -0,0 +1,49 @@ +t4425b.scala:5: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:6: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:7: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println( "" match { case X(_) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:8: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:9: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:10: error: object X is not a case class, nor does it have an unapply/unapplySeq member +Note: def unapply(x: String)(y: String): Nothing exists in object X, but it cannot be used as an extractor due to its second non-implicit parameter list + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:18: error: too many patterns for object X: expected 1, found 2 + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:19: error: too many patterns for object X: expected 1, found 2 + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:22: error: too many patterns for object X: expected 1, found 2 + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:23: error: too many patterns for object X: expected 1, found 2 + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:31: error: too many patterns for object X offering Nothing: expected 1, found 2 + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:32: error: too many patterns for object X offering Nothing: expected 1, found 2 + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:35: error: too many patterns for object X offering Nothing: expected 1, found 2 + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +t4425b.scala:36: error: too many patterns for object X offering Nothing: expected 1, found 2 + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + ^ +14 errors found diff --git a/tests/untried/neg/t4425b.scala b/tests/untried/neg/t4425b.scala new file mode 100644 index 000000000000..23c4855c7d06 --- /dev/null +++ b/tests/untried/neg/t4425b.scala @@ -0,0 +1,38 @@ +object Test1 { + object X { def unapply(x : String)(y: String) = throw new Exception } + + def f1(): Unit = { + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + println( "" match { case X(_) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + } +} + +object Test2 { + object X { def unapply(x : String) = throw new Exception } + + def f1(): Unit = { + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + println( "" match { case X(_) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + } +} + +object Test3 { + object X { def unapply(x : String) = None } + + def f1(): Unit = { + println( "" match { case _ X _ => "ok" ; case _ => "fail" }) + println((X: Any) match { case _ X _ => "ok" ; case _ => "fail" }) + println( "" match { case X(_) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_) => "ok" ; case _ => "fail" }) + println( "" match { case X(_, _) => "ok" ; case _ => "fail" }) + println((X: Any) match { case X(_, _) => "ok" ; case _ => "fail" }) + } +} diff --git a/tests/untried/neg/t4431.check b/tests/untried/neg/t4431.check new file mode 100644 index 000000000000..7896ec1a623f --- /dev/null +++ b/tests/untried/neg/t4431.check @@ -0,0 +1,7 @@ +t4431.scala:5: error: class BB needs to be abstract, since there is a deferred declaration of method f which is not implemented in a subclass + class BB extends B { def f (): Unit } + ^ +t4431.scala:8: error: trait cannot redefine final method from class AnyRef + trait C { def wait (): Unit } + ^ +two errors found diff --git a/tests/untried/neg/t4431.scala b/tests/untried/neg/t4431.scala new file mode 100644 index 000000000000..5fbb239e04c1 --- /dev/null +++ b/tests/untried/neg/t4431.scala @@ -0,0 +1,16 @@ +object Test { + // this works. + class B { final def f(): Unit = () } + trait A extends B { def f (): Unit } + class BB extends B { def f (): Unit } + + // this earns a VerifyError. + trait C { def wait (): Unit } + class D { } + + def main(args: Array[String]): Unit = { + new B with A { } + new BB +// new D with C { } + } +} diff --git a/tests/untried/neg/t4440.check b/tests/untried/neg/t4440.check new file mode 100644 index 000000000000..10e7188e32bb --- /dev/null +++ b/tests/untried/neg/t4440.check @@ -0,0 +1,15 @@ +t4440.scala:12: warning: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") + ^ +t4440.scala:13: warning: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") // this is the case we want + ^ +t4440.scala:16: warning: The outer reference in this type test cannot be checked at run time. + case _: a.Inner => println("a") + ^ +t4440.scala:17: warning: The outer reference in this type test cannot be checked at run time. + case _: b.Inner => println("b") // this is the case we want + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t4440.flags b/tests/untried/neg/t4440.flags new file mode 100644 index 000000000000..779916d58f80 --- /dev/null +++ b/tests/untried/neg/t4440.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t4440.scala b/tests/untried/neg/t4440.scala new file mode 100644 index 000000000000..383b141edd27 --- /dev/null +++ b/tests/untried/neg/t4440.scala @@ -0,0 +1,19 @@ +// constructors used to drop outer fields when they were not accessed +// however, how can you know (respecting separate compilation) that they're not accessed!? +class Outer { final class Inner } + +// the matches below require Inner's outer pointer +// until SI-4440 is fixed properly, we can't make this a run test +// in principle, the output should be "a\nb", but without outer checks it's "b\na" +object Test extends App { + val a = new Outer + val b = new Outer + (new a.Inner: Any) match { + case _: b.Inner => println("b") + case _: a.Inner => println("a") // this is the case we want + } + (new b.Inner: Any) match { + case _: a.Inner => println("a") + case _: b.Inner => println("b") // this is the case we want + } +} diff --git a/tests/untried/neg/t4457_1.check b/tests/untried/neg/t4457_1.check new file mode 100644 index 000000000000..c6b83c6ce587 --- /dev/null +++ b/tests/untried/neg/t4457_1.check @@ -0,0 +1,7 @@ +t4457_1.scala:27: error: ambiguous reference to overloaded definition, +both method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NZ[A])ImplicitConvAmbiguity2.AA[Float] +and method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NE[A])ImplicitConvAmbiguity2.AA[A] +match argument types (Float) + val x = aFunc(4F) + ^ +one error found diff --git a/tests/untried/neg/t4457_1.scala b/tests/untried/neg/t4457_1.scala new file mode 100644 index 000000000000..11dae1097ff3 --- /dev/null +++ b/tests/untried/neg/t4457_1.scala @@ -0,0 +1,33 @@ +object ImplicitConvAmbiguity2 { + + class N[T] + class NE[T] extends N[T] + class NN[T] extends N[T] + class NQ[T] extends N[T] + class NZ[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 conv7(i: Float) = new NZ[Float] + implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar] + + // These two will be in conflict in typeMe1 + def aFunc[A](a: NE[A]) = new AA[A] + def aFunc[A](a: NZ[A]) = new AA[Float] + + def aFunc[A](a: NN[A]) = new BB[A] + def aFunc[A](a: NQ[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/neg/t4457_2.check b/tests/untried/neg/t4457_2.check new file mode 100644 index 000000000000..770a355395da --- /dev/null +++ b/tests/untried/neg/t4457_2.check @@ -0,0 +1,13 @@ +t4457_2.scala:27: error: ambiguous reference to overloaded definition, +both method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NZ[A])ImplicitConvAmbiguity2.AA[A] +and method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NE[A])ImplicitConvAmbiguity2.AA[A] +match argument types (Float) + val x = aFunc(4F) + ^ +t4457_2.scala:31: error: ambiguous reference to overloaded definition, +both method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NZ[A])ImplicitConvAmbiguity2.AA[A] +and method aFunc in object ImplicitConvAmbiguity2 of type [A](a: ImplicitConvAmbiguity2.NE[A])ImplicitConvAmbiguity2.AA[A] +match argument types (Float) + bFunc(aFunc(4F)) + ^ +two errors found diff --git a/tests/untried/neg/t4457_2.scala b/tests/untried/neg/t4457_2.scala new file mode 100644 index 000000000000..f2664cc14ee6 --- /dev/null +++ b/tests/untried/neg/t4457_2.scala @@ -0,0 +1,33 @@ +object ImplicitConvAmbiguity2 { + + class N[T] + class NE[T] extends N[T] + class NN[T] extends N[T] + class NQ[T] extends N[T] + class NZ[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 conv7(i: Float) = new NZ[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: NZ[A]) = new AA[A] + + def aFunc[A](a: NN[A]) = new BB[A] + + def aFunc[A](a: NQ[A]) = new BB[A] + + def bFunc[T](e1: N[T]) = {} + + def typeMe2: Unit = { + val x = aFunc(4F) + bFunc(x) + } + def typeMe1: Unit = { + bFunc(aFunc(4F)) + } +} diff --git a/tests/untried/neg/t4460a.check b/tests/untried/neg/t4460a.check new file mode 100644 index 000000000000..b711e7acb184 --- /dev/null +++ b/tests/untried/neg/t4460a.check @@ -0,0 +1,4 @@ +t4460a.scala:6: error: called constructor's definition must precede calling constructor's definition + def this() = this() // was binding to Predef. !! + ^ +one error found diff --git a/tests/untried/neg/t4460a.scala b/tests/untried/neg/t4460a.scala new file mode 100644 index 000000000000..0a7a22178d04 --- /dev/null +++ b/tests/untried/neg/t4460a.scala @@ -0,0 +1,7 @@ +trait A + +class B(val x: Int) { + self: A => + + def this() = this() // was binding to Predef. !! +} diff --git a/tests/untried/neg/t4460b.check b/tests/untried/neg/t4460b.check new file mode 100644 index 000000000000..f0e703fd104b --- /dev/null +++ b/tests/untried/neg/t4460b.check @@ -0,0 +1,4 @@ +t4460b.scala:7: error: called constructor's definition must precede calling constructor's definition + def this() = this() // was binding to Predef. !! + ^ +one error found diff --git a/tests/untried/neg/t4460b.scala b/tests/untried/neg/t4460b.scala new file mode 100644 index 000000000000..1233017dd4a9 --- /dev/null +++ b/tests/untried/neg/t4460b.scala @@ -0,0 +1,9 @@ +trait A + +class Outer() { + class B(val x: Int) { + self: A => + + def this() = this() // was binding to Predef. !! + } +} diff --git a/tests/untried/neg/t4460c.check b/tests/untried/neg/t4460c.check new file mode 100644 index 000000000000..4e96711b8bb6 --- /dev/null +++ b/tests/untried/neg/t4460c.check @@ -0,0 +1,7 @@ +t4460c.scala:4: error: overloaded method constructor B with alternatives: + (a: String)B + (x: Int)B + cannot be applied to () + def this(a: String) = this() + ^ +one error found diff --git a/tests/untried/neg/t4460c.scala b/tests/untried/neg/t4460c.scala new file mode 100644 index 000000000000..1ae258508e80 --- /dev/null +++ b/tests/untried/neg/t4460c.scala @@ -0,0 +1,7 @@ +class B(val x: Int) { + self: A => + + def this(a: String) = this() +} + +class A() diff --git a/tests/untried/neg/t4515.check b/tests/untried/neg/t4515.check new file mode 100644 index 000000000000..708fcfbd294f --- /dev/null +++ b/tests/untried/neg/t4515.check @@ -0,0 +1,16 @@ +t4515.scala:37: error: type mismatch; + found : _$1 where type _$1 + required: _$2 + handler.onEvent(target, ctx.getEvent, node, ctx) + ^ +t4515.scala:37: error: type mismatch; + found : Main.DerivedPushNode[_$1] where type _$1 + required: Main.PushNode[_$2] + handler.onEvent(target, ctx.getEvent, node, ctx) + ^ +t4515.scala:37: error: type mismatch; + found : Main.PushEventContext[_$1] where type _$1 + required: Main.PushEventContext[_$2] + handler.onEvent(target, ctx.getEvent, node, ctx) + ^ +three errors found diff --git a/tests/untried/neg/t4515.scala b/tests/untried/neg/t4515.scala new file mode 100644 index 000000000000..8965b96867e2 --- /dev/null +++ b/tests/untried/neg/t4515.scala @@ -0,0 +1,41 @@ +import scala.collection.mutable.HashMap + +object Main { + trait Target { } + + trait PushEventContext[EventType] { + def getEvent: EventType + } + trait PushNode[EventType] { } + trait DerivedPushNode[EventType] extends PushNode[EventType] { } + + trait HandlerBase[EventType] { + def onEvent(target: Target, + event: EventType, + node: PushNode[EventType], + ctx: PushEventContext[EventType]): Unit + } + val handlers = new HashMap[DerivedPushNode[_], HandlerBase[_]] + + object TimerPushService { + private val INSTANCE: TimerPushService = new TimerPushService + def get: TimerPushService = INSTANCE + } + + class TimerPushService { + def add[EventType](node: DerivedPushNode[EventType], + context: PushEventContext[EventType]): Unit = {} + + def pollEvents[EventType](node: DerivedPushNode[EventType]): List[PushEventContext[EventType]] = + Nil + } + + def onTimer(target: Target): Unit = { + val pushService = TimerPushService.get + for ((node, handler) <- handlers) { + for (ctx <- pushService.pollEvents(node)) { + handler.onEvent(target, ctx.getEvent, node, ctx) + } + } + } +} diff --git a/tests/untried/neg/t452.check b/tests/untried/neg/t452.check new file mode 100644 index 000000000000..aac663068ebc --- /dev/null +++ b/tests/untried/neg/t452.check @@ -0,0 +1,6 @@ +t452.scala:3: error: type mismatch; + found : Test.type + required: Test.Foo + def this() = this(this); + ^ +one error found diff --git a/tests/untried/neg/t452.scala b/tests/untried/neg/t452.scala new file mode 100644 index 000000000000..855406d0c446 --- /dev/null +++ b/tests/untried/neg/t452.scala @@ -0,0 +1,8 @@ +object Test { + class Foo(x: Foo) { + def this() = this(this); + } + def main(args: Array[String]): Unit = { + new Foo(); + } +} diff --git a/tests/untried/neg/t4541.check b/tests/untried/neg/t4541.check new file mode 100644 index 000000000000..7bd8ff78f945 --- /dev/null +++ b/tests/untried/neg/t4541.check @@ -0,0 +1,7 @@ +t4541.scala:11: error: variable data in class Sparse cannot be accessed in Sparse[Int] + Access to protected method data not permitted because + prefix type Sparse[Int] does not conform to + class Sparse$mcI$sp where the access take place + that.data + ^ +one error found diff --git a/tests/untried/neg/t4541.scala b/tests/untried/neg/t4541.scala new file mode 100644 index 000000000000..744af1c2887d --- /dev/null +++ b/tests/untried/neg/t4541.scala @@ -0,0 +1,16 @@ + + + + + + +@SerialVersionUID(1L) +final class Sparse[@specialized(Int) T](d: Array[T]) extends Serializable { + protected var data: Array[T] = d + def set(that: Sparse[T]) = { + that.data + } +} + + + diff --git a/tests/untried/neg/t4541b.check b/tests/untried/neg/t4541b.check new file mode 100644 index 000000000000..8a52fd97f4d4 --- /dev/null +++ b/tests/untried/neg/t4541b.check @@ -0,0 +1,7 @@ +t4541b.scala:13: error: variable data in class SparseArray cannot be accessed in SparseArray[Int] + Access to protected method data not permitted because + prefix type SparseArray[Int] does not conform to + class SparseArray$mcI$sp where the access take place + use(that.data.clone) + ^ +one error found diff --git a/tests/untried/neg/t4541b.scala b/tests/untried/neg/t4541b.scala new file mode 100644 index 000000000000..ba406cad6d80 --- /dev/null +++ b/tests/untried/neg/t4541b.scala @@ -0,0 +1,16 @@ + + + + + +@SerialVersionUID(1L) +final class SparseArray[@specialized(Int) T](private var data: Array[T]) extends Serializable { + def use(inData: Array[T]) = { + data = inData; + } + + def set(that: SparseArray[T]) = { + use(that.data.clone) + } +} + diff --git a/tests/untried/neg/t4568.check b/tests/untried/neg/t4568.check new file mode 100644 index 000000000000..f94d69948693 --- /dev/null +++ b/tests/untried/neg/t4568.check @@ -0,0 +1,4 @@ +t4568.scala:8: error: recursive method isSubListOf needs result type + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + ^ +one error found diff --git a/tests/untried/neg/t4568.scala b/tests/untried/neg/t4568.scala new file mode 100644 index 000000000000..6fda28736482 --- /dev/null +++ b/tests/untried/neg/t4568.scala @@ -0,0 +1,13 @@ +object SubList { + implicit def sublistable[A](x: List[A]) = new SubListable(x) + + class SubListable[A](x: List[A]) { + def isSubListOf(y: List[A]) = { + x match { + case Nil => true + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + } + } + } + +} diff --git a/tests/untried/neg/t4584.check b/tests/untried/neg/t4584.check new file mode 100644 index 000000000000..97d07afa0edb --- /dev/null +++ b/tests/untried/neg/t4584.check @@ -0,0 +1,7 @@ +t4584.scala:1: error: error in unicode escape +class A { val \u2 + ^ +t4584.scala:1: error: illegal character '\uffff' +class A { val \u2 + ^ +two errors found diff --git a/tests/untried/neg/t4584.scala b/tests/untried/neg/t4584.scala new file mode 100644 index 000000000000..b34aba91a2ba --- /dev/null +++ b/tests/untried/neg/t4584.scala @@ -0,0 +1 @@ +class A { val \u2 \ No newline at end of file diff --git a/tests/untried/neg/t464-neg.check b/tests/untried/neg/t464-neg.check new file mode 100644 index 000000000000..e822e7fb6bfe --- /dev/null +++ b/tests/untried/neg/t464-neg.check @@ -0,0 +1,16 @@ +t464-neg.scala:7: error: not found: value f1 + f1() + ^ +t464-neg.scala:8: error: method f1 in class A cannot be accessed in A + super.f1() + ^ +t464-neg.scala:9: error: value f2 is not a member of B + def otherb(b2: B) = b2.f2() + ^ +t464-neg.scala:10: error: method f3 in class A cannot be accessed in B + f3() + ^ +t464-neg.scala:11: error: method f3 in class A cannot be accessed in A + super.f3() + ^ +5 errors found diff --git a/tests/untried/neg/t464-neg.scala b/tests/untried/neg/t464-neg.scala new file mode 100644 index 000000000000..c2f027a21a94 --- /dev/null +++ b/tests/untried/neg/t464-neg.scala @@ -0,0 +1,12 @@ +class A { + private[this] def f1(): Unit = {} + protected[this] def f2(): Unit = {} + private[A] def f3(): Unit = {} +} +class B extends A { + f1() + super.f1() + def otherb(b2: B) = b2.f2() + f3() + super.f3() +} diff --git a/tests/untried/neg/t4691_exhaust_extractor.check b/tests/untried/neg/t4691_exhaust_extractor.check new file mode 100644 index 000000000000..6396944145df --- /dev/null +++ b/tests/untried/neg/t4691_exhaust_extractor.check @@ -0,0 +1,15 @@ +t4691_exhaust_extractor.scala:17: warning: match may not be exhaustive. +It would fail on the following input: Bar3() + def f1(x: Foo) = x match { + ^ +t4691_exhaust_extractor.scala:23: warning: match may not be exhaustive. +It would fail on the following input: Bar3() + def f2(x: Foo) = x match { + ^ +t4691_exhaust_extractor.scala:29: warning: match may not be exhaustive. +It would fail on the following input: Bar3() + def f3(x: Foo) = x match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t4691_exhaust_extractor.flags b/tests/untried/neg/t4691_exhaust_extractor.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t4691_exhaust_extractor.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t4691_exhaust_extractor.scala b/tests/untried/neg/t4691_exhaust_extractor.scala new file mode 100644 index 000000000000..25b64186dbd7 --- /dev/null +++ b/tests/untried/neg/t4691_exhaust_extractor.scala @@ -0,0 +1,33 @@ +sealed trait Foo +class Bar1 extends Foo +class Bar2 extends Foo +class Bar3 extends Foo + +// these extractors are known to always succeed as they return a Some +object Baz1 { + def unapply(x: Bar1): Some[Int] = Some(1) +} +object Baz2 { + def unapply(x: Bar2): Some[Int] = Some(2) +} + + +object Test { + // warning: missing Bar3 + def f1(x: Foo) = x match { + case _: Bar1 => 1 + case _: Bar2 => 2 + } + + // warning: missing Bar3 + def f2(x: Foo) = x match { + case _: Bar1 => 1 + case Baz2(x) => x + } + + // warning: missing Bar3 + def f3(x: Foo) = x match { + case Baz1(x) => x + case Baz2(x) => x + } +} diff --git a/tests/untried/neg/t4727.check b/tests/untried/neg/t4727.check new file mode 100644 index 000000000000..a17cdde04417 --- /dev/null +++ b/tests/untried/neg/t4727.check @@ -0,0 +1,5 @@ +t4727.scala:5: error: an expression of type Null is ineligible for implicit conversion +Error occurred in an application involving default arguments. + new C[Int] + ^ +one error found diff --git a/tests/untried/neg/t4727.scala b/tests/untried/neg/t4727.scala new file mode 100644 index 000000000000..40c06713caa6 --- /dev/null +++ b/tests/untried/neg/t4727.scala @@ -0,0 +1,7 @@ +class C[T](x : T = null) + +object Test { + def main(args: Array[String]): Unit = { + new C[Int] + } +} diff --git a/tests/untried/neg/t4728.check b/tests/untried/neg/t4728.check new file mode 100644 index 000000000000..c6ef182d34f1 --- /dev/null +++ b/tests/untried/neg/t4728.check @@ -0,0 +1,7 @@ +t4728.scala:10: error: ambiguous reference to overloaded definition, +both method f in object Ambiguous of type (ys: Y*)Int +and method f in object Ambiguous of type (x: X)Int +match argument types (Y) and expected result type Any + println(Ambiguous.f(new Y)) + ^ +one error found diff --git a/tests/untried/neg/t4728.scala b/tests/untried/neg/t4728.scala new file mode 100644 index 000000000000..83d3fc7c2e5b --- /dev/null +++ b/tests/untried/neg/t4728.scala @@ -0,0 +1,11 @@ +class X +class Y extends X +object Ambiguous { + def f(x: X) = 1 + def f(ys: Y*) = 2 +} + +object Test extends App { + println(Ambiguous.f(new X)) + println(Ambiguous.f(new Y)) +} diff --git a/tests/untried/neg/t473.check b/tests/untried/neg/t473.check new file mode 100644 index 000000000000..a14222c9624b --- /dev/null +++ b/tests/untried/neg/t473.check @@ -0,0 +1,4 @@ +t473.scala:3: error: super constructor cannot be passed a self reference unless parameter is declared by-name +case object Voop extends Foo(Voop) + ^ +one error found diff --git a/tests/untried/neg/t473.scala b/tests/untried/neg/t473.scala new file mode 100644 index 000000000000..c7631705ac3e --- /dev/null +++ b/tests/untried/neg/t473.scala @@ -0,0 +1,3 @@ +class Foo(x: Foo) +case object Bar extends Foo(null) +case object Voop extends Foo(Voop) diff --git a/tests/untried/neg/t4749.check b/tests/untried/neg/t4749.check new file mode 100644 index 000000000000..3539140954cd --- /dev/null +++ b/tests/untried/neg/t4749.check @@ -0,0 +1,34 @@ +t4749.scala:2: warning: Fail1 has a main method with parameter type Array[String], but bippy.Fail1 will not be a runnable program. + Reason: main method must have exact signature (Array[String])Unit + object Fail1 { + ^ +t4749.scala:6: warning: Fail2 has a main method with parameter type Array[String], but bippy.Fail2 will not be a runnable program. + Reason: main methods cannot be generic. + object Fail2 { + ^ +t4749.scala:13: warning: Fail3 has a main method with parameter type Array[String], but bippy.Fail3 will not be a runnable program. + Reason: main methods cannot refer to type parameters or abstract types. + object Fail3 extends Bippy[Unit] { } + ^ +t4749.scala:16: warning: Fail4 has a main method with parameter type Array[String], but bippy.Fail4 will not be a runnable program. + Reason: companion is a trait, which means no static forwarder can be generated. + + object Fail4 { + ^ +t4749.scala:21: warning: Fail5 has a main method with parameter type Array[String], but bippy.Fail5 will not be a runnable program. + Reason: companion contains its own main method, which means no static forwarder can be generated. + + object Fail5 extends Fail5 { } + ^ +t4749.scala:26: warning: Fail6 has a main method with parameter type Array[String], but bippy.Fail6 will not be a runnable program. + Reason: companion contains its own main method (implementation restriction: no main is allowed, regardless of signature), which means no static forwarder can be generated. + + object Fail6 { + ^ +t4749.scala:42: warning: Win3 has a main method with parameter type Array[String], but bippy.Win3 will not be a runnable program. + Reason: main method must have exact signature (Array[String])Unit + object Win3 extends WinBippy[Unit] { } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +7 warnings found +one error found diff --git a/tests/untried/neg/t4749.flags b/tests/untried/neg/t4749.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t4749.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t4749.scala b/tests/untried/neg/t4749.scala new file mode 100644 index 000000000000..2c67e2ea9617 --- /dev/null +++ b/tests/untried/neg/t4749.scala @@ -0,0 +1,44 @@ +package bippy { + object Fail1 { + def main(args: Array[String]): Any = () + } + + object Fail2 { + def main[T](args: Array[String]): T = null.asInstanceOf[T] + } + + abstract class Bippy[T] { + def main(args: Array[String]): T = null.asInstanceOf[T] + } + object Fail3 extends Bippy[Unit] { } + + + object Fail4 { + def main(args: Array[String]): Unit = () + } + trait Fail4 { } + + object Fail5 extends Fail5 { } + class Fail5 { + def main(args: Array[String]): Unit = () + } + + object Fail6 { + def main(args: Array[String]): Unit = () + } + class Fail6 { + def main = "bippy" + } + + object Win1 { + def main(args: Array[String]): Unit = () + } + object Win2 extends Bippy[Unit] { + override def main(args: Array[String]): Unit = () + } + trait WinBippy[T] { + def main(args: Array[String]): T = null.asInstanceOf[T] + } + object Win3 extends WinBippy[Unit] { } +} + diff --git a/tests/untried/neg/t4762.check b/tests/untried/neg/t4762.check new file mode 100644 index 000000000000..a0525f6226b2 --- /dev/null +++ b/tests/untried/neg/t4762.check @@ -0,0 +1,9 @@ +t4762.scala:15: warning: private[this] value x in class B shadows mutable x inherited from class A. Changes to x will not be visible within class B - you may want to give them distinct names. + /* (99,99) */ (this.x, this.y), + ^ +t4762.scala:48: warning: private[this] value x in class Derived shadows mutable x inherited from class Base. Changes to x will not be visible within class Derived - you may want to give them distinct names. + class Derived( x : Int ) extends Base( x ) { override def toString = x.toString } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t4762.flags b/tests/untried/neg/t4762.flags new file mode 100644 index 000000000000..e93641e9319e --- /dev/null +++ b/tests/untried/neg/t4762.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t4762.scala b/tests/untried/neg/t4762.scala new file mode 100644 index 000000000000..07b3152a6711 --- /dev/null +++ b/tests/untried/neg/t4762.scala @@ -0,0 +1,51 @@ +// https://issues.scala-lang.org/browse/SI-4762 + +// In A, x and y are -1. +class A(var x: Int) { + val y: Int = -1 +} + +// In B, x and y are 99 and private[this], implicitly so +// in the case of x. +class B(x: Int) extends A(-1) { + private[this] def y: Int = 99 + + // Three distinct results. + def f = List( + /* (99,99) */ (this.x, this.y), + /* (-1,99) */ ((this: B).x, (this: B).y), + /* (-1,-1) */ ((this: A).x, (this: A).y) + ) + + // The 99s tell us we are reading the private[this] + // data of a different instance. + def g(b: B) = List( + /* (-1,99) */ (b.x, b.y), + /* (-1,99) */ ((b: B).x, (b: B).y), + /* (-1,-1) */ ((b: A).x, (b: A).y) + ) +} + +object Test { + def f(x: A) = /* -2 */ x.x + x.y + def g1(x: B) = /* -2 */ (x: A).x + (x: A).y + def g2(x: B) = (x: B).x + (x: B).y + // java.lang.IllegalAccessError: tried to access method B.y()I from class Test$ + + def main(args: Array[String]): Unit = { + val b = new B(99) + b.f foreach println + b.g(new B(99)) foreach println + + println(f(b)) + println(g1(b)) + println(g2(b)) + } +} + +class bug4762 { + class Base( var x : Int ) { def increment(): Unit = { x = x + 1 } } + class Derived( x : Int ) extends Base( x ) { override def toString = x.toString } + + val derived = new Derived( 1 ) +} diff --git a/tests/untried/neg/t4818.check b/tests/untried/neg/t4818.check new file mode 100644 index 000000000000..a5e15e456b82 --- /dev/null +++ b/tests/untried/neg/t4818.check @@ -0,0 +1,6 @@ +t4818.scala:4: error: type mismatch; + found : Int(5) + required: Nothing + def f(x: Any) = x match { case Fn(f) => f(5) } + ^ +one error found diff --git a/tests/untried/neg/t4818.scala b/tests/untried/neg/t4818.scala new file mode 100644 index 000000000000..faae2292065d --- /dev/null +++ b/tests/untried/neg/t4818.scala @@ -0,0 +1,7 @@ +object Test { + case class Fn[A, B](f: A => B) + + def f(x: Any) = x match { case Fn(f) => f(5) } + + Fn((x: String) => x) +} diff --git a/tests/untried/neg/t4831.check b/tests/untried/neg/t4831.check new file mode 100644 index 000000000000..3b8b836f05a5 --- /dev/null +++ b/tests/untried/neg/t4831.check @@ -0,0 +1,7 @@ +t4831.scala:10: error: reference to b is ambiguous; +it is imported twice in the same scope by +import O.b +and import O.{a=>b} + println(b) + ^ +one error found diff --git a/tests/untried/neg/t4831.scala b/tests/untried/neg/t4831.scala new file mode 100644 index 000000000000..82346ec57dc0 --- /dev/null +++ b/tests/untried/neg/t4831.scala @@ -0,0 +1,11 @@ +object O { + val a = 0 + val b = 1 +} + +import O.{a => b} +import O.b + +object test { + println(b) +} diff --git a/tests/untried/neg/t4842.check b/tests/untried/neg/t4842.check new file mode 100644 index 000000000000..b53bbdbd15d0 --- /dev/null +++ b/tests/untried/neg/t4842.check @@ -0,0 +1,7 @@ +t4842.scala:2: error: self constructor arguments cannot reference unconstructed `this` + def this(x: Int) = this(new { println(Foo.this)}) // error + ^ +t4842.scala:6: error: self constructor arguments cannot reference unconstructed `this` + def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error + ^ +two errors found diff --git a/tests/untried/neg/t4842.scala b/tests/untried/neg/t4842.scala new file mode 100644 index 000000000000..c6244efda7b2 --- /dev/null +++ b/tests/untried/neg/t4842.scala @@ -0,0 +1,7 @@ +class Foo (x: AnyRef) { + def this(x: Int) = this(new { println(Foo.this)}) // error +} + +class TypeArg[X](val x: X)(a: AnyRef) { + def this() = { this(???)(new { println(TypeArg.this.x) } ); println("next") } // error +} diff --git a/tests/untried/neg/t4851.check b/tests/untried/neg/t4851.check new file mode 100644 index 000000000000..132dd91b504a --- /dev/null +++ b/tests/untried/neg/t4851.check @@ -0,0 +1,51 @@ +S.scala:2: warning: Adaptation of argument list by inserting () has been deprecated: leaky (Object-receiving) target makes this especially dangerous. + signature: J(x: Any): J + given arguments: + after adaptation: new J((): Unit) + val x1 = new J + ^ +S.scala:3: warning: Adaptation of argument list by inserting () has been deprecated: leaky (Object-receiving) target makes this especially dangerous. + signature: J(x: Any): J + given arguments: + after adaptation: new J((): Unit) + val x2 = new J() + ^ +S.scala:4: warning: Adapting argument list by creating a 5-tuple: this may not be what you want. + signature: J(x: Any): J + given arguments: 1, 2, 3, 4, 5 + after adaptation: new J((1, 2, 3, 4, 5): (Int, Int, Int, Int, Int)) + val x3 = new J(1, 2, 3, 4, 5) + ^ +S.scala:6: warning: Adapting argument list by creating a 3-tuple: this may not be what you want. + signature: Some.apply[A](x: A): Some[A] + given arguments: 1, 2, 3 + after adaptation: Some((1, 2, 3): (Int, Int, Int)) + val y1 = Some(1, 2, 3) + ^ +S.scala:7: warning: Adapting argument list by creating a 3-tuple: this may not be what you want. + signature: Some(x: A): Some[A] + given arguments: 1, 2, 3 + after adaptation: new Some((1, 2, 3): (Int, Int, Int)) + val y2 = new Some(1, 2, 3) + ^ +S.scala:9: warning: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want. + signature: J2[T](x: T): J2[T] + given arguments: + after adaptation: new J2((): Unit) + val z1 = new J2 + ^ +S.scala:10: warning: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want. + signature: J2[T](x: T): J2[T] + given arguments: + after adaptation: new J2((): Unit) + val z2 = new J2() + ^ +S.scala:14: warning: Adapting argument list by creating a 3-tuple: this may not be what you want. + signature: Test.anyId(a: Any): Any + given arguments: 1, 2, 3 + after adaptation: Test.anyId((1, 2, 3): (Int, Int, Int)) + val w1 = anyId(1, 2 ,3) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/t4851.flags b/tests/untried/neg/t4851.flags new file mode 100644 index 000000000000..ca0d0a0ba31b --- /dev/null +++ b/tests/untried/neg/t4851.flags @@ -0,0 +1 @@ +-Ywarn-adapted-args -Xfatal-warnings -deprecation diff --git a/tests/untried/neg/t4851/J.java b/tests/untried/neg/t4851/J.java new file mode 100644 index 000000000000..9c35b8a16e49 --- /dev/null +++ b/tests/untried/neg/t4851/J.java @@ -0,0 +1,15 @@ +public class J { + Object x; + + public J(Object x) { + this.x = x; + } + + public J(int x1, int x2, int x3, int x4, int x5, int x6) { + this.x = null; + } + + public String toString() { + return "J:" + x.getClass(); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t4851/J2.java b/tests/untried/neg/t4851/J2.java new file mode 100644 index 000000000000..82954d94893a --- /dev/null +++ b/tests/untried/neg/t4851/J2.java @@ -0,0 +1,11 @@ +public class J2 { + T x; + + public J(T x) { + this.x = x; + } + + public String toString() { + return "J2:" + x.getClass(); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t4851/S.scala b/tests/untried/neg/t4851/S.scala new file mode 100644 index 000000000000..779ba376b03f --- /dev/null +++ b/tests/untried/neg/t4851/S.scala @@ -0,0 +1,28 @@ +object Test { + val x1 = new J + val x2 = new J() + val x3 = new J(1, 2, 3, 4, 5) + + val y1 = Some(1, 2, 3) + val y2 = new Some(1, 2, 3) + + val z1 = new J2 + val z2 = new J2() + val z3 = new J2(()) + + def anyId(a: Any) = a + val w1 = anyId(1, 2 ,3) + + def main(args: Array[String]): Unit = { + println(x1) + println(x2) + println(x3) + println(y1) + + println(z1) + println(z2) + println(z3) + + println(w1) + } +} diff --git a/tests/untried/neg/t4877.check b/tests/untried/neg/t4877.check new file mode 100644 index 000000000000..5a2413ca8b28 --- /dev/null +++ b/tests/untried/neg/t4877.check @@ -0,0 +1,22 @@ +t4877.scala:4: error: type mismatch; + found : AnyRef{def bar: Int} + required: AnyRef{def bar: String} + def foo: AnyRef { def bar: String } = new AnyRef { def bar = 42 } + ^ +t4877.scala:6: error: type mismatch; + found : AnyRef{def bar(x: Int): String} + required: AnyRef{def bar(x: Int): Int} + def foo3: AnyRef { def bar(x: Int): Int } = new AnyRef { def bar(x: Int) = "abc" } + ^ +t4877.scala:7: error: type mismatch; + found : C{def bar(x: Int): Int} + required: C{def bar(x: Int): Int; def quux(x: Int): Int} + def foo4: C { def bar(x: Int): Int ; def quux(x: Int): Int } = new C { def bar(x: Int) = 5 } + ^ +t4877.scala:17: error: type mismatch; + found : AnyRef{type Mom = String; def bar(x: Int): Int; def bippy(): List[Int]} + required: B.this.Bippy + (which expands to) AnyRef{type Mom; def bar(x: Int): this.Mom; def bippy(): List[this.Mom]} + val x: Bippy = new AnyRef { + ^ +four errors found diff --git a/tests/untried/neg/t4877.flags b/tests/untried/neg/t4877.flags new file mode 100644 index 000000000000..7ccd56103ae5 --- /dev/null +++ b/tests/untried/neg/t4877.flags @@ -0,0 +1 @@ +-Xlint \ No newline at end of file diff --git a/tests/untried/neg/t4877.scala b/tests/untried/neg/t4877.scala new file mode 100644 index 000000000000..8968a8a8f6d4 --- /dev/null +++ b/tests/untried/neg/t4877.scala @@ -0,0 +1,22 @@ +trait C { } + +class A { + def foo: AnyRef { def bar: String } = new AnyRef { def bar = 42 } + def foo2: AnyRef { def bar: String } = new AnyRef { def bar = "abc" } + def foo3: AnyRef { def bar(x: Int): Int } = new AnyRef { def bar(x: Int) = "abc" } + def foo4: C { def bar(x: Int): Int ; def quux(x: Int): Int } = new C { def bar(x: Int) = 5 } +} + +class B { + type Bippy = { + type Mom + def bar(x: Int): Mom + def bippy(): List[Mom] + } + + val x: Bippy = new AnyRef { + type Mom = String + def bar(x: Int) = 55 + def bippy() = List(bar(55)) + } +} diff --git a/tests/untried/neg/t4879.check b/tests/untried/neg/t4879.check new file mode 100644 index 000000000000..c7edd583c896 --- /dev/null +++ b/tests/untried/neg/t4879.check @@ -0,0 +1,13 @@ +t4879.scala:6: error: pattern type is incompatible with expected type; + found : C.type + required: C +Note: if you intended to match against the class, try `case C(_)` + case C => true + ^ +t4879.scala:10: error: pattern type is incompatible with expected type; + found : D.type + required: D[T,U,V] +Note: if you intended to match against the class, try `case D(_,_,_)` + case D => true + ^ +two errors found diff --git a/tests/untried/neg/t4879.scala b/tests/untried/neg/t4879.scala new file mode 100644 index 000000000000..7d6561e9e091 --- /dev/null +++ b/tests/untried/neg/t4879.scala @@ -0,0 +1,15 @@ +case class C(d: Double) { } +case class D[T, U, V](bingo: Int, donkey: String, private val vegas: Set[A])(jehovah: Int) { } + +class A { + def f = (new C(5)) match { + case C => true + case _ => false + } + def g[T, U, V](x: D[T, U, V]) = x match { + case D => true + case _ => false + } +} + + diff --git a/tests/untried/neg/t4882.check b/tests/untried/neg/t4882.check new file mode 100644 index 000000000000..0aafc8277067 --- /dev/null +++ b/tests/untried/neg/t4882.check @@ -0,0 +1,4 @@ +t4882.scala:2: error: `implicit' modifier not allowed for constructors + implicit def this(a: String) = this(a.toInt) + ^ +one error found diff --git a/tests/untried/neg/t4882.scala b/tests/untried/neg/t4882.scala new file mode 100644 index 000000000000..4e58ef78795a --- /dev/null +++ b/tests/untried/neg/t4882.scala @@ -0,0 +1,3 @@ +class Foo(value: Int) { + implicit def this(a: String) = this(a.toInt) +} diff --git a/tests/untried/neg/t4928.check b/tests/untried/neg/t4928.check new file mode 100644 index 000000000000..18a5d57a62cb --- /dev/null +++ b/tests/untried/neg/t4928.check @@ -0,0 +1,5 @@ +t4928.scala:3: error: parameter 'a' is already specified at parameter position 1 +Note that 'z' is not a parameter name of the invoked method. + f(z = 0, a = 1) + ^ +one error found diff --git a/tests/untried/neg/t4928.scala b/tests/untried/neg/t4928.scala new file mode 100644 index 000000000000..17a59803146c --- /dev/null +++ b/tests/untried/neg/t4928.scala @@ -0,0 +1,4 @@ +class C { + def f(a: Int, b: Int = 0) = 0 + f(z = 0, a = 1) +} diff --git a/tests/untried/neg/t4987.check b/tests/untried/neg/t4987.check new file mode 100644 index 000000000000..8d7344d27b55 --- /dev/null +++ b/tests/untried/neg/t4987.check @@ -0,0 +1,4 @@ +t4987.scala:2: error: constructor Foo2 in class Foo2 cannot be accessed in object Bar2 +object Bar2 { new Foo2(0, 0) } + ^ +one error found diff --git a/tests/untried/neg/t4987.scala b/tests/untried/neg/t4987.scala new file mode 100644 index 000000000000..e55acd4127f8 --- /dev/null +++ b/tests/untried/neg/t4987.scala @@ -0,0 +1,2 @@ +class Foo2 private (a: Int, b: Int) +object Bar2 { new Foo2(0, 0) } diff --git a/tests/untried/neg/t4989.check b/tests/untried/neg/t4989.check new file mode 100644 index 000000000000..814507fc3ffb --- /dev/null +++ b/tests/untried/neg/t4989.check @@ -0,0 +1,7 @@ +t4989.scala:14: error: method print in class A cannot be directly accessed from class C because class B redeclares it as abstract + override def print(): String = super.print() // should be an error + ^ +t4989.scala:18: error: method print in class A cannot be directly accessed from trait T because class B redeclares it as abstract + override def print(): String = super.print() // should be an error + ^ +two errors found diff --git a/tests/untried/neg/t4989.scala b/tests/untried/neg/t4989.scala new file mode 100644 index 000000000000..e7ff80ed74c2 --- /dev/null +++ b/tests/untried/neg/t4989.scala @@ -0,0 +1,68 @@ +abstract class A0 { + def print(): String +} + +class A extends A0 { + def print(): String = "A" +} + +abstract class B extends A { + def print() : String +} + +class C extends B { + override def print(): String = super.print() // should be an error +} + +trait T extends B { + override def print(): String = super.print() // should be an error +} + +class D extends A { + override def print(): String = super.print() // okay +} + + +// it's okay do this when trait are in the mix, as the +// suitable super accessor methods are used. +object ConcreteMethodAndIntermediaryAreTraits { + trait T1 { + def print(): String = "" + } + + trait T2 extends T1 { + def print(): String + } + + class C3 extends T2 { + def print(): String = super.print() // okay + } +} + +object IntermediaryIsTrait { + class T1 { + def print(): String = "" + } + + trait T2 extends T1 { + def print(): String + } + + class C3 extends T2 { + override def print(): String = super.print() // okay + } +} + +object ConcreteMethodIsTrait { + trait T1 { + def print(): String = "" + } + + abstract class T2 extends T1 { + def print(): String + } + + class C3 extends T2 { + override def print(): String = super.print() // okay + } +} diff --git a/tests/untried/neg/t500.check b/tests/untried/neg/t500.check new file mode 100644 index 000000000000..b3f5c8597875 --- /dev/null +++ b/tests/untried/neg/t500.check @@ -0,0 +1,4 @@ +t500.scala:3: error: lower bound X does not conform to upper bound Y + type T >: X <: Y; + ^ +one error found diff --git a/tests/untried/neg/t500.scala b/tests/untried/neg/t500.scala new file mode 100644 index 000000000000..d843d71f076b --- /dev/null +++ b/tests/untried/neg/t500.scala @@ -0,0 +1,22 @@ +object Magic { + abstract class O[X,Y] { + type T >: X <: Y; + class I { def magic(v: T): T = v; } + } + def magic[X,Y](v: X): Y = { + val o: O[X,Y] = null; + val i: o.I = new o.I(); + i.magic(v); + } +} + +object Test { + def main(args: Array[String]): Unit = { + try { + val i: Int = Magic.magic("42"); + Console.println(i); + } catch { + case ex: Throwable => ex.printStackTrace() + } + } +} diff --git a/tests/untried/neg/t501.check b/tests/untried/neg/t501.check new file mode 100644 index 000000000000..3e3bf390757a --- /dev/null +++ b/tests/untried/neg/t501.check @@ -0,0 +1,4 @@ +t501.scala:3: error: lower bound X does not conform to upper bound Y + abstract class I { type T >: X <: Y; } + ^ +one error found diff --git a/tests/untried/neg/t501.scala b/tests/untried/neg/t501.scala new file mode 100644 index 000000000000..437ab8f21e89 --- /dev/null +++ b/tests/untried/neg/t501.scala @@ -0,0 +1,18 @@ +object Magic { + class O[X,Y] { + abstract class I { type T >: X <: Y; } + val i: I = null; + def magic(v: i.T): i.T = v; + } + def magic[X,Y](v: X): Y = { + val o: O[X,Y] = new O(); + o.magic(v); + } +} + +object Test { + def main(args: Array[String]): Unit = { + val i: Int = Magic.magic("42"); + Console.println(i); + } +} diff --git a/tests/untried/neg/t5031.check b/tests/untried/neg/t5031.check new file mode 100644 index 000000000000..2f1090c32158 --- /dev/null +++ b/tests/untried/neg/t5031.check @@ -0,0 +1,5 @@ +package.scala:2: error: Companions 'class Test' and 'object Test' must be defined in same file: + Found in t5031/package.scala and t5031/Id.scala + class Test + ^ +one error found diff --git a/tests/untried/neg/t5031/Id.scala b/tests/untried/neg/t5031/Id.scala new file mode 100644 index 000000000000..2f0db002d254 --- /dev/null +++ b/tests/untried/neg/t5031/Id.scala @@ -0,0 +1,4 @@ +package t5031 + +object Test + diff --git a/tests/untried/neg/t5031/package.scala b/tests/untried/neg/t5031/package.scala new file mode 100644 index 000000000000..17b63220bece --- /dev/null +++ b/tests/untried/neg/t5031/package.scala @@ -0,0 +1,3 @@ +package object t5031 { + class Test +} diff --git a/tests/untried/neg/t5031b.check b/tests/untried/neg/t5031b.check new file mode 100644 index 000000000000..3bc2284a4d79 --- /dev/null +++ b/tests/untried/neg/t5031b.check @@ -0,0 +1,5 @@ +b.scala:3: error: Companions 'class Bippy' and 'object Bippy' must be defined in same file: + Found in t5031b/a.scala and t5031b/b.scala +object Bippy + ^ +one error found diff --git a/tests/untried/neg/t5031b/a.scala b/tests/untried/neg/t5031b/a.scala new file mode 100644 index 000000000000..0ab9aa9769ef --- /dev/null +++ b/tests/untried/neg/t5031b/a.scala @@ -0,0 +1,3 @@ +package foo + +class Bippy diff --git a/tests/untried/neg/t5031b/b.scala b/tests/untried/neg/t5031b/b.scala new file mode 100644 index 000000000000..bdef237af561 --- /dev/null +++ b/tests/untried/neg/t5031b/b.scala @@ -0,0 +1,3 @@ +package foo + +object Bippy diff --git a/tests/untried/neg/t5044.check b/tests/untried/neg/t5044.check new file mode 100644 index 000000000000..197da2a4e8ab --- /dev/null +++ b/tests/untried/neg/t5044.check @@ -0,0 +1,9 @@ +t5044.scala:7: error: recursive value a needs type + val id = m(a) + ^ +t5044.scala:6: warning: type-checking the invocation of method foo checks if the named argument expression 'id = ...' is a valid assignment +in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for id. + val a = foo(id = 1) + ^ +one warning found +one error found diff --git a/tests/untried/neg/t5044.scala b/tests/untried/neg/t5044.scala new file mode 100644 index 000000000000..8ea8ef67f88b --- /dev/null +++ b/tests/untried/neg/t5044.scala @@ -0,0 +1,9 @@ +class T { + def foo[T](id: T) = 0 + def m(a: Int) = 0 + + def f: Unit = { + val a = foo(id = 1) + val id = m(a) + } +} diff --git a/tests/untried/neg/t5060.check b/tests/untried/neg/t5060.check new file mode 100644 index 000000000000..09b2d9a4b1b5 --- /dev/null +++ b/tests/untried/neg/t5060.check @@ -0,0 +1,7 @@ +t5060.scala:2: error: covariant type T occurs in contravariant position in type => AnyRef{def contains(x: T): Unit} of value foo0 + val foo0 = { + ^ +t5060.scala:6: error: covariant type T occurs in contravariant position in type => AnyRef{def contains(x: T): Unit} of method foo1 + def foo1 = { + ^ +two errors found diff --git a/tests/untried/neg/t5060.scala b/tests/untried/neg/t5060.scala new file mode 100644 index 000000000000..4d934a9a164d --- /dev/null +++ b/tests/untried/neg/t5060.scala @@ -0,0 +1,19 @@ +class A[+T] { + val foo0 = { + class AsVariantAsIWantToBe { def contains(x: T) = () } + new AsVariantAsIWantToBe + } + def foo1 = { + class VarianceIsTheSpiceOfTypes { def contains(x: T) = () } + new VarianceIsTheSpiceOfTypes + } +} + +object Test { + def main(args: Array[String]): Unit = { + val xs: A[String] = new A[String] + println(xs.foo0 contains "abc") + println((xs: A[Any]).foo0 contains 5) + // java.lang.NoSuchMethodException: A$AsVariantAsIWantToBe$1.contains(java.lang.String) + } +} diff --git a/tests/untried/neg/t5063.check b/tests/untried/neg/t5063.check new file mode 100644 index 000000000000..c6e553c1b5f6 --- /dev/null +++ b/tests/untried/neg/t5063.check @@ -0,0 +1,4 @@ +t5063.scala:2: error: value + is not a member of AnyRef + super.+("") + ^ +one error found diff --git a/tests/untried/neg/t5063.scala b/tests/untried/neg/t5063.scala new file mode 100644 index 000000000000..5b34b53fb7fc --- /dev/null +++ b/tests/untried/neg/t5063.scala @@ -0,0 +1,3 @@ +class A { + super.+("") +} diff --git a/tests/untried/neg/t5067.check b/tests/untried/neg/t5067.check new file mode 100644 index 000000000000..32491766d75c --- /dev/null +++ b/tests/untried/neg/t5067.check @@ -0,0 +1,6 @@ +t5067.scala:3: error: type mismatch; + found : ((Int, Int)) => Int + required: (Int, Int) => Int + override def tupled: (Int, Int) => Int = super.tupled + ^ +one error found diff --git a/tests/untried/neg/t5067.scala b/tests/untried/neg/t5067.scala new file mode 100644 index 000000000000..f8235c0e8354 --- /dev/null +++ b/tests/untried/neg/t5067.scala @@ -0,0 +1,4 @@ +class Foo extends Function2[Int, Int, Int] { + def apply(x: Int, y: Int) = x + y + override def tupled: (Int, Int) => Int = super.tupled +} diff --git a/tests/untried/neg/t5078.check b/tests/untried/neg/t5078.check new file mode 100644 index 000000000000..8f66445b03c8 --- /dev/null +++ b/tests/untried/neg/t5078.check @@ -0,0 +1,13 @@ +t5078.scala:7: error: an unapply method must accept a single argument. + val Foo(x1) = 1 + ^ +t5078.scala:7: error: recursive value x1 needs type + val Foo(x1) = 1 + ^ +t5078.scala:8: error: an unapply method must accept a single argument. + val Foo2(y2) = 2 + ^ +t5078.scala:8: error: recursive value y2 needs type + val Foo2(y2) = 2 + ^ +four errors found diff --git a/tests/untried/neg/t5078.scala b/tests/untried/neg/t5078.scala new file mode 100644 index 000000000000..2e727e773de8 --- /dev/null +++ b/tests/untried/neg/t5078.scala @@ -0,0 +1,11 @@ +object Foo { def unapply: Option[Int] = Some(42) } +object Foo2 { def unapply(): Option[Int] = Some(42) } + + +object Test { + def main(args: Array[String]): Unit = { + val Foo(x1) = 1 + val Foo2(y2) = 2 + () + } +} diff --git a/tests/untried/neg/t5093.check b/tests/untried/neg/t5093.check new file mode 100644 index 000000000000..daba46001153 --- /dev/null +++ b/tests/untried/neg/t5093.check @@ -0,0 +1,10 @@ +t5093.scala:2: error: illegal cyclic reference involving type C + def f[C[X] <: C[X]](l: C[_]) = l.x + ^ +t5093.scala:2: error: cyclic aliasing or subtyping involving type C + def f[C[X] <: C[X]](l: C[_]) = l.x + ^ +t5093.scala:2: error: C does not take type parameters + def f[C[X] <: C[X]](l: C[_]) = l.x + ^ +three errors found diff --git a/tests/untried/neg/t5093.scala b/tests/untried/neg/t5093.scala new file mode 100644 index 000000000000..9cde364dee4c --- /dev/null +++ b/tests/untried/neg/t5093.scala @@ -0,0 +1,3 @@ +class T { + def f[C[X] <: C[X]](l: C[_]) = l.x +} diff --git a/tests/untried/neg/t510.check b/tests/untried/neg/t510.check new file mode 100644 index 000000000000..355a6cdf0748 --- /dev/null +++ b/tests/untried/neg/t510.check @@ -0,0 +1,4 @@ +t510.scala:19: error: cyclic aliasing or subtyping involving type T + def g(t: e.T): Unit = { + ^ +one error found diff --git a/tests/untried/neg/t510.scala b/tests/untried/neg/t510.scala new file mode 100644 index 000000000000..a1cd2df009d7 --- /dev/null +++ b/tests/untried/neg/t510.scala @@ -0,0 +1,26 @@ +abstract class C { + + type T <: Any; + +} + +abstract class D[S <: C](_c: S) extends C { + + val c: S = _c; + type T <: c.T; + +} + +abstract class E(e: E) extends D[E](e); + +object Test { + + def f(e: E): Unit = { + def g(t: e.T): Unit = { + val i: Int = t; + () + } + () + } + +} diff --git a/tests/untried/neg/t5106.check b/tests/untried/neg/t5106.check new file mode 100644 index 000000000000..ac16041cf7a8 --- /dev/null +++ b/tests/untried/neg/t5106.check @@ -0,0 +1,11 @@ +t5106.scala:3: error: type mismatch; + found : Int(4) + required: String + val (n, l): (String, Int) = (4, "") + ^ +t5106.scala:3: error: type mismatch; + found : String("") + required: Int + val (n, l): (String, Int) = (4, "") + ^ +two errors found diff --git a/tests/untried/neg/t5106.scala b/tests/untried/neg/t5106.scala new file mode 100644 index 000000000000..6508662fd48e --- /dev/null +++ b/tests/untried/neg/t5106.scala @@ -0,0 +1,5 @@ +class A { + def f: Unit = { + val (n, l): (String, Int) = (4, "") + } +} diff --git a/tests/untried/neg/t512.check b/tests/untried/neg/t512.check new file mode 100644 index 000000000000..051e5ee19f1d --- /dev/null +++ b/tests/untried/neg/t512.check @@ -0,0 +1,7 @@ +t512.scala:3: error: not found: value something + val xxx = something || + ^ +t512.scala:4: error: not found: value something_else + something_else; + ^ +two errors found diff --git a/tests/untried/neg/t512.scala b/tests/untried/neg/t512.scala new file mode 100644 index 000000000000..0a0ccde75ce1 --- /dev/null +++ b/tests/untried/neg/t512.scala @@ -0,0 +1,5 @@ +package test; +class Foo { + val xxx = something || + something_else; +} diff --git a/tests/untried/neg/t5120.check b/tests/untried/neg/t5120.check new file mode 100644 index 000000000000..34d4ebde316f --- /dev/null +++ b/tests/untried/neg/t5120.check @@ -0,0 +1,12 @@ +t5120.scala:11: error: type mismatch; + found : Object + required: _1 + List(str, other) foreach (_.x1 = new AnyRef) + ^ +t5120.scala:25: error: type mismatch; + found : Thread + required: h.T + (which expands to) _2 + List(str, num).foreach(h => h.f1 = new Thread()) + ^ +two errors found diff --git a/tests/untried/neg/t5120.scala b/tests/untried/neg/t5120.scala new file mode 100644 index 000000000000..478436d85dc7 --- /dev/null +++ b/tests/untried/neg/t5120.scala @@ -0,0 +1,29 @@ +class Cell[T](x0: T) { + type U = T + var x1: U = x0 +} + +object Test { + val str: Cell[String] = new Cell("a") + val other: Cell[Int] = new Cell(0) + + def main(args: Array[String]): Unit = { + List(str, other) foreach (_.x1 = new AnyRef) + str.x1.length + } +} +// another way demonstrating the same underlying problem, as reported by roman kalukiewicz + +class Holder[_T](_f1 : _T, _f2 : _T) { + type T = _T + var f1 : T = _f1 + var f2 : T = _f2 +} +object Test2 { + val str = new Holder("t1", "t2") + val num = new Holder(1, 2) + List(str, num).foreach(h => h.f1 = new Thread()) + def main(args: Array[String]): Unit = { + println(str.f1) + } +} diff --git a/tests/untried/neg/t5148.check b/tests/untried/neg/t5148.check new file mode 100644 index 000000000000..f426bd201034 --- /dev/null +++ b/tests/untried/neg/t5148.check @@ -0,0 +1,5 @@ +error: bad symbolic reference. A signature in Imports.class refers to type Request +in class scala.tools.nsc.interpreter.IMain which is not available. +It may be completely missing from the current classpath, or the version on +the classpath might be incompatible with the version used when compiling Imports.class. +one error found diff --git a/tests/untried/neg/t5148.scala b/tests/untried/neg/t5148.scala new file mode 100644 index 000000000000..fca64e57df48 --- /dev/null +++ b/tests/untried/neg/t5148.scala @@ -0,0 +1,4 @@ +package scala.tools.nsc +package interpreter + +class IMain extends Imports diff --git a/tests/untried/neg/t515.check b/tests/untried/neg/t515.check new file mode 100644 index 000000000000..47d2d30d0180 --- /dev/null +++ b/tests/untried/neg/t515.check @@ -0,0 +1,6 @@ +t515.scala:7: error: type mismatch; + found : String + required: Test.Truc + val parent: Truc = file.getMachin + ^ +one error found diff --git a/tests/untried/neg/t515.scala b/tests/untried/neg/t515.scala new file mode 100644 index 000000000000..bb2376dcab5c --- /dev/null +++ b/tests/untried/neg/t515.scala @@ -0,0 +1,8 @@ +object Test extends App { + class Truc { + def getMachin() = "machin" + def getMachinAsTruc() = this + } + val file = new Truc + val parent: Truc = file.getMachin +} diff --git a/tests/untried/neg/t5152.check b/tests/untried/neg/t5152.check new file mode 100644 index 000000000000..fd510dbae0a1 --- /dev/null +++ b/tests/untried/neg/t5152.check @@ -0,0 +1,11 @@ +t5152.scala:7: error: kinds of the type arguments (Test.B) do not conform to the expected kinds of the type parameters (type E) in class A. +Test.B's type parameters do not match type E's expected parameters: +type E has one type parameter, but type _ has none + class B[E[_]] extends A[B] { } // B is depth 2 but A requires 1 + ^ +t5152.scala:11: error: kinds of the type arguments (Test.B1) do not conform to the expected kinds of the type parameters (type E) in class A1. +Test.B1's type parameters do not match type E's expected parameters: +type _ has no type parameters, but type G has one + class B1[E[_]] extends A1[B1] // B1 is depth 2 but A1 requires 3 + ^ +two errors found diff --git a/tests/untried/neg/t5152.scala b/tests/untried/neg/t5152.scala new file mode 100644 index 000000000000..56df31ed41b3 --- /dev/null +++ b/tests/untried/neg/t5152.scala @@ -0,0 +1,17 @@ +object Test { + new C + new C1 + new C2 + + class A[E[_]] { } + class B[E[_]] extends A[B] { } // B is depth 2 but A requires 1 + class C extends B { } + + class A1[E[F[G[_]]]] { } + class B1[E[_]] extends A1[B1] // B1 is depth 2 but A1 requires 3 + class C1 extends B1 { } + + class A2[E[_]] { } + class B2[E] extends A2[B2] { } // this one is correct + class C2 extends B2 { } +} diff --git a/tests/untried/neg/t5182.check b/tests/untried/neg/t5182.check new file mode 100644 index 000000000000..3161f92680cc --- /dev/null +++ b/tests/untried/neg/t5182.check @@ -0,0 +1,7 @@ +t5182.scala:2: error: unknown annotation argument name: qwe + @java.lang.Deprecated(qwe = "wer") def ok(q:Int) = 1 + ^ +t5182.scala:3: error: classfile annotation arguments have to be supplied as named arguments + @java.lang.Deprecated("wer") def whereAmI(q:Int) = 1 + ^ +two errors found diff --git a/tests/untried/neg/t5182.flags b/tests/untried/neg/t5182.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t5182.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t5182.scala b/tests/untried/neg/t5182.scala new file mode 100644 index 000000000000..0687e99efb57 --- /dev/null +++ b/tests/untried/neg/t5182.scala @@ -0,0 +1,5 @@ +class test { + @java.lang.Deprecated(qwe = "wer") def ok(q:Int) = 1 + @java.lang.Deprecated("wer") def whereAmI(q:Int) = 1 + @java.lang.Deprecated() def bippy(q:Int) = 1 +} diff --git a/tests/untried/neg/t5189.check b/tests/untried/neg/t5189.check new file mode 100644 index 000000000000..4885de99cd9e --- /dev/null +++ b/tests/untried/neg/t5189.check @@ -0,0 +1,6 @@ +t5189.scala:3: error: type mismatch; + found : Nothing => Any + required: Any => Any + def f(x: Any): Any => Any = x match { case Foo(bar) => bar } + ^ +one error found diff --git a/tests/untried/neg/t5189.scala b/tests/untried/neg/t5189.scala new file mode 100644 index 000000000000..19e8e74667e0 --- /dev/null +++ b/tests/untried/neg/t5189.scala @@ -0,0 +1,5 @@ +class TestNeg1 { + case class Foo[T, U](f: T => U) + def f(x: Any): Any => Any = x match { case Foo(bar) => bar } + // uh-oh, Any => Any should be Nothing => Any. +} diff --git a/tests/untried/neg/t5189_inferred.check b/tests/untried/neg/t5189_inferred.check new file mode 100644 index 000000000000..9cc5dcc24248 --- /dev/null +++ b/tests/untried/neg/t5189_inferred.check @@ -0,0 +1,6 @@ +t5189_inferred.scala:7: error: type mismatch; + found : scala.collection.immutable.Nil.type + required: ?A1 where type ?A1 + f(Invariant(arr): Covariant[Any])(0) = Nil + ^ +one error found diff --git a/tests/untried/neg/t5189_inferred.scala b/tests/untried/neg/t5189_inferred.scala new file mode 100644 index 000000000000..c97b4117cf40 --- /dev/null +++ b/tests/untried/neg/t5189_inferred.scala @@ -0,0 +1,8 @@ +trait Covariant[+A] +case class Invariant[A](xs: Array[A]) extends Covariant[A] + +class Test { + val arr = Array("abc") + def f[A](v: Covariant[A]) /*inferred!*/ = v match { case Invariant(xs) => xs } + f(Invariant(arr): Covariant[Any])(0) = Nil +} diff --git a/tests/untried/neg/t5189b.check b/tests/untried/neg/t5189b.check new file mode 100644 index 000000000000..46996e96d064 --- /dev/null +++ b/tests/untried/neg/t5189b.check @@ -0,0 +1,11 @@ +t5189b.scala:38: error: type mismatch; + found : TestNeg.Wrapped[?T7] where type ?T7 <: T (this is a GADT skolem) + required: TestNeg.Wrapped[T] +Note: ?T7 <: T, but class Wrapped is invariant in type W. +You may wish to define W as +W instead. (SLS 4.5) + case Wrapper/*[_ <: T ]*/(wrapped) => wrapped // : Wrapped[_ <: T], which is a subtype of Wrapped[T] if and only if Wrapped is covariant in its type parameter + ^ +t5189b.scala:51: error: value foo is not a member of type parameter T + case Some(xs) => xs.foo // the error message should not refer to a skolem (testing extrapolation) + ^ +two errors found diff --git a/tests/untried/neg/t5189b.scala b/tests/untried/neg/t5189b.scala new file mode 100644 index 000000000000..7c1871dc97e9 --- /dev/null +++ b/tests/untried/neg/t5189b.scala @@ -0,0 +1,80 @@ +class TestPos { + class AbsWrapperCov[+A] + case class Wrapper[B](x: B) extends AbsWrapperCov[B] + + def unwrap[T](x: AbsWrapperCov[T]): T = x match { + case Wrapper/*[_ <: T ]*/(x) => x // _ <: T, which is a subtype of T + } + + def unwrapOption[T](x: Option[T]): T = x match { + case Some(xs) => xs + } + + + case class Down[+T](x: T) + case class Up[-T](f: T => Unit) + + def f1[T](x1: Down[T])(x2: Up[T]) = ((x1, x2)) match { + case (Down(x), Up(f)) => f(x) + } +} + + +object TestNeg extends App { + class AbsWrapperCov[+A] + case class Wrapper[B](x: Wrapped[B]) extends AbsWrapperCov[B] + + /* + when inferring Wrapper's type parameter B from x's type AbsWrapperCov[T], + we must take into account that x's actual type is AbsWrapperCov[Tactual] forSome {type Tactual <: T} + as AbsWrapperCov is covariant in A -- in other words, we must not assume we know T exactly, all we know is its upper bound + + since method application is the only way to generate this slack between run-time and compile-time types, + we'll simply replace the skolems that represent method type parameters as seen from the method's body by + other skolems that are (upper/lower)-bounded by the type-parameter skolems + (depending on whether the skolem appears in a covariant/contravariant position) + */ + def unwrap[T](x: AbsWrapperCov[T]): Wrapped[T] = x match { + case Wrapper/*[_ <: T ]*/(wrapped) => wrapped // : Wrapped[_ <: T], which is a subtype of Wrapped[T] if and only if Wrapped is covariant in its type parameter + } + + class Wrapped[W](var cell: W) // must be invariant (to trigger the bug) + + // class A { def imNotAB = println("notB")} + // class B + // + // val w = new Wrapped(new A) + // unwrap[Any](Wrapper(w)).cell = new B + // w.cell.imNotAB + + def unwrapOption[T](x: Option[T]): T = x match { + case Some(xs) => xs.foo // the error message should not refer to a skolem (testing extrapolation) + } + +} + +// class TestPos1 { +// class Base[T] +// case class C[T](x: T) extends Base[T] +// def foo[T](b: Base[T]): T = b match { case C(x) => x } +// +// 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 +// } +// } +// } +// +// class TestNeg1 { +// case class Foo[T, U](f: T => U) +// def f(x: Any): Any => Any = x match { case Foo(bar) => bar } +// // uh-oh, Any => Any should be Nothing => Any. +// } + diff --git a/tests/untried/neg/t520.check b/tests/untried/neg/t520.check new file mode 100644 index 000000000000..0035f89a7912 --- /dev/null +++ b/tests/untried/neg/t520.check @@ -0,0 +1,4 @@ +t520.scala:8: error: overloaded method verifyKeyword needs result type + verifyKeyword("", source, pos); + ^ +one error found diff --git a/tests/untried/neg/t520.scala b/tests/untried/neg/t520.scala new file mode 100644 index 000000000000..076aca3122b5 --- /dev/null +++ b/tests/untried/neg/t520.scala @@ -0,0 +1,9 @@ +object test { + + def verifyKeyword(keyword : String, source : java.io.File, pos : Int) = { + assert(keyword != null); + } + + def verifyKeyword(source : java.io.File, pos : Int) = + verifyKeyword("", source, pos); +} diff --git a/tests/untried/neg/t521.check b/tests/untried/neg/t521.check new file mode 100644 index 000000000000..a10019565523 --- /dev/null +++ b/tests/untried/neg/t521.check @@ -0,0 +1,15 @@ +t521.scala:10: error: class PlainFile needs to be abstract, since method path in class AbstractFile of type => String is not defined +class PlainFile(val file : File) extends AbstractFile {} + ^ +t521.scala:13: error: overriding value file in class PlainFile of type java.io.File; + value file needs `override' modifier +final class ZipArchive(val file : File, archive : ZipFile) extends PlainFile(file) { + ^ +t521.scala:13: error: class ZipArchive needs to be abstract, since method path in class AbstractFile of type => String is not defined +final class ZipArchive(val file : File, archive : ZipFile) extends PlainFile(file) { + ^ +t521.scala:15: error: overriding value path in class VirtualFile of type String; + method path needs to be a stable, immutable value + override def path = ""; + ^ +four errors found diff --git a/tests/untried/neg/t521.scala b/tests/untried/neg/t521.scala new file mode 100644 index 000000000000..c6afebc0be0b --- /dev/null +++ b/tests/untried/neg/t521.scala @@ -0,0 +1,17 @@ +package test + +import java.io.File +import java.util.zip.ZipFile + +abstract class AbstractFile { + def path : String; +} + +class PlainFile(val file : File) extends AbstractFile {} +class VirtualFile(val name : String, val path : String) extends AbstractFile {} + +final class ZipArchive(val file : File, archive : ZipFile) extends PlainFile(file) { + class Entry(name : String, path : String) extends VirtualFile(name, path) { + override def path = ""; + } +} diff --git a/tests/untried/neg/t5318.check b/tests/untried/neg/t5318.check new file mode 100644 index 000000000000..d6a3a57935d0 --- /dev/null +++ b/tests/untried/neg/t5318.check @@ -0,0 +1,5 @@ +t5318.scala:7: error: diverging implicit expansion for type CompilerHang.this.TC[F] +starting with method tc in class CompilerHang + breakage // type checker doesn't terminate, should report inference failure + ^ +one error found diff --git a/tests/untried/neg/t5318.scala b/tests/untried/neg/t5318.scala new file mode 100644 index 000000000000..5be82a02a60d --- /dev/null +++ b/tests/untried/neg/t5318.scala @@ -0,0 +1,8 @@ +class CompilerHang { + trait TC[M[_]] + trait S[A] + + implicit def tc[M[_]](implicit M0: TC[M]): TC[S] = null + def breakage[F[_] : TC] = 0 + breakage // type checker doesn't terminate, should report inference failure +} diff --git a/tests/untried/neg/t5318b.check b/tests/untried/neg/t5318b.check new file mode 100644 index 000000000000..47a10d673382 --- /dev/null +++ b/tests/untried/neg/t5318b.check @@ -0,0 +1,5 @@ +t5318b.scala:7: error: diverging implicit expansion for type DivergingImplicitReported.this.TC[F] +starting with method tc in class DivergingImplicitReported + breakage // correct: diverging implicit expansion + ^ +one error found \ No newline at end of file diff --git a/tests/untried/neg/t5318b.scala b/tests/untried/neg/t5318b.scala new file mode 100644 index 000000000000..a2d55b1e4a73 --- /dev/null +++ b/tests/untried/neg/t5318b.scala @@ -0,0 +1,8 @@ +class DivergingImplicitReported { + trait TC[M] + trait S + + implicit def tc[M](implicit M0: TC[M]): TC[S] = null + def breakage[F: TC] = 0 + breakage // correct: diverging implicit expansion +} diff --git a/tests/untried/neg/t5318c.check b/tests/untried/neg/t5318c.check new file mode 100644 index 000000000000..594539be6968 --- /dev/null +++ b/tests/untried/neg/t5318c.check @@ -0,0 +1,5 @@ +t5318c.scala:13: error: diverging implicit expansion for type CompilerHang.this.TC[F] +starting with method tc in class CompilerHang + breakage // type checker doesn't terminate, should report inference failure + ^ +one error found diff --git a/tests/untried/neg/t5318c.scala b/tests/untried/neg/t5318c.scala new file mode 100644 index 000000000000..477a9874ad17 --- /dev/null +++ b/tests/untried/neg/t5318c.scala @@ -0,0 +1,14 @@ +class CompilerHang { + trait TC[M[_]] + trait S[A] + + class C[M[_]] { + type TCM = TC[M] + } + + // A nefarious implicit, to motivate the removal of `&& sym.owner.isTerm` from + // `isFreeTypeParamNoSkolem`. + implicit def tc[x[_], CC[x[_]] <: C[x]](implicit M0: CC[x]#TCM): CC[x]#TCM = null + def breakage[F[_] : TC] = 0 + breakage // type checker doesn't terminate, should report inference failure +} diff --git a/tests/untried/neg/t5340.check b/tests/untried/neg/t5340.check new file mode 100644 index 000000000000..2de19293c4be --- /dev/null +++ b/tests/untried/neg/t5340.check @@ -0,0 +1,6 @@ +t5340.scala:17: error: type mismatch; + found : MyApp.r.E + required: MyApp.s.E + println(b: s.E) + ^ +one error found diff --git a/tests/untried/neg/t5340.scala b/tests/untried/neg/t5340.scala new file mode 100644 index 000000000000..b283f1333842 --- /dev/null +++ b/tests/untried/neg/t5340.scala @@ -0,0 +1,29 @@ +class Poly { + class E + object E { + implicit def conv(value: Any): E = sys.error("") + } +} + +object MyApp { + val r: Poly = sys.error("") + val s: Poly = sys.error("") + val b: r.E = sys.error("") + + // okay + s.E.conv(b): s.E + + // compilation fails with error below + println(b: s.E) + + // amb prefix: MyApp.s.type#class E MyApp.r.type#class E + // amb prefix: MyApp.s.type#class E MyApp.r.type#class E + // ../test/pending/run/t5310.scala:17: error: type mismatch; + // found : MyApp.r.E + // required: MyApp.s.E + // println(b: s.E) + // ^ + + // The type error is as expected, but the `amb prefix` should be logged, + // rather than printed to standard out. +} diff --git a/tests/untried/neg/t5352.check b/tests/untried/neg/t5352.check new file mode 100644 index 000000000000..1675da9e9aca --- /dev/null +++ b/tests/untried/neg/t5352.check @@ -0,0 +1,13 @@ +t5352.scala:11: error: type mismatch; + found : boop.Bar + required: boop.BarF + (which expands to) AnyRef{def f(): Int} + x = xs.head + ^ +t5352.scala:14: error: method f in class Bar1 cannot be accessed in boop.Bar1 + Access to protected method f not permitted because + enclosing object boop is not a subclass of + class Bar1 in object boop where target is defined + (new Bar1).f + ^ +two errors found diff --git a/tests/untried/neg/t5352.flags b/tests/untried/neg/t5352.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t5352.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t5352.scala b/tests/untried/neg/t5352.scala new file mode 100644 index 000000000000..ed74a840f0c0 --- /dev/null +++ b/tests/untried/neg/t5352.scala @@ -0,0 +1,15 @@ +object boop { + abstract class Bar { protected def f(): Any } + class Bar1 extends Bar { protected def f(): Int = 5 } + class Bar2 extends Bar { protected def f(): Int = 5 } + + val xs = List(new Bar1, new Bar2) + + type BarF = { def f(): Int } + + var x: BarF = _ + x = xs.head + x.f + + (new Bar1).f +} diff --git a/tests/untried/neg/t5354.check b/tests/untried/neg/t5354.check new file mode 100644 index 000000000000..e47cecb5fee9 --- /dev/null +++ b/tests/untried/neg/t5354.check @@ -0,0 +1,7 @@ +t5354.scala:9: error: ambiguous implicit values: + both method x123 in package foo of type => foo.Bippy + and method z of type => foo.Bippy + match expected type foo.Bippy + implicitly[Bippy] + ^ +one error found diff --git a/tests/untried/neg/t5354.scala b/tests/untried/neg/t5354.scala new file mode 100644 index 000000000000..99b565015507 --- /dev/null +++ b/tests/untried/neg/t5354.scala @@ -0,0 +1,15 @@ +package object foo { + implicit def x123: Bippy = new Bippy("x") +} +package foo { + class Bippy(override val toString: String){ } + class Dingus { + def f1 = { + implicit def z: Bippy = new Bippy("z") + implicitly[Bippy] + } + } + object Test extends App { + println(new Dingus().f1) + } +} diff --git a/tests/untried/neg/t5357.check b/tests/untried/neg/t5357.check new file mode 100644 index 000000000000..3385559071a6 --- /dev/null +++ b/tests/untried/neg/t5357.check @@ -0,0 +1,4 @@ +t5357.scala:5: error: Pattern variables must start with a lower-case letter. (SLS 8.1.1.) + case A: N => 1 + ^ +one error found diff --git a/tests/untried/neg/t5357.scala b/tests/untried/neg/t5357.scala new file mode 100644 index 000000000000..6a52283dd6b6 --- /dev/null +++ b/tests/untried/neg/t5357.scala @@ -0,0 +1,9 @@ +trait M + +case class N() extends M { + def mytest(x: M) = x match { + case A: N => 1 + case _ => 0 + } +} + diff --git a/tests/untried/neg/t5358.check b/tests/untried/neg/t5358.check new file mode 100644 index 000000000000..59e83bba2f41 --- /dev/null +++ b/tests/untried/neg/t5358.check @@ -0,0 +1,7 @@ +t5358.scala:3: error: class C inherits conflicting members: + method hi in trait A of type => String and + method hi in trait B of type => String +(Note: this can be resolved by declaring an override in class C.) +class C extends A with B + ^ +one error found diff --git a/tests/untried/neg/t5358.scala b/tests/untried/neg/t5358.scala new file mode 100644 index 000000000000..13d827ed82b3 --- /dev/null +++ b/tests/untried/neg/t5358.scala @@ -0,0 +1,4 @@ +trait A { def hi = "A" } +trait B { def hi = "B" } +class C extends A with B + diff --git a/tests/untried/neg/t5361.check b/tests/untried/neg/t5361.check new file mode 100644 index 000000000000..d7fee87ccdf3 --- /dev/null +++ b/tests/untried/neg/t5361.check @@ -0,0 +1,4 @@ +t5361.scala:2: error: only declarations allowed here + val x : { val self = this } = new { self => } + ^ +one error found diff --git a/tests/untried/neg/t5361.scala b/tests/untried/neg/t5361.scala new file mode 100644 index 000000000000..1705c09df3ea --- /dev/null +++ b/tests/untried/neg/t5361.scala @@ -0,0 +1,3 @@ +class A { + val x : { val self = this } = new { self => } +} diff --git a/tests/untried/neg/t5376.check b/tests/untried/neg/t5376.check new file mode 100644 index 000000000000..0376163c35e5 --- /dev/null +++ b/tests/untried/neg/t5376.check @@ -0,0 +1,11 @@ +t5376.scala:12: error: type mismatch; + found : String("a") + required: Int + "a": Int + ^ +t5376.scala:22: error: type mismatch; + found : String("a") + required: Int + "a": Int + ^ +two errors found diff --git a/tests/untried/neg/t5376.scala b/tests/untried/neg/t5376.scala new file mode 100644 index 000000000000..9dcaccbf1ba3 --- /dev/null +++ b/tests/untried/neg/t5376.scala @@ -0,0 +1,24 @@ +object Test { + object O1 { implicit def f(s: String): Int = 1 } + object O2 { implicit def f(s: String): Int = 2 } + object O3 { def f(s: String): Int = 3 } + + // Import two implicits with the same name in the same scope. + def m1 = { + import O1._ + import O2._ + + // Implicit usage compiles. + "a": Int + } + + // Import one implict and one non-implicit method with the + // same name in the same scope. + def m2 = { + import O1._ + import O3._ + + // Implicit usage compiles. + "a": Int + } +} diff --git a/tests/untried/neg/t5378.check b/tests/untried/neg/t5378.check new file mode 100644 index 000000000000..c1460083f6c6 --- /dev/null +++ b/tests/untried/neg/t5378.check @@ -0,0 +1,31 @@ +t5378.scala:7: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + def contains = new { def apply[T1 <: T](value: T1) = ??? } + ^ +t5378.scala:8: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + def contains1 = new { def apply[T1 <: A1](value: T1) = ??? } + ^ +t5378.scala:9: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + def contains2 = new { def apply[T1 <: A2](value: T1) = ??? } + ^ +t5378.scala:15: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + new Bippy { def apply[T1 <: T](value: T1) = ??? } + ^ +t5378.scala:16: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + new Bippy { def apply[T1 <: B1](value: T1) = ??? } + ^ +t5378.scala:17: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + new Bippy { def apply[T1 <: B2](value: T1) = ??? } + ^ +t5378.scala:21: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + def apply1[T1 <: B3](value: T1) = ??? + ^ +t5378.scala:23: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def apply3(value: B3) = ??? + ^ +t5378.scala:28: error: Parameter type in structural refinement may not refer to an abstract type defined outside that refinement + def apply1(s: String)(x: Int)(value: T) = ??? + ^ +t5378.scala:29: error: Type bound in structural refinement may not refer to an abstract type defined outside that refinement + def apply2[T1 <: T](s: String)(x: Int)(value: T1) = ??? + ^ +10 errors found diff --git a/tests/untried/neg/t5378.scala b/tests/untried/neg/t5378.scala new file mode 100644 index 000000000000..fa6afa02be36 --- /dev/null +++ b/tests/untried/neg/t5378.scala @@ -0,0 +1,54 @@ +import scala.language.reflectiveCalls + +class Coll[+T] { + type A1 <: T + type A2 <: A1 + + def contains = new { def apply[T1 <: T](value: T1) = ??? } + def contains1 = new { def apply[T1 <: A1](value: T1) = ??? } + def contains2 = new { def apply[T1 <: A2](value: T1) = ??? } + def contains3 = { + trait Bippy { + type B1 <: T + type B2 <: B1 + } + new Bippy { def apply[T1 <: T](value: T1) = ??? } + new Bippy { def apply[T1 <: B1](value: T1) = ??? } + new Bippy { def apply[T1 <: B2](value: T1) = ??? } + new Bippy { + type B3 = B2 + type B4 = List[B2] + def apply1[T1 <: B3](value: T1) = ??? + def apply2[T1 <: B4](value: T1) = ??? + def apply3(value: B3) = ??? + def apply4(value: B4) = value.head + } + } + def contains4 = new { + def apply1(s: String)(x: Int)(value: T) = ??? + def apply2[T1 <: T](s: String)(x: Int)(value: T1) = ??? + } + def containsOk = { + trait Bippy { + type B1 <: AnyRef + type B2 <: B1 + } + new Bippy { def apply[T1 <: AnyRef](value: T1) = ??? } + new Bippy { type B1 = String ; def apply[T1 <: B1](value: T1) = ??? } + new Bippy { type B2 = String ; def apply[T1 <: B2](value: T1) = ??? } + } +} + +object Test { + def main(args: Array[String]): Unit = { + val xs = new Coll[List[String]] + val ys: Coll[Traversable[String]] = xs + + println(ys contains Nil) + // java.lang.NoSuchMethodException: Coll$$anon$1.apply(scala.collection.Traversable) + // at java.lang.Class.getMethod(Class.java:1605) + // at Test$.reflMethod$Method1(a.scala:14) + // at Test$.main(a.scala:14) + // at Test.main(a.scala) + } +} diff --git a/tests/untried/neg/t5390.check b/tests/untried/neg/t5390.check new file mode 100644 index 000000000000..6a0129b898d8 --- /dev/null +++ b/tests/untried/neg/t5390.check @@ -0,0 +1,4 @@ +t5390.scala:7: error: forward reference extends over definition of value b + val b = a.B("") + ^ +one error found diff --git a/tests/untried/neg/t5390.scala b/tests/untried/neg/t5390.scala new file mode 100644 index 000000000000..de596a478d79 --- /dev/null +++ b/tests/untried/neg/t5390.scala @@ -0,0 +1,10 @@ +class A { + object B { def apply(s: String) = 0} +} + +object X { + def foo: Unit = { + val b = a.B("") + val a = new A + } +} diff --git a/tests/untried/neg/t5390b.check b/tests/untried/neg/t5390b.check new file mode 100644 index 000000000000..cbf8fafa6bbe --- /dev/null +++ b/tests/untried/neg/t5390b.check @@ -0,0 +1,4 @@ +t5390b.scala:7: error: forward reference extends over definition of value b + val b = a.B("") + ^ +one error found diff --git a/tests/untried/neg/t5390b.scala b/tests/untried/neg/t5390b.scala new file mode 100644 index 000000000000..94032c907d88 --- /dev/null +++ b/tests/untried/neg/t5390b.scala @@ -0,0 +1,10 @@ +class A { + case class B(s: String) +} + +object X { + def foo: Unit = { + val b = a.B("") + val a = new A + } +} diff --git a/tests/untried/neg/t5390c.check b/tests/untried/neg/t5390c.check new file mode 100644 index 000000000000..f8a794d690a3 --- /dev/null +++ b/tests/untried/neg/t5390c.check @@ -0,0 +1,4 @@ +t5390c.scala:7: error: forward reference extends over definition of value b + val b = new a.B("") + ^ +one error found diff --git a/tests/untried/neg/t5390c.scala b/tests/untried/neg/t5390c.scala new file mode 100644 index 000000000000..6277400dc4f4 --- /dev/null +++ b/tests/untried/neg/t5390c.scala @@ -0,0 +1,10 @@ +class A { + case class B(s: String) +} + +object X { + def foo: Unit = { + val b = new a.B("") + val a = new A + } +} diff --git a/tests/untried/neg/t5390d.check b/tests/untried/neg/t5390d.check new file mode 100644 index 000000000000..daa29142e739 --- /dev/null +++ b/tests/untried/neg/t5390d.check @@ -0,0 +1,4 @@ +t5390d.scala:7: error: forward reference extends over definition of value b + val b = a.B.toString + ^ +one error found diff --git a/tests/untried/neg/t5390d.scala b/tests/untried/neg/t5390d.scala new file mode 100644 index 000000000000..d376b714bc8f --- /dev/null +++ b/tests/untried/neg/t5390d.scala @@ -0,0 +1,10 @@ +class A { + case class B(s: String) +} + +object X { + def foo: Unit = { + val b = a.B.toString + val a = new A + } +} diff --git a/tests/untried/neg/t5426.check b/tests/untried/neg/t5426.check new file mode 100644 index 000000000000..98f3ddaaaec2 --- /dev/null +++ b/tests/untried/neg/t5426.check @@ -0,0 +1,15 @@ +t5426.scala:2: warning: comparing values of types Some[Int] and Int using `==' will always yield false + def f1 = Some(5) == 5 + ^ +t5426.scala:3: warning: comparing values of types Int and Some[Int] using `==' will always yield false + def f2 = 5 == Some(5) + ^ +t5426.scala:8: warning: comparing values of types Int and Some[Int] using `==' will always yield false + (x1 == x2) + ^ +t5426.scala:9: warning: comparing values of types Some[Int] and Int using `==' will always yield false + (x2 == x1) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t5426.flags b/tests/untried/neg/t5426.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t5426.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t5426.scala b/tests/untried/neg/t5426.scala new file mode 100644 index 000000000000..af0f98196942 --- /dev/null +++ b/tests/untried/neg/t5426.scala @@ -0,0 +1,10 @@ +class A { + def f1 = Some(5) == 5 + def f2 = 5 == Some(5) + + val x1 = 5 + val x2 = Some(5) + + (x1 == x2) + (x2 == x1) +} diff --git a/tests/untried/neg/t5429.check b/tests/untried/neg/t5429.check new file mode 100644 index 000000000000..4350696bc83a --- /dev/null +++ b/tests/untried/neg/t5429.check @@ -0,0 +1,142 @@ +t5429.scala:20: error: overriding value value in class A of type Int; + object value needs `override' modifier + object value // fail + ^ +t5429.scala:21: error: overriding lazy value lazyvalue in class A of type Int; + object lazyvalue needs `override' modifier + object lazyvalue // fail + ^ +t5429.scala:22: error: overriding method nullary in class A of type => Int; + object nullary needs `override' modifier + object nullary // fail + ^ +t5429.scala:23: error: overriding method emptyArg in class A of type ()Int; + object emptyArg needs `override' modifier + object emptyArg // fail + ^ +t5429.scala:27: error: overriding value value in class A0 of type Any; + object value needs `override' modifier + object value // fail + ^ +t5429.scala:28: error: overriding lazy value lazyvalue in class A0 of type Any; + object lazyvalue needs `override' modifier + object lazyvalue // fail + ^ +t5429.scala:29: error: overriding method nullary in class A0 of type => Any; + object nullary needs `override' modifier + object nullary // fail + ^ +t5429.scala:30: error: overriding method emptyArg in class A0 of type ()Any; + object emptyArg needs `override' modifier + object emptyArg // fail + ^ +t5429.scala:35: error: overriding value value in class A of type Int; + object value has incompatible type + override object value // fail + ^ +t5429.scala:36: error: overriding lazy value lazyvalue in class A of type Int; + object lazyvalue must be declared lazy to override a concrete lazy value + override object lazyvalue // fail + ^ +t5429.scala:37: error: overriding method nullary in class A of type => Int; + object nullary has incompatible type + override object nullary // fail + ^ +t5429.scala:38: error: overriding method emptyArg in class A of type ()Int; + object emptyArg has incompatible type + override object emptyArg // fail + ^ +t5429.scala:39: error: object oneArg overrides nothing. +Note: the super classes of class C contain the following, non final members named oneArg: +def oneArg(x: String): Int + override object oneArg // fail + ^ +t5429.scala:43: error: overriding lazy value lazyvalue in class A0 of type Any; + object lazyvalue must be declared lazy to override a concrete lazy value + override object lazyvalue // !!! this fails, but should succeed (lazy over lazy) + ^ +t5429.scala:46: error: object oneArg overrides nothing. +Note: the super classes of class C0 contain the following, non final members named oneArg: +def oneArg(x: String): Any + override object oneArg // fail + ^ +t5429.scala:50: error: overriding value value in class A of type Int; + value value needs `override' modifier + val value = 0 // fail + ^ +t5429.scala:51: error: overriding lazy value lazyvalue in class A of type Int; + value lazyvalue needs `override' modifier + val lazyvalue = 0 // fail + ^ +t5429.scala:52: error: overriding method nullary in class A of type => Int; + value nullary needs `override' modifier + val nullary = 5 // fail + ^ +t5429.scala:53: error: overriding method emptyArg in class A of type ()Int; + value emptyArg needs `override' modifier + val emptyArg = 10 // fail + ^ +t5429.scala:58: error: overriding lazy value lazyvalue in class A0 of type Any; + value lazyvalue must be declared lazy to override a concrete lazy value + override val lazyvalue = 0 // fail (non-lazy) + ^ +t5429.scala:61: error: value oneArg overrides nothing. +Note: the super classes of class D0 contain the following, non final members named oneArg: +def oneArg(x: String): Any + override val oneArg = 15 // fail + ^ +t5429.scala:65: error: overriding value value in class A of type Int; + method value needs `override' modifier + def value = 0 // fail + ^ +t5429.scala:66: error: overriding lazy value lazyvalue in class A of type Int; + method lazyvalue needs `override' modifier + def lazyvalue = 2 // fail + ^ +t5429.scala:67: error: overriding method nullary in class A of type => Int; + method nullary needs `override' modifier + def nullary = 5 // fail + ^ +t5429.scala:68: error: overriding method emptyArg in class A of type ()Int; + method emptyArg needs `override' modifier + def emptyArg = 10 // fail + ^ +t5429.scala:72: error: overriding value value in class A0 of type Any; + method value needs to be a stable, immutable value + override def value = 0 // fail + ^ +t5429.scala:73: error: overriding lazy value lazyvalue in class A0 of type Any; + method lazyvalue needs to be a stable, immutable value + override def lazyvalue = 2 // fail + ^ +t5429.scala:76: error: method oneArg overrides nothing. +Note: the super classes of class E0 contain the following, non final members named oneArg: +def oneArg(x: String): Any + override def oneArg = 15 // fail + ^ +t5429.scala:80: error: overriding value value in class A of type Int; + lazy value value needs `override' modifier + lazy val value = 0 // fail + ^ +t5429.scala:81: error: overriding lazy value lazyvalue in class A of type Int; + lazy value lazyvalue needs `override' modifier + lazy val lazyvalue = 2 // fail + ^ +t5429.scala:82: error: overriding method nullary in class A of type => Int; + lazy value nullary needs `override' modifier + lazy val nullary = 5 // fail + ^ +t5429.scala:83: error: overriding method emptyArg in class A of type ()Int; + lazy value emptyArg needs `override' modifier + lazy val emptyArg = 10 // fail + ^ +t5429.scala:87: error: overriding value value in class A0 of type Any; + lazy value value cannot override a concrete non-lazy value + override lazy val value = 0 // fail (strict over lazy) + ^ +t5429.scala:91: error: value oneArg overrides nothing. +Note: the super classes of class F0 contain the following, non final members named oneArg: +def oneArg(x: String): Any + override lazy val oneArg = 15 // fail + ^ +34 errors found diff --git a/tests/untried/neg/t5429.scala b/tests/untried/neg/t5429.scala new file mode 100644 index 000000000000..1cd4dcd03204 --- /dev/null +++ b/tests/untried/neg/t5429.scala @@ -0,0 +1,93 @@ +// /scala/trac/5429/a.scala +// Wed Feb 1 08:05:27 PST 2012 + +class A { + val value = 0 + lazy val lazyvalue = 2 + def nullary = 5 + def emptyArg() = 10 + def oneArg(x: String) = 15 +} +class A0 { + val value: Any = 0 + lazy val lazyvalue: Any = 2 + def nullary: Any = 5 + def emptyArg(): Any = 10 + def oneArg(x: String): Any = 15 +} + +class B extends A { + object value // fail + object lazyvalue // fail + object nullary // fail + object emptyArg // fail + object oneArg // overload +} +class B0 extends A0 { + object value // fail + object lazyvalue // fail + object nullary // fail + object emptyArg // fail + object oneArg // overload +} + +class C extends A { + override object value // fail + override object lazyvalue // fail + override object nullary // fail + override object emptyArg // fail + override object oneArg // fail +} +class C0 extends A0 { + override object value // !!! this succeeds, but should fail (lazy over strict) + override object lazyvalue // !!! this fails, but should succeed (lazy over lazy) + override object nullary // override + override object emptyArg // override + override object oneArg // fail +} + +class D extends A { + val value = 0 // fail + val lazyvalue = 0 // fail + val nullary = 5 // fail + val emptyArg = 10 // fail + val oneArg = 15 // overload +} +class D0 extends A0 { + override val value = 0 // override + override val lazyvalue = 0 // fail (non-lazy) + override val nullary = 5 // override + override val emptyArg = 10 // override + override val oneArg = 15 // fail +} + +class E extends A { + def value = 0 // fail + def lazyvalue = 2 // fail + def nullary = 5 // fail + def emptyArg = 10 // fail + def oneArg = 15 // overload +} +class E0 extends A0 { + override def value = 0 // fail + override def lazyvalue = 2 // fail + override def nullary = 5 // override + override def emptyArg = 10 // override + override def oneArg = 15 // fail +} + +class F extends A { + lazy val value = 0 // fail + lazy val lazyvalue = 2 // fail + lazy val nullary = 5 // fail + lazy val emptyArg = 10 // fail + lazy val oneArg = 15 // overload +} +class F0 extends A0 { + override lazy val value = 0 // fail (strict over lazy) + override lazy val lazyvalue = 2 // override (lazy over lazy) + override lazy val nullary = 5 // override + override lazy val emptyArg = 10 // override + override lazy val oneArg = 15 // fail +} + diff --git a/tests/untried/neg/t5440.check b/tests/untried/neg/t5440.check new file mode 100644 index 000000000000..1c4592cceccd --- /dev/null +++ b/tests/untried/neg/t5440.check @@ -0,0 +1,7 @@ +t5440.scala:3: warning: match may not be exhaustive. +It would fail on the following inputs: (List(_), Nil), (Nil, List(_)) + (list1, list2) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t5440.flags b/tests/untried/neg/t5440.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t5440.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t5440.scala b/tests/untried/neg/t5440.scala new file mode 100644 index 000000000000..909bab1e30ed --- /dev/null +++ b/tests/untried/neg/t5440.scala @@ -0,0 +1,7 @@ +object Test { + def merge(list1: List[Long], list2: List[Long]): Boolean = + (list1, list2) match { + case (hd1::_, hd2::_) => true + case (Nil, Nil) => true + } +} diff --git a/tests/untried/neg/t545.check b/tests/untried/neg/t545.check new file mode 100644 index 000000000000..aae575fa9699 --- /dev/null +++ b/tests/untried/neg/t545.check @@ -0,0 +1,4 @@ +t545.scala:4: error: value blah is not a member of Test.Foo + val x = foo.blah match { + ^ +one error found diff --git a/tests/untried/neg/t545.scala b/tests/untried/neg/t545.scala new file mode 100644 index 000000000000..f1f9909dcb20 --- /dev/null +++ b/tests/untried/neg/t545.scala @@ -0,0 +1,9 @@ +object Test { + class Foo + val foo = new Foo + val x = foo.blah match { + case List(x) => x + case Nil => null + case _ => throw new Error("too many!") + } +} diff --git a/tests/untried/neg/t5452-new.check b/tests/untried/neg/t5452-new.check new file mode 100644 index 000000000000..1850a7004ae6 --- /dev/null +++ b/tests/untried/neg/t5452-new.check @@ -0,0 +1,8 @@ +t5452-new.scala:30: error: overloaded method value apply with alternatives: + ()Queryable[CoffeesTable] + (t: Tree)(implicit evidence$2: scala.reflect.ClassTag[CoffeesTable])Nothing + (implicit evidence$1: scala.reflect.ClassTag[CoffeesTable])Nothing + cannot be applied to (Queryable[CoffeesTable]) + Queryable[CoffeesTable]( q.treeFilter(null) ) + ^ +one error found diff --git a/tests/untried/neg/t5452-new.scala b/tests/untried/neg/t5452-new.scala new file mode 100644 index 000000000000..ef5f199e794e --- /dev/null +++ b/tests/untried/neg/t5452-new.scala @@ -0,0 +1,31 @@ +import scala.reflect.{ClassTag, classTag} + +// /scala/trac/5452/a.scala +// Mon Feb 13 22:52:36 PST 2012 + +// import scala.reflect.runtime.universe._ + +trait Tree + +object Bip { + def ??? = sys.error("") +} +import Bip._ + +case class Queryable[T]() { + def treeFilter( t:Tree ) : Queryable[T] = ??? +} + +object Queryable { + def apply[T:ClassTag] = ??? + def apply[T:ClassTag]( t:Tree ) = ??? +} + +trait CoffeesTable{ + def sales : Int +} + +object Test extends App{ + val q = new Queryable[CoffeesTable] + Queryable[CoffeesTable]( q.treeFilter(null) ) +} diff --git a/tests/untried/neg/t5452-old.check b/tests/untried/neg/t5452-old.check new file mode 100644 index 000000000000..1860c98c5309 --- /dev/null +++ b/tests/untried/neg/t5452-old.check @@ -0,0 +1,8 @@ +t5452-old.scala:28: error: overloaded method value apply with alternatives: + ()Queryable[CoffeesTable] + (t: Tree)(implicit evidence$2: Manifest[CoffeesTable])Nothing + (implicit evidence$1: Manifest[CoffeesTable])Nothing + cannot be applied to (Queryable[CoffeesTable]) + Queryable[CoffeesTable]( q.treeFilter(null) ) + ^ +one error found diff --git a/tests/untried/neg/t5452-old.scala b/tests/untried/neg/t5452-old.scala new file mode 100644 index 000000000000..4f6dcbbe469a --- /dev/null +++ b/tests/untried/neg/t5452-old.scala @@ -0,0 +1,29 @@ +// /scala/trac/5452/a.scala +// Mon Feb 13 22:52:36 PST 2012 + +// import scala.reflect.runtime.universe._ + +trait Tree + +object Bip { + def ??? = sys.error("") +} +import Bip._ + +case class Queryable[T]() { + def treeFilter( t:Tree ) : Queryable[T] = ??? +} + +object Queryable { + def apply[T:Manifest] = ??? + def apply[T:Manifest]( t:Tree ) = ??? +} + +trait CoffeesTable{ + def sales : Int +} + +object Test extends App{ + val q = new Queryable[CoffeesTable] + Queryable[CoffeesTable]( q.treeFilter(null) ) +} diff --git a/tests/untried/neg/t5455.check b/tests/untried/neg/t5455.check new file mode 100644 index 000000000000..788daf99fa8f --- /dev/null +++ b/tests/untried/neg/t5455.check @@ -0,0 +1,4 @@ +t5455.scala:4: error: lazy vals are not tailcall transformed + @annotation.tailrec final lazy val bar: Thing[Int] = { + ^ +one error found diff --git a/tests/untried/neg/t5455.scala b/tests/untried/neg/t5455.scala new file mode 100644 index 000000000000..6e54335787d5 --- /dev/null +++ b/tests/untried/neg/t5455.scala @@ -0,0 +1,16 @@ +trait Test { + def root: Test + + @annotation.tailrec final lazy val bar: Thing[Int] = { + if (this eq root) + Thing(() => System.identityHashCode(bar)) + else + root.bar + } + + def f = bar.f() +} + +case class Thing[A](f: () => A) { + override def toString = "" + f() +} diff --git a/tests/untried/neg/t5493.check b/tests/untried/neg/t5493.check new file mode 100644 index 000000000000..78b1536bc78c --- /dev/null +++ b/tests/untried/neg/t5493.check @@ -0,0 +1,4 @@ +t5493.scala:2: error: not found: value iDontExist + def meh(xs: Any): Any = xs :: iDontExist :: Nil + ^ +one error found diff --git a/tests/untried/neg/t5493.scala b/tests/untried/neg/t5493.scala new file mode 100644 index 000000000000..459cf53bbd90 --- /dev/null +++ b/tests/untried/neg/t5493.scala @@ -0,0 +1,3 @@ +object Test { + def meh(xs: Any): Any = xs :: iDontExist :: Nil +} diff --git a/tests/untried/neg/t5497.check b/tests/untried/neg/t5497.check new file mode 100644 index 000000000000..4d6d52b519d5 --- /dev/null +++ b/tests/untried/neg/t5497.check @@ -0,0 +1,4 @@ +t5497.scala:3: error: not found: value sq + case other => println(null.asInstanceOf[sq.Filter].tableName) + ^ +one error found diff --git a/tests/untried/neg/t5497.scala b/tests/untried/neg/t5497.scala new file mode 100644 index 000000000000..c846b1ba579d --- /dev/null +++ b/tests/untried/neg/t5497.scala @@ -0,0 +1,5 @@ +object TestQueryable extends App{ + ({ + case other => println(null.asInstanceOf[sq.Filter].tableName) + } : Any => Unit)(null) +} diff --git a/tests/untried/neg/t550.check b/tests/untried/neg/t550.check new file mode 100644 index 000000000000..da862e110e66 --- /dev/null +++ b/tests/untried/neg/t550.check @@ -0,0 +1,7 @@ +t550.scala:6: error: type List takes type parameters + def sum[a](xs: List)(implicit m: Monoid[a]): a = + ^ +t550.scala:8: error: could not find implicit value for parameter m: Monoid[a] + sum(List(1,2,3)) + ^ +two errors found diff --git a/tests/untried/neg/t550.scala b/tests/untried/neg/t550.scala new file mode 100644 index 000000000000..5212a2658dd7 --- /dev/null +++ b/tests/untried/neg/t550.scala @@ -0,0 +1,9 @@ +abstract class Monoid[a] { + def unit: a +} + +object test { + def sum[a](xs: List)(implicit m: Monoid[a]): a = + if (xs.isEmpty) m.unit else xs.head + sum(List(1,2,3)) +} diff --git a/tests/untried/neg/t5510.check b/tests/untried/neg/t5510.check new file mode 100644 index 000000000000..322a2f5e25f4 --- /dev/null +++ b/tests/untried/neg/t5510.check @@ -0,0 +1,19 @@ +t5510.scala:2: error: unclosed string literal + val s1 = s"xxx + ^ +t5510.scala:3: error: unclosed string literal + val s2 = s"xxx $x + ^ +t5510.scala:4: error: unclosed string literal + val s3 = s"xxx $$ + ^ +t5510.scala:5: error: unclosed string literal + val s4 = ""s" + ^ +t5510.scala:6: error: unclosed multi-line string literal + val s5 = ""s""" $s1 $s2 s" + ^ +t5510.scala:7: error: unclosed multi-line string literal +} + ^ +6 errors found diff --git a/tests/untried/neg/t5510.scala b/tests/untried/neg/t5510.scala new file mode 100644 index 000000000000..12630eb2cd7e --- /dev/null +++ b/tests/untried/neg/t5510.scala @@ -0,0 +1,7 @@ +object Test { + val s1 = s"xxx + val s2 = s"xxx $x + val s3 = s"xxx $$ + val s4 = ""s" + val s5 = ""s""" $s1 $s2 s" +} diff --git a/tests/untried/neg/t5529.check b/tests/untried/neg/t5529.check new file mode 100644 index 000000000000..da3f84e1ec7f --- /dev/null +++ b/tests/untried/neg/t5529.check @@ -0,0 +1,7 @@ +t5529.scala:12: error: File is already defined as class File + type File + ^ +t5529.scala:10: error: class type required but test.Test.File found + sealed class Dir extends File { } + ^ +two errors found diff --git a/tests/untried/neg/t5529.scala b/tests/untried/neg/t5529.scala new file mode 100644 index 000000000000..033009a8a621 --- /dev/null +++ b/tests/untried/neg/t5529.scala @@ -0,0 +1,13 @@ +// /scala/trac/5529/a.scala +// Tue Feb 28 13:11:28 PST 2012 + +package test; + +object Test { + sealed class File { + val i = 1 + } + sealed class Dir extends File { } + + type File +} diff --git a/tests/untried/neg/t5543.check b/tests/untried/neg/t5543.check new file mode 100644 index 000000000000..b61de0f78b96 --- /dev/null +++ b/tests/untried/neg/t5543.check @@ -0,0 +1,10 @@ +t5543.scala:3: error: not found: type T + def this(x: T) { this() } + ^ +t5543.scala:11: error: not found: value x + def this(a: Int, b: Int = x) { + ^ +t5543.scala:18: error: not found: value x + def this(a: Int = x) { this() } + ^ +three errors found diff --git a/tests/untried/neg/t5543.scala b/tests/untried/neg/t5543.scala new file mode 100644 index 000000000000..4e03e6e11470 --- /dev/null +++ b/tests/untried/neg/t5543.scala @@ -0,0 +1,19 @@ +class C1 { + type T + def this(x: T) { this() } +} + +class C1a[T] { + def this(x: T) { this() } // works, no error here +} + +class C2(x: Int) { + def this(a: Int, b: Int = x) { + this(b) + } +} + +class C3 { + val x = 0 + def this(a: Int = x) { this() } +} diff --git a/tests/untried/neg/t5544.check b/tests/untried/neg/t5544.check new file mode 100644 index 000000000000..d4113935a33d --- /dev/null +++ b/tests/untried/neg/t5544.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: value baz is not a member of object Api + Api.baz + ^ +one error found diff --git a/tests/untried/neg/t5544/Api_1.scala b/tests/untried/neg/t5544/Api_1.scala new file mode 100644 index 000000000000..77637f440ac1 --- /dev/null +++ b/tests/untried/neg/t5544/Api_1.scala @@ -0,0 +1,8 @@ +import scala.annotation.StaticAnnotation + +class ann(val bar: Any) extends StaticAnnotation + +object Api { + @ann({def baz = "baz!!"}) + def foo = println("foo") +} diff --git a/tests/untried/neg/t5544/Test_2.scala b/tests/untried/neg/t5544/Test_2.scala new file mode 100644 index 000000000000..4c8c99cbc79e --- /dev/null +++ b/tests/untried/neg/t5544/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Api.baz +} diff --git a/tests/untried/neg/t5553_1.check b/tests/untried/neg/t5553_1.check new file mode 100644 index 000000000000..afd64898881c --- /dev/null +++ b/tests/untried/neg/t5553_1.check @@ -0,0 +1,54 @@ +t5553_1.scala:18: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (z: String)Base[T] +and method apply in object Foo1 of type (a: Int)Base[T] +match expected type ? + def test1[T] = Foo1[T] + ^ +t5553_1.scala:19: error: type mismatch; + found : [T](z: String)Base[T] (a: Int)Base[T] + required: Int + def test2[T]: Int = Foo1[T] + ^ +t5553_1.scala:20: error: type mismatch; + found : [T(in method apply)](z: String)Base[T(in method apply)] (a: Int)Base[T(in method apply)] + required: Base[T(in method test3)] + def test3[T]: Base[T] = Foo1[T] + ^ +t5553_1.scala:24: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (z: String)Base[T] +and method apply in object Foo2 of type (a: Int)Base[T] +match expected type ? + def test4[T] = Foo2[T] + ^ +t5553_1.scala:25: error: type mismatch; + found : [T](z: String)Base[T] (a: Int)Base[T] + required: Int + def test5[T]: Int = Foo2[T] + ^ +t5553_1.scala:26: error: type mismatch; + found : [T(in method apply)](z: String)Base[T(in method apply)] (a: Int)Base[T(in method apply)] + required: Base[T(in method test6)] + def test6[T]: Base[T] = Foo2[T] + ^ +t5553_1.scala:30: error: ambiguous reference to overloaded definition, +both method apply in object Foo3 of type (z: String)String +and method apply in object Foo3 of type (a: Int)Base[T] +match expected type ? + def test7[T] = Foo3[T] + ^ +t5553_1.scala:31: error: type mismatch; + found : [T](z: String)String (a: Int)Base[T] + required: String + def test8[T]: String = Foo3[T] + ^ +t5553_1.scala:32: error: type mismatch; + found : [T](z: String)String (a: Int)Base[T] + required: Int + def test9[T]: Int = Foo3[T] + ^ +t5553_1.scala:33: error: type mismatch; + found : [T(in method apply)](z: String)String (a: Int)Base[T(in method apply)] + required: Base[T(in method test10)] + def test10[T]: Base[T] = Foo3[T] + ^ +10 errors found diff --git a/tests/untried/neg/t5553_1.scala b/tests/untried/neg/t5553_1.scala new file mode 100644 index 000000000000..32d61ec85270 --- /dev/null +++ b/tests/untried/neg/t5553_1.scala @@ -0,0 +1,34 @@ +class Base[T] + +object Foo1 { + def apply[T](a: Int): Base[T] = new Base[T] + def apply[T](z: String): Base[T] = new Base[T] +} + +object Foo2 { + def apply[T](a: Int): Base[T] = new Base[T] + def apply[T](z: String="abc"): Base[T] = new Base[T] +} + +object Foo3 { + def apply[T](a: Int): Base[T] = new Base[T] + def apply[T](z: String="abc"): String = z +} +object Test { + def test1[T] = Foo1[T] + def test2[T]: Int = Foo1[T] + def test3[T]: Base[T] = Foo1[T] +} + +object Test2 { + def test4[T] = Foo2[T] + def test5[T]: Int = Foo2[T] + def test6[T]: Base[T] = Foo2[T] +} + +object Test3{ + def test7[T] = Foo3[T] + def test8[T]: String = Foo3[T] + def test9[T]: Int = Foo3[T] + def test10[T]: Base[T] = Foo3[T] +} diff --git a/tests/untried/neg/t5553_2.check b/tests/untried/neg/t5553_2.check new file mode 100644 index 000000000000..599fdb05239a --- /dev/null +++ b/tests/untried/neg/t5553_2.check @@ -0,0 +1,50 @@ +t5553_2.scala:27: error: type mismatch; + found : Base[T] + required: Int + def test4[T]: Int = Foo1[T](1) + ^ +t5553_2.scala:34: error: type mismatch; + found : String + required: Base[T] + def test7[T]: Base[T] = Foo2[T] + ^ +t5553_2.scala:35: error: type mismatch; + found : String + required: Int + def test8[T]: Int = Foo2[T] + ^ +t5553_2.scala:40: error: type mismatch; + found : String + required: Int + def test9[T]: Int = Foo3[T] + ^ +t5553_2.scala:41: error: type mismatch; + found : String + required: Base[T] + def test10[T]: Base[T] = Foo3[T] + ^ +t5553_2.scala:47: error: could not find implicit value for parameter z: String + def test13[T]: Int = Foo3[T] + ^ +t5553_2.scala:48: error: could not find implicit value for parameter z: String + def test14[T]: Base[T] = Foo3[T] + ^ +t5553_2.scala:49: error: could not find implicit value for parameter z: String + def test15[T]: String = Foo3[T] + ^ +t5553_2.scala:50: error: could not find implicit value for parameter z: String + def test16[T] = Foo3[T] + ^ +t5553_2.scala:54: error: ambiguous reference to overloaded definition, +both method apply in object Foo4 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo4 of type (x: Int)Base[T] +match argument types (Int) + def test17[T] = Foo4[T](1) + ^ +t5553_2.scala:55: error: ambiguous reference to overloaded definition, +both method apply in object Foo4 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo4 of type (x: Int)Base[T] +match argument types (Int) and expected result type Base[T] + def test18[T]: Base[T] = Foo4[T](1) + ^ +11 errors found diff --git a/tests/untried/neg/t5553_2.scala b/tests/untried/neg/t5553_2.scala new file mode 100644 index 000000000000..16958aec8e22 --- /dev/null +++ b/tests/untried/neg/t5553_2.scala @@ -0,0 +1,59 @@ +class Base[T] + +object Foo1 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int, z: String="abc"): String = z +} + +object Foo2 { + def apply[T](a: Int): Base[T] = new Base[T] + def apply[T]: String = "abc" +} + +object Foo3 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](implicit z: String): String = z +} + +object Foo4 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): Base[T] = new Base[T] +} + +object Test1 { + def test1[T] = Foo1[T](1) + def test2[T]: String = Foo1[T](1) + def test3[T]: Base[T] = Foo1[T](1) + def test4[T]: Int = Foo1[T](1) + +} + +object Test2 { + def test5[T] = Foo2[T] + def test6[T]: String = Foo2[T] + def test7[T]: Base[T] = Foo2[T] + def test8[T]: Int = Foo2[T] +} + +object Test3 { + implicit val v: String = "abc" + def test9[T]: Int = Foo3[T] + def test10[T]: Base[T] = Foo3[T] + def test11[T]: String = Foo3[T] + def test12[T] = Foo3[T] +} + +object Test4 { + def test13[T]: Int = Foo3[T] + def test14[T]: Base[T] = Foo3[T] + def test15[T]: String = Foo3[T] + def test16[T] = Foo3[T] +} + +object Test5 { + def test17[T] = Foo4[T](1) + def test18[T]: Base[T] = Foo4[T](1) + //def test19[T]: String = Foo4[T](1) // #5554 +} + + diff --git a/tests/untried/neg/t5554.check b/tests/untried/neg/t5554.check new file mode 100644 index 000000000000..8f657fd32f97 --- /dev/null +++ b/tests/untried/neg/t5554.check @@ -0,0 +1,67 @@ +t5554.scala:14: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (x: Int)(implicit z: String)String +and method apply in object Foo1 of type (x: Int)Base[T] +match argument types (Int) + def test1[T]: Int = Foo1[T](1) + ^ +t5554.scala:16: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (x: Int)(implicit z: String)String +and method apply in object Foo1 of type (x: Int)Base[T] +match argument types (Int) + def test3[T]: String = Foo1[T](1) + ^ +t5554.scala:17: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (x: Int)(implicit z: String)String +and method apply in object Foo1 of type (x: Int)Base[T] +match argument types (Int) + def test4[T] = Foo1[T](1) + ^ +t5554.scala:22: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (x: Int)(implicit z: String)String +and method apply in object Foo1 of type (x: Int)Base[T] +match argument types (Int) + def test5[T]: Int = Foo1[T](1) + ^ +t5554.scala:25: error: ambiguous reference to overloaded definition, +both method apply in object Foo1 of type (x: Int)(implicit z: String)String +and method apply in object Foo1 of type (x: Int)Base[T] +match argument types (Int) + def test8[T] = Foo1[T](1) + ^ +t5554.scala:29: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) + def test9[T]: String = Foo2[T](1) + ^ +t5554.scala:30: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) and expected result type Base[T] + def test10[T]: Base[T] = Foo2[T](1) + ^ +t5554.scala:31: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) + def test11[T] = Foo2[T](1) + ^ +t5554.scala:36: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) + def test12[T]: String = Foo2[T](1) + ^ +t5554.scala:37: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) and expected result type Base[T] + def test13[T]: Base[T] = Foo2[T](1) + ^ +t5554.scala:38: error: ambiguous reference to overloaded definition, +both method apply in object Foo2 of type (x: Int)(implicit z: String)Base[T] +and method apply in object Foo2 of type (x: Int)Base[T] +match argument types (Int) + def test14[T] = Foo2[T](1) + ^ +11 errors found diff --git a/tests/untried/neg/t5554.scala b/tests/untried/neg/t5554.scala new file mode 100644 index 000000000000..d279abea7fdc --- /dev/null +++ b/tests/untried/neg/t5554.scala @@ -0,0 +1,39 @@ +class Base[T] + +object Foo1 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): String = z +} + +object Foo2 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): Base[T] = new Base[T] +} + +object Test1 { + def test1[T]: Int = Foo1[T](1) + def test2[T]: Base[T] = Foo1[T](1) + def test3[T]: String = Foo1[T](1) + def test4[T] = Foo1[T](1) +} + +object Test2 { + implicit val v: String = "foo" + def test5[T]: Int = Foo1[T](1) + def test6[T]: Base[T] = Foo1[T](1) + def test7[T]: String = Foo1[T](1) + def test8[T] = Foo1[T](1) +} + +object Test3 { + def test9[T]: String = Foo2[T](1) + def test10[T]: Base[T] = Foo2[T](1) + def test11[T] = Foo2[T](1) +} + +object Test4 { + implicit val v: String = "foo" + def test12[T]: String = Foo2[T](1) + def test13[T]: Base[T] = Foo2[T](1) + def test14[T] = Foo2[T](1) +} diff --git a/tests/untried/neg/t556.check b/tests/untried/neg/t556.check new file mode 100644 index 000000000000..30cc296b356f --- /dev/null +++ b/tests/untried/neg/t556.check @@ -0,0 +1,7 @@ +t556.scala:3: error: missing parameter type + def g:Int = f((x,y)=>x) + ^ +t556.scala:3: error: missing parameter type + def g:Int = f((x,y)=>x) + ^ +two errors found diff --git a/tests/untried/neg/t556.scala b/tests/untried/neg/t556.scala new file mode 100644 index 000000000000..b0113258c946 --- /dev/null +++ b/tests/untried/neg/t556.scala @@ -0,0 +1,4 @@ +object Main extends App { + def f(a:Int=>Int):Int = a(4) + def g:Int = f((x,y)=>x) +} diff --git a/tests/untried/neg/t5564.check b/tests/untried/neg/t5564.check new file mode 100644 index 000000000000..e7e13ccc9c26 --- /dev/null +++ b/tests/untried/neg/t5564.check @@ -0,0 +1,4 @@ +t5564.scala:8: error: inferred type arguments [A] do not conform to method bar's type parameter bounds [B >: A <: C] + def bar[B >: A <: C]: T = throw new Exception + ^ +one error found diff --git a/tests/untried/neg/t5564.scala b/tests/untried/neg/t5564.scala new file mode 100644 index 000000000000..663cf88726d7 --- /dev/null +++ b/tests/untried/neg/t5564.scala @@ -0,0 +1,9 @@ + + + +trait C + + +class Foo[@specialized(Int) T, A] { + def bar[B >: A <: C]: T = throw new Exception +} diff --git a/tests/untried/neg/t5572.check b/tests/untried/neg/t5572.check new file mode 100644 index 000000000000..3c9adf41cdc0 --- /dev/null +++ b/tests/untried/neg/t5572.check @@ -0,0 +1,16 @@ +t5572.scala:16: error: type mismatch; + found : B + required: A + Z.transf(a, b) match { + ^ +t5572.scala:16: error: type mismatch; + found : A + required: B + Z.transf(a, b) match { + ^ +t5572.scala:18: error: type mismatch; + found : A + required: B + run(sth, b) + ^ +three errors found diff --git a/tests/untried/neg/t5572.scala b/tests/untried/neg/t5572.scala new file mode 100644 index 000000000000..81f848362bda --- /dev/null +++ b/tests/untried/neg/t5572.scala @@ -0,0 +1,23 @@ +class A +class B + +trait X + +object Z { + def transf(a: A, b: B): X = null +} + +class Test { + + def bar(): (A, B) + + def foo: Unit = { + val (b, a) = bar() + Z.transf(a, b) match { + case sth => + run(sth, b) + } + } + + def run(x: X, z: B): Unit = () +} diff --git a/tests/untried/neg/t5578.check b/tests/untried/neg/t5578.check new file mode 100644 index 000000000000..56123d2e0f2c --- /dev/null +++ b/tests/untried/neg/t5578.check @@ -0,0 +1,7 @@ +t5578.scala:33: error: type mismatch; + found : NumericOpsExp.this.Plus[T] + required: NumericOpsExp.this.Rep[T] + (which expands to) NumericOpsExp.this.Exp[T] + def plus[T: Numeric](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x,y) + ^ +one error found diff --git a/tests/untried/neg/t5578.scala b/tests/untried/neg/t5578.scala new file mode 100644 index 000000000000..ce72f32d53b6 --- /dev/null +++ b/tests/untried/neg/t5578.scala @@ -0,0 +1,39 @@ +trait Base { + type Rep[T] +} + +trait Expressions { + // constants/symbols (atomic) + abstract class Exp[T] + // ... + case class Sym[T](n: Int) extends Exp[T] + + // operations (composite, defined in subtraits) + abstract class Def[T] + + // additional members for managing encountered definitions + def findOrCreateDefinition[T](rhs: Def[T]): Sym[T] + implicit def toExp[T:Manifest](d: Def[T]): Exp[T] = findOrCreateDefinition(d) +} + +trait BaseExp extends Base with Expressions { + type Rep[T] = Exp[T] + + def findOrCreateDefinition[T](rhs: Def[T]): Sym[T] = null // stub +} + +trait NumericOps extends Base { + def plus[T](x: Rep[T], y: Rep[T]): Rep[T] +} + +trait NumericOpsExp extends BaseExp { + case class Plus[T:Numeric](x: Rep[T], y: Rep[T]) + extends Def[T] + + def plus[T: Numeric](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x,y) + + // Possible solutions: +// def plus[T: Numeric: Manifest](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x, y) +// def plus[T](x: Rep[T], y: Rep[T])(implicit num: Numeric[T], man: Manifest[T]): Rep[T] = Plus(x,y) + +} diff --git a/tests/untried/neg/t558.check b/tests/untried/neg/t558.check new file mode 100644 index 000000000000..f33ddc451f10 --- /dev/null +++ b/tests/untried/neg/t558.check @@ -0,0 +1,4 @@ +t558.scala:13: error: value file is not a member of NewModel.this.RootURL + final val source = top.file; + ^ +one error found diff --git a/tests/untried/neg/t558.scala b/tests/untried/neg/t558.scala new file mode 100644 index 000000000000..58b030347cda --- /dev/null +++ b/tests/untried/neg/t558.scala @@ -0,0 +1,19 @@ +package scala.tools.nsc.models; +import scala.tools.nsc.io.AbstractFile; + +abstract class NewModel { + abstract class SymbolURL { + val top : RootURL; + val name : String; + val source : AbstractFile; + } + abstract class NodeURL extends SymbolURL { + val parent : SymbolURL; + final val top = parent.top; + final val source = top.file; + + } + abstract class RootURL extends SymbolURL { + final val top : RootURL = this; + } +} diff --git a/tests/untried/neg/t5580a.check b/tests/untried/neg/t5580a.check new file mode 100644 index 000000000000..50a31857d591 --- /dev/null +++ b/tests/untried/neg/t5580a.check @@ -0,0 +1,6 @@ +t5580a.scala:9: error: polymorphic expression cannot be instantiated to expected type; + found : [A]scala.collection.mutable.Set[A] + required: scala.collection.mutable.Map[bar,scala.collection.mutable.Set[bar]] + if (map.get(tmp).isEmpty) map.put(tmp,collection.mutable.Set()) + ^ +one error found diff --git a/tests/untried/neg/t5580a.scala b/tests/untried/neg/t5580a.scala new file mode 100644 index 000000000000..742f0e85ea89 --- /dev/null +++ b/tests/untried/neg/t5580a.scala @@ -0,0 +1,11 @@ +import scala.collection.mutable.WeakHashMap + +class bar{ } +class foo{ + val map = WeakHashMap[AnyRef, collection.mutable.Map[bar, collection.mutable.Set[bar]]]() + + def test={ + val tmp:bar=null + if (map.get(tmp).isEmpty) map.put(tmp,collection.mutable.Set()) + } +} diff --git a/tests/untried/neg/t5580b.check b/tests/untried/neg/t5580b.check new file mode 100644 index 000000000000..45fde46ff99f --- /dev/null +++ b/tests/untried/neg/t5580b.check @@ -0,0 +1,6 @@ +t5580b.scala:11: error: polymorphic expression cannot be instantiated to expected type; + found : [A]scala.collection.mutable.Set[A] + required: scala.collection.mutable.Map[bar,scala.collection.mutable.Set[bar]] + if (map.get(tmp).isEmpty) map.put(tmp,collection.mutable.Set()) + ^ +one error found diff --git a/tests/untried/neg/t5580b.scala b/tests/untried/neg/t5580b.scala new file mode 100644 index 000000000000..2161da45849c --- /dev/null +++ b/tests/untried/neg/t5580b.scala @@ -0,0 +1,13 @@ +import scala.collection.mutable.WeakHashMap +import scala.collection.JavaConversions._ + +class bar { } + +class foo { + val map = WeakHashMap[AnyRef, collection.mutable.Map[bar, collection.mutable.Set[bar]]]() + + def test={ + val tmp:bar=null + if (map.get(tmp).isEmpty) map.put(tmp,collection.mutable.Set()) + } +} diff --git a/tests/untried/neg/t5617.check b/tests/untried/neg/t5617.check new file mode 100644 index 000000000000..79cc3a1e3240 --- /dev/null +++ b/tests/untried/neg/t5617.check @@ -0,0 +1,8 @@ +t5617.scala:12: error: method foo overrides nothing. +Note: the super classes of trait C contain the following, non final members named foo: +def foo(u: Unit): Int +def foo(x: Boolean): Int +def foo(i: Int)(b: String): Int + override def foo(s: String): Int + ^ +one error found diff --git a/tests/untried/neg/t5617.scala b/tests/untried/neg/t5617.scala new file mode 100644 index 000000000000..41541b5e9033 --- /dev/null +++ b/tests/untried/neg/t5617.scala @@ -0,0 +1,14 @@ +trait A { + def foo(i: Int)(b: String): Int + def foo(u: Unit): Int // not reported + def foo(x: Float): Int // not reported +} +trait B[X] extends A { + def foo(x: X): Int + def foo(u: Unit): Int + final def foo(x: Float): Int = 0 // not reported +} +trait C extends B[Boolean] { + override def foo(s: String): Int + val foo = 0 // not reported +} diff --git a/tests/untried/neg/t562.check b/tests/untried/neg/t562.check new file mode 100644 index 000000000000..8c3823642a4c --- /dev/null +++ b/tests/untried/neg/t562.check @@ -0,0 +1,4 @@ +t562.scala:10: error: super may be not be used on value y + override val y = super.y; + ^ +one error found diff --git a/tests/untried/neg/t562.scala b/tests/untried/neg/t562.scala new file mode 100644 index 000000000000..c4a6e61742b9 --- /dev/null +++ b/tests/untried/neg/t562.scala @@ -0,0 +1,11 @@ +package test; + +abstract class XXX; + +trait YYY extends XXX { + val y = 10; +} + +class Foo extends XXX with YYY { + override val y = super.y; +} diff --git a/tests/untried/neg/t563.check b/tests/untried/neg/t563.check new file mode 100644 index 000000000000..1431c85eb052 --- /dev/null +++ b/tests/untried/neg/t563.check @@ -0,0 +1,4 @@ +t563.scala:6: error: missing parameter type + map(n,ptr => Option(ptr.get)); + ^ +one error found diff --git a/tests/untried/neg/t563.scala b/tests/untried/neg/t563.scala new file mode 100644 index 000000000000..204ad3cbdda7 --- /dev/null +++ b/tests/untried/neg/t563.scala @@ -0,0 +1,7 @@ +object Test { + def map[A,R](a : List[A], f : A => R) : List[R] = a.map(f); + + def split(sn : Iterable[List[Option[Int]]]) : Unit = + for (n <- sn) + map(n,ptr => Option(ptr.get)); +} diff --git a/tests/untried/neg/t565.check b/tests/untried/neg/t565.check new file mode 100644 index 000000000000..136cc94b6fd6 --- /dev/null +++ b/tests/untried/neg/t565.check @@ -0,0 +1,5 @@ +t565.scala:2: error: only classes can have declared but undefined members +(Note that variables need to be initialized to be defined) + var s0: String + ^ +one error found diff --git a/tests/untried/neg/t565.scala b/tests/untried/neg/t565.scala new file mode 100644 index 000000000000..9a4732fcc347 --- /dev/null +++ b/tests/untried/neg/t565.scala @@ -0,0 +1,3 @@ +object test { + var s0: String +} diff --git a/tests/untried/neg/t5663-badwarneq.check b/tests/untried/neg/t5663-badwarneq.check new file mode 100644 index 000000000000..732e4f44d0e0 --- /dev/null +++ b/tests/untried/neg/t5663-badwarneq.check @@ -0,0 +1,42 @@ +t5663-badwarneq.scala:47: warning: comparing case class values of types Some[Int] and None.type using `==' will always yield false + println(new Some(1) == None) // Should complain on type, was: spuriously complains on fresh object + ^ +t5663-badwarneq.scala:48: warning: comparing case class values of types Some[Int] and Thing using `==' will always yield false + println(Some(1) == new Thing(1)) // Should complain on type, was: spuriously complains on fresh object + ^ +t5663-badwarneq.scala:56: warning: ThingOne and Thingy are unrelated: they will most likely never compare equal + println(t1 == t2) // true, but apparently unrelated, a compromise warning + ^ +t5663-badwarneq.scala:57: warning: ThingThree and Thingy are unrelated: they will most likely never compare equal + println(t4 == t2) // true, complains because ThingThree is final and Thingy not a subclass, stronger claim than unrelated + ^ +t5663-badwarneq.scala:60: warning: comparing case class values of types ThingTwo and Some[Int] using `==' will always yield false + println(t3 == Some(1)) // false, warn on different cases + ^ +t5663-badwarneq.scala:61: warning: comparing values of types ThingOne and Cousin using `==' will always yield false + println(t1 == c) // should warn + ^ +t5663-badwarneq.scala:69: warning: comparing case class values of types Simple and SimpleSibling.type using `==' will always yield false + println(new Simple() == SimpleSibling) // like Some(1) == None, but needn't be final case + ^ +t5663-badwarneq.scala:72: warning: ValueClass1 and Int are unrelated: they will never compare equal + println(new ValueClass1(5) == 5) // bad + ^ +t5663-badwarneq.scala:74: warning: comparing values of types Int and ValueClass1 using `==' will always yield false + println(5 == new ValueClass1(5)) // bad + ^ +t5663-badwarneq.scala:78: warning: ValueClass2[String] and String are unrelated: they will never compare equal + println(new ValueClass2("abc") == "abc") // bad + ^ +t5663-badwarneq.scala:79: warning: ValueClass2[Int] and ValueClass1 are unrelated: they will never compare equal + println(new ValueClass2(5) == new ValueClass1(5)) // bad - different value classes + ^ +t5663-badwarneq.scala:81: warning: comparing values of types ValueClass3 and ValueClass2[Int] using `==' will always yield false + println(ValueClass3(5) == new ValueClass2(5)) // bad + ^ +t5663-badwarneq.scala:82: warning: comparing values of types ValueClass3 and Int using `==' will always yield false + println(ValueClass3(5) == 5) // bad + ^ +error: No warnings can be incurred under -Xfatal-warnings. +13 warnings found +one error found diff --git a/tests/untried/neg/t5663-badwarneq.flags b/tests/untried/neg/t5663-badwarneq.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t5663-badwarneq.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t5663-badwarneq.scala b/tests/untried/neg/t5663-badwarneq.scala new file mode 100644 index 000000000000..1cc554264ce4 --- /dev/null +++ b/tests/untried/neg/t5663-badwarneq.scala @@ -0,0 +1,94 @@ + +// alias +trait Thingy + +class Gramps + +// sibling classes that extend a case class +case class Thing(i: Int) extends Gramps +class ThingOne(x:Int) extends Thing(x) +class ThingTwo(y:Int) extends Thing(y) with Thingy +final class ThingThree(z:Int) extends Thing(z) + +// not case cousin +class Cousin extends Gramps + +class SimpleParent +case class Simple() extends SimpleParent +case object SimpleSibling extends SimpleParent + +// value classes +final class ValueClass1(val value: Int) extends AnyVal +final class ValueClass2[T](val value: T) extends AnyVal +final case class ValueClass3(val value: Int) extends AnyVal + +/* It's not possible to run partest without -deprecation. + * Since detecting the warnings requires a neg test with + * -Xfatal-warnings, and deprecation terminates the compile, + * we'll just comment out the nasty part. The point was + * just to show there's nothing special about a trait + * that extends a case class, which is only permitted + * (deprecatingly) by omitting the parens. + * +// common ancestor is something else +class AnyThing +case class SomeThing extends AnyThing // deprecation +class OtherThing extends AnyThing + +// how you inherit caseness doesn't matter +trait InThing extends SomeThing +class MyThing extends InThing +*/ + +object Test { + def main(a: Array[String]): Unit = { + // nothing to do with Gavin + println(new Some(1) == new Some(1)) // OK, true + println(new Some(1) == None) // Should complain on type, was: spuriously complains on fresh object + println(Some(1) == new Thing(1)) // Should complain on type, was: spuriously complains on fresh object + + val t1 = new ThingOne(11) + val t2: Thingy = new ThingTwo(11) + val t3 = new ThingTwo(11) + val t4 = new ThingThree(11) + val c = new Cousin + + println(t1 == t2) // true, but apparently unrelated, a compromise warning + println(t4 == t2) // true, complains because ThingThree is final and Thingy not a subclass, stronger claim than unrelated + println(t2 == t3) // OK, two Thingy + println(t3 == t2) // ditto with case receiver + println(t3 == Some(1)) // false, warn on different cases + println(t1 == c) // should warn + + // don't warn on fresh cases + println(new ThingOne(11) == t1) // OK, was: two cases not warnable on trunk + println(new ThingTwo(11) == t2) // true, was: spuriously complains on fresh object + println(new ThingOne(11) == t3) // two cases not warnable on trunk + println(new ThingTwo(11) == t3) // ditto + + println(new Simple() == SimpleSibling) // like Some(1) == None, but needn't be final case + + println(new ValueClass1(5) == new ValueClass1(5)) // ok + println(new ValueClass1(5) == 5) // bad + println(new ValueClass1(5) == (5: Any)) // ok, have to let it through + println(5 == new ValueClass1(5)) // bad + println((5: Any) == new ValueClass1(5) == (5: Any)) // ok + + println(new ValueClass2("abc") == new ValueClass2("abc")) // ok + println(new ValueClass2("abc") == "abc") // bad + println(new ValueClass2(5) == new ValueClass1(5)) // bad - different value classes + println(ValueClass3(5) == new ValueClass3(5)) // ok + println(ValueClass3(5) == new ValueClass2(5)) // bad + println(ValueClass3(5) == 5) // bad + + /* + val mine = new MyThing + val some = new SomeThing + val other = new OtherThing + println(mine == some) // OK, two Something + println(some == mine) + println(mine == other) // OK, two Anything? + println(mine == t1) // false + */ + } +} diff --git a/tests/untried/neg/t5666.check b/tests/untried/neg/t5666.check new file mode 100644 index 000000000000..1c714796ba45 --- /dev/null +++ b/tests/untried/neg/t5666.check @@ -0,0 +1,37 @@ +t5666.scala:2: error: class Any is abstract; cannot be instantiated + new Any + ^ +t5666.scala:3: error: class AnyVal is abstract; cannot be instantiated + new AnyVal + ^ +t5666.scala:4: error: class Double is abstract; cannot be instantiated + new Double + ^ +t5666.scala:5: error: class Float is abstract; cannot be instantiated + new Float + ^ +t5666.scala:6: error: class Long is abstract; cannot be instantiated + new Long + ^ +t5666.scala:7: error: class Int is abstract; cannot be instantiated + new Int + ^ +t5666.scala:8: error: class Char is abstract; cannot be instantiated + new Char + ^ +t5666.scala:9: error: class Short is abstract; cannot be instantiated + new Short + ^ +t5666.scala:10: error: class Byte is abstract; cannot be instantiated + new Byte + ^ +t5666.scala:11: error: class Boolean is abstract; cannot be instantiated + new Boolean + ^ +t5666.scala:12: error: class Unit is abstract; cannot be instantiated + new Unit + ^ +t5666.scala:13: error: class Nothing is abstract; cannot be instantiated + new Nothing + ^ +12 errors found diff --git a/tests/untried/neg/t5666.scala b/tests/untried/neg/t5666.scala new file mode 100644 index 000000000000..21ab9f45a197 --- /dev/null +++ b/tests/untried/neg/t5666.scala @@ -0,0 +1,14 @@ +object t5666 { + new Any + new AnyVal + new Double + new Float + new Long + new Int + new Char + new Short + new Byte + new Boolean + new Unit + new Nothing +} diff --git a/tests/untried/neg/t5675.check b/tests/untried/neg/t5675.check new file mode 100644 index 000000000000..da608a2b78bc --- /dev/null +++ b/tests/untried/neg/t5675.check @@ -0,0 +1,2 @@ +error: there were 1 feature warning(s); re-run with -feature for details +one error found diff --git a/tests/untried/neg/t5675.flags b/tests/untried/neg/t5675.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t5675.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t5675.scala b/tests/untried/neg/t5675.scala new file mode 100644 index 000000000000..12f2973c7ffe --- /dev/null +++ b/tests/untried/neg/t5675.scala @@ -0,0 +1,7 @@ +class PostFix { + val list = List(1, 2, 3) + def main(args: Array[String]): Unit = { + val a = list filter (2 !=) + val b = list filter (2 != _) + } +} diff --git a/tests/untried/neg/t5683.check b/tests/untried/neg/t5683.check new file mode 100644 index 000000000000..7c0e50113c07 --- /dev/null +++ b/tests/untried/neg/t5683.check @@ -0,0 +1,16 @@ +t5683.scala:12: error: inferred kinds of the type arguments (Object,Int) do not conform to the expected kinds of the type parameters (type M,type B). +Object's type parameters do not match type M's expected parameters: +class Object has no type parameters, but type M has one + val crash: K[StringW,Int,Int] = k{ (y: Int) => null: W[String, Int] } + ^ +t5683.scala:12: error: type mismatch; + found : Int => Test.W[String,Int] + required: Int => M[B] + val crash: K[StringW,Int,Int] = k{ (y: Int) => null: W[String, Int] } + ^ +t5683.scala:12: error: type mismatch; + found : Test.K[M,Int,B] + required: Test.K[Test.StringW,Int,Int] + val crash: K[StringW,Int,Int] = k{ (y: Int) => null: W[String, Int] } + ^ +three errors found diff --git a/tests/untried/neg/t5683.scala b/tests/untried/neg/t5683.scala new file mode 100644 index 000000000000..05ab03579274 --- /dev/null +++ b/tests/untried/neg/t5683.scala @@ -0,0 +1,23 @@ +object Test { + trait NT[X] + trait W[W, A] extends NT[Int] + type StringW[T] = W[String, T] + trait K[M[_], A, B] + + def k[M[_], B](f: Int => M[B]): K[M, Int, B] = null + + val okay1: K[StringW,Int,Int] = k{ (y: Int) => null: StringW[Int] } + val okay2 = k[StringW,Int]{ (y: Int) => null: W[String, Int] } + + val crash: K[StringW,Int,Int] = k{ (y: Int) => null: W[String, Int] } + + // remove `extends NT[Int]`, and the last line gives an inference error + // rather than a crash. + // test/files/pos/t5683.scala:12: error: no type parameters for method k: (f: Int => M[B])Test.K[M,Int,B] exist so that it can be applied to arguments (Int => Test.W[String,Int]) + // --- because --- + // argument expression's type is not compatible with formal parameter type; + // found : Int => Test.W[String,Int] + // required: Int => ?M[?B] + // val crash: K[StringW,Int,Int] = k{ (y: Int) => null: W[String, Int] } + // ^ +} diff --git a/tests/untried/neg/t5687.check b/tests/untried/neg/t5687.check new file mode 100644 index 000000000000..5096077ee5d8 --- /dev/null +++ b/tests/untried/neg/t5687.check @@ -0,0 +1,8 @@ +t5687.scala:4: error: type arguments [T] do not conform to class Template's type parameter bounds [T <: AnyRef] + type Repr[T]<:Template[T] + ^ +t5687.scala:20: error: overriding type Repr in class Template with bounds[T] <: Template[T]; + type Repr has incompatible type + type Repr = CurveTemplate[T] + ^ +two errors found diff --git a/tests/untried/neg/t5687.scala b/tests/untried/neg/t5687.scala new file mode 100644 index 000000000000..6ffecf972054 --- /dev/null +++ b/tests/untried/neg/t5687.scala @@ -0,0 +1,55 @@ +abstract class Template[T <: AnyRef](private val t: T) { + +// type Repr[A<:AnyRef]<:Template[T] + type Repr[T]<:Template[T] + + def access1(timeout: Int): Repr[T] = this.asInstanceOf[Repr[T]] + def access2: Repr[T] = this.asInstanceOf[Repr[T]] + val access3: Repr[T] = this.asInstanceOf[Repr[T]] + def access4(v: Repr[T]): Repr[T] = this.asInstanceOf[Repr[T]] + def access5(x: X): Repr[T] = this.asInstanceOf[Repr[T]] + def access5(x: Y): Repr[T] = this.asInstanceOf[Repr[T]] + + def withReadModifiers(readModifiers:Int): Repr[T] = this.asInstanceOf[Repr[T]] +} + +class Curve + +class CurveTemplate [T <: Curve](t: T) extends Template(t) { +// type Repr[A<: AnyRef] = CurveTemplate[T] + type Repr = CurveTemplate[T] +} + +class Base +class X extends Base +class Y extends Base + + +object Example { + def test1(): Unit = { + new CurveTemplate(new Curve).access1(10) + + new CurveTemplate(new Curve).access2 + + new CurveTemplate(new Curve).access3 + + new CurveTemplate(new Curve).access4(null) + + new CurveTemplate(new Curve).access5(new X) + + () + + } + + def test2(): Unit = { + new CurveTemplate(new Curve).access1(10).withReadModifiers(1) + + new CurveTemplate(new Curve).access2.withReadModifiers(1) + + new CurveTemplate(new Curve).access3.withReadModifiers(1) + + new CurveTemplate(new Curve).access4(null).withReadModifiers(1) + + new CurveTemplate(new Curve).access5(new X).withReadModifiers(1) + } +} diff --git a/tests/untried/neg/t5689.check b/tests/untried/neg/t5689.check new file mode 100644 index 000000000000..7d4f7fb63aa7 --- /dev/null +++ b/tests/untried/neg/t5689.check @@ -0,0 +1,8 @@ +t5689.scala:4: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(i: c.Expr[Double]): c.Expr[String] + or : (c: scala.reflect.macros.blackbox.Context)(i: c.Tree): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(i: c.Expr[Double]): c.Expr[Int] +type mismatch for return type: c.Expr[Int] does not conform to c.Expr[String] + def returnsString(i: Double): String = macro returnsIntImpl + ^ +one error found diff --git a/tests/untried/neg/t5689.flags b/tests/untried/neg/t5689.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/t5689.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/t5689.scala b/tests/untried/neg/t5689.scala new file mode 100644 index 000000000000..d757a5541767 --- /dev/null +++ b/tests/untried/neg/t5689.scala @@ -0,0 +1,6 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def returnsString(i: Double): String = macro returnsIntImpl + def returnsIntImpl(c: Context)(i: c.Expr[Double]): c.Expr[Int] = ??? +} diff --git a/tests/untried/neg/t5696.check b/tests/untried/neg/t5696.check new file mode 100644 index 000000000000..e0fb61b83961 --- /dev/null +++ b/tests/untried/neg/t5696.check @@ -0,0 +1,19 @@ +t5696.scala:6: error: too many argument lists for constructor invocation + new G(1)(2) {} + ^ +t5696.scala:14: error: too many argument lists for constructor invocation + new G()(2) {} + ^ +t5696.scala:22: error: too many argument lists for constructor invocation + new G[Int]()(2) {} + ^ +t5696.scala:30: error: too many argument lists for constructor invocation + new G[Int]()(2)(3) {} + ^ +t5696.scala:38: error: too many argument lists for constructor invocation + new G[Int]()()(2) {} + ^ +t5696.scala:46: error: too many argument lists for constructor invocation + object x extends G(1)(2) {} + ^ +6 errors found diff --git a/tests/untried/neg/t5696.scala b/tests/untried/neg/t5696.scala new file mode 100644 index 000000000000..051e3a07f92c --- /dev/null +++ b/tests/untried/neg/t5696.scala @@ -0,0 +1,47 @@ +class TestApply1 { + class G(y: Int) { + def apply(x: Int) = 1 + } + + new G(1)(2) {} +} + +class TestApply2 { + class G { + def apply(x: Int) = 1 + } + + new G()(2) {} +} + +class TestApply3 { + class G[X] { + def apply(x: Int) = 1 + } + + new G[Int]()(2) {} +} + +class TestApply4 { + class G[X] { + def apply(x: Int)(y: Int) = 1 + } + + new G[Int]()(2)(3) {} +} + +class TestApply5 { + class G[X]()() { + def apply(x: Int) = 1 + } + + new G[Int]()()(2) {} +} + +class TestApply6 { + class G(y: Int) { + def apply(x: Int) = 1 + } + + object x extends G(1)(2) {} +} diff --git a/tests/untried/neg/t5702-neg-bad-and-wild.check b/tests/untried/neg/t5702-neg-bad-and-wild.check new file mode 100644 index 000000000000..a52136dbf889 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-and-wild.check @@ -0,0 +1,28 @@ +t5702-neg-bad-and-wild.scala:10: error: bad simple pattern: bad use of _* (a sequence pattern must be the last pattern) + case List(1, _*,) => // bad use of _* (a sequence pattern must be the last pattern) + ^ +t5702-neg-bad-and-wild.scala:10: error: illegal start of simple pattern + case List(1, _*,) => // bad use of _* (a sequence pattern must be the last pattern) + ^ +t5702-neg-bad-and-wild.scala:12: error: illegal start of simple pattern + case List(1, _*3,) => // illegal start of simple pattern + ^ +t5702-neg-bad-and-wild.scala:14: error: bad simple pattern: use _* to match a sequence + case List(1, x*) => // use _* to match a sequence + ^ +t5702-neg-bad-and-wild.scala:15: error: bad simple pattern: trailing * is not a valid pattern + case List(x*, 1) => // trailing * is not a valid pattern + ^ +t5702-neg-bad-and-wild.scala:16: error: bad simple pattern: trailing * is not a valid pattern + case (1, x*) => // trailing * is not a valid pattern + ^ +t5702-neg-bad-and-wild.scala:17: error: bad simple pattern: bad use of _* (sequence pattern not allowed) + case (1, x@_*) => // bad use of _* (sequence pattern not allowed) + ^ +t5702-neg-bad-and-wild.scala:23: error: bad simple pattern: bad use of _* (a sequence pattern must be the last pattern) + val K(ns @ _*, x) = k // bad use of _* (a sequence pattern must be the last pattern) + ^ +t5702-neg-bad-and-wild.scala:24: error: bad simple pattern: bad use of _* (sequence pattern not allowed) + val (b, _ * ) = (5,6) // bad use of _* (sequence pattern not allowed) + ^ +9 errors found diff --git a/tests/untried/neg/t5702-neg-bad-and-wild.scala b/tests/untried/neg/t5702-neg-bad-and-wild.scala new file mode 100644 index 000000000000..aadda37da7c3 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-and-wild.scala @@ -0,0 +1,29 @@ + +object Test { + case class K(i: Int) + + def main(args: Array[String]) { + val k = new K(9) + val is = List(1,2,3) + + is match { + case List(1, _*,) => // bad use of _* (a sequence pattern must be the last pattern) + // illegal start of simple pattern + case List(1, _*3,) => // illegal start of simple pattern + //case List(1, _*3:) => // poor recovery by parens + case List(1, x*) => // use _* to match a sequence + case List(x*, 1) => // trailing * is not a valid pattern + case (1, x*) => // trailing * is not a valid pattern + case (1, x@_*) => // bad use of _* (sequence pattern not allowed) + } + +// good syntax, bad semantics, detected by typer +//gowild.scala:14: error: star patterns must correspond with varargs parameters + val K(is @ _*) = k + val K(ns @ _*, x) = k // bad use of _* (a sequence pattern must be the last pattern) + val (b, _ * ) = (5,6) // bad use of _* (sequence pattern not allowed) +// no longer complains +//bad-and-wild.scala:15: error: ')' expected but '}' found. + } +} + diff --git a/tests/untried/neg/t5702-neg-bad-brace.check b/tests/untried/neg/t5702-neg-bad-brace.check new file mode 100644 index 000000000000..503f7d95edc1 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-brace.check @@ -0,0 +1,10 @@ +t5702-neg-bad-brace.scala:14: error: Unmatched closing brace '}' ignored here + case List(1, _*} => + ^ +t5702-neg-bad-brace.scala:14: error: illegal start of simple pattern + case List(1, _*} => + ^ +t5702-neg-bad-brace.scala:15: error: ')' expected but '}' found. + } + ^ +three errors found diff --git a/tests/untried/neg/t5702-neg-bad-brace.scala b/tests/untried/neg/t5702-neg-bad-brace.scala new file mode 100644 index 000000000000..16a341cf8c17 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-brace.scala @@ -0,0 +1,17 @@ + +object Test { + + def main(args: Array[String]) { + val is = List(1,2,3) + + is match { +// the erroneous brace is ignored, so we can't halt on it. +// maybe brace healing can detect overlapping unmatched (...} +// In this case, the fix emits an extra error: +// t5702-neg-bad-brace.scala:10: error: Unmatched closing brace '}' ignored here +// t5702-neg-bad-brace.scala:10: error: illegal start of simple pattern (i.e., =>) +// t5702-neg-bad-brace.scala:11: error: ')' expected but '}' found. + case List(1, _*} => + } + } +} diff --git a/tests/untried/neg/t5702-neg-bad-xbrace.check b/tests/untried/neg/t5702-neg-bad-xbrace.check new file mode 100644 index 000000000000..9240abea4489 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-xbrace.check @@ -0,0 +1,7 @@ +t5702-neg-bad-xbrace.scala:19: error: bad simple pattern: bad brace or paren after _* + case {_*)} => y + ^ +t5702-neg-bad-xbrace.scala:28: error: bad simple pattern: bad brace or paren after _* + val {a, z@_*)} = xml + ^ +two errors found diff --git a/tests/untried/neg/t5702-neg-bad-xbrace.scala b/tests/untried/neg/t5702-neg-bad-xbrace.scala new file mode 100644 index 000000000000..64bbdb18bec8 --- /dev/null +++ b/tests/untried/neg/t5702-neg-bad-xbrace.scala @@ -0,0 +1,31 @@ + +object Test { + def main(args: Array[String]) { + /* PiS example, minus a brace + val yearMade = 1965 + val old = + { if (yearMade < 2000) yearMade} + else xml.NodeSeq.Empty } + println(old) + */ + + // bad brace or paren after _* + // actually, we know it's a bad paren... + // we skip it because not in a context looking for rparen + val xyear = 1965 + val ancient = + { + val when = xyear match { + case {_*)} => y + case _ => "2035" + } + {when} + } + println(ancient) + + val xml = appleboychild + // bad brace or paren after _* + val {a, z@_*)} = xml + println("A for "+ a +", ending with "+ z) + } +} diff --git a/tests/untried/neg/t5702-neg-ugly-xbrace.check b/tests/untried/neg/t5702-neg-ugly-xbrace.check new file mode 100644 index 000000000000..cdd2438b0e2e --- /dev/null +++ b/tests/untried/neg/t5702-neg-ugly-xbrace.check @@ -0,0 +1,19 @@ +t5702-neg-ugly-xbrace.scala:11: error: bad simple pattern: bad brace or paren after _* + val {a, z@_*) = xml + ^ +t5702-neg-ugly-xbrace.scala:12: error: Missing closing brace `}' assumed here + println("A for "+ a +", ending with "+ z) + ^ +t5702-neg-ugly-xbrace.scala:13: error: in XML literal: in XML content, please use '}}' to express '}' + } + ^ +t5702-neg-ugly-xbrace.scala:11: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed + val {a, z@_*) = xml + ^ +t5702-neg-ugly-xbrace.scala:14: error: illegal start of simple pattern +} +^ +t5702-neg-ugly-xbrace.scala:14: error: '}' expected but eof found. +} + ^ +6 errors found diff --git a/tests/untried/neg/t5702-neg-ugly-xbrace.scala b/tests/untried/neg/t5702-neg-ugly-xbrace.scala new file mode 100644 index 000000000000..0ff7bfa09d5a --- /dev/null +++ b/tests/untried/neg/t5702-neg-ugly-xbrace.scala @@ -0,0 +1,14 @@ + +object Test { + def main(args: Array[String]) { + + val xml = appleboychild + // This is the more likely typo, and the uglier parse. + // We could turn it into a } if } does not follow (to + // avoid handing }} back to xml) but that is quite ad hoc. + // Assuming } for ) after _* would not be not outlandish. + // bad brace or paren after _* + val {a, z@_*) = xml + println("A for "+ a +", ending with "+ z) + } +} diff --git a/tests/untried/neg/t5728.check b/tests/untried/neg/t5728.check new file mode 100644 index 000000000000..14f9c42ae007 --- /dev/null +++ b/tests/untried/neg/t5728.check @@ -0,0 +1,4 @@ +t5728.scala:3: error: implicit classes must accept exactly one primary constructor parameter + implicit class Foo + ^ +one error found diff --git a/tests/untried/neg/t5728.scala b/tests/untried/neg/t5728.scala new file mode 100644 index 000000000000..99337d06d46d --- /dev/null +++ b/tests/untried/neg/t5728.scala @@ -0,0 +1,7 @@ +object Test { + + implicit class Foo + + implicit def Foo = new Foo + +} diff --git a/tests/untried/neg/t5735.check b/tests/untried/neg/t5735.check new file mode 100644 index 000000000000..f6e002804404 --- /dev/null +++ b/tests/untried/neg/t5735.check @@ -0,0 +1,6 @@ +t5735.scala:6: error: type mismatch; + found : (x: Int)Int => String + required: Int + val z: Int = a + ^ +one error found diff --git a/tests/untried/neg/t5735.scala b/tests/untried/neg/t5735.scala new file mode 100644 index 000000000000..fde71ff962e0 --- /dev/null +++ b/tests/untried/neg/t5735.scala @@ -0,0 +1,7 @@ +abstract class Base { + def a: String = "one" +} +class Clazz extends Base { + def a(x: Int): Int = 2 + val z: Int = a +} diff --git a/tests/untried/neg/t5753.check b/tests/untried/neg/t5753.check new file mode 100644 index 000000000000..379416c1793d --- /dev/null +++ b/tests/untried/neg/t5753.check @@ -0,0 +1,5 @@ +Test_2.scala:9: error: macro implementation not found: foo +(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) + println(foo(42)) + ^ +one error found diff --git a/tests/untried/neg/t5753.flags b/tests/untried/neg/t5753.flags new file mode 100644 index 000000000000..cd66464f2f63 --- /dev/null +++ b/tests/untried/neg/t5753.flags @@ -0,0 +1 @@ +-language:experimental.macros \ No newline at end of file diff --git a/tests/untried/neg/t5753/Impls_Macros_1.scala b/tests/untried/neg/t5753/Impls_Macros_1.scala new file mode 100644 index 000000000000..9872c69171e8 --- /dev/null +++ b/tests/untried/neg/t5753/Impls_Macros_1.scala @@ -0,0 +1,6 @@ +import scala.reflect.macros.blackbox.Context + +trait Impls { + def impl(c: Context)(x: c.Expr[Any]) = x +} + diff --git a/tests/untried/neg/t5753/Test_2.scala b/tests/untried/neg/t5753/Test_2.scala new file mode 100644 index 000000000000..d52ed65c604a --- /dev/null +++ b/tests/untried/neg/t5753/Test_2.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.blackbox.Context + +object Macros extends Impls { + def foo(x: Any): Any = macro impl +} + +object Test extends App { + import Macros._ + println(foo(42)) +} + diff --git a/tests/untried/neg/t576.check b/tests/untried/neg/t576.check new file mode 100644 index 000000000000..7105c92866b0 --- /dev/null +++ b/tests/untried/neg/t576.check @@ -0,0 +1,4 @@ +t576.scala:14: error: overloaded method insert needs result type + if (true) sibling.insert(node); + ^ +one error found diff --git a/tests/untried/neg/t576.scala b/tests/untried/neg/t576.scala new file mode 100644 index 000000000000..fd83217a4549 --- /dev/null +++ b/tests/untried/neg/t576.scala @@ -0,0 +1,20 @@ +package lampion.collections; + +abstract class BaseListXXX { + type Node <: BaseNode; + abstract class BaseNode { + } +} +trait PriorityTreeXXX extends BaseListXXX { + type Node <: BasicTreeNode; + + trait BasicTreeNode extends BaseNode { + def sibling: Node; + def insert(dir : Int, node : Node) = { + if (true) sibling.insert(node); + //else insert(node); + + } + def insert(node : Node) : Unit = {} + } +} diff --git a/tests/untried/neg/t5761.check b/tests/untried/neg/t5761.check new file mode 100644 index 000000000000..2d66af26f652 --- /dev/null +++ b/tests/untried/neg/t5761.check @@ -0,0 +1,19 @@ +t5761.scala:4: error: not enough arguments for constructor D: (x: Int)D[Int]. +Unspecified value parameter x. + println(new D[Int]{}) // crash + ^ +t5761.scala:8: error: not enough arguments for constructor D: (x: Int)D[Int]. +Unspecified value parameter x. + println(new D[Int]()) // no crash + ^ +t5761.scala:9: error: not enough arguments for constructor D: (x: Int)D[Int]. +Unspecified value parameter x. + println(new D[Int]{}) // crash + ^ +t5761.scala:13: error: not found: type Tread + new Tread("sth") { }.run() + ^ +t5761.scala:13: error: value run is not a member of AnyRef + new Tread("sth") { }.run() + ^ +5 errors found diff --git a/tests/untried/neg/t5761.scala b/tests/untried/neg/t5761.scala new file mode 100644 index 000000000000..040c4eb75a93 --- /dev/null +++ b/tests/untried/neg/t5761.scala @@ -0,0 +1,16 @@ +class D[-A](x: A) { } + +object Test1 { + println(new D[Int]{}) // crash +} + +object Test2 { + println(new D[Int]()) // no crash + println(new D[Int]{}) // crash +} + +object Test3 { + new Tread("sth") { }.run() +} + + diff --git a/tests/untried/neg/t5762.check b/tests/untried/neg/t5762.check new file mode 100644 index 000000000000..2a2f12144ab7 --- /dev/null +++ b/tests/untried/neg/t5762.check @@ -0,0 +1,15 @@ +t5762.scala:6: warning: non-variable type argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure + case _: D[Int] if bippy => 1 + ^ +t5762.scala:7: warning: non-variable type argument String in type pattern D[String] is unchecked since it is eliminated by erasure + case _: D[String] => 2 + ^ +t5762.scala:20: warning: non-variable type argument D[Int] in type pattern D[D[Int]] is unchecked since it is eliminated by erasure + case _: D[D[Int]] if bippy => 1 + ^ +t5762.scala:21: warning: non-variable type argument D[String] in type pattern D[D[String]] is unchecked since it is eliminated by erasure + case _: D[D[String]] => 2 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t5762.flags b/tests/untried/neg/t5762.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t5762.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t5762.scala b/tests/untried/neg/t5762.scala new file mode 100644 index 000000000000..fb73552b12eb --- /dev/null +++ b/tests/untried/neg/t5762.scala @@ -0,0 +1,24 @@ +class D[-A] + +object Test { + var bippy: Boolean = true + def f1(x: D[Int with String]) = x match { + case _: D[Int] if bippy => 1 + case _: D[String] => 2 + } + // Correctly warns: + // + // a.scala:5: warning: non variable type-argument Int in type pattern D[Int] is unchecked since it is eliminated by erasure + // case _: D[Int] => 1 + // ^ + // a.scala:6: warning: non variable type-argument String in type pattern D[String] is unchecked since it is eliminated by erasure + // case _: D[String] => 2 + // ^ + // two warnings found + + def f2(x: D[D[Int] with D[String]]) = x match { + case _: D[D[Int]] if bippy => 1 + case _: D[D[String]] => 2 + } + // No warnings! +} diff --git a/tests/untried/neg/t5799.check b/tests/untried/neg/t5799.check new file mode 100644 index 000000000000..3b43d06a944f --- /dev/null +++ b/tests/untried/neg/t5799.check @@ -0,0 +1,4 @@ +t5799.scala:2: error: secondary constructor is not allowed in value class + def this(s: String) = this(s.toDouble) + ^ +one error found diff --git a/tests/untried/neg/t5799.scala b/tests/untried/neg/t5799.scala new file mode 100644 index 000000000000..9bd6ab7dd100 --- /dev/null +++ b/tests/untried/neg/t5799.scala @@ -0,0 +1,8 @@ +class Foo(val bar: Double) extends AnyVal { + def this(s: String) = this(s.toDouble) +} +object Test { + def main(args: Array[String]): Unit = + new Foo("") + } + diff --git a/tests/untried/neg/t5801.check b/tests/untried/neg/t5801.check new file mode 100644 index 000000000000..abf8e6e9326a --- /dev/null +++ b/tests/untried/neg/t5801.check @@ -0,0 +1,22 @@ +t5801.scala:1: error: object sth is not a member of package scala +import scala.sth + ^ +t5801.scala:4: error: not found: value sth + def foo(a: Int)(implicit b: sth.Sth): Unit = {} + ^ +t5801.scala:7: error: not found: value sth + def bar(x: Int)(implicit y: Int): sth.Sth = null + ^ +t5801.scala:8: error: could not find implicit value for parameter y: Int + bar(1) + ^ +t5801.scala:10: error: not found: value sth + def meh(x: Int)(implicit a: sth.Sth, b: Int): Unit = {} + ^ +t5801.scala:13: error: not found: value sth + def meh2(x: Int)(implicit b: Int, a: sth.Sth): Unit = {} + ^ +t5801.scala:14: error: could not find implicit value for parameter b: Int + meh2(1) + ^ +7 errors found diff --git a/tests/untried/neg/t5801.scala b/tests/untried/neg/t5801.scala new file mode 100644 index 000000000000..d452222ac89a --- /dev/null +++ b/tests/untried/neg/t5801.scala @@ -0,0 +1,16 @@ +import scala.sth + +object Test extends App { + def foo(a: Int)(implicit b: sth.Sth): Unit = {} + foo(1) + + def bar(x: Int)(implicit y: Int): sth.Sth = null + bar(1) + + def meh(x: Int)(implicit a: sth.Sth, b: Int): Unit = {} + meh(1) + + def meh2(x: Int)(implicit b: Int, a: sth.Sth): Unit = {} + meh2(1) +} + diff --git a/tests/untried/neg/t5803.check b/tests/untried/neg/t5803.check new file mode 100644 index 000000000000..6a2de2e1df36 --- /dev/null +++ b/tests/untried/neg/t5803.check @@ -0,0 +1,4 @@ +t5803.scala:3: error: could not find implicit value for parameter ev: Nothing + new Foo(): String + ^ +one error found diff --git a/tests/untried/neg/t5803.scala b/tests/untried/neg/t5803.scala new file mode 100644 index 000000000000..f818272f8656 --- /dev/null +++ b/tests/untried/neg/t5803.scala @@ -0,0 +1,4 @@ +object Test { + class Foo()(implicit ev: Nothing) + new Foo(): String +} diff --git a/tests/untried/neg/t5821.check b/tests/untried/neg/t5821.check new file mode 100644 index 000000000000..f9c00604bc8a --- /dev/null +++ b/tests/untried/neg/t5821.check @@ -0,0 +1,4 @@ +t5821.scala:1: error: not found: object SthImportant +import SthImportant._ + ^ +one error found diff --git a/tests/untried/neg/t5821.scala b/tests/untried/neg/t5821.scala new file mode 100644 index 000000000000..4af0a2bf7f26 --- /dev/null +++ b/tests/untried/neg/t5821.scala @@ -0,0 +1,8 @@ +import SthImportant._ + +class Bar + +class Foo2 { + type Sth = Array[Bar] + def foo(xs: Sth): Bar = if ((xs eq null) || (xs.length == 0)) null else xs(0) +} diff --git a/tests/untried/neg/t5830.check b/tests/untried/neg/t5830.check new file mode 100644 index 000000000000..58c3a1be38f5 --- /dev/null +++ b/tests/untried/neg/t5830.check @@ -0,0 +1,9 @@ +t5830.scala:6: warning: unreachable code + case 'a' => println("b") // unreachable + ^ +t5830.scala:4: warning: could not emit switch for @switch annotated match + def unreachable(ch: Char) = (ch: @switch) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t5830.flags b/tests/untried/neg/t5830.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t5830.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t5830.scala b/tests/untried/neg/t5830.scala new file mode 100644 index 000000000000..18e89c20f184 --- /dev/null +++ b/tests/untried/neg/t5830.scala @@ -0,0 +1,9 @@ +import scala.annotation.switch + +class Test { + def unreachable(ch: Char) = (ch: @switch) match { + case 'a' => println("b") // ok + case 'a' => println("b") // unreachable + case 'c' => + } +} diff --git a/tests/untried/neg/t5839.check b/tests/untried/neg/t5839.check new file mode 100644 index 000000000000..d4b125bd1e8c --- /dev/null +++ b/tests/untried/neg/t5839.check @@ -0,0 +1,6 @@ +t5839.scala:5: error: type mismatch; + found : (x: String => String)Int (x: Int)Int + required: Int => String + val x: String = goo(foo _) + ^ +one error found diff --git a/tests/untried/neg/t5839.scala b/tests/untried/neg/t5839.scala new file mode 100644 index 000000000000..d3a5d4b25f14 --- /dev/null +++ b/tests/untried/neg/t5839.scala @@ -0,0 +1,7 @@ +object Test { + def goo[T](x: Int => T): T = x(1) + implicit def f(x: Int): String = "" + def foo(x: Int): Int = x + 1 + val x: String = goo(foo _) + def foo(x: String => String) = 1 +} diff --git a/tests/untried/neg/t585.check b/tests/untried/neg/t585.check new file mode 100644 index 000000000000..d332ac541460 --- /dev/null +++ b/tests/untried/neg/t585.check @@ -0,0 +1,4 @@ +t585.scala:1: error: unclosed comment +/* +^ +one error found diff --git a/tests/untried/neg/t585.scala b/tests/untried/neg/t585.scala new file mode 100644 index 000000000000..0875e2cb0f9c --- /dev/null +++ b/tests/untried/neg/t585.scala @@ -0,0 +1,4 @@ +/* +/* * / +/* * / +*/ diff --git a/tests/untried/neg/t5856.check b/tests/untried/neg/t5856.check new file mode 100644 index 000000000000..08a61bdc070a --- /dev/null +++ b/tests/untried/neg/t5856.check @@ -0,0 +1,31 @@ +t5856.scala:10: error: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected + val s9 = s"$" + ^ +t5856.scala:10: error: unclosed string literal + val s9 = s"$" + ^ +t5856.scala:2: error: error in interpolated string: identifier or block expected + val s1 = s"$null" + ^ +t5856.scala:3: error: error in interpolated string: identifier or block expected + val s2 = s"$false" + ^ +t5856.scala:4: error: error in interpolated string: identifier or block expected + val s3 = s"$true" + ^ +t5856.scala:5: error: error in interpolated string: identifier or block expected + val s4 = s"$yield" + ^ +t5856.scala:6: error: error in interpolated string: identifier or block expected + val s5 = s"$return" + ^ +t5856.scala:7: error: error in interpolated string: identifier or block expected + val s6 = s"$new" + ^ +t5856.scala:8: error: error in interpolated string: identifier or block expected + val s7 = s"$s1 $null $super" + ^ +t5856.scala:9: error: error in interpolated string: identifier or block expected + val s8 = s"$super" + ^ +10 errors found diff --git a/tests/untried/neg/t5856.scala b/tests/untried/neg/t5856.scala new file mode 100644 index 000000000000..2ceee590af55 --- /dev/null +++ b/tests/untried/neg/t5856.scala @@ -0,0 +1,11 @@ +object Test { + val s1 = s"$null" + val s2 = s"$false" + val s3 = s"$true" + val s4 = s"$yield" + val s5 = s"$return" + val s6 = s"$new" + val s7 = s"$s1 $null $super" + val s8 = s"$super" + val s9 = s"$" +} \ No newline at end of file diff --git a/tests/untried/neg/t5878.check b/tests/untried/neg/t5878.check new file mode 100644 index 000000000000..c60c4653a27e --- /dev/null +++ b/tests/untried/neg/t5878.check @@ -0,0 +1,13 @@ +t5878.scala:1: error: value class may not wrap another user-defined value class +case class Foo(x: Bar) extends AnyVal + ^ +t5878.scala:2: error: value class may not wrap another user-defined value class +case class Bar(x: Foo) extends AnyVal + ^ +t5878.scala:4: error: value class may not wrap another user-defined value class +class Foo1(val x: Bar1) extends AnyVal + ^ +t5878.scala:5: error: value class may not wrap another user-defined value class +class Bar1(val x: Foo1) extends AnyVal + ^ +four errors found diff --git a/tests/untried/neg/t5878.scala b/tests/untried/neg/t5878.scala new file mode 100644 index 000000000000..b4e33627ef83 --- /dev/null +++ b/tests/untried/neg/t5878.scala @@ -0,0 +1,6 @@ +case class Foo(x: Bar) extends AnyVal +case class Bar(x: Foo) extends AnyVal + +class Foo1(val x: Bar1) extends AnyVal +class Bar1(val x: Foo1) extends AnyVal + diff --git a/tests/untried/neg/t588.check b/tests/untried/neg/t588.check new file mode 100644 index 000000000000..ff08f77a6fe7 --- /dev/null +++ b/tests/untried/neg/t588.check @@ -0,0 +1,13 @@ +t588.scala:3: error: double definition: +def visit(f: Int => Unit): Boolean at line 2 and +def visit(f: Int => String): Boolean at line 3 +have same type after erasure: (f: Function1)Boolean + def visit(f: Int => String): Boolean + ^ +t588.scala:10: error: double definition: +def f(node: Test.this.TypeA): Unit at line 9 and +def f(brac: Test.this.TypeB): Unit at line 10 +have same type after erasure: (node: Test#TraitA)Unit + def f(brac : TypeB) : Unit; + ^ +two errors found diff --git a/tests/untried/neg/t588.scala b/tests/untried/neg/t588.scala new file mode 100644 index 000000000000..f30937377eef --- /dev/null +++ b/tests/untried/neg/t588.scala @@ -0,0 +1,15 @@ +abstract class Test0 { + def visit(f: Int => Unit): Boolean + def visit(f: Int => String): Boolean +} +trait Test { + type TypeA <: TraitA; + type TypeB <: TypeA with TraitB; + + def f(node : TypeA) : Unit; + def f(brac : TypeB) : Unit; + + trait TraitA; + trait TraitB; + +} diff --git a/tests/untried/neg/t5882.check b/tests/untried/neg/t5882.check new file mode 100644 index 000000000000..e0958e19d983 --- /dev/null +++ b/tests/untried/neg/t5882.check @@ -0,0 +1,9 @@ +t5882.scala:4: error: implementation restriction: nested class is not allowed in value class +This restriction is planned to be removed in subsequent releases. + case class Scope() + ^ +t5882.scala:5: error: implementation restriction: nested object is not allowed in value class +This restriction is planned to be removed in subsequent releases. + object Bar + ^ +two errors found diff --git a/tests/untried/neg/t5882.scala b/tests/untried/neg/t5882.scala new file mode 100644 index 000000000000..3a55abdc9ad0 --- /dev/null +++ b/tests/untried/neg/t5882.scala @@ -0,0 +1,6 @@ +// SIP-15 was changed to allow nested classes. See run/t5882.scala + +class NodeOps(val n: Any) extends AnyVal { + case class Scope() + object Bar +} diff --git a/tests/untried/neg/t5892.check b/tests/untried/neg/t5892.check new file mode 100644 index 000000000000..839bf9de2302 --- /dev/null +++ b/tests/untried/neg/t5892.check @@ -0,0 +1,17 @@ +t5892.scala:5: error: type mismatch; + found : Boolean(false) + required: String +class C[@annot(false) X] { + ^ +t5892.scala:9: error: not found: value b2s +class D[@annot(b2s(false)) X] { + ^ +t5892.scala:13: error: type mismatch; + found : Boolean(false) + required: String +@annot(false) class E { + ^ +t5892.scala:17: error: not found: value b2s +@annot(b2s(false)) class F { + ^ +four errors found diff --git a/tests/untried/neg/t5892.scala b/tests/untried/neg/t5892.scala new file mode 100644 index 000000000000..5e3b2f313e1a --- /dev/null +++ b/tests/untried/neg/t5892.scala @@ -0,0 +1,25 @@ +import language.implicitConversions + +class annot(a: String) extends annotation.StaticAnnotation + +class C[@annot(false) X] { + implicit def b2s(b: Boolean): String = "" +} + +class D[@annot(b2s(false)) X] { + implicit def b2s(b: Boolean): String = "" +} + +@annot(false) class E { + implicit def b2s(b: Boolean): String = "" +} + +@annot(b2s(false)) class F { + implicit def b2s(b: Boolean): String = "" +} + +object T { + implicit def b2s(b: Boolean): String = "" + @annot(false) val x = 0 + @annot(b2s(false)) val y = 0 +} diff --git a/tests/untried/neg/t5903a.check b/tests/untried/neg/t5903a.check new file mode 100644 index 000000000000..34003b0a82cb --- /dev/null +++ b/tests/untried/neg/t5903a.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: too many patterns for <$anon: AnyRef> offering (SomeTree.type, SomeTree.type): expected 2, found 3 + case nq"$x + $y + $z" => println((x, y)) + ^ +one error found diff --git a/tests/untried/neg/t5903a/Macros_1.scala b/tests/untried/neg/t5903a/Macros_1.scala new file mode 100644 index 000000000000..5d084ceed5e6 --- /dev/null +++ b/tests/untried/neg/t5903a/Macros_1.scala @@ -0,0 +1,28 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +trait Tree +case object SomeTree extends Tree + +object NewQuasiquotes { + implicit class QuasiquoteInterpolation(c: StringContext) { + object nq { + def unapply(t: Tree): Any = macro QuasiquoteMacros.unapplyImpl + } + } +} + +object QuasiquoteMacros { + def unapplyImpl(c: Context)(t: c.Tree) = { + import c.universe._ + q""" + new { + def isEmpty = false + def get = this + def _1 = SomeTree + def _2 = SomeTree + def unapply(t: Tree) = this + }.unapply($t) + """ + } +} diff --git a/tests/untried/neg/t5903a/Test_2.scala b/tests/untried/neg/t5903a/Test_2.scala new file mode 100644 index 000000000000..4d78dfb5e5f4 --- /dev/null +++ b/tests/untried/neg/t5903a/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import NewQuasiquotes._ + SomeTree match { + case nq"$x + $y + $z" => println((x, y)) + } +} diff --git a/tests/untried/neg/t5903b.check b/tests/untried/neg/t5903b.check new file mode 100644 index 000000000000..e7637d3edb59 --- /dev/null +++ b/tests/untried/neg/t5903b.check @@ -0,0 +1,6 @@ +Test_2.scala:4: error: type mismatch; + found : Int + required: String + case t"$x" => println(x) + ^ +one error found diff --git a/tests/untried/neg/t5903b/Macros_1.scala b/tests/untried/neg/t5903b/Macros_1.scala new file mode 100644 index 000000000000..6ce49c022867 --- /dev/null +++ b/tests/untried/neg/t5903b/Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply[T](x: T): Any = macro Macros.unapplyImpl[T] + } + } +} + +object Macros { + def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + import c.universe._ + q""" + new { + def isEmpty = false + def get = "2" + def unapply(x: String) = this + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/t5903b/Test_2.scala b/tests/untried/neg/t5903b/Test_2.scala new file mode 100644 index 000000000000..0f6f80d327db --- /dev/null +++ b/tests/untried/neg/t5903b/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + 2 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg/t5903c.check b/tests/untried/neg/t5903c.check new file mode 100644 index 000000000000..05bd775d3022 --- /dev/null +++ b/tests/untried/neg/t5903c.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: String is not supported + case t"$x" => println(x) + ^ +one error found diff --git a/tests/untried/neg/t5903c/Macros_1.scala b/tests/untried/neg/t5903c/Macros_1.scala new file mode 100644 index 000000000000..4792f0045489 --- /dev/null +++ b/tests/untried/neg/t5903c/Macros_1.scala @@ -0,0 +1,26 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply[T](x: T): Any = macro Macros.unapplyImpl[T] + } + } +} + +object Macros { + def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + import c.universe._ + if (!(c.weakTypeOf[Int] =:= c.weakTypeOf[T])) c.abort(c.enclosingPosition, s"${c.weakTypeOf[T]} is not supported") + else { + q""" + new { + def isEmpty = false + def get = 2 + def unapply(x: Int) = this + }.unapply($x) + """ + } + } +} diff --git a/tests/untried/neg/t5903c/Test_2.scala b/tests/untried/neg/t5903c/Test_2.scala new file mode 100644 index 000000000000..a1fd31dd4983 --- /dev/null +++ b/tests/untried/neg/t5903c/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + "2" match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg/t5903d.check b/tests/untried/neg/t5903d.check new file mode 100644 index 000000000000..54a91a7ba6d3 --- /dev/null +++ b/tests/untried/neg/t5903d.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: extractor macros can only be whitebox + case t"$x" => println(x) + ^ +one error found diff --git a/tests/untried/neg/t5903d/Macros_1.scala b/tests/untried/neg/t5903d/Macros_1.scala new file mode 100644 index 000000000000..3500c2a782d4 --- /dev/null +++ b/tests/untried/neg/t5903d/Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply(x: Int): Any = macro Macros.unapplyImpl + } + } +} + +object Macros { + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + q""" + class Match(x: Int) { + def isEmpty = false + def get = x + } + new { def unapply(x: Int) = new Match(x) }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/t5903d/Test_2.scala b/tests/untried/neg/t5903d/Test_2.scala new file mode 100644 index 000000000000..95c717a9d83a --- /dev/null +++ b/tests/untried/neg/t5903d/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + 42 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg/t5903e.check b/tests/untried/neg/t5903e.check new file mode 100644 index 000000000000..3bdeb091a0e4 --- /dev/null +++ b/tests/untried/neg/t5903e.check @@ -0,0 +1,4 @@ +Test_2.scala:4: error: value class may not be a member of another class + case t"$x" => println(x) + ^ +one error found diff --git a/tests/untried/neg/t5903e/Macros_1.scala b/tests/untried/neg/t5903e/Macros_1.scala new file mode 100644 index 000000000000..a64ff7e0b9a8 --- /dev/null +++ b/tests/untried/neg/t5903e/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply(x: Int): Any = macro Macros.unapplyImpl + } + } +} + +object Macros { + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) extends AnyVal { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg/t5903e/Test_2.scala b/tests/untried/neg/t5903e/Test_2.scala new file mode 100644 index 000000000000..d69d47243685 --- /dev/null +++ b/tests/untried/neg/t5903e/Test_2.scala @@ -0,0 +1,6 @@ +class C { + import Interpolation._ + 42 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg/t591.check b/tests/untried/neg/t591.check new file mode 100644 index 000000000000..d33f6d7a2fed --- /dev/null +++ b/tests/untried/neg/t591.check @@ -0,0 +1,5 @@ +t591.scala:38: error: method input_= is defined twice + conflicting symbols both originated in file 't591.scala' + def input_=(in : Input) = {} + ^ +one error found diff --git a/tests/untried/neg/t591.scala b/tests/untried/neg/t591.scala new file mode 100644 index 000000000000..0f0b02395c98 --- /dev/null +++ b/tests/untried/neg/t591.scala @@ -0,0 +1,41 @@ +abstract class BaseList { + type Node <: BaseNode; + + + abstract class BaseNode { + protected def self : Node; + private[BaseList] def self00 = self; + def dirty : Unit = {} + def replaceWith(node : Node) = {} + } + + implicit def baseNode2Node(bnode : BaseNode): Node = bnode.self00; + + +} + + +trait BaseFlow extends BaseList { + type Node <: BFNode; + type Flow <: FlowBase; + type Output <: OutputBase; + type Input <: InputBase; + + abstract class FlowBase { + + } + trait OutputBase extends FlowBase { + + } + trait InputBase extends FlowBase { + + } + + trait BFNode extends BaseNode { + private var input : Input = _; + private var output : Output = _; + + def input_=(in : Input) = {} + + } +} diff --git a/tests/untried/neg/t593.check b/tests/untried/neg/t593.check new file mode 100644 index 000000000000..c1aeab8ec47f --- /dev/null +++ b/tests/untried/neg/t593.check @@ -0,0 +1,4 @@ +t593.scala:1: error: traits or objects may not have parameters +trait Wrapper[T](x : T) { + ^ +one error found diff --git a/tests/untried/neg/t593.scala b/tests/untried/neg/t593.scala new file mode 100644 index 000000000000..df7199a42ae7 --- /dev/null +++ b/tests/untried/neg/t593.scala @@ -0,0 +1,2 @@ +trait Wrapper[T](x : T) { +} diff --git a/tests/untried/neg/t5956.check b/tests/untried/neg/t5956.check new file mode 100644 index 000000000000..f5ae42c799fc --- /dev/null +++ b/tests/untried/neg/t5956.check @@ -0,0 +1,7 @@ +t5956.scala:1: error: C is already defined as case class C +object O { case class C[T](); class C() } + ^ +t5956.scala:2: error: C is already defined as case class C +object T { case class C[T](); case class C() } + ^ +two errors found diff --git a/tests/untried/neg/t5956.flags b/tests/untried/neg/t5956.flags new file mode 100644 index 000000000000..dcc59ebe32ef --- /dev/null +++ b/tests/untried/neg/t5956.flags @@ -0,0 +1 @@ +-deprecation diff --git a/tests/untried/neg/t5956.scala b/tests/untried/neg/t5956.scala new file mode 100644 index 000000000000..3cc10f3e1929 --- /dev/null +++ b/tests/untried/neg/t5956.scala @@ -0,0 +1,2 @@ +object O { case class C[T](); class C() } +object T { case class C[T](); case class C() } diff --git a/tests/untried/neg/t5969.check b/tests/untried/neg/t5969.check new file mode 100644 index 000000000000..9d8ac9a3a5a6 --- /dev/null +++ b/tests/untried/neg/t5969.check @@ -0,0 +1,7 @@ +t5969.scala:9: error: overloaded method value g with alternatives: + (x: C2)String + (x: C1)String + cannot be applied to (String) + if (false) List(g(x)) else List[C1]() map g + ^ +one error found diff --git a/tests/untried/neg/t5969.scala b/tests/untried/neg/t5969.scala new file mode 100644 index 000000000000..d010cacd1bb8 --- /dev/null +++ b/tests/untried/neg/t5969.scala @@ -0,0 +1,11 @@ +class C1 +class C2 +class A { + def f(x: Any) = x + def g(x: C1): String = "A" + def g(x: C2): String = "B" + + def crash() = f(List[String]() flatMap { x => + if (false) List(g(x)) else List[C1]() map g + }) +} diff --git a/tests/untried/neg/t6011.check b/tests/untried/neg/t6011.check new file mode 100644 index 000000000000..cb7f18903134 --- /dev/null +++ b/tests/untried/neg/t6011.check @@ -0,0 +1,12 @@ +t6011.scala:4: warning: unreachable code + case 'a' | 'c' => 1 // unreachable + ^ +t6011.scala:10: warning: unreachable code + case 'b' | 'a' => 1 // unreachable + ^ +t6011.scala:8: warning: could not emit switch for @switch annotated match + def f2(ch: Char): Any = (ch: @annotation.switch) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t6011.flags b/tests/untried/neg/t6011.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t6011.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6011.scala b/tests/untried/neg/t6011.scala new file mode 100644 index 000000000000..31a9f99a2a0a --- /dev/null +++ b/tests/untried/neg/t6011.scala @@ -0,0 +1,23 @@ +object Test { + def f(ch: Char): Any = ch match { + case 'a' => 1 + case 'a' | 'c' => 1 // unreachable + } + + // won't be compiled to a switch since it has an unreachable (duplicate) case + def f2(ch: Char): Any = (ch: @annotation.switch) match { + case 'a' | 'b' => 1 + case 'b' | 'a' => 1 // unreachable + case _ => + } + + // s'all good + def f3(ch: Char): Any = (ch: @annotation.switch) match { + case 'a' | 'b' if (true: Boolean) => 1 + case 'b' | 'a' => 1 // ok + case _ => // need third case to check switch annotation (two-case switches are always okay to compile to if-then-else) + } + + + def main(args: Array[String]): Unit = f('a') +} diff --git a/tests/untried/neg/t6013.check b/tests/untried/neg/t6013.check new file mode 100644 index 000000000000..502da999f56f --- /dev/null +++ b/tests/untried/neg/t6013.check @@ -0,0 +1,7 @@ +DerivedScala.scala:4: error: class C needs to be abstract, since there is a deferred declaration of method foo in class B of type => Int which is not implemented in a subclass +class C extends B + ^ +DerivedScala.scala:7: error: class DerivedScala needs to be abstract, since there is a deferred declaration of method foo in class Abstract of type ()Boolean which is not implemented in a subclass +class DerivedScala extends Abstract + ^ +two errors found diff --git a/tests/untried/neg/t6013/Abstract.java b/tests/untried/neg/t6013/Abstract.java new file mode 100644 index 000000000000..c0ef046bbd56 --- /dev/null +++ b/tests/untried/neg/t6013/Abstract.java @@ -0,0 +1,7 @@ +public abstract class Abstract extends Base { + // overrides Base#bar under the erasure model + public void bar(java.util.List foo) { return; } + + // must force re-implementation in derived classes + public abstract boolean foo(); +} diff --git a/tests/untried/neg/t6013/Base.java b/tests/untried/neg/t6013/Base.java new file mode 100644 index 000000000000..b73d7fd821e4 --- /dev/null +++ b/tests/untried/neg/t6013/Base.java @@ -0,0 +1,10 @@ +abstract public class Base { + // This must considered to be overridden by Abstract#foo based + // on the erased signatures. This special case is handled by + // `javaErasedOverridingSym` in `RefChecks`. + public abstract void bar(java.util.List foo) { return; } + + // But, a concrete method in a Java superclass must not excuse + // a deferred method in the Java subclass! + public boolean foo() { return true; } +} diff --git a/tests/untried/neg/t6013/DerivedScala.scala b/tests/untried/neg/t6013/DerivedScala.scala new file mode 100644 index 000000000000..fc0c55d39853 --- /dev/null +++ b/tests/untried/neg/t6013/DerivedScala.scala @@ -0,0 +1,7 @@ +// Scala extending Scala (this case was working fine before this bug.) +class A { def foo: Int = 0 } +abstract class B extends A { def foo: Int } +class C extends B + +// Scala extending Java +class DerivedScala extends Abstract diff --git a/tests/untried/neg/t6040.check b/tests/untried/neg/t6040.check new file mode 100644 index 000000000000..16c90ede7e29 --- /dev/null +++ b/tests/untried/neg/t6040.check @@ -0,0 +1,9 @@ +t6040.scala:1: error: extension of type scala.Dynamic needs to be enabled +by making the implicit value scala.language.dynamics visible. +This can be achieved by adding the import clause 'import scala.language.dynamics' +or by setting the compiler option -language:dynamics. +See the Scala docs for value scala.language.dynamics for a discussion +why the feature needs to be explicitly enabled. +class X extends Dynamic + ^ +one error found diff --git a/tests/untried/neg/t6040.scala b/tests/untried/neg/t6040.scala new file mode 100644 index 000000000000..7e2c1b1057fe --- /dev/null +++ b/tests/untried/neg/t6040.scala @@ -0,0 +1 @@ +class X extends Dynamic diff --git a/tests/untried/neg/t6042.check b/tests/untried/neg/t6042.check new file mode 100644 index 000000000000..221f06e2c57e --- /dev/null +++ b/tests/untried/neg/t6042.check @@ -0,0 +1,4 @@ +t6042.scala:7: error: illegal type selection from volatile type a.OpSemExp (with upper bound LazyExp[a.OpSemExp] with _$1) + def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with This` + ^ +one error found diff --git a/tests/untried/neg/t6042.scala b/tests/untried/neg/t6042.scala new file mode 100644 index 000000000000..5a123d17cad7 --- /dev/null +++ b/tests/untried/neg/t6042.scala @@ -0,0 +1,8 @@ +trait LazyExp[+This <: LazyExp[This]] { this: This => + type OpSemExp <: LazyExp[OpSemExp] with This + type Val +} + +object Test { + def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with This` +} diff --git a/tests/untried/neg/t6048.check b/tests/untried/neg/t6048.check new file mode 100644 index 000000000000..f8eddf5471ce --- /dev/null +++ b/tests/untried/neg/t6048.check @@ -0,0 +1,18 @@ +t6048.scala:3: warning: unreachable code + case _ if false => x // unreachable + ^ +t6048.scala:8: warning: unreachable code + case _ if false => x // unreachable + ^ +t6048.scala:13: warning: patterns after a variable pattern cannot match (SLS 8.1.1) + case _ => x + ^ +t6048.scala:14: warning: unreachable code due to variable pattern on line 13 + case 5 if true => x // unreachable + ^ +t6048.scala:14: warning: unreachable code + case 5 if true => x // unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +5 warnings found +one error found diff --git a/tests/untried/neg/t6048.flags b/tests/untried/neg/t6048.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t6048.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6048.scala b/tests/untried/neg/t6048.scala new file mode 100644 index 000000000000..803e651d1908 --- /dev/null +++ b/tests/untried/neg/t6048.scala @@ -0,0 +1,22 @@ +class A { + def f1(x: Int) = x match { + case _ if false => x // unreachable + case 5 => x + } + + def f2(x: Int) = x match { + case _ if false => x // unreachable + case 5 if true => x + } + + def f3(x: Int) = x match { + case _ => x + case 5 if true => x // unreachable + } + + def test1(x: Int) = x match { + case c if c < 0 => 0 + case 1 => 1 + case _ => 2 + } +} diff --git a/tests/untried/neg/t6074.check b/tests/untried/neg/t6074.check new file mode 100644 index 000000000000..38670e5b3d66 --- /dev/null +++ b/tests/untried/neg/t6074.check @@ -0,0 +1,4 @@ +t6074.scala:5: error: constructor A in class A cannot be accessed in object T + def t = new A() + ^ +one error found diff --git a/tests/untried/neg/t6074.scala b/tests/untried/neg/t6074.scala new file mode 100644 index 000000000000..8c14f00f19d7 --- /dev/null +++ b/tests/untried/neg/t6074.scala @@ -0,0 +1,6 @@ +class A private () { } +class B { } +object T { + implicit def a2b(a: A): B = null + def t = new A() +} diff --git a/tests/untried/neg/t608.check b/tests/untried/neg/t608.check new file mode 100644 index 000000000000..5c7f49d00420 --- /dev/null +++ b/tests/untried/neg/t608.check @@ -0,0 +1,6 @@ +t608.scala:16: error: type mismatch; + found : hs{type a = ha} + required: hs{type s = hs; type a = ha} + = g(f(x).bimap(id)) + ^ +one error found diff --git a/tests/untried/neg/t608.scala b/tests/untried/neg/t608.scala new file mode 100644 index 000000000000..34dc4c03525d --- /dev/null +++ b/tests/untried/neg/t608.scala @@ -0,0 +1,17 @@ +trait CrashDueToTypeError { + def id[a](x :a) :a = x + + trait Bifunctor { + type a; // content + type s <: Bifunctor + + // uncomment this-vvvvvvvvvvvvvvvvvvvvvvvvvvvv, and it compiles + def bimap[c](f :a=>c) :s{/*type s=Bifunctor.this.s;*/type a=c; } + } + + def hylo[hs <: Bifunctor,ha,hb,hc] + (f :hb=>hs{type s=hs; type a=ha}, + g :hs{type s=hs; type a=ha}=>hc)(x :hb) + :hc + = g(f(x).bimap(id)) +} diff --git a/tests/untried/neg/t6082.check b/tests/untried/neg/t6082.check new file mode 100644 index 000000000000..b68de5ce087a --- /dev/null +++ b/tests/untried/neg/t6082.check @@ -0,0 +1,13 @@ +t6082.scala:1: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class annot(notValue: String) extends annotation.ClassfileAnnotation + ^ +t6082.scala:2: error: classfile annotation arguments have to be supplied as named arguments +@annot("") class C + ^ +t6082.scala:2: error: annotation annot is missing argument notValue +@annot("") class C + ^ +one warning found +two errors found diff --git a/tests/untried/neg/t6082.scala b/tests/untried/neg/t6082.scala new file mode 100644 index 000000000000..9acc3963d0b1 --- /dev/null +++ b/tests/untried/neg/t6082.scala @@ -0,0 +1,2 @@ +class annot(notValue: String) extends annotation.ClassfileAnnotation +@annot("") class C diff --git a/tests/untried/neg/t6083.check b/tests/untried/neg/t6083.check new file mode 100644 index 000000000000..c9b5ba05d3bf --- /dev/null +++ b/tests/untried/neg/t6083.check @@ -0,0 +1,10 @@ +t6083.scala:6: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class annot(value: String) extends annotation.ClassfileAnnotation + ^ +t6083.scala:7: error: annotation argument needs to be a constant; found: conv.i2s(101) +@annot(101) class C + ^ +one warning found +one error found diff --git a/tests/untried/neg/t6083.scala b/tests/untried/neg/t6083.scala new file mode 100644 index 000000000000..1de18e65279e --- /dev/null +++ b/tests/untried/neg/t6083.scala @@ -0,0 +1,7 @@ +object conv { + implicit def i2s(i: Int): String = "" +} +import conv._ + +class annot(value: String) extends annotation.ClassfileAnnotation +@annot(101) class C diff --git a/tests/untried/neg/t6120.check b/tests/untried/neg/t6120.check new file mode 100644 index 000000000000..a7d17e29cf15 --- /dev/null +++ b/tests/untried/neg/t6120.check @@ -0,0 +1,20 @@ +t6120.scala:5: warning: postfix operator bippy should be enabled +by making the implicit value scala.language.postfixOps visible. +This can be achieved by adding the import clause 'import scala.language.postfixOps' +or by setting the compiler option -language:postfixOps. +See the Scala docs for value scala.language.postfixOps for a discussion +why the feature should be explicitly enabled. + def f = null == null bippy + ^ +t6120.scala:5: warning: method bippy in class BooleanOps is deprecated: bobo + def f = null == null bippy + ^ +t6120.scala:5: warning: comparing values of types Null and Null using `==' will always yield true + def f = null == null bippy + ^ +t6120.scala:6: warning: method bippy in class BooleanOps is deprecated: bobo + def g = true.bippy + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t6120.flags b/tests/untried/neg/t6120.flags new file mode 100644 index 000000000000..04d7c7d417aa --- /dev/null +++ b/tests/untried/neg/t6120.flags @@ -0,0 +1 @@ +-feature -deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6120.scala b/tests/untried/neg/t6120.scala new file mode 100644 index 000000000000..425f09db47bb --- /dev/null +++ b/tests/untried/neg/t6120.scala @@ -0,0 +1,7 @@ +class A { + implicit class BooleanOps(val b: Boolean) { + @deprecated("bobo", "2.11.0") def bippy() = 5 + } + def f = null == null bippy + def g = true.bippy +} diff --git a/tests/untried/neg/t6123-explaintypes-macros.check b/tests/untried/neg/t6123-explaintypes-macros.check new file mode 100644 index 000000000000..2c86f3c9cc28 --- /dev/null +++ b/tests/untried/neg/t6123-explaintypes-macros.check @@ -0,0 +1,10 @@ +c.universe.Expr[Any]* <: c.universe.Expr[String]*? +false +BadMac_2.scala:6: error: macro implementation has incompatible shape: + required: (c: scala.reflect.macros.blackbox.Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] + or : (c: scala.reflect.macros.blackbox.Context)(format: c.Tree, params: Tree*): c.Tree + found : (c: scala.reflect.macros.blackbox.Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] +type mismatch for parameter params: c.Expr[Any]* does not conform to c.Expr[String]* + def printf(format: String, params: Any*): Unit = macro printf_impl + ^ +one error found diff --git a/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.flags b/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.flags new file mode 100644 index 000000000000..b36707c7cfcf --- /dev/null +++ b/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.scala b/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.scala new file mode 100644 index 000000000000..75ded4ef7d0b --- /dev/null +++ b/tests/untried/neg/t6123-explaintypes-macros/BadMac_2.scala @@ -0,0 +1,8 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +// explain some macro types to me +object BadMac { + def printf(format: String, params: Any*): Unit = macro printf_impl + def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] = ??? +} diff --git a/tests/untried/neg/t6123-explaintypes-macros/Macros.flags b/tests/untried/neg/t6123-explaintypes-macros/Macros.flags new file mode 100644 index 000000000000..b36707c7cfcf --- /dev/null +++ b/tests/untried/neg/t6123-explaintypes-macros/Macros.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/tests/untried/neg/t6123-explaintypes-macros/Macros.scala b/tests/untried/neg/t6123-explaintypes-macros/Macros.scala new file mode 100644 index 000000000000..f2238b39a739 --- /dev/null +++ b/tests/untried/neg/t6123-explaintypes-macros/Macros.scala @@ -0,0 +1,10 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def printf(format: String, params: Any*): Unit = macro printf_impl + def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ??? +} + +// something trivial to run +object Test extends App diff --git a/tests/untried/neg/t6138.check b/tests/untried/neg/t6138.check new file mode 100644 index 000000000000..8fd997824824 --- /dev/null +++ b/tests/untried/neg/t6138.check @@ -0,0 +1,7 @@ +t6138.scala:4: error: ambiguous reference to overloaded definition, +both method getClass in object definitions of type (s: Int)Any +and method getClass in object definitions of type (s: String)Any +match argument types (Nothing) + getClass(???): String + ^ +one error found diff --git a/tests/untried/neg/t6138.scala b/tests/untried/neg/t6138.scala new file mode 100644 index 000000000000..2f45a46b1cd6 --- /dev/null +++ b/tests/untried/neg/t6138.scala @@ -0,0 +1,5 @@ +object definitions { + def getClass(s: String): Any = ??? + def getClass(s: Int): Any = ??? + getClass(???): String +} diff --git a/tests/untried/neg/t6162-inheritance.check b/tests/untried/neg/t6162-inheritance.check new file mode 100644 index 000000000000..13c78030d955 --- /dev/null +++ b/tests/untried/neg/t6162-inheritance.check @@ -0,0 +1,18 @@ +usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. +class SubFoo extends Foo + ^ +usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated +object SubT extends T + ^ +usage.scala:8: warning: inheritance from trait S in package t6126 is deprecated + new S { + ^ +usage.scala:3: warning: inheritance from class Foo in package t6126 is deprecated: `Foo` will be made final in a future version. +class SubFoo extends Foo + ^ +usage.scala:5: warning: inheritance from trait T in package t6126 is deprecated +object SubT extends T + ^ +error: No warnings can be incurred under -Xfatal-warnings. +5 warnings found +one error found diff --git a/tests/untried/neg/t6162-inheritance.flags b/tests/untried/neg/t6162-inheritance.flags new file mode 100644 index 000000000000..65faf53579c2 --- /dev/null +++ b/tests/untried/neg/t6162-inheritance.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation \ No newline at end of file diff --git a/tests/untried/neg/t6162-inheritance/defn.scala b/tests/untried/neg/t6162-inheritance/defn.scala new file mode 100644 index 000000000000..bb582d27b0dd --- /dev/null +++ b/tests/untried/neg/t6162-inheritance/defn.scala @@ -0,0 +1,10 @@ +package scala.t6126 + +@deprecatedInheritance("`Foo` will be made final in a future version.", "2.10.0") +class Foo + +@deprecatedInheritance() +trait T + +@deprecatedInheritance() +trait S diff --git a/tests/untried/neg/t6162-inheritance/usage.scala b/tests/untried/neg/t6162-inheritance/usage.scala new file mode 100644 index 000000000000..097e4f590309 --- /dev/null +++ b/tests/untried/neg/t6162-inheritance/usage.scala @@ -0,0 +1,10 @@ +package scala.t6126 + +class SubFoo extends Foo + +object SubT extends T + +object O { + new S { + } +} diff --git a/tests/untried/neg/t6162-overriding.check b/tests/untried/neg/t6162-overriding.check new file mode 100644 index 000000000000..6bff75d88dc4 --- /dev/null +++ b/tests/untried/neg/t6162-overriding.check @@ -0,0 +1,9 @@ +t6162-overriding.scala:14: warning: overriding method bar in class Bar is deprecated: `bar` will be made private in a future version. + override def bar = 43 + ^ +t6162-overriding.scala:15: warning: overriding method baz in class Bar is deprecated + override def baz = 43 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t6162-overriding.flags b/tests/untried/neg/t6162-overriding.flags new file mode 100644 index 000000000000..65faf53579c2 --- /dev/null +++ b/tests/untried/neg/t6162-overriding.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation \ No newline at end of file diff --git a/tests/untried/neg/t6162-overriding.scala b/tests/untried/neg/t6162-overriding.scala new file mode 100644 index 000000000000..4cab0c2dee43 --- /dev/null +++ b/tests/untried/neg/t6162-overriding.scala @@ -0,0 +1,17 @@ +package scala.t6162 + +class Bar { + @deprecatedOverriding("`bar` will be made private in a future version.", "2.10.0") + def bar = 42 + + @deprecatedOverriding() + def baz = 42 + + def baz(a: Any) = 0 +} + +class SubBar extends Bar { + override def bar = 43 + override def baz = 43 + override def baz(a: Any) = 43 // okay +} diff --git a/tests/untried/neg/t6214.check b/tests/untried/neg/t6214.check new file mode 100644 index 000000000000..6349a3e71c23 --- /dev/null +++ b/tests/untried/neg/t6214.check @@ -0,0 +1,4 @@ +t6214.scala:5: error: missing parameter type + m { s => case class Foo() } + ^ +one error found diff --git a/tests/untried/neg/t6214.scala b/tests/untried/neg/t6214.scala new file mode 100644 index 000000000000..0d5ffc5dedfa --- /dev/null +++ b/tests/untried/neg/t6214.scala @@ -0,0 +1,7 @@ +object Test { + def m(f: String => Unit) = 0 + def m(f: Int => Unit) = 0 + def foo: Unit = { + m { s => case class Foo() } + } +} diff --git a/tests/untried/neg/t6227.check b/tests/untried/neg/t6227.check new file mode 100644 index 000000000000..5e3c636712db --- /dev/null +++ b/tests/untried/neg/t6227.check @@ -0,0 +1,4 @@ +t6227.scala:2: error: illegal combination of modifiers: implicit and case for: class IntOps + implicit case class IntOps( i: Int ) { + ^ +one error found diff --git a/tests/untried/neg/t6227.scala b/tests/untried/neg/t6227.scala new file mode 100644 index 000000000000..46416839d159 --- /dev/null +++ b/tests/untried/neg/t6227.scala @@ -0,0 +1,6 @@ +object Test { + implicit case class IntOps( i: Int ) { + def twice = i * 2 + } +} + diff --git a/tests/untried/neg/t6258.check b/tests/untried/neg/t6258.check new file mode 100644 index 000000000000..73363d82806d --- /dev/null +++ b/tests/untried/neg/t6258.check @@ -0,0 +1,16 @@ +t6258.scala:2: error: missing parameter type for expanded function +The argument types of an anonymous function must be fully known. (SLS 8.5) +Expected type was: PartialFunction[?, Int] + val f : PartialFunction[_, Int] = { case a : Int => a } // undefined param + ^ +t6258.scala:5: error: missing parameter type for expanded function +The argument types of an anonymous function must be fully known. (SLS 8.5) +Expected type was: PartialFunction[?,Int] + foo { case a : Int => a } // undefined param + ^ +t6258.scala:22: error: missing parameter type for expanded function +The argument types of an anonymous function must be fully known. (SLS 8.5) +Expected type was: PartialFunction[?,Any] + bar[M[Any]] (foo { // undefined param + ^ +three errors found diff --git a/tests/untried/neg/t6258.scala b/tests/untried/neg/t6258.scala new file mode 100644 index 000000000000..19794b325f50 --- /dev/null +++ b/tests/untried/neg/t6258.scala @@ -0,0 +1,25 @@ +object Test { + val f : PartialFunction[_, Int] = { case a : Int => a } // undefined param + + def foo[A](pf: PartialFunction[A, Int]): Unit = {}; + foo { case a : Int => a } // undefined param + + val g : PartialFunction[Int, _] = { case a : Int => a } // okay +} + + +// Another variation, seen in the wild with Specs2. +class X { + trait Matcher[-T] + + def bar[T](m: Matcher[T]) = null + def bar[T](i: Int) = null + + def foo[T](p: PartialFunction[T, Any]): Matcher[T] = null + + case class M[X](a: X) + + bar[M[Any]] (foo { // undefined param + case M(_) => null + }) +} diff --git a/tests/untried/neg/t6260-named.check b/tests/untried/neg/t6260-named.check new file mode 100644 index 000000000000..ed6ab5e76f68 --- /dev/null +++ b/tests/untried/neg/t6260-named.check @@ -0,0 +1,13 @@ +t6260-named.scala:12: error: bridge generated for member method apply: (a: C[Any])C[Any] in object O +which overrides method apply: (v1: T1)R in trait Function1 +clashes with definition of the member itself; +both have erased type (v1: Object)Object + def apply(a: C[Any]) = a + ^ +t6260-named.scala:14: error: bridge generated for member method apply: (a: C[Any])C[Any] in class X +which overrides method apply: (a: A)A in trait T +clashes with definition of the member itself; +both have erased type (a: Object)Object + class X extends T[C[Any]] { def apply(a: C[Any]) = a } + ^ +two errors found diff --git a/tests/untried/neg/t6260-named.scala b/tests/untried/neg/t6260-named.scala new file mode 100644 index 000000000000..7cd9ce8473e8 --- /dev/null +++ b/tests/untried/neg/t6260-named.scala @@ -0,0 +1,15 @@ +class C[A](private val a: Any) extends AnyVal +trait T[A] { + def apply(a: A): A +} + +object Test { + (x: C[Any]) => {println(s"f($x)"); x} // okay + new T[C[Any]] { def apply(a: C[Any]) = a } // okay + + // we can't rename the specific apply method to avoid the clash + object O extends Function1[C[Any], C[Any]] { + def apply(a: C[Any]) = a + } + class X extends T[C[Any]] { def apply(a: C[Any]) = a } +} diff --git a/tests/untried/neg/t6260c.check b/tests/untried/neg/t6260c.check new file mode 100644 index 000000000000..cbbcfd1504c9 --- /dev/null +++ b/tests/untried/neg/t6260c.check @@ -0,0 +1,7 @@ +t6260c.scala:4: error: bridge generated for member method f: ()Option[A] in class Bar1 +which overrides method f: ()A in class Foo1 +clashes with definition of the member itself; +both have erased type ()Object + class Bar1[A] extends Foo1[Option[A]] { def f(): Option[A] = ??? } + ^ +one error found diff --git a/tests/untried/neg/t6260c.scala b/tests/untried/neg/t6260c.scala new file mode 100644 index 000000000000..02bf15237667 --- /dev/null +++ b/tests/untried/neg/t6260c.scala @@ -0,0 +1,4 @@ +final class Option[+A](val value: A) extends AnyVal + +abstract class Foo1[A] { def f(): A } + class Bar1[A] extends Foo1[Option[A]] { def f(): Option[A] = ??? } diff --git a/tests/untried/neg/t6263.check b/tests/untried/neg/t6263.check new file mode 100644 index 000000000000..9e9c7c615b99 --- /dev/null +++ b/tests/untried/neg/t6263.check @@ -0,0 +1,9 @@ +t6263.scala:5: error: type mismatch; + found : A.this.c.type (with underlying type C) + required: AnyRef +Note that C extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + type t = c.type + ^ +one error found diff --git a/tests/untried/neg/t6263.scala b/tests/untried/neg/t6263.scala new file mode 100644 index 000000000000..6575185b5ce4 --- /dev/null +++ b/tests/untried/neg/t6263.scala @@ -0,0 +1,6 @@ +class C(val a: Any) extends AnyVal +class A { + implicit def c2AnyRef(c: C): AnyRef = new {} + val c = new C(0) + type t = c.type +} diff --git a/tests/untried/neg/t6264.check b/tests/untried/neg/t6264.check new file mode 100644 index 000000000000..c0975a80b264 --- /dev/null +++ b/tests/untried/neg/t6264.check @@ -0,0 +1,6 @@ +t6264.scala:3: warning: non-variable type argument Tuple1[_] in type Tuple2[_, Tuple1[_]] is unchecked since it is eliminated by erasure + x.isInstanceOf[Tuple2[_, Tuple1[_]]] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t6264.flags b/tests/untried/neg/t6264.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t6264.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t6264.scala b/tests/untried/neg/t6264.scala new file mode 100644 index 000000000000..dc3b72793443 --- /dev/null +++ b/tests/untried/neg/t6264.scala @@ -0,0 +1,6 @@ +class Foo { + def foo(x: AnyRef): Unit = { + x.isInstanceOf[Tuple2[_, Tuple1[_]]] + () + } +} diff --git a/tests/untried/neg/t6276.check b/tests/untried/neg/t6276.check new file mode 100644 index 000000000000..f275de9d0a74 --- /dev/null +++ b/tests/untried/neg/t6276.check @@ -0,0 +1,21 @@ +t6276.scala:4: warning: method a in class C does nothing other than call itself recursively + def a: Any = a // warn + ^ +t6276.scala:5: warning: value b in class C does nothing other than call itself recursively + val b: Any = b // warn + ^ +t6276.scala:7: warning: method c in class C does nothing other than call itself recursively + def c: Any = this.c // warn + ^ +t6276.scala:8: warning: method d in class C does nothing other than call itself recursively + def d: Any = C.this.d // warn + ^ +t6276.scala:13: warning: method a does nothing other than call itself recursively + def a: Any = a // warn + ^ +t6276.scala:22: warning: method a does nothing other than call itself recursively + def a = a // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/tests/untried/neg/t6276.flags b/tests/untried/neg/t6276.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t6276.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t6276.scala b/tests/untried/neg/t6276.scala new file mode 100644 index 000000000000..a3b0d6d5db0c --- /dev/null +++ b/tests/untried/neg/t6276.scala @@ -0,0 +1,44 @@ +object Test { + def foo(a: Int, b: Int, c: Int): Unit = { + class C { + def a: Any = a // warn + val b: Any = b // warn + + def c: Any = this.c // warn + def d: Any = C.this.d // warn + } + + def method: Unit = { + // method local + def a: Any = a // warn + } + + trait T { + def a: Any + } + + new T { + // inherited return type + def a = a // warn + } + + // no warnings below + new { + def a: Any = {println(""); a} + val b: Any = {println(""); b} + def c(i: Int): Any = c(i - 0) + } + + class D { + def other: D = null + def foo: Any = other.foo + } + + class E { + def foo: Any = 0 + class D extends E { + override def foo: Any = E.this.foo + } + } + } +} diff --git a/tests/untried/neg/t6283.check b/tests/untried/neg/t6283.check new file mode 100644 index 000000000000..69e417ee93ad --- /dev/null +++ b/tests/untried/neg/t6283.check @@ -0,0 +1,4 @@ +t6283.scala:1: error: `abstract' modifier cannot be used with value classes +abstract class Funky(val i: Int) extends AnyVal + ^ +one error found diff --git a/tests/untried/neg/t6283.scala b/tests/untried/neg/t6283.scala new file mode 100644 index 000000000000..d41eb18a74ee --- /dev/null +++ b/tests/untried/neg/t6283.scala @@ -0,0 +1 @@ +abstract class Funky(val i: Int) extends AnyVal diff --git a/tests/untried/neg/t6289.check b/tests/untried/neg/t6289.check new file mode 100644 index 000000000000..f6f43cabd36e --- /dev/null +++ b/tests/untried/neg/t6289.check @@ -0,0 +1,10 @@ +#partest java6 +t6289/J.java:2: method does not override or implement a method from a supertype + @Override public void foo() { } + ^ +1 error +#partest java7 +t6289/J.java:2: error: method does not override or implement a method from a supertype + @Override public void foo() { } + ^ +1 error diff --git a/tests/untried/neg/t6289.flags b/tests/untried/neg/t6289.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t6289.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t6289/J.java b/tests/untried/neg/t6289/J.java new file mode 100644 index 000000000000..83f50c9ae2b9 --- /dev/null +++ b/tests/untried/neg/t6289/J.java @@ -0,0 +1,5 @@ +public class J { + @Override public void foo() { } + + public void bar() { foo(); } +} diff --git a/tests/untried/neg/t6289/SUT_5.scala b/tests/untried/neg/t6289/SUT_5.scala new file mode 100644 index 000000000000..0a996352c039 --- /dev/null +++ b/tests/untried/neg/t6289/SUT_5.scala @@ -0,0 +1,5 @@ + +/** The System Under Test. + * We bail on the earlier round that generates the first error. + */ +class SUT extends J diff --git a/tests/untried/neg/t630.check b/tests/untried/neg/t630.check new file mode 100644 index 000000000000..0814ef0c1876 --- /dev/null +++ b/tests/untried/neg/t630.check @@ -0,0 +1,5 @@ +t630.scala:20: error: overriding value foo in trait Bar of type Req2; + object foo has incompatible type + object foo extends Req1 + ^ +one error found diff --git a/tests/untried/neg/t630.scala b/tests/untried/neg/t630.scala new file mode 100644 index 000000000000..8a073963b0c4 --- /dev/null +++ b/tests/untried/neg/t630.scala @@ -0,0 +1,23 @@ +trait Req1 + +trait Req2 { + def test() = Console.println("Test") +} + +trait Foo { + val foo : Req1 +} + +trait Bar { + val foo : Req2 + def test() = foo.test +} + +object Test + extends Foo + with Bar +{ + object foo extends Req1 + + def main(argv : Array[String]) = test +} diff --git a/tests/untried/neg/t631.check b/tests/untried/neg/t631.check new file mode 100644 index 000000000000..3759565e1178 --- /dev/null +++ b/tests/untried/neg/t631.check @@ -0,0 +1,4 @@ +t631.scala:1: error: `implicit' modifier cannot be used for top-level objects +implicit object Test { + ^ +one error found diff --git a/tests/untried/neg/t631.scala b/tests/untried/neg/t631.scala new file mode 100644 index 000000000000..631db3eb1029 --- /dev/null +++ b/tests/untried/neg/t631.scala @@ -0,0 +1,3 @@ +implicit object Test { + Console.println("foo") +} diff --git a/tests/untried/neg/t6323a.check b/tests/untried/neg/t6323a.check new file mode 100644 index 000000000000..261a60ef3c6e --- /dev/null +++ b/tests/untried/neg/t6323a.check @@ -0,0 +1,15 @@ +t6323a.scala:10: materializing requested scala.reflect.type.ClassTag[Test] using `package`.this.materializeClassTag[Test]() + val lookAtMe = m.reflect(Test("a",List(5))) + ^ +t6323a.scala:11: materializing requested reflect.runtime.universe.type.TypeTag[Test] using `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) + val value = u.typeOf[Test] + ^ +t6323a.scala:11: `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) is not a valid implicit value for reflect.runtime.universe.TypeTag[Test] because: +failed to typecheck the materialized tag: +cannot create a TypeTag referring to class Test.Test local to the reifee: use WeakTypeTag instead + val value = u.typeOf[Test] + ^ +t6323a.scala:11: error: No TypeTag available for Test + val value = u.typeOf[Test] + ^ +one error found diff --git a/tests/untried/neg/t6323a.flags b/tests/untried/neg/t6323a.flags new file mode 100644 index 000000000000..4c6cdb71e2fa --- /dev/null +++ b/tests/untried/neg/t6323a.flags @@ -0,0 +1 @@ +-Xlog-implicits \ No newline at end of file diff --git a/tests/untried/neg/t6323a.scala b/tests/untried/neg/t6323a.scala new file mode 100644 index 000000000000..a32eb915dba4 --- /dev/null +++ b/tests/untried/neg/t6323a.scala @@ -0,0 +1,21 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => m} +import scala.reflect.runtime.{universe => u} + +object Test extends App { + locally { + try { + case class Test(a:String,b:List[Int]) + + val lookAtMe = m.reflect(Test("a",List(5))) + val value = u.typeOf[Test] + val members = value.members + val member = value.members.filter(_.name.encoded == "a") + val aAccessor = lookAtMe.reflectMethod(member.head.asMethod) + val thisShouldBeA = aAccessor.apply() + println(thisShouldBeA) + } catch { + case ScalaReflectionException(msg) => println(msg) + } + } +} diff --git a/tests/untried/neg/t633.check b/tests/untried/neg/t633.check new file mode 100644 index 000000000000..d69d3be70e26 --- /dev/null +++ b/tests/untried/neg/t633.check @@ -0,0 +1,4 @@ +t633.scala:3: error: not found: type ListBuffer + def t(a : ListBuffer[String]) = { + ^ +one error found diff --git a/tests/untried/neg/t633.scala b/tests/untried/neg/t633.scala new file mode 100644 index 000000000000..fd4e560720c1 --- /dev/null +++ b/tests/untried/neg/t633.scala @@ -0,0 +1,8 @@ +object Test +{ + def t(a : ListBuffer[String]) = { + Console.println(a.length) + } + + def main(argv : Array[String]) = t(null) +} diff --git a/tests/untried/neg/t6335.check b/tests/untried/neg/t6335.check new file mode 100644 index 000000000000..1727a05eb208 --- /dev/null +++ b/tests/untried/neg/t6335.check @@ -0,0 +1,9 @@ +t6335.scala:6: error: method Z is defined twice + conflicting symbols both originated in file 't6335.scala' + implicit class Z[A](val i: A) { def zz = i } + ^ +t6335.scala:3: error: method X is defined twice + conflicting symbols both originated in file 't6335.scala' + implicit class X(val x: Int) { def xx = x } + ^ +two errors found diff --git a/tests/untried/neg/t6335.scala b/tests/untried/neg/t6335.scala new file mode 100644 index 000000000000..6c898af5b487 --- /dev/null +++ b/tests/untried/neg/t6335.scala @@ -0,0 +1,7 @@ +object ImplicitClass { + def X(i: Int): Unit = {} + implicit class X(val x: Int) { def xx = x } + + def Z[A](i: A): Unit = {} + implicit class Z[A](val i: A) { def zz = i } +} diff --git a/tests/untried/neg/t6336.check b/tests/untried/neg/t6336.check new file mode 100644 index 000000000000..f70a5f70ab35 --- /dev/null +++ b/tests/untried/neg/t6336.check @@ -0,0 +1,7 @@ +t6336.scala:3: error: Parameter type in structural refinement may not refer to a user-defined value class + val a = new { def y[T](x: X[T]) = x.i } + ^ +t6336.scala:4: error: Result type in structural refinement may not refer to a user-defined value class + val b = new { def y[T](x: T): X[T] = new X(2) } + ^ +two errors found diff --git a/tests/untried/neg/t6336.scala b/tests/untried/neg/t6336.scala new file mode 100644 index 000000000000..d8b795e3edbf --- /dev/null +++ b/tests/untried/neg/t6336.scala @@ -0,0 +1,12 @@ +object D { + def main(args: Array[String]): Unit = { + val a = new { def y[T](x: X[T]) = x.i } + val b = new { def y[T](x: T): X[T] = new X(2) } + val x = new X(3) + val t = a.y(x) + println(t) + } +} + +class X[T](val i: Int) extends AnyVal + diff --git a/tests/untried/neg/t6337.check b/tests/untried/neg/t6337.check new file mode 100644 index 000000000000..8448f71320d9 --- /dev/null +++ b/tests/untried/neg/t6337.check @@ -0,0 +1,7 @@ +t6337.scala:10: error: value class may not wrap another user-defined value class +class X[T](val i: XX[T]) extends AnyVal + ^ +t6337.scala:20: error: value class may not wrap another user-defined value class +class X1[T](val i: XX1[T]) extends AnyVal + ^ +two errors found diff --git a/tests/untried/neg/t6337.scala b/tests/untried/neg/t6337.scala new file mode 100644 index 000000000000..a6cb9bb33ad6 --- /dev/null +++ b/tests/untried/neg/t6337.scala @@ -0,0 +1,21 @@ +object C { + + def main(args: Array[String]) = { + val x = new X(new XX(3)) + println(x.i.x + 9) + } + +} + +class X[T](val i: XX[T]) extends AnyVal +class XX[T](val x: T) extends AnyVal + +object C1 { + def main(args: Array[String]): Unit = { + val x = new X1(new XX1(Some(3))) + println(x.i.x.get + 9) + } +} + +class X1[T](val i: XX1[T]) extends AnyVal +class XX1[T](val x: Option[T]) extends AnyVal diff --git a/tests/untried/neg/t6340.check b/tests/untried/neg/t6340.check new file mode 100644 index 000000000000..f18b8c3f4ba2 --- /dev/null +++ b/tests/untried/neg/t6340.check @@ -0,0 +1,10 @@ +t6340.scala:11: error: value D is not a member of object Foo + import Foo.{ A, B, C, D, E, X, Y, Z } + ^ +t6340.scala:16: error: not found: type D + val d = new D + ^ +t6340.scala:17: error: not found: type W + val w = new W + ^ +three errors found diff --git a/tests/untried/neg/t6340.scala b/tests/untried/neg/t6340.scala new file mode 100644 index 000000000000..8934d5c15d6f --- /dev/null +++ b/tests/untried/neg/t6340.scala @@ -0,0 +1,21 @@ +object Foo { + class A + class B + class C + class X + class Y + class Z +} + +object Test { + import Foo.{ A, B, C, D, E, X, Y, Z } + + val a = new A + val b = new B + val c = new C + val d = new D + val w = new W + val x = new X + val y = new Y + val z = new Z +} diff --git a/tests/untried/neg/t6355a.check b/tests/untried/neg/t6355a.check new file mode 100644 index 000000000000..5768d31f0b48 --- /dev/null +++ b/tests/untried/neg/t6355a.check @@ -0,0 +1,7 @@ +t6355a.scala:12: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic(name: String)(x: Int): Int = 2 + ^ +t6355a.scala:18: error: implementation restriction: applyDynamic cannot be overloaded except by methods with different numbers of type parameters, e.g. applyDynamic[T1](method: String)(arg: T1) and applyDynamic[T1, T2](method: String)(arg1: T1, arg2: T2) + def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 + ^ +two errors found diff --git a/tests/untried/neg/t6355a.scala b/tests/untried/neg/t6355a.scala new file mode 100644 index 000000000000..0500ed04c630 --- /dev/null +++ b/tests/untried/neg/t6355a.scala @@ -0,0 +1,19 @@ +package foo + +import scala.language.dynamics + +class DoesntExtendDynamic { + def applyDynamic(name: String)(s: String): Int = 1 + def applyDynamic(name: String)(x: Int): Int = 2 +} + +class A extends Dynamic { + def applyDynamic(name: String)(s: String): Int = 1 + def applyDynamic(name: String)(x: Int): Int = 2 +} + +class B extends Dynamic { + def applyDynamic[T1](name: String)(x: T1): Int = 1 + def applyDynamic[T1, T2](name: String)(x: T1, y: T2): Int = 2 + def applyDynamic[T1, T2](name: String)(x: String, y: T1, z: T2): Int = 3 +} diff --git a/tests/untried/neg/t6355b.check b/tests/untried/neg/t6355b.check new file mode 100644 index 000000000000..f827f07e53bd --- /dev/null +++ b/tests/untried/neg/t6355b.check @@ -0,0 +1,11 @@ +t6355b.scala:14: error: value applyDynamic is not a member of A +error after rewriting to x.("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy(42)) + ^ +t6355b.scala:15: error: value applyDynamic is not a member of A +error after rewriting to x.("bippy") +possible cause: maybe a wrong Dynamic method signature? + println(x.bippy("42")) + ^ +two errors found diff --git a/tests/untried/neg/t6355b.scala b/tests/untried/neg/t6355b.scala new file mode 100644 index 000000000000..5f3c97cb0c68 --- /dev/null +++ b/tests/untried/neg/t6355b.scala @@ -0,0 +1,17 @@ +import scala.language.dynamics + +class A extends Dynamic { + def selectDynamic(method: String): B = new B(method) +} +class B(method: String) { + def apply(x: Int) = s"$method(x: Int) called with x = $x" + def apply(x: String) = s"""$method(x: String) called with x = "$x"""" +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + println(x.bippy(42)) + println(x.bippy("42")) + } +} diff --git a/tests/untried/neg/t6357.check b/tests/untried/neg/t6357.check new file mode 100644 index 000000000000..a534d1439abb --- /dev/null +++ b/tests/untried/neg/t6357.check @@ -0,0 +1,4 @@ +t6357.scala:3: error: value class may not be a local class + final class Y(val j: Int) extends AnyVal + ^ +one error found diff --git a/tests/untried/neg/t6357.scala b/tests/untried/neg/t6357.scala new file mode 100644 index 000000000000..47f56296389c --- /dev/null +++ b/tests/untried/neg/t6357.scala @@ -0,0 +1,6 @@ +object K { + def q = { + final class Y(val j: Int) extends AnyVal + 3 + } +} diff --git a/tests/untried/neg/t6359.check b/tests/untried/neg/t6359.check new file mode 100644 index 000000000000..5bcdc57331a0 --- /dev/null +++ b/tests/untried/neg/t6359.check @@ -0,0 +1,9 @@ +t6359.scala:3: error: implementation restriction: nested object is not allowed in value class +This restriction is planned to be removed in subsequent releases. + object X + ^ +t6359.scala:4: error: implementation restriction: nested class is not allowed in value class +This restriction is planned to be removed in subsequent releases. + class Y + ^ +two errors found diff --git a/tests/untried/neg/t6359.scala b/tests/untried/neg/t6359.scala new file mode 100644 index 000000000000..96550fd90678 --- /dev/null +++ b/tests/untried/neg/t6359.scala @@ -0,0 +1,8 @@ +class M(val t: Int) extends AnyVal { + def lazyString = { + object X + class Y + + () => {X; new Y} + } +} diff --git a/tests/untried/neg/t6375.check b/tests/untried/neg/t6375.check new file mode 100644 index 000000000000..89d7d8060fea --- /dev/null +++ b/tests/untried/neg/t6375.check @@ -0,0 +1,27 @@ +t6375.scala:6: warning: no valid targets for annotation on value x1 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @getter) + @Bippy val x1: Int // warn + ^ +t6375.scala:7: warning: no valid targets for annotation on value x2 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.field @getter) + @(Bippy @field) val x2: Int // warn + ^ +t6375.scala:9: warning: no valid targets for annotation on value x4 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.setter @getter) + @(Bippy @setter) val x4: Int // warn + ^ +t6375.scala:10: warning: no valid targets for annotation on value x5 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.param @getter) + @(Bippy @param) val x5: Int // warn + ^ +t6375.scala:20: warning: no valid targets for annotation on value q1 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.getter @field) + @(Bippy @getter) private[this] val q1: Int = 1 // warn + ^ +t6375.scala:40: warning: no valid targets for annotation on value p2 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.getter @param) + @(Bippy @getter) p2: Int, // warn + ^ +t6375.scala:41: warning: no valid targets for annotation on value p3 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.setter @param) + @(Bippy @setter) p3: Int, // warn + ^ +t6375.scala:42: warning: no valid targets for annotation on value p4 - it is discarded unused. You may specify targets with meta-annotations, e.g. @(Bippy @scala.annotation.meta.field @param) + @(Bippy @field) p4: Int // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/t6375.flags b/tests/untried/neg/t6375.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t6375.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t6375.scala b/tests/untried/neg/t6375.scala new file mode 100644 index 000000000000..21634df6882d --- /dev/null +++ b/tests/untried/neg/t6375.scala @@ -0,0 +1,67 @@ +import scala.annotation.meta._ + +class Bippy extends scala.annotation.StaticAnnotation + +abstract class Foo { + @Bippy val x1: Int // warn + @(Bippy @field) val x2: Int // warn + @(Bippy @getter) val x3: Int // no warn + @(Bippy @setter) val x4: Int // warn + @(Bippy @param) val x5: Int // warn +} + +object Bar extends Foo { + val x1 = 1 + val x2 = 2 + val x3 = 3 + val x4 = 4 + val x5 = 5 + + @(Bippy @getter) private[this] val q1: Int = 1 // warn + @(Bippy @getter) private val q2: Int = 1 // no warn + + def f1(@(Bippy @param) x: Int): Int = 0 // no warn + def f2(@(Bippy @getter) x: Int): Int = 0 // warn - todo + def f3(@(Bippy @setter) x: Int): Int = 0 // warn - todo + def f4(@(Bippy @field) x: Int): Int = 0 // warn - todo + def f5(@Bippy x: Int): Int = 0 // no warn + + @(Bippy @companionClass) def g1(x: Int): Int = 0 // warn - todo + @(Bippy @companionObject) def g2(x: Int): Int = 0 // warn - todo + @(Bippy @companionMethod) def g3(x: Int): Int = 0 // no warn + @Bippy def g4(x: Int): Int = 0 // no warn + + @(Bippy @companionObject @companionMethod) def g5(x: Int): Int = 0 // no warn +} + +class Dingo( + @Bippy p0: Int, // no warn + @(Bippy @param) p1: Int, // no warn + @(Bippy @getter) p2: Int, // warn + @(Bippy @setter) p3: Int, // warn + @(Bippy @field) p4: Int // warn +) + +class ValDingo( + @Bippy val p0: Int, // no warn + @(Bippy @param) val p1: Int, // no warn + @(Bippy @getter) val p2: Int, // no warn + @(Bippy @setter) val p3: Int, // warn - todo + @(Bippy @field) val p4: Int // no warn +) + +class VarDingo( + @Bippy var p0: Int, // no warn + @(Bippy @param) var p1: Int, // no warn + @(Bippy @getter) var p2: Int, // no warn + @(Bippy @setter) var p3: Int, // no warn + @(Bippy @field) var p4: Int // no warn +) + +case class CaseDingo( + @Bippy p0: Int, // no warn + @(Bippy @param) p1: Int, // no warn + @(Bippy @getter) p2: Int, // no warn + @(Bippy @setter) p3: Int, // warn - todo + @(Bippy @field) p4: Int // no warn +) diff --git a/tests/untried/neg/t639.check b/tests/untried/neg/t639.check new file mode 100644 index 000000000000..6d41d872de68 --- /dev/null +++ b/tests/untried/neg/t639.check @@ -0,0 +1,7 @@ +t639.scala:3: error: not found: object a +import a._ + ^ +t639.scala:5: error: not found: type B +@B + ^ +two errors found diff --git a/tests/untried/neg/t639.scala b/tests/untried/neg/t639.scala new file mode 100644 index 000000000000..eaeed944a4c9 --- /dev/null +++ b/tests/untried/neg/t639.scala @@ -0,0 +1,6 @@ +package foo123 + +import a._ + +@B +class C diff --git a/tests/untried/neg/t6406-regextract.check b/tests/untried/neg/t6406-regextract.check new file mode 100644 index 000000000000..19425a68b051 --- /dev/null +++ b/tests/untried/neg/t6406-regextract.check @@ -0,0 +1,6 @@ +t6406-regextract.scala:4: warning: method unapplySeq in class Regex is deprecated: Extracting a match result from anything but a CharSequence or Match is deprecated + List(1) collect { case r(i) => i } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t6406-regextract.flags b/tests/untried/neg/t6406-regextract.flags new file mode 100644 index 000000000000..7de3c0f3eea0 --- /dev/null +++ b/tests/untried/neg/t6406-regextract.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation diff --git a/tests/untried/neg/t6406-regextract.scala b/tests/untried/neg/t6406-regextract.scala new file mode 100644 index 000000000000..0f5dad908d4b --- /dev/null +++ b/tests/untried/neg/t6406-regextract.scala @@ -0,0 +1,5 @@ + +object Test extends App { + val r = "(\\d+)".r + List(1) collect { case r(i) => i } +} diff --git a/tests/untried/neg/t6436.check b/tests/untried/neg/t6436.check new file mode 100644 index 000000000000..5cee6fb5581d --- /dev/null +++ b/tests/untried/neg/t6436.check @@ -0,0 +1,10 @@ +t6436.scala:8: error: type mismatch; + found : StringContext + required: ?{def q: ?} +Note that implicit conversions are not applicable because they are ambiguous: + both method foo1 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + and method foo2 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + are possible conversion functions from StringContext to ?{def q: ?} + println(q"a") + ^ +one error found diff --git a/tests/untried/neg/t6436.scala b/tests/untried/neg/t6436.scala new file mode 100644 index 000000000000..2c4050253885 --- /dev/null +++ b/tests/untried/neg/t6436.scala @@ -0,0 +1,9 @@ +object quasiquotes { + implicit def foo1(ctx: StringContext) = new { def q = ??? } + implicit def foo2(ctx: StringContext) = new { def q = ??? } +} + +object Test extends App { + import quasiquotes._ + println(q"a") +} diff --git a/tests/untried/neg/t6436b.check b/tests/untried/neg/t6436b.check new file mode 100644 index 000000000000..21ab972b7972 --- /dev/null +++ b/tests/untried/neg/t6436b.check @@ -0,0 +1,10 @@ +t6436b.scala:8: error: type mismatch; + found : StringContext + required: ?{def q: ?} +Note that implicit conversions are not applicable because they are ambiguous: + both method foo1 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + and method foo2 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + are possible conversion functions from StringContext to ?{def q: ?} + println(StringContext("a").q()) + ^ +one error found diff --git a/tests/untried/neg/t6436b.scala b/tests/untried/neg/t6436b.scala new file mode 100644 index 000000000000..8023329e9051 --- /dev/null +++ b/tests/untried/neg/t6436b.scala @@ -0,0 +1,9 @@ +object quasiquotes { + implicit def foo1(ctx: StringContext) = new { def q = ??? } + implicit def foo2(ctx: StringContext) = new { def q = ??? } +} + +object Test extends App { + import quasiquotes._ + println(StringContext("a").q()) +} diff --git a/tests/untried/neg/t6443c.check b/tests/untried/neg/t6443c.check new file mode 100644 index 000000000000..7b7f419f6c18 --- /dev/null +++ b/tests/untried/neg/t6443c.check @@ -0,0 +1,7 @@ +t6443c.scala:16: error: double definition: +def foo(d: B.D)(a: Any,d2: d.type): Unit at line 11 and +def foo(d: B.D)(a: Any)(d2: d.type): Unit at line 16 +have same type after erasure: (d: B.D, a: Object, d2: B.D)Unit + def foo(d: D)(a: Any)(d2: d.type): Unit = () + ^ +one error found diff --git a/tests/untried/neg/t6443c.scala b/tests/untried/neg/t6443c.scala new file mode 100644 index 000000000000..817224e0433a --- /dev/null +++ b/tests/untried/neg/t6443c.scala @@ -0,0 +1,21 @@ +trait A { + type D >: Null <: C + def foo(d: D)(a: Any, d2: d.type): Unit + trait C { + def bar: Unit = foo(null)(null, null) + } +} +object B extends A { + class D extends C + + def foo(d: D)(a: Any, d2: d.type): Unit = () // Bridge method required here! + + // No bridge method should be added, but we'll be happy enough if + // the "same type after erasure" error kicks in before the duplicated + // bridge causes a problem. + def foo(d: D)(a: Any)(d2: d.type): Unit = () +} + +object Test extends App { + new B.D().bar +} diff --git a/tests/untried/neg/t6446-additional.check b/tests/untried/neg/t6446-additional.check new file mode 100755 index 000000000000..a87af2f1e55c --- /dev/null +++ b/tests/untried/neg/t6446-additional.check @@ -0,0 +1,39 @@ + phase name id description + ---------- -- ----------- + parser 1 parse source into ASTs, perform simple desugaring + namer 2 resolve names, attach symbols to named trees +packageobjects 3 load package objects + typer 4 the meat and potatoes: type the trees + patmat 5 translate match expressions +superaccessors 6 add super accessors in traits and nested classes + extmethods 7 add extension methods for inline classes + pickler 8 serialize symbol tables + refchecks 9 reference/override checking, translate nested objects + uncurry 10 uncurry, translate function values to anonymous classes + tailcalls 11 replace tail calls by jumps + specialize 12 @specialized-driven class and method specialization + explicitouter 13 this refs to outer pointers + erasure 14 erase types, add interfaces for traits + posterasure 15 clean up erased inline classes + lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 17 move nested functions to top level + constructors 18 move field definitions into constructors + flatten 19 eliminate inner classes + mixin 20 mixin composition + cleanup 21 platform-specific cleanups, generate reflective calls + delambdafy 22 remove lambdas + icode 23 generate portable intermediate code +#partest -optimise + inliner 24 optimization: do inlining +inlinehandlers 25 optimization: inline exception handlers + closelim 26 optimization: eliminate uncalled closures + constopt 27 optimization: optimize null and other constants + dce 28 optimization: eliminate dead code + jvm 29 generate JVM bytecode + ploogin 30 A sample phase that does so many things it's kind of hard... + terminal 31 the last phase during a compilation run +#partest !-optimise + jvm 24 generate JVM bytecode + ploogin 25 A sample phase that does so many things it's kind of hard... + terminal 26 the last phase during a compilation run +#partest diff --git a/tests/untried/neg/t6446-additional/ploogin_1.scala b/tests/untried/neg/t6446-additional/ploogin_1.scala new file mode 100644 index 000000000000..dbf433f9a41d --- /dev/null +++ b/tests/untried/neg/t6446-additional/ploogin_1.scala @@ -0,0 +1,31 @@ + +package t6446 + +import scala.tools.nsc.{ Global, Phase } +import scala.tools.nsc.plugins.{ Plugin, PluginComponent } +import scala.reflect.io.Path +import scala.reflect.io.File + +/** A test plugin. */ +class Ploogin(val global: Global) extends Plugin { + import global._ + + val name = "ploogin" + val description = "A sample plugin for testing." + val components = List[PluginComponent](TestComponent) + + private object TestComponent extends PluginComponent { + val global: Ploogin.this.global.type = Ploogin.this.global + //override val runsBefore = List("refchecks") + val runsAfter = List("jvm") + val phaseName = Ploogin.this.name + override def description = "A sample phase that does so many things it's kind of hard to describe briefly." + def newPhase(prev: Phase) = new TestPhase(prev) + class TestPhase(prev: Phase) extends StdPhase(prev) { + override def description = TestComponent.this.description + def apply(unit: CompilationUnit): Unit = { + // kewl kode + } + } + } +} diff --git a/tests/untried/neg/t6446-additional/sample_2.flags b/tests/untried/neg/t6446-additional/sample_2.flags new file mode 100644 index 000000000000..4d518c228611 --- /dev/null +++ b/tests/untried/neg/t6446-additional/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xshow-phases diff --git a/tests/untried/neg/t6446-additional/sample_2.scala b/tests/untried/neg/t6446-additional/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t6446-additional/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t6446-additional/scalac-plugin.xml b/tests/untried/neg/t6446-additional/scalac-plugin.xml new file mode 100644 index 000000000000..e849bb59197e --- /dev/null +++ b/tests/untried/neg/t6446-additional/scalac-plugin.xml @@ -0,0 +1,4 @@ + +sample-plugin +t6446.Ploogin + diff --git a/tests/untried/neg/t6446-list.check b/tests/untried/neg/t6446-list.check new file mode 100755 index 000000000000..fa5c581941ad --- /dev/null +++ b/tests/untried/neg/t6446-list.check @@ -0,0 +1 @@ +ploogin - A sample plugin for testing. diff --git a/tests/untried/neg/t6446-list/ploogin_1.scala b/tests/untried/neg/t6446-list/ploogin_1.scala new file mode 100644 index 000000000000..dbf433f9a41d --- /dev/null +++ b/tests/untried/neg/t6446-list/ploogin_1.scala @@ -0,0 +1,31 @@ + +package t6446 + +import scala.tools.nsc.{ Global, Phase } +import scala.tools.nsc.plugins.{ Plugin, PluginComponent } +import scala.reflect.io.Path +import scala.reflect.io.File + +/** A test plugin. */ +class Ploogin(val global: Global) extends Plugin { + import global._ + + val name = "ploogin" + val description = "A sample plugin for testing." + val components = List[PluginComponent](TestComponent) + + private object TestComponent extends PluginComponent { + val global: Ploogin.this.global.type = Ploogin.this.global + //override val runsBefore = List("refchecks") + val runsAfter = List("jvm") + val phaseName = Ploogin.this.name + override def description = "A sample phase that does so many things it's kind of hard to describe briefly." + def newPhase(prev: Phase) = new TestPhase(prev) + class TestPhase(prev: Phase) extends StdPhase(prev) { + override def description = TestComponent.this.description + def apply(unit: CompilationUnit): Unit = { + // kewl kode + } + } + } +} diff --git a/tests/untried/neg/t6446-list/sample_2.flags b/tests/untried/neg/t6446-list/sample_2.flags new file mode 100644 index 000000000000..9cb3232964fb --- /dev/null +++ b/tests/untried/neg/t6446-list/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-list diff --git a/tests/untried/neg/t6446-list/sample_2.scala b/tests/untried/neg/t6446-list/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t6446-list/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t6446-list/scalac-plugin.xml b/tests/untried/neg/t6446-list/scalac-plugin.xml new file mode 100644 index 000000000000..e849bb59197e --- /dev/null +++ b/tests/untried/neg/t6446-list/scalac-plugin.xml @@ -0,0 +1,4 @@ + +sample-plugin +t6446.Ploogin + diff --git a/tests/untried/neg/t6446-missing.check b/tests/untried/neg/t6446-missing.check new file mode 100755 index 000000000000..029c8057c35b --- /dev/null +++ b/tests/untried/neg/t6446-missing.check @@ -0,0 +1,38 @@ +Error: unable to load class: t6446.Ploogin + phase name id description + ---------- -- ----------- + parser 1 parse source into ASTs, perform simple desugaring + namer 2 resolve names, attach symbols to named trees +packageobjects 3 load package objects + typer 4 the meat and potatoes: type the trees + patmat 5 translate match expressions +superaccessors 6 add super accessors in traits and nested classes + extmethods 7 add extension methods for inline classes + pickler 8 serialize symbol tables + refchecks 9 reference/override checking, translate nested objects + uncurry 10 uncurry, translate function values to anonymous classes + tailcalls 11 replace tail calls by jumps + specialize 12 @specialized-driven class and method specialization + explicitouter 13 this refs to outer pointers + erasure 14 erase types, add interfaces for traits + posterasure 15 clean up erased inline classes + lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 17 move nested functions to top level + constructors 18 move field definitions into constructors + flatten 19 eliminate inner classes + mixin 20 mixin composition + cleanup 21 platform-specific cleanups, generate reflective calls + delambdafy 22 remove lambdas + icode 23 generate portable intermediate code +#partest !-optimise + jvm 24 generate JVM bytecode + terminal 25 the last phase during a compilation run +#partest -optimise + inliner 24 optimization: do inlining +inlinehandlers 25 optimization: inline exception handlers + closelim 26 optimization: eliminate uncalled closures + constopt 27 optimization: optimize null and other constants + dce 28 optimization: eliminate dead code + jvm 29 generate JVM bytecode + terminal 30 the last phase during a compilation run +#partest diff --git a/tests/untried/neg/t6446-missing/sample_2.flags b/tests/untried/neg/t6446-missing/sample_2.flags new file mode 100644 index 000000000000..4d518c228611 --- /dev/null +++ b/tests/untried/neg/t6446-missing/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xshow-phases diff --git a/tests/untried/neg/t6446-missing/sample_2.scala b/tests/untried/neg/t6446-missing/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t6446-missing/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t6446-missing/scalac-plugin.xml b/tests/untried/neg/t6446-missing/scalac-plugin.xml new file mode 100644 index 000000000000..9c34d63f83bc --- /dev/null +++ b/tests/untried/neg/t6446-missing/scalac-plugin.xml @@ -0,0 +1,4 @@ + +missing-plugin +t6446.Ploogin + diff --git a/tests/untried/neg/t6446-show-phases.check b/tests/untried/neg/t6446-show-phases.check new file mode 100644 index 000000000000..3ae3f96ef26c --- /dev/null +++ b/tests/untried/neg/t6446-show-phases.check @@ -0,0 +1,37 @@ + phase name id description + ---------- -- ----------- + parser 1 parse source into ASTs, perform simple desugaring + namer 2 resolve names, attach symbols to named trees +packageobjects 3 load package objects + typer 4 the meat and potatoes: type the trees + patmat 5 translate match expressions +superaccessors 6 add super accessors in traits and nested classes + extmethods 7 add extension methods for inline classes + pickler 8 serialize symbol tables + refchecks 9 reference/override checking, translate nested objects + uncurry 10 uncurry, translate function values to anonymous classes + tailcalls 11 replace tail calls by jumps + specialize 12 @specialized-driven class and method specialization + explicitouter 13 this refs to outer pointers + erasure 14 erase types, add interfaces for traits + posterasure 15 clean up erased inline classes + lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 17 move nested functions to top level + constructors 18 move field definitions into constructors + flatten 19 eliminate inner classes + mixin 20 mixin composition + cleanup 21 platform-specific cleanups, generate reflective calls + delambdafy 22 remove lambdas + icode 23 generate portable intermediate code +#partest !-optimise + jvm 24 generate JVM bytecode + terminal 25 the last phase during a compilation run +#partest -optimise + inliner 24 optimization: do inlining +inlinehandlers 25 optimization: inline exception handlers + closelim 26 optimization: eliminate uncalled closures + constopt 27 optimization: optimize null and other constants + dce 28 optimization: eliminate dead code + jvm 29 generate JVM bytecode + terminal 30 the last phase during a compilation run +#partest diff --git a/tests/untried/neg/t6446-show-phases.flags b/tests/untried/neg/t6446-show-phases.flags new file mode 100644 index 000000000000..845666e100da --- /dev/null +++ b/tests/untried/neg/t6446-show-phases.flags @@ -0,0 +1 @@ +-Xshow-phases diff --git a/tests/untried/neg/t6446-show-phases.scala b/tests/untried/neg/t6446-show-phases.scala new file mode 100644 index 000000000000..a9afb042d251 --- /dev/null +++ b/tests/untried/neg/t6446-show-phases.scala @@ -0,0 +1,3 @@ + +// testing compiler flag output only +object Test extends App diff --git a/tests/untried/neg/t6455.check b/tests/untried/neg/t6455.check new file mode 100644 index 000000000000..8f2aad0b9e67 --- /dev/null +++ b/tests/untried/neg/t6455.check @@ -0,0 +1,4 @@ +t6455.scala:5: error: value withFilter is not a member of object O + O.withFilter(f => true) + ^ +one error found diff --git a/tests/untried/neg/t6455.flags b/tests/untried/neg/t6455.flags new file mode 100644 index 000000000000..112fc720a057 --- /dev/null +++ b/tests/untried/neg/t6455.flags @@ -0,0 +1 @@ +-Xfuture \ No newline at end of file diff --git a/tests/untried/neg/t6455.scala b/tests/untried/neg/t6455.scala new file mode 100644 index 000000000000..f62be3eb0dad --- /dev/null +++ b/tests/untried/neg/t6455.scala @@ -0,0 +1,6 @@ +object O { def filter(p: Int => Boolean): O.type = this } + +class Test { + // should not compile because we no longer rewrite withFilter => filter under -Xfuture + O.withFilter(f => true) +} diff --git a/tests/untried/neg/t6483.check b/tests/untried/neg/t6483.check new file mode 100644 index 000000000000..66e35071071c --- /dev/null +++ b/tests/untried/neg/t6483.check @@ -0,0 +1,9 @@ +t6483.scala:7: error: implementation restriction: qualified super reference is not allowed in value class +This restriction is planned to be removed in subsequent releases. + override def foo = super[T].foo // error + ^ +t6483.scala:20: error: implementation restriction: nested class is not allowed in value class +This restriction is planned to be removed in subsequent releases. + class Inner extends T { + ^ +two errors found diff --git a/tests/untried/neg/t6483.scala b/tests/untried/neg/t6483.scala new file mode 100644 index 000000000000..3d6713db4795 --- /dev/null +++ b/tests/untried/neg/t6483.scala @@ -0,0 +1,24 @@ +trait T extends Any { + def foo = 1 + type X +} + +class C1(val a: Any) extends AnyVal with T { + override def foo = super[T].foo // error +} + +class C2(val a: Int) extends AnyVal with T { + override def foo = super.foo + a // okay +} + +class C3(val a: Int) extends AnyVal with T { + override def foo = C3.super.foo + a // okay +} + +class C4(val a: Int) extends AnyVal with T { + def foo: Unit = { + class Inner extends T { + override def foo = super[T].foo + a // no (direct) error, other than that a nested class is currently illegal. + } + } +} diff --git a/tests/untried/neg/t649.check b/tests/untried/neg/t649.check new file mode 100644 index 000000000000..5a270d475187 --- /dev/null +++ b/tests/untried/neg/t649.check @@ -0,0 +1,4 @@ +t649.scala:3: error: overloaded method foo needs result type + def foo[A] = foo[A] + ^ +one error found diff --git a/tests/untried/neg/t649.scala b/tests/untried/neg/t649.scala new file mode 100644 index 000000000000..2519eb5cf319 --- /dev/null +++ b/tests/untried/neg/t649.scala @@ -0,0 +1,4 @@ +object test { + def foo[A] = 0 + def foo[A] = foo[A] +} diff --git a/tests/untried/neg/t650.check b/tests/untried/neg/t650.check new file mode 100644 index 000000000000..320ae66704d9 --- /dev/null +++ b/tests/untried/neg/t650.check @@ -0,0 +1,4 @@ +t650.scala:4: error: missing type arguments +trait Test2 extends LinkedList; + ^ +one error found diff --git a/tests/untried/neg/t650.scala b/tests/untried/neg/t650.scala new file mode 100644 index 000000000000..cdb4b3da479f --- /dev/null +++ b/tests/untried/neg/t650.scala @@ -0,0 +1,4 @@ +// test/Test2.scala +package test; +import scala.collection.mutable._; +trait Test2 extends LinkedList; diff --git a/tests/untried/neg/t6526.check b/tests/untried/neg/t6526.check new file mode 100644 index 000000000000..606c18c3019c --- /dev/null +++ b/tests/untried/neg/t6526.check @@ -0,0 +1,16 @@ +t6526.scala:8: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position + @tailrec def inner(i: Int): Int = 1 + inner(i) + ^ +t6526.scala:14: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position + @tailrec def inner(i: Int): Int = 1 + inner(i) + ^ +t6526.scala:20: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position + @tailrec def inner(i: Int): Int = 1 + inner(i) + ^ +t6526.scala:30: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position + @tailrec def inner(i: Int): Int = 1 + inner(i) + ^ +t6526.scala:39: error: could not optimize @tailrec annotated method inner: it contains a recursive call not in tail position + def inner(i: Int): Int = 1 + inner(i) + ^ +5 errors found diff --git a/tests/untried/neg/t6526.scala b/tests/untried/neg/t6526.scala new file mode 100644 index 000000000000..0bc249aa9866 --- /dev/null +++ b/tests/untried/neg/t6526.scala @@ -0,0 +1,41 @@ +import scala.annotation.tailrec + +class TailRec { + def bar(f: => Any) = "" + + // transform the qualifier of a Select + bar { + @tailrec def inner(i: Int): Int = 1 + inner(i) + inner(0) + }.length + + // transform the body of a function + () => { + @tailrec def inner(i: Int): Int = 1 + inner(i) + inner(0) + } + + // transform the qualifier of a Select + { + @tailrec def inner(i: Int): Int = 1 + inner(i) + inner(0) + "" + }.length + + // The receiver of a tail recursive call must itself be transformed + object X { + @tailrec // okay, all other annotated methods should fail. + def foo: Any = { + { + @tailrec def inner(i: Int): Int = 1 + inner(i) + inner(0) + this + }.foo + } + } + + Some(new AnyRef) map { phooie => + @tailrec + def inner(i: Int): Int = 1 + inner(i) + } getOrElse 42 +} diff --git a/tests/untried/neg/t6534.check b/tests/untried/neg/t6534.check new file mode 100644 index 000000000000..c2e80b377a9b --- /dev/null +++ b/tests/untried/neg/t6534.check @@ -0,0 +1,10 @@ +t6534.scala:6: error: redefinition of equals method. See SIP-15, criterion 4. is not allowed in value class +class Bippy3(val x: Int) extends AnyVal { override def equals(x: Any) = false } // error + ^ +t6534.scala:7: error: redefinition of hashCode method. See SIP-15, criterion 4. is not allowed in value class +class Bippy4(val x: Int) extends AnyVal { override def hashCode = -1 } // error + ^ +t6534.scala:9: error: redefinition of equals method. See SIP-15, criterion 4. is not allowed in value class +case class Bippy6(val x: Int) extends AnyVal { override def productPrefix = "Dingo" ; override def equals(x: Any) = false } // error + ^ +three errors found diff --git a/tests/untried/neg/t6534.flags b/tests/untried/neg/t6534.flags new file mode 100644 index 000000000000..1008b0a70c76 --- /dev/null +++ b/tests/untried/neg/t6534.flags @@ -0,0 +1 @@ +-Xlint diff --git a/tests/untried/neg/t6534.scala b/tests/untried/neg/t6534.scala new file mode 100644 index 000000000000..de588b69a7c2 --- /dev/null +++ b/tests/untried/neg/t6534.scala @@ -0,0 +1,10 @@ +trait Foo extends Any { override def equals(x: Any) = false } +trait Ding extends Any { override def hashCode = -1 } + +class Bippy1(val x: Int) extends AnyVal with Foo { } // warn +class Bippy2(val x: Int) extends AnyVal with Ding { } // warn +class Bippy3(val x: Int) extends AnyVal { override def equals(x: Any) = false } // error +class Bippy4(val x: Int) extends AnyVal { override def hashCode = -1 } // error +case class Bippy5(val x: Int) extends AnyVal { override def productPrefix = "Dingo" } // nothing +case class Bippy6(val x: Int) extends AnyVal { override def productPrefix = "Dingo" ; override def equals(x: Any) = false } // error + diff --git a/tests/untried/neg/t6535.check b/tests/untried/neg/t6535.check new file mode 100644 index 000000000000..1225ea70db23 --- /dev/null +++ b/tests/untried/neg/t6535.check @@ -0,0 +1,6 @@ +t6535.scala:2: error: encountered unrecoverable cycle resolving import. +Note: this is often due in part to a class depending on a definition nested within its companion. +If applicable, you may wish to try moving some members into another object. + import Bs.B._ + ^ +one error found diff --git a/tests/untried/neg/t6535.scala b/tests/untried/neg/t6535.scala new file mode 100644 index 000000000000..30a750311c16 --- /dev/null +++ b/tests/untried/neg/t6535.scala @@ -0,0 +1,15 @@ +object As { + import Bs.B._ + + object A + extends scala.AnyRef // needed for the cycle; + // replacing with a locally defined closs doesn't + // hit the locked import and hence doesn't cycle. +} + +object Bs { + import As.A._ + + object B + extends scala.AnyRef // scala.Immutable, ... +} diff --git a/tests/untried/neg/t6539.check b/tests/untried/neg/t6539.check new file mode 100644 index 000000000000..8c94a8ad4c66 --- /dev/null +++ b/tests/untried/neg/t6539.check @@ -0,0 +1,16 @@ +Test_2.scala:2: error: cto may only be used as an argument to m + M.cto // error + ^ +Test_2.scala:3: error: cto may only be used as an argument to m + M.m(M.cto, ()) // error + ^ +Test_2.scala:5: error: cto may only be used as an argument to m + M.cto // error + ^ +Test_2.scala:9: error: splice must be enclosed within a reify {} block + val splice = expr.splice + ^ +Test_2.scala:10: error: cannot use value except for signatures of macro implementations + val value = expr.value + ^ +5 errors found diff --git a/tests/untried/neg/t6539/Macro_1.scala b/tests/untried/neg/t6539/Macro_1.scala new file mode 100644 index 000000000000..60db669c4630 --- /dev/null +++ b/tests/untried/neg/t6539/Macro_1.scala @@ -0,0 +1,10 @@ +import language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object M { + def m(a: Any, b: Any): Any = macro mImpl + def mImpl(c: Context)(a: c.Expr[Any], b: c.Expr[Any]) = c.universe.reify(println(a.splice)) + + @reflect.internal.annotations.compileTimeOnly("cto may only be used as an argument to " + "m") + def cto = 0 +} diff --git a/tests/untried/neg/t6539/Test_2.scala b/tests/untried/neg/t6539/Test_2.scala new file mode 100644 index 000000000000..26f45042225e --- /dev/null +++ b/tests/untried/neg/t6539/Test_2.scala @@ -0,0 +1,12 @@ +object Test { + M.cto // error + M.m(M.cto, ()) // error + M.m((), M.cto) // okay + M.cto // error + + locally { + val expr = scala.reflect.runtime.universe.reify(2) + val splice = expr.splice + val value = expr.value + } +} diff --git a/tests/untried/neg/t6558.check b/tests/untried/neg/t6558.check new file mode 100644 index 000000000000..6ad3cecd5023 --- /dev/null +++ b/tests/untried/neg/t6558.check @@ -0,0 +1,10 @@ +t6558.scala:4: error: not found: type classs + @classs + ^ +t6558.scala:7: error: not found: type typeparam + class D[@typeparam T] + ^ +t6558.scala:10: error: not found: type valueparam + @valueparam x: Any + ^ +three errors found diff --git a/tests/untried/neg/t6558.scala b/tests/untried/neg/t6558.scala new file mode 100644 index 000000000000..b4304ff68621 --- /dev/null +++ b/tests/untried/neg/t6558.scala @@ -0,0 +1,12 @@ +class AnnotNotFound { + def foo(a: Any) = () + + @classs + class C + + class D[@typeparam T] + + class E( + @valueparam x: Any + ) +} diff --git a/tests/untried/neg/t6558b.check b/tests/untried/neg/t6558b.check new file mode 100644 index 000000000000..cfa384fc08f4 --- /dev/null +++ b/tests/untried/neg/t6558b.check @@ -0,0 +1,7 @@ +t6558b.scala:5: error: not found: type inargument + @inargument + ^ +t6558b.scala:11: error: not found: type infunction + @infunction + ^ +two errors found diff --git a/tests/untried/neg/t6558b.scala b/tests/untried/neg/t6558b.scala new file mode 100644 index 000000000000..2aa06f69cf60 --- /dev/null +++ b/tests/untried/neg/t6558b.scala @@ -0,0 +1,15 @@ +class AnnotNotFound { + def foo(a: Any) = () + + foo { + @inargument + def foo = 0 + foo + } + + () => { + @infunction + def foo = 0 + () + } +} diff --git a/tests/untried/neg/t6563.check b/tests/untried/neg/t6563.check new file mode 100644 index 000000000000..75dca1507dcc --- /dev/null +++ b/tests/untried/neg/t6563.check @@ -0,0 +1,4 @@ +t6563.scala:4: error: not found: value e + e("f") + ^ +one error found diff --git a/tests/untried/neg/t6563.scala b/tests/untried/neg/t6563.scala new file mode 100644 index 000000000000..33db51b0f949 --- /dev/null +++ b/tests/untried/neg/t6563.scala @@ -0,0 +1,8 @@ +class A{ + def b(c: => Unit): Unit = {} + b{ + e("f") + new G()(){} + } +} +class G(h:String="i")() diff --git a/tests/untried/neg/t6566a.check b/tests/untried/neg/t6566a.check new file mode 100644 index 000000000000..7668f9d2fbc9 --- /dev/null +++ b/tests/untried/neg/t6566a.check @@ -0,0 +1,4 @@ +t6566a.scala:2: error: covariant type T occurs in invariant position in type T of type MyType + class TypeCheat[+T] { type MyType = T } + ^ +one error found diff --git a/tests/untried/neg/t6566a.scala b/tests/untried/neg/t6566a.scala new file mode 100644 index 000000000000..74a0b38e5689 --- /dev/null +++ b/tests/untried/neg/t6566a.scala @@ -0,0 +1,17 @@ +object WhatsYourTypeIsMyType { + class TypeCheat[+T] { type MyType = T } + + class Foo { + val tc = new TypeCheat[Foo] + var x: tc.MyType = _ + def setX() = x = new Foo + } + class Bar extends Foo { + override val tc = new TypeCheat[Bar] + def unsound = this + + setX() + println(x.unsound) + } + def main(args: Array[String]): Unit = new Bar +} diff --git a/tests/untried/neg/t6566b.check b/tests/untried/neg/t6566b.check new file mode 100644 index 000000000000..fb3fe81fca15 --- /dev/null +++ b/tests/untried/neg/t6566b.check @@ -0,0 +1,4 @@ +t6566b.scala:3: error: covariant type T occurs in invariant position in type T of type MyType + type MyType = T + ^ +one error found diff --git a/tests/untried/neg/t6566b.scala b/tests/untried/neg/t6566b.scala new file mode 100644 index 000000000000..0d488dbe8a6c --- /dev/null +++ b/tests/untried/neg/t6566b.scala @@ -0,0 +1,19 @@ +object WhatsYourTypeIsMyType { + trait WithMyType[+T] { + type MyType = T + } + + class Foo extends WithMyType[Foo] { + var x: MyType = _ + def setX() = x = new Foo + } + + class Bar extends Foo with WithMyType[Bar] { + def unsound: Unit = { println("iAmABar") } + + setX() + println(x.unsound) + } + + def main(args: Array[String]): Unit = new Bar +} diff --git a/tests/untried/neg/t6567.check b/tests/untried/neg/t6567.check new file mode 100644 index 000000000000..a733d75354cf --- /dev/null +++ b/tests/untried/neg/t6567.check @@ -0,0 +1,9 @@ +t6567.scala:8: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply. + Option[B](a) + ^ +t6567.scala:10: warning: Suspicious application of an implicit view (Test.this.a2b) in the argument to Option.apply. + val b: Option[B] = Option(a) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t6567.flags b/tests/untried/neg/t6567.flags new file mode 100644 index 000000000000..e93641e9319e --- /dev/null +++ b/tests/untried/neg/t6567.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6567.scala b/tests/untried/neg/t6567.scala new file mode 100644 index 000000000000..650e5e39ae07 --- /dev/null +++ b/tests/untried/neg/t6567.scala @@ -0,0 +1,11 @@ +class A +class B + +object Test { + val a: A = null + implicit def a2b(a: A) = new B + + Option[B](a) + + val b: Option[B] = Option(a) +} diff --git a/tests/untried/neg/t6574.check b/tests/untried/neg/t6574.check new file mode 100644 index 000000000000..c67b4ed80403 --- /dev/null +++ b/tests/untried/neg/t6574.check @@ -0,0 +1,7 @@ +t6574.scala:4: error: could not optimize @tailrec annotated method notTailPos$extension: it contains a recursive call not in tail position + println("tail") + ^ +t6574.scala:8: error: could not optimize @tailrec annotated method differentTypeArgs$extension: it is called recursively with different type arguments + {(); new Bad[String, Unit](0)}.differentTypeArgs + ^ +two errors found diff --git a/tests/untried/neg/t6574.scala b/tests/untried/neg/t6574.scala new file mode 100644 index 000000000000..9e1d624e5222 --- /dev/null +++ b/tests/untried/neg/t6574.scala @@ -0,0 +1,10 @@ +class Bad[X, Y](val v: Int) extends AnyVal { + @annotation.tailrec final def notTailPos[Z](a: Int)(b: String): Unit = { + this.notTailPos[Z](a)(b) + println("tail") + } + + @annotation.tailrec final def differentTypeArgs {: Unit = + {(); new Bad[String, Unit](0)}.differentTypeArgs + } +} diff --git a/tests/untried/neg/t6597.check b/tests/untried/neg/t6597.check new file mode 100644 index 000000000000..1d52519d1dc0 --- /dev/null +++ b/tests/untried/neg/t6597.check @@ -0,0 +1,4 @@ +t6597.scala:3: error: illegal combination of modifiers: implicit and case for: class Quux + implicit case class Quux(value: Int) extends AnyVal with T + ^ +one error found diff --git a/tests/untried/neg/t6597.scala b/tests/untried/neg/t6597.scala new file mode 100644 index 000000000000..dde53bcc8901 --- /dev/null +++ b/tests/untried/neg/t6597.scala @@ -0,0 +1,5 @@ +object Test { + trait T extends Any + implicit case class Quux(value: Int) extends AnyVal with T + object Quux +} diff --git a/tests/untried/neg/t6601.check b/tests/untried/neg/t6601.check new file mode 100644 index 000000000000..1410e1b11a79 --- /dev/null +++ b/tests/untried/neg/t6601.check @@ -0,0 +1,4 @@ +AccessPrivateConstructor_2.scala:2: error: constructor PrivateConstructor in class PrivateConstructor cannot be accessed in class AccessPrivateConstructor + new PrivateConstructor("") // Scalac should forbid accessing to the private constructor! + ^ +one error found diff --git a/tests/untried/neg/t6601/AccessPrivateConstructor_2.scala b/tests/untried/neg/t6601/AccessPrivateConstructor_2.scala new file mode 100644 index 000000000000..816bc10d7945 --- /dev/null +++ b/tests/untried/neg/t6601/AccessPrivateConstructor_2.scala @@ -0,0 +1,3 @@ +class AccessPrivateConstructor { + new PrivateConstructor("") // Scalac should forbid accessing to the private constructor! +} diff --git a/tests/untried/neg/t6601/PrivateConstructor_1.scala b/tests/untried/neg/t6601/PrivateConstructor_1.scala new file mode 100644 index 000000000000..f09d7ad06825 --- /dev/null +++ b/tests/untried/neg/t6601/PrivateConstructor_1.scala @@ -0,0 +1 @@ +class PrivateConstructor private(val s: String) extends AnyVal diff --git a/tests/untried/neg/t663.check b/tests/untried/neg/t663.check new file mode 100644 index 000000000000..633e27ee1243 --- /dev/null +++ b/tests/untried/neg/t663.check @@ -0,0 +1,7 @@ +t663.scala:11: error: name clash between defined and inherited member: +def asMatch(node: Test.this.Matchable): Any in trait MatchableImpl and +def asMatch(m: Test.this.Node): Any at line 11 +have same type after erasure: (node: test.Test#NodeImpl)Object + def asMatch(m : Node) : Any = { + ^ +one error found diff --git a/tests/untried/neg/t663.scala b/tests/untried/neg/t663.scala new file mode 100644 index 000000000000..797c4a300d8c --- /dev/null +++ b/tests/untried/neg/t663.scala @@ -0,0 +1,18 @@ +package test; +trait Test { + type Matchable <: Node with MatchableImpl; + trait MatchableImpl extends NodeImpl { + def asMatch(node : Matchable) : Any; + } + type Node <: NodeImpl; + trait NodeImpl; + trait CoreIfImpl extends MatchableImpl { + // NO_CRASH: def asMatch(m : Matchable) = { + def asMatch(m : Node) : Any = { + if (m.isInstanceOf[MatchableImpl]) { + null; + } else null; + // NO_CRASH: null; + } + } +} diff --git a/tests/untried/neg/t664.check b/tests/untried/neg/t664.check new file mode 100644 index 000000000000..cbdf53daea4b --- /dev/null +++ b/tests/untried/neg/t664.check @@ -0,0 +1,7 @@ +t664.scala:4: error: type Foo is not a member of test.Test + trait Foo extends super.Foo { + ^ +t664.scala:5: error: type Bar is not a member of AnyRef + trait Bar extends super.Bar; + ^ +two errors found diff --git a/tests/untried/neg/t664.scala b/tests/untried/neg/t664.scala new file mode 100644 index 000000000000..f3b8d06053ff --- /dev/null +++ b/tests/untried/neg/t664.scala @@ -0,0 +1,7 @@ +package test; +abstract class Test; +trait Test2 extends Test { + trait Foo extends super.Foo { + trait Bar extends super.Bar; + } +} diff --git a/tests/untried/neg/t6663.check b/tests/untried/neg/t6663.check new file mode 100644 index 000000000000..aa4faa4a46d2 --- /dev/null +++ b/tests/untried/neg/t6663.check @@ -0,0 +1,6 @@ +t6663.scala:16: error: type mismatch; + found : String + required: Int + var v = new C(42).foo[String].get :Int + ^ +one error found diff --git a/tests/untried/neg/t6663.scala b/tests/untried/neg/t6663.scala new file mode 100644 index 000000000000..4a358dfbc5c4 --- /dev/null +++ b/tests/untried/neg/t6663.scala @@ -0,0 +1,19 @@ +import language.dynamics + +class C(v: Any) extends Dynamic { + def selectDynamic[T](n: String): Option[T] = Option(v.asInstanceOf[T]) + def applyDynamic[T](n: String)(): Option[T] = Option(v.asInstanceOf[T]) +} + +object Test extends App { + // this should be converted to + // C(42).selectDynamic[String]("foo").get + // causing a compile error. + + // but, before fixing SI-6663, became + // C(42).selectDynamic("foo").get, ignoring + // the [String] type parameter + var v = new C(42).foo[String].get :Int + println(v) +} + diff --git a/tests/untried/neg/t6666.check b/tests/untried/neg/t6666.check new file mode 100644 index 000000000000..43c825275384 --- /dev/null +++ b/tests/untried/neg/t6666.check @@ -0,0 +1,37 @@ +t6666.scala:23: error: Implementation restriction: access of method x$2 in object O1 from <$anon: Function0>, would require illegal premature access to object O1 + F.byname(x) + ^ +t6666.scala:30: error: Implementation restriction: access of value x$3 in object O2 from <$anon: Function0>, would require illegal premature access to object O2 + F.byname(x) + ^ +t6666.scala:37: error: Implementation restriction: access of method x$4 in object O3 from <$anon: Function0>, would require illegal premature access to object O3 + F.hof(() => x) + ^ +t6666.scala:50: error: Implementation restriction: access of method x$6 in class C1 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class C1 + F.byname(x) + ^ +t6666.scala:54: error: Implementation restriction: access of value x$7 in class C2 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class C2 + F.byname(x) + ^ +t6666.scala:58: error: Implementation restriction: access of method x$8 in class C3 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class C3 + F.hof(() => x) + ^ +t6666.scala:62: error: Implementation restriction: access of method x$9 in class C4 from object Nested$4, would require illegal premature access to the unconstructed `this` of class C4 + object Nested { def xx = x} + ^ +t6666.scala:76: error: Implementation restriction: access of method x$11 in class C11 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class C11 + F.byname(x) + ^ +t6666.scala:95: error: Implementation restriction: access of method x$12 in class C13 from <$anon: Function0>, would require illegal premature access to the unconstructed `this` of class C13 + F.hof(() => x) + ^ +t6666.scala:104: error: Implementation restriction: access of method x$13 in class C14 from object Nested$5, would require illegal premature access to the unconstructed `this` of class C14 + object Nested { def xx = x} + ^ +t6666.scala:112: error: Implementation restriction: access of method foo$1 in class COuter from class CInner$1, would require illegal premature access to the unconstructed `this` of class COuter + class CInner extends C({foo}) + ^ +t6666.scala:118: error: Implementation restriction: access of method x$14 in class CEarly from object Nested$6, would require illegal premature access to the unconstructed `this` of class CEarly + object Nested { def xx = x} + ^ +12 errors found diff --git a/tests/untried/neg/t6666.flags b/tests/untried/neg/t6666.flags new file mode 100644 index 000000000000..2349d8294d80 --- /dev/null +++ b/tests/untried/neg/t6666.flags @@ -0,0 +1 @@ +-Ydelambdafy:inline diff --git a/tests/untried/neg/t6666.scala b/tests/untried/neg/t6666.scala new file mode 100644 index 000000000000..2495c8727d52 --- /dev/null +++ b/tests/untried/neg/t6666.scala @@ -0,0 +1,121 @@ +class C(a: Any) +object F { + def byname(a: => Any) = println(a) + def hof(a: () => Any) = println(a()) +} + +class COkay extends C(0) { + def this(a: Any) { + this() + def x = "".toString + F.byname(x) + } +} + +// +// The thunk's apply method accesses the MODULE$ +// field before it is set. +// +// 0: getstatic #23; //Field O1$.MODULE$:LO1$; +// 3: invokevirtual #26; //Method O1$.O1$$x$1:()Ljava/lang/String; +object O1 extends C({ + def x = "".toString + F.byname(x) +}) + +// java.lang.NullPointerException +// at O2$$anonfun$$init$$1.apply(:11) +object O2 extends C({ + lazy val x = "".toString + F.byname(x) +}) + +// java.lang.NullPointerException +// at O3$$anonfun$$init$$1.apply(:11) +object O3 extends C({ + def x = "".toString + F.hof(() => x) +}) + +// Okay, the nested classes don't get an outer pointer passed, +// just an extra param for `x: String`. +object O6 extends C({ + val x = "".toString + F.byname(x); F.hof(() => x); (new { val xx = x }.xx) +}) + + +class C1 extends C({ + def x = "".toString + F.byname(x) +}) +class C2 extends C({ + lazy val x = "".toString + F.byname(x) +}) +class C3 extends C({ + def x = "".toString + F.hof(() => x) +}) +class C4 extends C({ + def x = "".toString + object Nested { def xx = x} + Nested.xx +}) + +// okay, for same reason as O6 +class C6 extends C({ + val x = "".toString + F.byname(x); F.hof(() => x); (new { val xx = x }.xx) +}) + +class C11(a: Any) { + def this() = { + this({ + def x = "".toString + F.byname(x) + }) + } +} + +// Crashes earlier in lazyVals. +// class C12(a: Any) { +// def this() = { +// this({ +// lazy val x = "".toString +// F.byname(x) +// }) +// } +// } + +class C13(a: Any) { + def this() = { + this({ + def x = "".toString + F.hof(() => x) + }) + } +} + +class C14(a: Any) { + def this() = { + this({ + def x = "".toString + object Nested { def xx = x} + Nested.xx + }) + } +} + +class COuter extends C({ + def foo = 0 + class CInner extends C({foo}) +}) + + +class CEarly(a: Any) extends { + val early = {def x = "".toString + object Nested { def xx = x} + Nested.xx + } +} with AnyRef diff --git a/tests/untried/neg/t6666b.check b/tests/untried/neg/t6666b.check new file mode 100644 index 000000000000..c3ffc7cfa9a2 --- /dev/null +++ b/tests/untried/neg/t6666b.check @@ -0,0 +1,7 @@ +t6666b.scala:11: error: Implementation restriction: access of method x$1 in class C5 from object Nested$3, would require illegal premature access to the unconstructed `this` of class C5 + object Nested { def xx = x} + ^ +t6666b.scala:22: error: Implementation restriction: access of method x$2 in class C15 from object Nested$4, would require illegal premature access to the unconstructed `this` of class C15 + object Nested { def xx = x} + ^ +two errors found diff --git a/tests/untried/neg/t6666b.scala b/tests/untried/neg/t6666b.scala new file mode 100644 index 000000000000..205ded76e588 --- /dev/null +++ b/tests/untried/neg/t6666b.scala @@ -0,0 +1,27 @@ +class C(a: Any) +object F { + def byname(a: => Any) = println(a) + def hof(a: () => Any) = println(a()) +} + + +class C5 extends C({ + def x = "".toString + val y = { + object Nested { def xx = x} + Nested.xx + } +}) + + +class C15(a: Any) { + def this() = { + this({ + def x = "".toString + val y = { + object Nested { def xx = x} + Nested.xx + } + }) + } +} diff --git a/tests/untried/neg/t6666c.check b/tests/untried/neg/t6666c.check new file mode 100644 index 000000000000..384e52a9fce5 --- /dev/null +++ b/tests/untried/neg/t6666c.check @@ -0,0 +1,10 @@ +t6666c.scala:2: error: Implementation restriction: access of method x$1 in class D from object X$4, would require illegal premature access to the unconstructed `this` of class D +class D extends C({def x = 0; object X { x }}) + ^ +t6666c.scala:5: error: Implementation restriction: access of method x$2 in class D1 from object X$5, would require illegal premature access to the unconstructed `this` of class D1 +class D1 extends C1({def x = 0; () => {object X { x }}}) + ^ +t6666c.scala:8: error: Implementation restriction: access of method x$3 from object X$6, would require illegal premature access to the unconstructed `this` of <$anon: Function0> +class D2 extends C2({def x = 0; object X { x }}) + ^ +three errors found diff --git a/tests/untried/neg/t6666c.flags b/tests/untried/neg/t6666c.flags new file mode 100644 index 000000000000..2349d8294d80 --- /dev/null +++ b/tests/untried/neg/t6666c.flags @@ -0,0 +1 @@ +-Ydelambdafy:inline diff --git a/tests/untried/neg/t6666c.scala b/tests/untried/neg/t6666c.scala new file mode 100644 index 000000000000..76cc358307a5 --- /dev/null +++ b/tests/untried/neg/t6666c.scala @@ -0,0 +1,8 @@ +class C(a: Any) +class D extends C({def x = 0; object X { x }}) + +class C1(a: () => Any) +class D1 extends C1({def x = 0; () => {object X { x }}}) + +class C2(a: => Any) +class D2 extends C2({def x = 0; object X { x }}) diff --git a/tests/untried/neg/t6666d.check b/tests/untried/neg/t6666d.check new file mode 100644 index 000000000000..b4785f0129a4 --- /dev/null +++ b/tests/untried/neg/t6666d.check @@ -0,0 +1,4 @@ +t6666d.scala:7: error: Implementation restriction: access of object TreeOrd$1 from object TreeOrd$2, would require illegal premature access to the unconstructed `this` of class Test + implicit object TreeOrd extends Ordering[K](){ + ^ +one error found diff --git a/tests/untried/neg/t6666d.scala b/tests/untried/neg/t6666d.scala new file mode 100644 index 000000000000..49a688f91b23 --- /dev/null +++ b/tests/untried/neg/t6666d.scala @@ -0,0 +1,18 @@ + +import scala.collection.immutable.TreeMap +import scala.math.Ordering + +class Test[K](param:TreeMap[K,Int]){ + def this() = this({ + implicit object TreeOrd extends Ordering[K](){ + def compare(a: K, b: K) = { + -1 + } + } + new TreeMap[K, Int]() + }) +} + +object Test extends App { + new Test() +} diff --git a/tests/untried/neg/t6666e.check b/tests/untried/neg/t6666e.check new file mode 100644 index 000000000000..3189612314a1 --- /dev/null +++ b/tests/untried/neg/t6666e.check @@ -0,0 +1,4 @@ +t6666e.scala:8: error: Implementation restriction: <$anon: Nothing => Unit> requires premature access to class Crash. + this(Nil.collect{case x =>}) + ^ +one error found diff --git a/tests/untried/neg/t6666e.scala b/tests/untried/neg/t6666e.scala new file mode 100644 index 000000000000..120a5878b2f0 --- /dev/null +++ b/tests/untried/neg/t6666e.scala @@ -0,0 +1,9 @@ + +import scala.collection.immutable.TreeMap +import scala.math.Ordering + + +class Crash(a: Any) { + def this() = + this(Nil.collect{case x =>}) +} diff --git a/tests/untried/neg/t6667.check b/tests/untried/neg/t6667.check new file mode 100644 index 000000000000..43313fa4fe29 --- /dev/null +++ b/tests/untried/neg/t6667.check @@ -0,0 +1,13 @@ +t6667.scala:8: error: ambiguous implicit values: + both value inScope1 in object Test of type => C + and value inScope2 in object Test of type => C + match expected type C + implicitly[C]: Unit // C.companion was used; whereas the ambiguity should abort the implicit search. + ^ +t6667.scala:9: error: ambiguous implicit values: + both value inScope1 in object Test of type => C + and value inScope2 in object Test of type => C + match expected type C + implicitly[C] // ambiguity reported, rather than falling back to C.companion + ^ +two errors found diff --git a/tests/untried/neg/t6667.scala b/tests/untried/neg/t6667.scala new file mode 100644 index 000000000000..fb857ebd3322 --- /dev/null +++ b/tests/untried/neg/t6667.scala @@ -0,0 +1,10 @@ +class C +object C { + implicit def companion = new C +} + +object Test { + implicit val inScope1, inScope2 = new C + implicitly[C]: Unit // C.companion was used; whereas the ambiguity should abort the implicit search. + implicitly[C] // ambiguity reported, rather than falling back to C.companion +} diff --git a/tests/untried/neg/t6667b.check b/tests/untried/neg/t6667b.check new file mode 100644 index 000000000000..99cea9a47cc7 --- /dev/null +++ b/tests/untried/neg/t6667b.check @@ -0,0 +1,13 @@ +t6667b.scala:16: error: ambiguous implicit values: + both value a in object Test of type => Test.Box + and value b of type Test.Box + match expected type Test.Box + new Test() + ^ +t6667b.scala:19: error: ambiguous implicit values: + both value a in object Test of type => Test.Box + and value b of type Test.Box + match expected type Test.Box + new Test() + ^ +two errors found diff --git a/tests/untried/neg/t6667b.scala b/tests/untried/neg/t6667b.scala new file mode 100644 index 000000000000..db31c0a9be69 --- /dev/null +++ b/tests/untried/neg/t6667b.scala @@ -0,0 +1,25 @@ +object Test { + abstract class Box { + val value: Int + } + + implicit val a: Box = new Box { + val value= 1 + } + + def main(args: Array[String]): Unit = { + implicit val b: Box= new Box { + val value= 2 + } + + new Object { + new Test() + } + // compare with: + new Test() + } +} + +class Test()(implicit x: Test.Box) { + println(x.value) +} diff --git a/tests/untried/neg/t667.check b/tests/untried/neg/t667.check new file mode 100644 index 000000000000..e68c6dea00ad --- /dev/null +++ b/tests/untried/neg/t667.check @@ -0,0 +1,4 @@ +t667.scala:8: error: illegal cyclic reference involving class Ni + class Ni extends super.Ni with Ni; + ^ +one error found diff --git a/tests/untried/neg/t667.scala b/tests/untried/neg/t667.scala new file mode 100644 index 000000000000..a79bc272e44f --- /dev/null +++ b/tests/untried/neg/t667.scala @@ -0,0 +1,10 @@ +package test; + +object test { + trait A { + trait Ni; + } + class B extends A { + class Ni extends super.Ni with Ni; + } +} diff --git a/tests/untried/neg/t6675.check b/tests/untried/neg/t6675.check new file mode 100644 index 000000000000..aecf04cb6813 --- /dev/null +++ b/tests/untried/neg/t6675.check @@ -0,0 +1,6 @@ +t6675.scala:10: warning: object X expects 3 patterns to hold (Int, Int, Int) but crushing into 3-tuple to fit single pattern (SI-6675) + "" match { case X(b) => b } // should warn under -Xlint. Not an error because of SI-6111 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t6675.flags b/tests/untried/neg/t6675.flags new file mode 100644 index 000000000000..2843ea9efc98 --- /dev/null +++ b/tests/untried/neg/t6675.flags @@ -0,0 +1 @@ +-deprecation -Xlint -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6675.scala b/tests/untried/neg/t6675.scala new file mode 100644 index 000000000000..4d500b77badc --- /dev/null +++ b/tests/untried/neg/t6675.scala @@ -0,0 +1,13 @@ +object X { + def unapply(s: String): Option[(Int,Int,Int)] = Some((1,2,3)) +} + +object Y { + def unapplySeq(s: String): Option[Seq[(Int,Int,Int)]] = Some(Seq((1,2,3))) +} + +object Test { + "" match { case X(b) => b } // should warn under -Xlint. Not an error because of SI-6111 + + "" match { case Y(b) => b } // no warning +} diff --git a/tests/untried/neg/t6675b.check b/tests/untried/neg/t6675b.check new file mode 100644 index 000000000000..77f6b3ccbcdf --- /dev/null +++ b/tests/untried/neg/t6675b.check @@ -0,0 +1,37 @@ +t6675b.scala:17: warning: object LeftOrRight expects 2 patterns to hold (Int, Int) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight(a) => a } // warn + ^ +t6675b.scala:19: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: (Int, Int) + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b, c)) => a } // fail + ^ +t6675b.scala:24: warning: object LeftOrRight expects 2 patterns to hold (A, A) but crushing into 2-tuple to fit single pattern (SI-6675) + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight(a) => a } // warn + ^ +t6675b.scala:26: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: (?A11, ?A12) where type ?A12 <: A (this is a GADT skolem), type ?A11 <: A (this is a GADT skolem) + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b, c)) => a } // fail + ^ +t6675b.scala:30: warning: object NativelyTwo expects 2 patterns to hold ((Int, Int), (Int, Int)) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:32: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: ((Int, Int), (Int, Int)) + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b, c)) => a } // fail + ^ +t6675b.scala:36: warning: object NativelyTwo expects 2 patterns to hold (A, A) but crushing into 2-tuple to fit single pattern (SI-6675) + def f1[A](x: A) = (Left(x): Either[A, A]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:37: warning: object NativelyTwo expects 2 patterns to hold ((A, A), (A, A)) but crushing into 2-tuple to fit single pattern (SI-6675) + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo(a) => a } // warn + ^ +t6675b.scala:39: error: constructor cannot be instantiated to expected type; + found : (T1, T2, T3) + required: ((?A17, ?A18), (?A19, ?A20)) where type ?A20 <: A (this is a GADT skolem), type ?A19 <: A (this is a GADT skolem), type ?A18 <: A (this is a GADT skolem), type ?A17 <: A (this is a GADT skolem) + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b, c)) => a } // fail + ^ +5 warnings found +four errors found diff --git a/tests/untried/neg/t6675b.flags b/tests/untried/neg/t6675b.flags new file mode 100644 index 000000000000..2fcfa0cddb13 --- /dev/null +++ b/tests/untried/neg/t6675b.flags @@ -0,0 +1 @@ +-deprecation -Xlint diff --git a/tests/untried/neg/t6675b.scala b/tests/untried/neg/t6675b.scala new file mode 100644 index 000000000000..c86c9c3955b3 --- /dev/null +++ b/tests/untried/neg/t6675b.scala @@ -0,0 +1,40 @@ +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 NativelyTwo { + def unapply[A](value: Either[A, A]): Option[(A, A)] = value match { + case scala.Left(x) => Some(x -> x) + case scala.Right(x) => Some(x -> x) + } +} + + +class A { + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight(a) => a } // warn + def f2 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b)) => a } // no warn + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case LeftOrRight((a, b, c)) => a } // fail +} + +class B { + def f1[A](x: A) = (Left(x): Either[A, A]) match { case LeftOrRight(a) => a } // no warn + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight(a) => a } // warn + def f3[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b)) => a } // no warn + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case LeftOrRight((a, b, c)) => a } // fail +} + +class C { + def f1 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo(a) => a } // warn + def f2 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b)) => a } // no warn + def f3 = (Left((0, 0)): Either[(Int, Int), (Int, Int)]) match { case NativelyTwo((a, b, c)) => a } // fail +} + +class D { + def f1[A](x: A) = (Left(x): Either[A, A]) match { case NativelyTwo(a) => a } // warn + def f2[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo(a) => a } // warn + def f3[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b)) => a } // no warn + def f4[A](x: A) = (Left(x -> x): Either[(A, A), (A, A)]) match { case NativelyTwo((a, b, c)) => a } // fail +} diff --git a/tests/untried/neg/t668.check b/tests/untried/neg/t668.check new file mode 100644 index 000000000000..b057ca793601 --- /dev/null +++ b/tests/untried/neg/t668.check @@ -0,0 +1,4 @@ +t668.scala:1: error: type Iterable takes type parameters +class Test extends Iterable + ^ +one error found diff --git a/tests/untried/neg/t668.scala b/tests/untried/neg/t668.scala new file mode 100644 index 000000000000..3256037b1e09 --- /dev/null +++ b/tests/untried/neg/t668.scala @@ -0,0 +1 @@ +class Test extends Iterable diff --git a/tests/untried/neg/t6680a.check b/tests/untried/neg/t6680a.check new file mode 100644 index 000000000000..03e4df10c121 --- /dev/null +++ b/tests/untried/neg/t6680a.check @@ -0,0 +1,11 @@ +t6680a.scala:10: error: type mismatch; + found : String("abc") + required: A + y.x = "abc" + ^ +t6680a.scala:17: error: type mismatch; + found : String("") + required: A + case class C[A](f:A=>A);def f(x:Any)=x match { case C(f)=>f("") };f(C[Int](x=>x)) + ^ +two errors found diff --git a/tests/untried/neg/t6680a.flags b/tests/untried/neg/t6680a.flags new file mode 100644 index 000000000000..19243266d108 --- /dev/null +++ b/tests/untried/neg/t6680a.flags @@ -0,0 +1 @@ +-Xstrict-inference \ No newline at end of file diff --git a/tests/untried/neg/t6680a.scala b/tests/untried/neg/t6680a.scala new file mode 100644 index 000000000000..93b796438fb9 --- /dev/null +++ b/tests/untried/neg/t6680a.scala @@ -0,0 +1,18 @@ +case class Cell[A](var x: A) +object Test { + def f1(x: Any) = x match { case y @ Cell(_) => y } // Inferred type is Cell[Any] + def f2(x: Cell[_]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[_] + def f3[A](x: Cell[A]) = x match { case y @ Cell(_) => y } // Inferred type is Cell[A] + + def main(args: Array[String]): Unit = { + val x = new Cell(1) + val y = f1(x) + y.x = "abc" + println(x.x + 1) + } +} + +// The tweetable variation +object Tweet { + case class C[A](f:A=>A);def f(x:Any)=x match { case C(f)=>f("") };f(C[Int](x=>x)) +} diff --git a/tests/untried/neg/t6728.check b/tests/untried/neg/t6728.check new file mode 100644 index 000000000000..d853d6f724da --- /dev/null +++ b/tests/untried/neg/t6728.check @@ -0,0 +1,4 @@ +t6728.scala:4: error: '(' expected but '}' found. + } + ^ +one error found diff --git a/tests/untried/neg/t6728.scala b/tests/untried/neg/t6728.scala new file mode 100644 index 000000000000..ba0b1a0fdf48 --- /dev/null +++ b/tests/untried/neg/t6728.scala @@ -0,0 +1,5 @@ +object X { + while(true) { + for + } +} diff --git a/tests/untried/neg/t6758.check b/tests/untried/neg/t6758.check new file mode 100644 index 000000000000..2cdd6b8ae53c --- /dev/null +++ b/tests/untried/neg/t6758.check @@ -0,0 +1,28 @@ +t6758.scala:5: error: not found: type inargument + @inargument + ^ +t6758.scala:11: error: not found: type infunction + @infunction + ^ +t6758.scala:18: error: not found: type nested + @nested + ^ +t6758.scala:25: error: not found: type param + def func(@param x: Int): Int = 0 + ^ +t6758.scala:28: error: not found: type typealias + @typealias + ^ +t6758.scala:32: error: not found: type classs + @classs + ^ +t6758.scala:35: error: not found: type module + @module + ^ +t6758.scala:38: error: not found: type typeparam + class D[@typeparam T] + ^ +t6758.scala:41: error: not found: type valueparam + @valueparam x: Any + ^ +9 errors found diff --git a/tests/untried/neg/t6758.scala b/tests/untried/neg/t6758.scala new file mode 100644 index 000000000000..acf333bf9059 --- /dev/null +++ b/tests/untried/neg/t6758.scala @@ -0,0 +1,43 @@ +class AnnotNotFound { + def foo(a: Any) = () + + foo { + @inargument + def foo = 0 + foo + } + + () => { + @infunction + def foo = 0 + () + } + + () => { + val bar: Int = { + @nested + val bar2: Int = 2 + 2 + } + () + } + + def func(@param x: Int): Int = 0 + + abstract class A { + @typealias + type B = Int + } + + @classs + class C + + @module + object D + + class D[@typeparam T] + + class E( + @valueparam x: Any + ) +} diff --git a/tests/untried/neg/t677.check b/tests/untried/neg/t677.check new file mode 100644 index 000000000000..122830a98fa2 --- /dev/null +++ b/tests/untried/neg/t677.check @@ -0,0 +1,6 @@ +t677.scala:2: error: type mismatch; + found : () => Int + required: Nothing + val zx: Nothing = {() => 4} + ^ +one error found diff --git a/tests/untried/neg/t677.scala b/tests/untried/neg/t677.scala new file mode 100644 index 000000000000..c65ee9640ff8 --- /dev/null +++ b/tests/untried/neg/t677.scala @@ -0,0 +1,3 @@ +object ga { + val zx: Nothing = {() => 4} +} diff --git a/tests/untried/neg/t6771b.check b/tests/untried/neg/t6771b.check new file mode 100644 index 000000000000..ba99e9178d75 --- /dev/null +++ b/tests/untried/neg/t6771b.check @@ -0,0 +1,6 @@ +t6771b.scala:14: error: type mismatch; + found : x.type (with underlying type String) + required: Test.a.type + b = b match { case x => x } + ^ +one error found diff --git a/tests/untried/neg/t6771b.scala b/tests/untried/neg/t6771b.scala new file mode 100644 index 000000000000..78f11f7750bd --- /dev/null +++ b/tests/untried/neg/t6771b.scala @@ -0,0 +1,16 @@ +// Currently, the pattern matcher widens the type of the +// scrutinee, so this doesn't typecheck. This test just +// confirms this behaviour, although it would be an improvement +// to change this and make this a `pos` test. +// +// But, to the intrepid hacker who works on this, a few notes: +// You'll have to look into places in the pattern matcher that +// call `dealias`, and see if they need to be `dealiasWiden`. +// For example, if `checkableType` used only `dealias`, `pos/t6671.scala` +// would fail. +object Test { + val a = ""; var b: a.type = a + + b = b match { case x => x } +} + diff --git a/tests/untried/neg/t6788.check b/tests/untried/neg/t6788.check new file mode 100644 index 000000000000..96a6f8b6016e --- /dev/null +++ b/tests/untried/neg/t6788.check @@ -0,0 +1,5 @@ +t6788.scala:6: error: not found: value foo +Error occurred in an application involving default arguments. + s.copy(b = foo) + ^ +one error found diff --git a/tests/untried/neg/t6788.scala b/tests/untried/neg/t6788.scala new file mode 100644 index 000000000000..77949ed621b9 --- /dev/null +++ b/tests/untried/neg/t6788.scala @@ -0,0 +1,7 @@ +case class B[T](b: T, a: List[Int]) // need two args, B must be polymorphic + +class A { + var s: B[Int] = _ // has to be a var + + s.copy(b = foo) +} diff --git a/tests/untried/neg/t6795.check b/tests/untried/neg/t6795.check new file mode 100644 index 000000000000..88ef3e9a526d --- /dev/null +++ b/tests/untried/neg/t6795.check @@ -0,0 +1,4 @@ +t6795.scala:3: error: `abstract override' modifier not allowed for type members +trait T1 extends T { abstract override type U = Int } + ^ +one error found diff --git a/tests/untried/neg/t6795.scala b/tests/untried/neg/t6795.scala new file mode 100644 index 000000000000..a523c89c821c --- /dev/null +++ b/tests/untried/neg/t6795.scala @@ -0,0 +1,3 @@ +trait T { type U } +// "abstract override" shouldn't be allowed on types +trait T1 extends T { abstract override type U = Int } diff --git a/tests/untried/neg/t6815.check b/tests/untried/neg/t6815.check new file mode 100644 index 000000000000..fae3819be115 --- /dev/null +++ b/tests/untried/neg/t6815.check @@ -0,0 +1,5 @@ +t6815.scala:15: error: stable identifier required, but Test.this.u.emptyValDef found. + Note that value emptyValDef is not stable because its type, Test.u.ValDef, is volatile. + case _: u.emptyValDef.T => // and, unlike in pos/t6185.scala, we shouldn't allow this. + ^ +one error found diff --git a/tests/untried/neg/t6815.scala b/tests/untried/neg/t6815.scala new file mode 100644 index 000000000000..ff973a7437b8 --- /dev/null +++ b/tests/untried/neg/t6815.scala @@ -0,0 +1,17 @@ +trait U { + trait ValOrDefDefApi { + def name: Any + } + type ValOrDefDef <: ValOrDefDefApi + type ValDef <: ValOrDefDef with ValDefApi { type T } + trait ValDefApi extends ValOrDefDefApi { this: ValDef => } + val emptyValDef: ValDef // the result type is volatile +} + +object Test { + val u: U = ??? + + (null: Any) match { + case _: u.emptyValDef.T => // and, unlike in pos/t6185.scala, we shouldn't allow this. + } +} diff --git a/tests/untried/neg/t6829.check b/tests/untried/neg/t6829.check new file mode 100644 index 000000000000..914a1c926071 --- /dev/null +++ b/tests/untried/neg/t6829.check @@ -0,0 +1,56 @@ +t6829.scala:35: error: type mismatch; + found : AgentSimulation.this.state.type (with underlying type G#State) + required: _9.State + lazy val actions: Map[G#Agent,G#Action] = agents.map(a => a -> a.chooseAction(state)).toMap + ^ +t6829.scala:45: error: trait AgentSimulation takes type parameters + pastHistory: List[G#State] = Nil) extends AgentSimulation + ^ +t6829.scala:47: error: class LearningSimulation takes type parameters + lazy val step: LearningSimulation = { + ^ +t6829.scala:49: error: not found: value actions + val (s,a,s2) = (state,actions(agent),nextState) + ^ +t6829.scala:49: error: not found: value nextState + val (s,a,s2) = (state,actions(agent),nextState) + ^ +t6829.scala:50: error: type mismatch; + found : s.type (with underlying type Any) + required: _53.State where val _53: G + val r = rewards(agent).r(s,a,s2) + ^ +t6829.scala:50: error: type mismatch; + found : a.type (with underlying type Any) + required: _53.Action where val _53: G + val r = rewards(agent).r(s,a,s2) + ^ +t6829.scala:50: error: type mismatch; + found : s2.type (with underlying type Any) + required: _53.State where val _53: G + val r = rewards(agent).r(s,a,s2) + ^ +t6829.scala:51: error: type mismatch; + found : s.type (with underlying type Any) + required: _50.State + agent.learn(s,a,s2,r): G#Agent + ^ +t6829.scala:51: error: type mismatch; + found : a.type (with underlying type Any) + required: _50.Action + agent.learn(s,a,s2,r): G#Agent + ^ +t6829.scala:51: error: type mismatch; + found : s2.type (with underlying type Any) + required: _50.State + agent.learn(s,a,s2,r): G#Agent + ^ +t6829.scala:53: error: not found: value nextState +Error occurred in an application involving default arguments. + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + ^ +t6829.scala:53: error: not found: value currentHistory +Error occurred in an application involving default arguments. + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + ^ +13 errors found diff --git a/tests/untried/neg/t6829.scala b/tests/untried/neg/t6829.scala new file mode 100644 index 000000000000..7cbe3c954250 --- /dev/null +++ b/tests/untried/neg/t6829.scala @@ -0,0 +1,64 @@ +package bugs + +/** + * Created with IntelliJ IDEA. + * User: arya + * Date: 12/18/12 + * Time: 4:17 PM + * To change this template use File | Settings | File Templates. + */ +object currenttype2 { + + type Reward = Double + + trait AbstractAgent[State,Action] { + type A = AbstractAgent[State,Action] + def chooseAction(s: State): Action + def startEpisode: A = this + def learn(s1: State, a: Action, s2: State, r: Reward): A + } + + case class RewardFunction[State,Action](r: (State,Action,State) => Reward) + + trait Rules[G<:GameDomain] { + def simulate(state: G#State, agentActions: List[(G#Agent,G#Action)]): G#State + } + + trait AgentSimulation[G<:GameDomain] { + val agents: List[G#Agent] + val state: G#State + val rewards: Map[G#Agent,G#Rewards] + val rules: Rules[G] + val pastHistory: List[G#State] + lazy val currentHistory = state :: pastHistory + + lazy val actions: Map[G#Agent,G#Action] = agents.map(a => a -> a.chooseAction(state)).toMap + lazy val nextState: G#State = rules.simulate(state, actions.toList) + + def step: AgentSimulation[G] + } + + case class LearningSimulation[G<:GameDomain](agents: List[G#Agent], + state: G#State, + rewards: Map[G#Agent,G#Rewards], + rules: Rules[G], + pastHistory: List[G#State] = Nil) extends AgentSimulation + { + lazy val step: LearningSimulation = { + val updatedAgents: List[G#Agent] = agents map { agent => + val (s,a,s2) = (state,actions(agent),nextState) + val r = rewards(agent).r(s,a,s2) + agent.learn(s,a,s2,r): G#Agent + } + copy(agents = updatedAgents, state = nextState, pastHistory = currentHistory) + } + } + + trait GameDomain { + domain => + type State + type Action + type Agent = AbstractAgent[State, Action] // agent supertype + type Rewards = RewardFunction[State,Action] + } + } diff --git a/tests/untried/neg/t6844.check b/tests/untried/neg/t6844.check new file mode 100644 index 000000000000..1fc24855205b --- /dev/null +++ b/tests/untried/neg/t6844.check @@ -0,0 +1,6 @@ +t6844.scala:4: error: type mismatch; + found : reflect.runtime.universe.TermName + required: reflect.runtime.universe.Tree + q"def foo($x)" + ^ +one error found diff --git a/tests/untried/neg/t6844.scala b/tests/untried/neg/t6844.scala new file mode 100644 index 000000000000..809d9d0f9871 --- /dev/null +++ b/tests/untried/neg/t6844.scala @@ -0,0 +1,5 @@ +import scala.reflect.runtime.universe._ +object Test extends App { + val x = TermName("x") + q"def foo($x)" +} diff --git a/tests/untried/neg/t6889.check b/tests/untried/neg/t6889.check new file mode 100644 index 000000000000..a77e8a010c98 --- /dev/null +++ b/tests/untried/neg/t6889.check @@ -0,0 +1,7 @@ +t6889.scala:16: error: the result type of an implicit conversion must be more specific than AnyRef + def f(x: Dingo): AnyRef = x // fail - no conversion to AnyRef + ^ +t6889.scala:17: error: an expression of type Null is ineligible for implicit conversion + var x: Int = null // fail - no conversion from Null + ^ +two errors found diff --git a/tests/untried/neg/t6889.scala b/tests/untried/neg/t6889.scala new file mode 100644 index 000000000000..ef1963669c4b --- /dev/null +++ b/tests/untried/neg/t6889.scala @@ -0,0 +1,18 @@ +package bippy { + trait Bippy[A] extends Any +} +package foo { + package object unrelated { + implicit def bippyDingo[A](x: bippy.Bippy[A]): AnyRef = Nil + } + package unrelated { + trait Unrelated + } +} + +object Test { + trait Dingo extends Any with bippy.Bippy[foo.unrelated.Unrelated] + + def f(x: Dingo): AnyRef = x // fail - no conversion to AnyRef + var x: Int = null // fail - no conversion from Null +} diff --git a/tests/untried/neg/t6902.check b/tests/untried/neg/t6902.check new file mode 100644 index 000000000000..ed0ed7530326 --- /dev/null +++ b/tests/untried/neg/t6902.check @@ -0,0 +1,12 @@ +t6902.scala:4: warning: unreachable code + case Some(b) => 3 // no warning was emitted + ^ +t6902.scala:9: warning: unreachable code + case Some(b) => 3 // no warning was emitted + ^ +t6902.scala:21: warning: unreachable code + case 1 => 3 // crash + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t6902.flags b/tests/untried/neg/t6902.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t6902.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t6902.scala b/tests/untried/neg/t6902.scala new file mode 100644 index 000000000000..ce5ff8b6fb4c --- /dev/null +++ b/tests/untried/neg/t6902.scala @@ -0,0 +1,23 @@ +object Test { + Some(Some(1)) collect { + case Some(a) => 2 + case Some(b) => 3 // no warning was emitted + } + + (Some(1): @ unchecked) match { + case Some(a) => 2 + case Some(b) => 3 // no warning was emitted + } + + // A variation of SI-6011, which eluded the fix + // in 2.10.0. + // + // duplicate keys in SWITCH, can't pick arbitrarily one of them to evict, see SI-6011. + // at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50) + // at scala.tools.nsc.Global.abort(Global.scala:249) + // at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850) + ((1: Byte): @unchecked @annotation.switch) match { + case 1 => 2 + case 1 => 3 // crash + } +} diff --git a/tests/untried/neg/t691.check b/tests/untried/neg/t691.check new file mode 100644 index 000000000000..77ff7b1d0234 --- /dev/null +++ b/tests/untried/neg/t691.check @@ -0,0 +1,4 @@ +t691.scala:27: error: ambiguous parent class qualifier + trait TiC extends super[Arrow].Ti2 with super[AssignArrow].Ti1; + ^ +one error found diff --git a/tests/untried/neg/t691.scala b/tests/untried/neg/t691.scala new file mode 100644 index 000000000000..233476f658d3 --- /dev/null +++ b/tests/untried/neg/t691.scala @@ -0,0 +1,29 @@ +trait Base { + trait AssignArrow { + type T <: Ti0; + trait Ti0; + } + abstract class Arrow extends AssignArrow; + val arrow : Arrow; +} + +trait Ext0 extends Base { + trait AssignArrow extends super.AssignArrow { + type T <: Ti1; + trait Ti1 extends super.Ti0; + } +} +trait Ext1 extends Base { + trait Arrow extends super.Arrow { + type T <: Ti2; + trait Ti2 extends super.Ti0; + trait TiXX extends Ti2; + } + val arrow : Arrow; +} +trait Composition extends Ext0 with Ext1 { + object arrow0 extends Arrow with AssignArrow { + type T = TiC + trait TiC extends super[Arrow].Ti2 with super[AssignArrow].Ti1; + } +} diff --git a/tests/untried/neg/t6912.check b/tests/untried/neg/t6912.check new file mode 100644 index 000000000000..137b65170555 --- /dev/null +++ b/tests/untried/neg/t6912.check @@ -0,0 +1,4 @@ +t6912.scala:8: error: not found: type Xxxx + def test[T]: Xxxx = Foo1[T] + ^ +one error found diff --git a/tests/untried/neg/t6912.scala b/tests/untried/neg/t6912.scala new file mode 100644 index 000000000000..f2540ee8c68d --- /dev/null +++ b/tests/untried/neg/t6912.scala @@ -0,0 +1,9 @@ +object Foo1 { + def apply[T](a: Int = 0): Nothing = sys.error("") + def apply[T](z: String = ""): Nothing = sys.error("") +} + +object Test { + // Triggered a cycle in Typers#adapt + def test[T]: Xxxx = Foo1[T] +} diff --git a/tests/untried/neg/t692.check b/tests/untried/neg/t692.check new file mode 100644 index 000000000000..0ca99717d69c --- /dev/null +++ b/tests/untried/neg/t692.check @@ -0,0 +1,19 @@ +t692.scala:3: error: not found: type T + trait Type[T0] extends Type0[T]; + ^ +t692.scala:10: error: class Foo takes type parameters + case class FooType() extends ClassType[Foo,AnyRef](ObjectType()); + ^ +t692.scala:13: error: class Foo takes type parameters + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + ^ +t692.scala:13: error: class Foo takes type parameters + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + ^ +t692.scala:14: error: class Foo takes type parameters + implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] = + ^ +t692.scala:19: error: class Foo takes type parameters + class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo; + ^ +6 errors found diff --git a/tests/untried/neg/t692.scala b/tests/untried/neg/t692.scala new file mode 100644 index 000000000000..24e1d2fea376 --- /dev/null +++ b/tests/untried/neg/t692.scala @@ -0,0 +1,20 @@ +abstract class test3 { + trait Type0[+T0]; + trait Type[T0] extends Type0[T]; + trait ClassType0[+C <: AnyRef] extends Type0[C]; + abstract class RefType[C <: AnyRef] extends Type[C]; + case class ObjectType() extends RefType[AnyRef]; + abstract class ClassType[C <: Z, Z <: AnyRef](zuper : RefType[Z]) extends RefType[C]; + + + case class FooType() extends ClassType[Foo,AnyRef](ObjectType()); + implicit def typeOfFoo = FooType(); + + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] = + BarType(elem); + + + class Foo[A <: AnyRef]; + class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo; +} diff --git a/tests/untried/neg/t6920.check b/tests/untried/neg/t6920.check new file mode 100644 index 000000000000..ee4eafb83ec3 --- /dev/null +++ b/tests/untried/neg/t6920.check @@ -0,0 +1,6 @@ +t6920.scala:9: error: too many arguments for method applyDynamicNamed: (values: Seq[(String, Any)])String +error after rewriting to CompilerError.this.test.applyDynamicNamed("crushTheCompiler")(scala.Tuple2("a", 1), scala.Tuple2("b", 2)) +possible cause: maybe a wrong Dynamic method signature? + test.crushTheCompiler(a = 1, b = 2) + ^ +one error found diff --git a/tests/untried/neg/t6920.scala b/tests/untried/neg/t6920.scala new file mode 100644 index 000000000000..25dc7b3b6bfd --- /dev/null +++ b/tests/untried/neg/t6920.scala @@ -0,0 +1,10 @@ +import scala.language.dynamics + +class DynTest extends Dynamic { + def applyDynamicNamed(name: String)(values: Seq[(String, Any)]) = "test" +} + +class CompilerError { + val test = new DynTest + test.crushTheCompiler(a = 1, b = 2) +} diff --git a/tests/untried/neg/t6928.check b/tests/untried/neg/t6928.check new file mode 100644 index 000000000000..28b8e382dcfb --- /dev/null +++ b/tests/untried/neg/t6928.check @@ -0,0 +1,7 @@ +t6928.scala:2: error: super constructor cannot be passed a self reference unless parameter is declared by-name +object B extends A(B) + ^ +t6928.scala:3: error: super constructor cannot be passed a self reference unless parameter is declared by-name +object C extends A(null, null, C) + ^ +two errors found diff --git a/tests/untried/neg/t6928.scala b/tests/untried/neg/t6928.scala new file mode 100644 index 000000000000..84bdcde45ab0 --- /dev/null +++ b/tests/untried/neg/t6928.scala @@ -0,0 +1,10 @@ +abstract class A( val someAs: A* ) +object B extends A(B) +object C extends A(null, null, C) + +object Test { + def main(args: Array[String]): Unit = { + println(B.someAs) + println(C.someAs) + } +} diff --git a/tests/untried/neg/t693.check b/tests/untried/neg/t693.check new file mode 100644 index 000000000000..25bd14150108 --- /dev/null +++ b/tests/untried/neg/t693.check @@ -0,0 +1,4 @@ +t693.scala:4: error: x is already defined as value x + val x : Int = 10; + ^ +one error found diff --git a/tests/untried/neg/t693.scala b/tests/untried/neg/t693.scala new file mode 100644 index 000000000000..3a9e6247a8f7 --- /dev/null +++ b/tests/untried/neg/t693.scala @@ -0,0 +1,5 @@ +abstract class test4 { + trait Type; + val x : Type = null; + val x : Int = 10; +} diff --git a/tests/untried/neg/t6931.check b/tests/untried/neg/t6931.check new file mode 100644 index 000000000000..7cf804a93632 --- /dev/null +++ b/tests/untried/neg/t6931.check @@ -0,0 +1,10 @@ +Test_2.scala:3: error: 1 + err"123" + ^ +Test_2.scala:3: error: 2 + err"123" + ^ +Test_2.scala:3: error: 3 + err"123" + ^ +three errors found diff --git a/tests/untried/neg/t6931/Macros_1.scala b/tests/untried/neg/t6931/Macros_1.scala new file mode 100644 index 000000000000..9e167e61db74 --- /dev/null +++ b/tests/untried/neg/t6931/Macros_1.scala @@ -0,0 +1,15 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + implicit class Error(ctx: StringContext) { + def err(args: Any*): Unit = macro impl + } + + def impl(c: Context)(args: c.Tree*): c.Tree = { + import c.universe._ + val q"Macros.Error(scala.StringContext.apply($arg)).err()" = c.macroApplication + for (i <- 1 to 3) c.error(arg.pos.withPoint(arg.pos.point + i - 1), i.toString) + q"()" + } +} diff --git a/tests/untried/neg/t6931/Test_2.scala b/tests/untried/neg/t6931/Test_2.scala new file mode 100644 index 000000000000..dbd7fc2605dc --- /dev/null +++ b/tests/untried/neg/t6931/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + err"123" +} diff --git a/tests/untried/neg/t6952.check b/tests/untried/neg/t6952.check new file mode 100644 index 000000000000..1a591d02c6b1 --- /dev/null +++ b/tests/untried/neg/t6952.check @@ -0,0 +1,13 @@ +t6952.scala:2: error: extension of type scala.Dynamic needs to be enabled +by making the implicit value scala.language.dynamics visible. +This can be achieved by adding the import clause 'import scala.language.dynamics' +or by setting the compiler option -language:dynamics. +See the Scala docs for value scala.language.dynamics for a discussion +why the feature needs to be explicitly enabled. +trait B extends Dynamic + ^ +t6952.scala:3: error: extension of type scala.Dynamic needs to be enabled +by making the implicit value scala.language.dynamics visible. +trait C extends A with Dynamic + ^ +two errors found diff --git a/tests/untried/neg/t6952.scala b/tests/untried/neg/t6952.scala new file mode 100644 index 000000000000..257ea3be6855 --- /dev/null +++ b/tests/untried/neg/t6952.scala @@ -0,0 +1,4 @@ +trait A +trait B extends Dynamic +trait C extends A with Dynamic +trait D extends B diff --git a/tests/untried/neg/t696.check b/tests/untried/neg/t696.check new file mode 100644 index 000000000000..b7bc5cdf98d5 --- /dev/null +++ b/tests/untried/neg/t696.check @@ -0,0 +1,9 @@ +t696.scala:5: error: diverging implicit expansion for type TypeUtil0.Type[Any] +starting with method WithType in object TypeUtil0 + as[Any](null) + ^ +t696.scala:6: error: diverging implicit expansion for type TypeUtil0.Type[X] +starting with method WithType in object TypeUtil0 + def foo[X]() = as[X](null) + ^ +two errors found diff --git a/tests/untried/neg/t696.scala b/tests/untried/neg/t696.scala new file mode 100644 index 000000000000..ca76f7ef6c1d --- /dev/null +++ b/tests/untried/neg/t696.scala @@ -0,0 +1,7 @@ +object TypeUtil0 { + trait Type[+T] + implicit def WithType[S,T](implicit tpeS : Type[S], tpeT : Type[T]) : Type[S with T] = null + def as[T](x : Any)(implicit tpe : Type[T]) = null + as[Any](null) + def foo[X]() = as[X](null) +} diff --git a/tests/untried/neg/t6963a.check b/tests/untried/neg/t6963a.check new file mode 100644 index 000000000000..5858e7740abe --- /dev/null +++ b/tests/untried/neg/t6963a.check @@ -0,0 +1,7 @@ +t6963a.scala:4: warning: method scanRight in trait TraversableLike has changed semantics in version 2.9.0: +The behavior of `scanRight` has changed. The previous behavior can be reproduced with scanRight.reverse. + List(1,2,3,4,5).scanRight(0)(_+_) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t6963a.flags b/tests/untried/neg/t6963a.flags new file mode 100644 index 000000000000..4c61ed9430d1 --- /dev/null +++ b/tests/untried/neg/t6963a.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Xmigration:2.7 diff --git a/tests/untried/neg/t6963a.scala b/tests/untried/neg/t6963a.scala new file mode 100644 index 000000000000..6808e541bb9d --- /dev/null +++ b/tests/untried/neg/t6963a.scala @@ -0,0 +1,5 @@ +object Test { + import scala.collection.mutable._ + + List(1,2,3,4,5).scanRight(0)(_+_) +} diff --git a/tests/untried/neg/t700.check b/tests/untried/neg/t700.check new file mode 100644 index 000000000000..4c0a2e5fda2d --- /dev/null +++ b/tests/untried/neg/t700.check @@ -0,0 +1,4 @@ +t700.scala:6: error: method foobar in trait Foo is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override' + def foobar: Unit = super.foobar + ^ +one error found diff --git a/tests/untried/neg/t700.scala b/tests/untried/neg/t700.scala new file mode 100644 index 000000000000..b08c8b55290e --- /dev/null +++ b/tests/untried/neg/t700.scala @@ -0,0 +1,10 @@ +trait Foo { + def foobar: Unit; +} + +trait Bar extends Foo { + def foobar: Unit = super.foobar +} + +// the following definition breaks the compiler +abstract class Foobar extends Bar diff --git a/tests/untried/neg/t7007.check b/tests/untried/neg/t7007.check new file mode 100644 index 000000000000..e22ecb9e4ef1 --- /dev/null +++ b/tests/untried/neg/t7007.check @@ -0,0 +1,7 @@ +t7007.scala:5: error: Implementation restriction: <$anon: A => B> requires premature access to class Crash. + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) + ^ +t7007.scala:5: error: Implementation restriction: <$anon: A => B> requires premature access to class Crash. + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) + ^ +two errors found diff --git a/tests/untried/neg/t7007.scala b/tests/untried/neg/t7007.scala new file mode 100644 index 000000000000..e41dccf55092 --- /dev/null +++ b/tests/untried/neg/t7007.scala @@ -0,0 +1,14 @@ +class A +class B extends A + +class Crash(b1: Seq[B], b2: Seq[B]) { + def this(a: Seq[A]) = this(a.collect{ case b: B => b}, a.collect{ case b: B => b}) +} + +object Main extends App { + + // runtime exception with either constructor + val c1 = new Crash(Seq(new B, new B)) + val c2 = new Crash(Seq(new B), Seq(new B)) + +} diff --git a/tests/untried/neg/t7020.check b/tests/untried/neg/t7020.check new file mode 100644 index 000000000000..76390b243ddc --- /dev/null +++ b/tests/untried/neg/t7020.check @@ -0,0 +1,19 @@ +t7020.scala:3: warning: match may not be exhaustive. +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) + List(5) match { + ^ +t7020.scala:10: warning: match may not be exhaustive. +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) + List(5) match { + ^ +t7020.scala:17: warning: match may not be exhaustive. +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) + List(5) match { + ^ +t7020.scala:24: warning: match may not be exhaustive. +It would fail on the following inputs: List((x: Int forSome x not in (1, 2, 4, 5, 6, 7))), List((x: Int forSome x not in (1, 2, 4, 5, 6, 7)), _), List(1, _), List(2, _), List(4, _), List(5, _), List(6, _), List(7, _), List(_, _) + List(5) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t7020.flags b/tests/untried/neg/t7020.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7020.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7020.scala b/tests/untried/neg/t7020.scala new file mode 100644 index 000000000000..cc5421bab177 --- /dev/null +++ b/tests/untried/neg/t7020.scala @@ -0,0 +1,30 @@ +object Test { + // warning was non-deterministic + List(5) match { + case 1 :: Nil | 2 :: Nil => + case (x@(4 | 5 | 6)) :: Nil => + case 7 :: Nil => + case Nil => + } + + List(5) match { + case 1 :: Nil | 2 :: Nil => + case (x@(4 | 5 | 6)) :: Nil => + case 7 :: Nil => + case Nil => + } + + List(5) match { + case 1 :: Nil | 2 :: Nil => + case (x@(4 | 5 | 6)) :: Nil => + case 7 :: Nil => + case Nil => + } + + List(5) match { + case 1 :: Nil | 2 :: Nil => + case (x@(4 | 5 | 6)) :: Nil => + case 7 :: Nil => + case Nil => + } +} diff --git a/tests/untried/neg/t708.check b/tests/untried/neg/t708.check new file mode 100644 index 000000000000..4983aab61368 --- /dev/null +++ b/tests/untried/neg/t708.check @@ -0,0 +1,5 @@ +t708.scala:8: error: overriding type S in trait X with bounds <: A.this.T; + type S has incompatible type + override private[A] type S = Any; + ^ +one error found diff --git a/tests/untried/neg/t708.scala b/tests/untried/neg/t708.scala new file mode 100644 index 000000000000..f86a0058119b --- /dev/null +++ b/tests/untried/neg/t708.scala @@ -0,0 +1,12 @@ +trait A { + type T; + trait X { + private[A] type S <: T; + /*private[A]*/ def foo : S; + } + trait Y extends X { + override private[A] type S = Any; + override /*private[A]*/ def foo = null; + } +} + diff --git a/tests/untried/neg/t7110.check b/tests/untried/neg/t7110.check new file mode 100644 index 000000000000..e484dc432551 --- /dev/null +++ b/tests/untried/neg/t7110.check @@ -0,0 +1,6 @@ +t7110.scala:2: warning: A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled. + try { ??? } // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7110.flags b/tests/untried/neg/t7110.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7110.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7110.scala b/tests/untried/neg/t7110.scala new file mode 100644 index 000000000000..79ac32521619 --- /dev/null +++ b/tests/untried/neg/t7110.scala @@ -0,0 +1,6 @@ +object Test { + try { ??? } // warn + + try { ??? } finally ??? // no warn + try { ??? } catch { case _: Throwable => } // no warn +} diff --git a/tests/untried/neg/t712.check b/tests/untried/neg/t712.check new file mode 100644 index 000000000000..831e94306354 --- /dev/null +++ b/tests/untried/neg/t712.check @@ -0,0 +1,5 @@ +t712.scala:10: error: value self is not a member of B.this.ParentImpl + Note: implicit method coerce is not applicable here because it comes after the application point and it lacks an explicit result type + implicit def coerce(p : ParentImpl) = p.self; + ^ +one error found diff --git a/tests/untried/neg/t712.scala b/tests/untried/neg/t712.scala new file mode 100644 index 000000000000..6f2627743fb4 --- /dev/null +++ b/tests/untried/neg/t712.scala @@ -0,0 +1,19 @@ +trait A { + type Node <: NodeImpl; + implicit def coerce(n : NodeImpl) = n.self; + trait NodeImpl { + def self : Node; + } +} +trait B extends A { + type Parent <: ParentImpl; + implicit def coerce(p : ParentImpl) = p.self; + trait ParentImpl; + type Symbol; + trait SymbolImpl { + def scope : Int; + } + implicit def coerceSym(sym : Symbol) : SymbolImpl; + var s : Symbol = _; + val s_scope = s.scope; +} diff --git a/tests/untried/neg/t715.check b/tests/untried/neg/t715.check new file mode 100644 index 000000000000..2c01047a63cb --- /dev/null +++ b/tests/untried/neg/t715.check @@ -0,0 +1,4 @@ +t715.scala:12: error: method chilren in trait NodeImpl is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override' + override def children = super.chilren; + ^ +one error found diff --git a/tests/untried/neg/t715.scala b/tests/untried/neg/t715.scala new file mode 100644 index 000000000000..87b2525a6387 --- /dev/null +++ b/tests/untried/neg/t715.scala @@ -0,0 +1,15 @@ +package test; +trait B { + type Node <: NodeImpl; + trait NodeImpl { + def self : Node; + def chilren : List[Node]; + } +} +trait C extends B { + type Node <: NodeImpl; + trait NodeImpl extends super.NodeImpl { + override def children = super.chilren; + children; + } +} diff --git a/tests/untried/neg/t7157.check b/tests/untried/neg/t7157.check new file mode 100644 index 000000000000..c6a7af9a2397 --- /dev/null +++ b/tests/untried/neg/t7157.check @@ -0,0 +1,73 @@ +Test_2.scala:5: error: too many arguments for macro method m1_0_0: ()Unit + m1_0_0(1) + ^ +Test_2.scala:6: error: too many arguments for macro method m1_0_0: ()Unit + m1_0_0(1, 2) + ^ +Test_2.scala:7: error: too many arguments for macro method m1_0_0: ()Unit + m1_0_0(1, 2, 3) + ^ +Test_2.scala:9: error: macro applications do not support named and/or default arguments + m1_1_1() + ^ +Test_2.scala:11: error: too many arguments for macro method m1_1_1: (x: Int)Unit + m1_1_1(1, 2) + ^ +Test_2.scala:12: error: too many arguments for macro method m1_1_1: (x: Int)Unit + m1_1_1(1, 2, 3) + ^ +Test_2.scala:14: error: macro applications do not support named and/or default arguments + m1_2_2() + ^ +Test_2.scala:15: error: macro applications do not support named and/or default arguments + m1_2_2(1) + ^ +Test_2.scala:17: error: too many arguments for macro method m1_2_2: (x: Int, y: Int)Unit + m1_2_2(1, 2, 3) + ^ +Test_2.scala:24: error: macro applications do not support named and/or default arguments + m1_1_inf() + ^ +Test_2.scala:29: error: macro applications do not support named and/or default arguments + m1_2_inf() + ^ +Test_2.scala:30: error: macro applications do not support named and/or default arguments + m1_2_inf(1) + ^ +Test_2.scala:35: error: too many arguments for macro method m2_0_0: ()Unit + m2_0_0()(1) + ^ +Test_2.scala:36: error: too many arguments for macro method m2_0_0: ()Unit + m2_0_0()(1, 2) + ^ +Test_2.scala:37: error: too many arguments for macro method m2_0_0: ()Unit + m2_0_0()(1, 2, 3) + ^ +Test_2.scala:39: error: macro applications do not support named and/or default arguments + m2_1_1()() + ^ +Test_2.scala:41: error: too many arguments for macro method m2_1_1: (x: Int)Unit + m2_1_1()(1, 2) + ^ +Test_2.scala:42: error: too many arguments for macro method m2_1_1: (x: Int)Unit + m2_1_1()(1, 2, 3) + ^ +Test_2.scala:44: error: macro applications do not support named and/or default arguments + m2_2_2()() + ^ +Test_2.scala:45: error: macro applications do not support named and/or default arguments + m2_2_2()(1) + ^ +Test_2.scala:47: error: too many arguments for macro method m2_2_2: (x: Int, y: Int)Unit + m2_2_2()(1, 2, 3) + ^ +Test_2.scala:54: error: macro applications do not support named and/or default arguments + m2_1_inf()() + ^ +Test_2.scala:59: error: macro applications do not support named and/or default arguments + m2_2_inf()() + ^ +Test_2.scala:60: error: macro applications do not support named and/or default arguments + m2_2_inf()(1) + ^ +24 errors found diff --git a/tests/untried/neg/t7157/Impls_Macros_1.scala b/tests/untried/neg/t7157/Impls_Macros_1.scala new file mode 100644 index 000000000000..e7a603006459 --- /dev/null +++ b/tests/untried/neg/t7157/Impls_Macros_1.scala @@ -0,0 +1,32 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Macros { + def impl1_0_0(c: Context)() = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_1_1(c: Context)(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_2_2(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def m1_0_0() = macro impl1_0_0 + def m1_1_1(x: Int) = macro impl1_1_1 + def m1_2_2(x: Int, y: Int) = macro impl1_2_2 + + def impl1_0_inf(c: Context)(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_1_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl1_2_inf(c: Context)(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def m1_0_inf(x: Int*) = macro impl1_0_inf + def m1_1_inf(x: Int, y: Int*) = macro impl1_1_inf + def m1_2_inf(x: Int, y: Int, z: Int*) = macro impl1_2_inf + + def impl2_0_0(c: Context)()() = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_1_1(c: Context)()(x: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_2_2(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def m2_0_0()() = macro impl2_0_0 + def m2_1_1()(x: Int) = macro impl2_1_1 + def m2_2_2()(x: Int, y: Int) = macro impl2_2_2 + + def impl2_0_inf(c: Context)()(x: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_1_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def impl2_2_inf(c: Context)()(x: c.Expr[Int], y: c.Expr[Int], z: c.Expr[Int]*) = { import c.universe._; c.Expr[Unit](q"""println("hello world")""") } + def m2_0_inf()(x: Int*) = macro impl2_0_inf + def m2_1_inf()(x: Int, y: Int*) = macro impl2_1_inf + def m2_2_inf()(x: Int, y: Int, z: Int*) = macro impl2_2_inf +} diff --git a/tests/untried/neg/t7157/Test_2.scala b/tests/untried/neg/t7157/Test_2.scala new file mode 100644 index 000000000000..faafb02a3888 --- /dev/null +++ b/tests/untried/neg/t7157/Test_2.scala @@ -0,0 +1,63 @@ +import Macros._ + +object Test extends App { + m1_0_0() + m1_0_0(1) + m1_0_0(1, 2) + m1_0_0(1, 2, 3) + + m1_1_1() + m1_1_1(1) + m1_1_1(1, 2) + m1_1_1(1, 2, 3) + + m1_2_2() + m1_2_2(1) + m1_2_2(1, 2) + m1_2_2(1, 2, 3) + + m1_0_inf() + m1_0_inf(1) + m1_0_inf(1, 2) + m1_0_inf(1, 2, 3) + + m1_1_inf() + m1_1_inf(1) + m1_1_inf(1, 2) + m1_1_inf(1, 2, 3) + + m1_2_inf() + m1_2_inf(1) + m1_2_inf(1, 2) + m1_2_inf(1, 2, 3) + + m2_0_0()() + m2_0_0()(1) + m2_0_0()(1, 2) + m2_0_0()(1, 2, 3) + + m2_1_1()() + m2_1_1()(1) + m2_1_1()(1, 2) + m2_1_1()(1, 2, 3) + + m2_2_2()() + m2_2_2()(1) + m2_2_2()(1, 2) + m2_2_2()(1, 2, 3) + + m2_0_inf()() + m2_0_inf()(1) + m2_0_inf()(1, 2) + m2_0_inf()(1, 2, 3) + + m2_1_inf()() + m2_1_inf()(1) + m2_1_inf()(1, 2) + m2_1_inf()(1, 2, 3) + + m2_2_inf()() + m2_2_inf()(1) + m2_2_inf()(1, 2) + m2_2_inf()(1, 2, 3) +} diff --git a/tests/untried/neg/t7171.check b/tests/untried/neg/t7171.check new file mode 100644 index 000000000000..ecd768afdae1 --- /dev/null +++ b/tests/untried/neg/t7171.check @@ -0,0 +1,6 @@ +t7171.scala:2: warning: The outer reference in this type test cannot be checked at run time. + final case class A() + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7171.flags b/tests/untried/neg/t7171.flags new file mode 100644 index 000000000000..464cc20ea684 --- /dev/null +++ b/tests/untried/neg/t7171.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked \ No newline at end of file diff --git a/tests/untried/neg/t7171.scala b/tests/untried/neg/t7171.scala new file mode 100644 index 000000000000..534b2070a394 --- /dev/null +++ b/tests/untried/neg/t7171.scala @@ -0,0 +1,11 @@ +trait T { + final case class A() + + // Was: + // error: scrutinee is incompatible with pattern type; + // found : T.this.A + // required: T#A + def foo(a: T#A) = a match { + case _: A => true; case _ => false + } +} diff --git a/tests/untried/neg/t7171b.check b/tests/untried/neg/t7171b.check new file mode 100644 index 000000000000..bf695afea727 --- /dev/null +++ b/tests/untried/neg/t7171b.check @@ -0,0 +1,6 @@ +t7171b.scala:2: warning: The outer reference in this type test cannot be checked at run time. + final case class A() + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7171b.flags b/tests/untried/neg/t7171b.flags new file mode 100644 index 000000000000..464cc20ea684 --- /dev/null +++ b/tests/untried/neg/t7171b.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked \ No newline at end of file diff --git a/tests/untried/neg/t7171b.scala b/tests/untried/neg/t7171b.scala new file mode 100644 index 000000000000..53c7787f8b57 --- /dev/null +++ b/tests/untried/neg/t7171b.scala @@ -0,0 +1,15 @@ +trait T { + final case class A() +} + +final class U extends T { + // this match should also not be deemed impossible + def foo(a: U#A) = a match { + case _: A => true; case _ => false + } + + // this match should also not be deemed impossible + def bar(a: T#A) = a match { + case _: A => true; case _ => false + } +} diff --git a/tests/untried/neg/t7214neg.check b/tests/untried/neg/t7214neg.check new file mode 100644 index 000000000000..291af04578dc --- /dev/null +++ b/tests/untried/neg/t7214neg.check @@ -0,0 +1,4 @@ +t7214neg.scala:28: error: not enough patterns for object Extractor offering Any: expected 1, found 0 + case Extractor() => + ^ +one error found diff --git a/tests/untried/neg/t7214neg.scala b/tests/untried/neg/t7214neg.scala new file mode 100644 index 000000000000..ff1ea8082d97 --- /dev/null +++ b/tests/untried/neg/t7214neg.scala @@ -0,0 +1,57 @@ +// pattern matcher crashes here trying to synthesize an uneeded outer test. +// no-symbol does not have an owner +// at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:49) +// at scala.tools.nsc.Global.abort(Global.scala:253) +// at scala.reflect.internal.Symbols$NoSymbol.owner(Symbols.scala:3248) +// at scala.reflect.internal.Symbols$Symbol.effectiveOwner(Symbols.scala:678) +// at scala.reflect.internal.Symbols$Symbol.isDefinedInPackage(Symbols.scala:664) +// at scala.reflect.internal.TreeGen.mkAttributedSelect(TreeGen.scala:188) +// at scala.reflect.internal.TreeGen.mkAttributedRef(TreeGen.scala:124) +// at scala.tools.nsc.ast.TreeDSL$CODE$.REF(TreeDSL.scala:308) +// at scala.tools.nsc.typechecker.PatternMatching$TreeMakers$TypeTestTreeMaker$treeCondStrategy$.outerTest(PatternMatching.scala:1209) +class Crash { + type Alias = C#T + + val c = new C + val t = new c.T + + // Crash via a Typed Pattern... + (t: Any) match { + case e: Alias => + } + + // ... or via a Typed Extractor Pattern. + object Extractor { + def unapply(a: Alias): Option[Any] = None + } + (t: Any) match { + case Extractor() => + case _ => + } + + // checking that correct outer tests are applied when + // aliases for path dependent types are involved. + val c2 = new C + type CdotT = c.T + type C2dotT = c2.T + + val outerField = t.getClass.getDeclaredFields.find(_.getName contains ("outer")).get + outerField.setAccessible(true) + + (t: Any) match { + case _: C2dotT => + println(s"!!! wrong match. t.outer=${outerField.get(t)} / c2 = $c2") // this matches on 2.10.0 + case _: CdotT => + case _ => + println(s"!!! wrong match. t.outer=${outerField.get(t)} / c = $c") + } +} + +class C { + class T +} + +object Test extends App { + new Crash +} + diff --git a/tests/untried/neg/t7235.check b/tests/untried/neg/t7235.check new file mode 100644 index 000000000000..357a3dfd83ea --- /dev/null +++ b/tests/untried/neg/t7235.check @@ -0,0 +1,4 @@ +t7235.scala:9: error: implementation restriction: cannot reify refinement type trees with non-empty bodies + val Block(List(ValDef(_, _, tpt: CompoundTypeTree, _)), _) = reify{ val x: C { def x: Int } = ??? }.tree + ^ +one error found diff --git a/tests/untried/neg/t7235.scala b/tests/untried/neg/t7235.scala new file mode 100644 index 000000000000..cfebad3faefb --- /dev/null +++ b/tests/untried/neg/t7235.scala @@ -0,0 +1,14 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +class C + +object Test extends App { + val Block(List(ValDef(_, _, tpt: CompoundTypeTree, _)), _) = reify{ val x: C { def x: Int } = ??? }.tree + println(tpt) + println(tpt.templ.parents) + println(tpt.templ.self) + println(tpt.templ.body) +} diff --git a/tests/untried/neg/t7238.check b/tests/untried/neg/t7238.check new file mode 100644 index 000000000000..b87f83ff65ea --- /dev/null +++ b/tests/untried/neg/t7238.check @@ -0,0 +1,6 @@ +t7238.scala:6: error: type mismatch; + found : Seq[Any] + required: Seq[String] + c.c()(Seq[Any](): _*) + ^ +one error found diff --git a/tests/untried/neg/t7238.scala b/tests/untried/neg/t7238.scala new file mode 100644 index 000000000000..d42dc8d385cc --- /dev/null +++ b/tests/untried/neg/t7238.scala @@ -0,0 +1,7 @@ +trait Main { + trait C { + def c(x: Any = 0)(bs: String*) + } + def c: C + c.c()(Seq[Any](): _*) +} diff --git a/tests/untried/neg/t7239.check b/tests/untried/neg/t7239.check new file mode 100644 index 000000000000..80b14f8fc6a8 --- /dev/null +++ b/tests/untried/neg/t7239.check @@ -0,0 +1,4 @@ +t7239.scala:10: error: not found: value foBar + fooBar = foBar.toInt + ^ +one error found diff --git a/tests/untried/neg/t7239.scala b/tests/untried/neg/t7239.scala new file mode 100644 index 000000000000..f62cac0a4934 --- /dev/null +++ b/tests/untried/neg/t7239.scala @@ -0,0 +1,12 @@ +class Foo { + def toInt = 12 +} +case class Bar( fooBar : Int ) + +// spurious "erroneous or inaccessible type" error in 2.10.1 +class Test { + var fooBar : Foo = null + def build = Bar( + fooBar = foBar.toInt + ) +} diff --git a/tests/untried/neg/t7251.check b/tests/untried/neg/t7251.check new file mode 100644 index 000000000000..8df8984d6372 --- /dev/null +++ b/tests/untried/neg/t7251.check @@ -0,0 +1,4 @@ +B_2.scala:5: error: object s.Outer$Triple$ is not a value + println( s.Outer$Triple$ ) + ^ +one error found diff --git a/tests/untried/neg/t7251/A_1.scala b/tests/untried/neg/t7251/A_1.scala new file mode 100644 index 000000000000..d05373ed2872 --- /dev/null +++ b/tests/untried/neg/t7251/A_1.scala @@ -0,0 +1,10 @@ +package s + +object Outer { + type Triple[+A, +B, +C] = Tuple3[A, B, C] + object Triple { + def apply[A, B, C](x: A, y: B, z: C) = Tuple3(x, y, z) + def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x) + } +} + diff --git a/tests/untried/neg/t7251/B_2.scala b/tests/untried/neg/t7251/B_2.scala new file mode 100644 index 000000000000..eb59b30902bc --- /dev/null +++ b/tests/untried/neg/t7251/B_2.scala @@ -0,0 +1,7 @@ +package s + +object Test { + def main(args: Array[String]): Unit = { + println( s.Outer$Triple$ ) + } +} diff --git a/tests/untried/neg/t7259.check b/tests/untried/neg/t7259.check new file mode 100644 index 000000000000..0ad627fc3bdf --- /dev/null +++ b/tests/untried/neg/t7259.check @@ -0,0 +1,7 @@ +t7259.scala:1: error: not found: type xxxxx +@xxxxx // error: not found: type xxxx + ^ +t7259.scala:8: error: type xxxxx is not a member of package annotation +@annotation.xxxxx // error: not found: type scala + ^ +two errors found diff --git a/tests/untried/neg/t7259.scala b/tests/untried/neg/t7259.scala new file mode 100644 index 000000000000..0fdfe18822f9 --- /dev/null +++ b/tests/untried/neg/t7259.scala @@ -0,0 +1,9 @@ +@xxxxx // error: not found: type xxxx +class Ok + +// +// This had the wrong error message in 2.9 and 2.10. +// + +@annotation.xxxxx // error: not found: type scala +class WrongErrorMessage diff --git a/tests/untried/neg/t7285.check b/tests/untried/neg/t7285.check new file mode 100644 index 000000000000..a38772bead22 --- /dev/null +++ b/tests/untried/neg/t7285.check @@ -0,0 +1,15 @@ +t7285.scala:15: warning: match may not be exhaustive. +It would fail on the following input: (Up, Down) + (d1, d2) match { + ^ +t7285.scala:33: warning: match may not be exhaustive. +It would fail on the following input: Down + (d1) match { + ^ +t7285.scala:51: warning: match may not be exhaustive. +It would fail on the following input: (Up, Down) + (d1, d2) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t7285.flags b/tests/untried/neg/t7285.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7285.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7285.scala b/tests/untried/neg/t7285.scala new file mode 100644 index 000000000000..14121d92b1b3 --- /dev/null +++ b/tests/untried/neg/t7285.scala @@ -0,0 +1,55 @@ +sealed abstract class Base + + +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 + } + } +} + +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 Test2.Base.Up => 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 + } +} diff --git a/tests/untried/neg/t7289.check b/tests/untried/neg/t7289.check new file mode 100644 index 000000000000..e4aeebbc6c1c --- /dev/null +++ b/tests/untried/neg/t7289.check @@ -0,0 +1,4 @@ +t7289.scala:8: error: could not find implicit value for parameter e: Test.Schtroumpf[scala.collection.immutable.Nil.type] + implicitly[Schtroumpf[Nil.type]] + ^ +one error found diff --git a/tests/untried/neg/t7289.scala b/tests/untried/neg/t7289.scala new file mode 100644 index 000000000000..ad9340055cd6 --- /dev/null +++ b/tests/untried/neg/t7289.scala @@ -0,0 +1,39 @@ +object Test extends App { + trait Schtroumpf[T] + + implicit def schtroumpf[T, U <: Coll[T], Coll[X] <: Traversable[X]] + (implicit minorSchtroumpf: Schtroumpf[T]): Schtroumpf[U] = ??? + + implicit val qoo: Schtroumpf[Int] = new Schtroumpf[Int]{} + implicitly[Schtroumpf[Nil.type]] +} + +/* +info1 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3468}"qoo: => Test.Schtroumpf[Int]" +info2 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3469}"schtroumpf: [T, U <: Coll[T], Coll[_] <: Traversable[_]](implicit minorSchtroumpf: Test.Schtroumpf[T])Test.Schtroumpf[U]" +isStrictlyMoreSpecific(info1, info2) + isSubType(Test.Schtroumpf[Int], Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] }) + isAsSpecificValueType(Test.Schtroumpf[Int], Test.Schtroumpf[U], undef2 = List(type T, type U, type Coll)) + + val et: ExistentialType = Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] } + val tp1 = Test.Schtroumpf[Int] + et.withTypeVars(isSubType(tp1, _, depth)) + solve() + tvars = tList(=?Nothing, =?Int, =?=?Int) + + +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=scala.collection.immutable.Nil.type ) +[ setInst] =?scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?scala.collection.immutable.Nil.type ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Int ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=Int ) +[ setInst] =?Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?Int ) +*/ diff --git a/tests/untried/neg/t7289_status_quo.check b/tests/untried/neg/t7289_status_quo.check new file mode 100644 index 000000000000..31c072e969fd --- /dev/null +++ b/tests/untried/neg/t7289_status_quo.check @@ -0,0 +1,22 @@ +t7289_status_quo.scala:9: error: could not find implicit value for parameter e: Test1.Ext[List[Int]] + implicitly[Ext[List[Int]]] // fails - not found + ^ +t7289_status_quo.scala:11: error: could not find implicit value for parameter e: Test1.Ext[List[List[List[Int]]]] + implicitly[Ext[List[List[List[Int]]]]] // fails - not found + ^ +t7289_status_quo.scala:15: error: ambiguous implicit values: + both method f in object Test1 of type [A, Coll <: CC[A], CC[X] <: Traversable[X]](implicit xi: Test1.Ext[A])Test1.Ext[Coll] + and value m in object Test1 of type => Test1.Ext[List[List[Int]]] + match expected type Test1.Ext[_ <: List[List[Int]]] + implicitly[Ext[_ <: List[List[Int]]]] // fails - ambiguous + ^ +t7289_status_quo.scala:20: error: could not find implicit value for parameter e: Test1.ExtCov[List[Int]] + implicitly[ExtCov[List[Int]]] // fails - not found + ^ +t7289_status_quo.scala:21: error: could not find implicit value for parameter e: Test1.ExtCov[List[List[Int]]] + implicitly[ExtCov[List[List[Int]]]] // fails - not found + ^ +t7289_status_quo.scala:22: error: could not find implicit value for parameter e: Test1.ExtCov[List[List[List[Int]]]] + implicitly[ExtCov[List[List[List[Int]]]]] // fails - not found + ^ +6 errors found diff --git a/tests/untried/neg/t7289_status_quo.scala b/tests/untried/neg/t7289_status_quo.scala new file mode 100644 index 000000000000..e1f9a9f8aa3e --- /dev/null +++ b/tests/untried/neg/t7289_status_quo.scala @@ -0,0 +1,23 @@ +// record the status quo after this fix +// not clear to @adriaanm why an upper-bounded existential in an invariant position +// is different from putting that upper bound in a covariant position +object Test1 { + trait Ext[T] + implicit def f[A, Coll <: CC[A], CC[X] <: Traversable[X]](implicit xi: Ext[A]): Ext[Coll] = ??? + implicit val m: Ext[List[List[Int]]] = new Ext[List[List[Int]]]{} + + implicitly[Ext[List[Int]]] // fails - not found + implicitly[Ext[List[List[Int]]]] // compiles + implicitly[Ext[List[List[List[Int]]]]] // fails - not found + + // Making Ext[+T] should incur the same behavior as these. (so says @paulp) + implicitly[Ext[_ <: List[Int]]] // compiles + implicitly[Ext[_ <: List[List[Int]]]] // fails - ambiguous + implicitly[Ext[_ <: List[List[List[Int]]]]] // compiles + + // But, we currently get: + trait ExtCov[+T] + implicitly[ExtCov[List[Int]]] // fails - not found + implicitly[ExtCov[List[List[Int]]]] // fails - not found + implicitly[ExtCov[List[List[List[Int]]]]] // fails - not found +} diff --git a/tests/untried/neg/t729.check b/tests/untried/neg/t729.check new file mode 100644 index 000000000000..fb858dc09a9e --- /dev/null +++ b/tests/untried/neg/t729.check @@ -0,0 +1,6 @@ +t729.scala:20: error: type mismatch; + found : ScalaParserAutoEdit.this.NodeImpl(in trait Parser) + required: ScalaParserAutoEdit.this.NodeImpl(in trait ScalaParserAutoEdit) + val yyy : NodeImpl = link.from; + ^ +one error found diff --git a/tests/untried/neg/t729.scala b/tests/untried/neg/t729.scala new file mode 100644 index 000000000000..83e7f4cd1e8d --- /dev/null +++ b/tests/untried/neg/t729.scala @@ -0,0 +1,23 @@ +trait Parser { + type Node <: NodeImpl; + implicit def coerce(n : NodeImpl) = n.self; + trait NodeImpl { + def self : Node; + } + trait Link { + def from : NodeImpl; + } +} + +trait ScalaParserAutoEdit extends Parser { + type Node <: NodeImpl; + implicit def coerce(node : NodeImpl) = node.self; + trait NodeImpl extends super[Parser].NodeImpl { + def self : Node; + def foo = { + var link : Link = null; + val xxx : NodeImpl = coerce(link.from); + val yyy : NodeImpl = link.from; + } + } +} diff --git a/tests/untried/neg/t7290.check b/tests/untried/neg/t7290.check new file mode 100644 index 000000000000..ad2d0e25b01e --- /dev/null +++ b/tests/untried/neg/t7290.check @@ -0,0 +1,12 @@ +t7290.scala:4: warning: Pattern contains duplicate alternatives: 0 + case 0 | 0 => 0 + ^ +t7290.scala:5: warning: Pattern contains duplicate alternatives: 2, 3 + case 2 | 2 | 2 | 3 | 2 | 3 => 0 + ^ +t7290.scala:6: warning: Pattern contains duplicate alternatives: 4 + case 4 | (_ @ 4) => 0 + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t7290.flags b/tests/untried/neg/t7290.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7290.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7290.scala b/tests/untried/neg/t7290.scala new file mode 100644 index 000000000000..b9db7f7e8a88 --- /dev/null +++ b/tests/untried/neg/t7290.scala @@ -0,0 +1,10 @@ +object Test extends App { + val y = (0: Int) match { + case 1 => 1 + case 0 | 0 => 0 + case 2 | 2 | 2 | 3 | 2 | 3 => 0 + case 4 | (_ @ 4) => 0 + case _ => -1 + } + assert(y == 0, y) +} diff --git a/tests/untried/neg/t7292-deprecation.check b/tests/untried/neg/t7292-deprecation.check new file mode 100644 index 000000000000..17f010dfdf33 --- /dev/null +++ b/tests/untried/neg/t7292-deprecation.check @@ -0,0 +1,12 @@ +t7292-deprecation.scala:2: warning: Octal escape literals are deprecated, use \u0000 instead. + val chr1 = '\0' + ^ +t7292-deprecation.scala:3: warning: Octal escape literals are deprecated, use \u0053 instead. + val str1 = "abc\123456" + ^ +t7292-deprecation.scala:4: warning: Octal escape literals are deprecated, use \n instead. + val lf = '\012' + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t7292-deprecation.flags b/tests/untried/neg/t7292-deprecation.flags new file mode 100644 index 000000000000..7de3c0f3eea0 --- /dev/null +++ b/tests/untried/neg/t7292-deprecation.flags @@ -0,0 +1 @@ +-Xfatal-warnings -deprecation diff --git a/tests/untried/neg/t7292-deprecation.scala b/tests/untried/neg/t7292-deprecation.scala new file mode 100644 index 000000000000..d857f0e1ecea --- /dev/null +++ b/tests/untried/neg/t7292-deprecation.scala @@ -0,0 +1,5 @@ +object OctalEscapes { + val chr1 = '\0' + val str1 = "abc\123456" + val lf = '\012' +} diff --git a/tests/untried/neg/t7292-removal.check b/tests/untried/neg/t7292-removal.check new file mode 100644 index 000000000000..1cd59b099290 --- /dev/null +++ b/tests/untried/neg/t7292-removal.check @@ -0,0 +1,10 @@ +t7292-removal.scala:2: error: Octal escape literals are unsupported, use \u0000 instead. + val chr1 = '\0' + ^ +t7292-removal.scala:3: error: Octal escape literals are unsupported, use \u0053 instead. + val str1 = "abc\123456" + ^ +t7292-removal.scala:4: error: Octal escape literals are unsupported, use \n instead. + val lf = '\012' + ^ +three errors found diff --git a/tests/untried/neg/t7292-removal.flags b/tests/untried/neg/t7292-removal.flags new file mode 100644 index 000000000000..29f4ede37ab4 --- /dev/null +++ b/tests/untried/neg/t7292-removal.flags @@ -0,0 +1 @@ +-Xfuture diff --git a/tests/untried/neg/t7292-removal.scala b/tests/untried/neg/t7292-removal.scala new file mode 100644 index 000000000000..d857f0e1ecea --- /dev/null +++ b/tests/untried/neg/t7292-removal.scala @@ -0,0 +1,5 @@ +object OctalEscapes { + val chr1 = '\0' + val str1 = "abc\123456" + val lf = '\012' +} diff --git a/tests/untried/neg/t7294.check b/tests/untried/neg/t7294.check new file mode 100644 index 000000000000..f15289c1c01a --- /dev/null +++ b/tests/untried/neg/t7294.check @@ -0,0 +1,6 @@ +t7294.scala:4: warning: fruitless type test: a value of type (Int, Int) cannot also be a Seq[A] + (1, 2) match { case Seq() => 0; case _ => 1 } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7294.flags b/tests/untried/neg/t7294.flags new file mode 100644 index 000000000000..3f3381a45bde --- /dev/null +++ b/tests/untried/neg/t7294.flags @@ -0,0 +1 @@ +-Xfuture -Xfatal-warnings diff --git a/tests/untried/neg/t7294.scala b/tests/untried/neg/t7294.scala new file mode 100644 index 000000000000..335d0711245d --- /dev/null +++ b/tests/untried/neg/t7294.scala @@ -0,0 +1,5 @@ +object Test { + // Treat TupleN as final under -Xfuture for the for the purposes + // of the "fruitless type test" warning. + (1, 2) match { case Seq() => 0; case _ => 1 } +} diff --git a/tests/untried/neg/t7294b.check b/tests/untried/neg/t7294b.check new file mode 100644 index 000000000000..0033b7212513 --- /dev/null +++ b/tests/untried/neg/t7294b.check @@ -0,0 +1,6 @@ +t7294b.scala:1: warning: inheritance from class Tuple2 in package scala is deprecated: Tuples will be made final in a future version. +class C extends Tuple2[Int, Int](0, 0) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7294b.flags b/tests/untried/neg/t7294b.flags new file mode 100644 index 000000000000..d1b831ea87cd --- /dev/null +++ b/tests/untried/neg/t7294b.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7294b.scala b/tests/untried/neg/t7294b.scala new file mode 100644 index 000000000000..deeed4fc79ea --- /dev/null +++ b/tests/untried/neg/t7294b.scala @@ -0,0 +1 @@ +class C extends Tuple2[Int, Int](0, 0) diff --git a/tests/untried/neg/t7299.check b/tests/untried/neg/t7299.check new file mode 100644 index 000000000000..74340c4841ed --- /dev/null +++ b/tests/untried/neg/t7299.check @@ -0,0 +1,7 @@ +t7299.scala:4: error: implementation restricts functions to 22 parameters + val eta1 = f _ + ^ +t7299.scala:5: error: implementation restricts functions to 22 parameters + val eta2 = g[Any] _ + ^ +two errors found diff --git a/tests/untried/neg/t7299.scala b/tests/untried/neg/t7299.scala new file mode 100644 index 000000000000..f3aae5ce5de9 --- /dev/null +++ b/tests/untried/neg/t7299.scala @@ -0,0 +1,6 @@ +object Test { + def f(a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int, a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int, a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int, a23: Int) = 0 + def g[A](a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int, a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int, a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int, a23: Int) = 0 + val eta1 = f _ + val eta2 = g[Any] _ +} diff --git a/tests/untried/neg/t7324.check b/tests/untried/neg/t7324.check new file mode 100644 index 000000000000..586947d5e708 --- /dev/null +++ b/tests/untried/neg/t7324.check @@ -0,0 +1,4 @@ +t7324.scala:2: error: Platform restriction: a parameter list's length cannot exceed 254. +class Bar( + ^ +one error found diff --git a/tests/untried/neg/t7324.scala b/tests/untried/neg/t7324.scala new file mode 100644 index 000000000000..81d7674d6822 --- /dev/null +++ b/tests/untried/neg/t7324.scala @@ -0,0 +1,57 @@ +object Bar extends App +class Bar( +_1: Int, _2: Int, _3: Int, _4: Int, _5: Int, _6: Int, _7: Int, _8: Int, _9: Int, _10: Int, +_11: Int, _12: Int, _13: Int, _14: Int, _15: Int, _16: Int, _17: Int, _18: Int, _19: Int, _20: Int, +_21: Int, _22: Int, _23: Int, _24: Int, _25: Int, _26: Int, _27: Int, _28: Int, _29: Int, _30: Int, +_31: Int, _32: Int, _33: Int, _34: Int, _35: Int, _36: Int, _37: Int, _38: Int, _39: Int, _40: Int, +_41: Int, _42: Int, _43: Int, _44: Int, _45: Int, _46: Int, _47: Int, _48: Int, _49: Int, _50: Int, +_51: Int, _52: Int, _53: Int, _54: Int, _55: Int, _56: Int, _57: Int, _58: Int, _59: Int, _60: Int, +_61: Int, _62: Int, _63: Int, _64: Int, _65: Int, _66: Int, _67: Int, _68: Int, _69: Int, _70: Int, +_71: Int, _72: Int, _73: Int, _74: Int, _75: Int, _76: Int, _77: Int, _78: Int, _79: Int, _80: Int, +_81: Int, _82: Int, _83: Int, _84: Int, _85: Int, _86: Int, _87: Int, _88: Int, _89: Int, _90: Int, +_91: Int, _92: Int, _93: Int, _94: Int, _95: Int, _96: Int, _97: Int, _98: Int, _99: Int, _100: Int, +_101: Int, _102: Int, _103: Int, _104: Int, _105: Int, _106: Int, _107: Int, _108: Int, _109: Int, _110: Int, +_111: Int, _112: Int, _113: Int, _114: Int, _115: Int, _116: Int, _117: Int, _118: Int, _119: Int, _120: Int, +_121: Int, _122: Int, _123: Int, _124: Int, _125: Int, _126: Int, _127: Int, _128: Int, _129: Int, _130: Int, +_131: Int, _132: Int, _133: Int, _134: Int, _135: Int, _136: Int, _137: Int, _138: Int, _139: Int, _140: Int, +_141: Int, _142: Int, _143: Int, _144: Int, _145: Int, _146: Int, _147: Int, _148: Int, _149: Int, _150: Int, +_151: Int, _152: Int, _153: Int, _154: Int, _155: Int, _156: Int, _157: Int, _158: Int, _159: Int, _160: Int, +_161: Int, _162: Int, _163: Int, _164: Int, _165: Int, _166: Int, _167: Int, _168: Int, _169: Int, _170: Int, +_171: Int, _172: Int, _173: Int, _174: Int, _175: Int, _176: Int, _177: Int, _178: Int, _179: Int, _180: Int, +_181: Int, _182: Int, _183: Int, _184: Int, _185: Int, _186: Int, _187: Int, _188: Int, _189: Int, _190: Int, +_191: Int, _192: Int, _193: Int, _194: Int, _195: Int, _196: Int, _197: Int, _198: Int, _199: Int, _200: Int, +_201: Int, _202: Int, _203: Int, _204: Int, _205: Int, _206: Int, _207: Int, _208: Int, _209: Int, _210: Int, +_211: Int, _212: Int, _213: Int, _214: Int, _215: Int, _216: Int, _217: Int, _218: Int, _219: Int, _220: Int, +_221: Int, _222: Int, _223: Int, _224: Int, _225: Int, _226: Int, _227: Int, _228: Int, _229: Int, _230: Int, +_231: Int, _232: Int, _233: Int, _234: Int, _235: Int, _236: Int, _237: Int, _238: Int, _239: Int, _240: Int, +_241: Int, _242: Int, _243: Int, _244: Int, _245: Int, _246: Int, _247: Int, _248: Int, _249: Int, _250: Int, +_251: Int, _252: Int, _253: Int, _254: Int, _255: Int +) + +class BarOK( +_1: Int, _2: Int, _3: Int, _4: Int, _5: Int, _6: Int, _7: Int, _8: Int, _9: Int, _10: Int, +_11: Int, _12: Int, _13: Int, _14: Int, _15: Int, _16: Int, _17: Int, _18: Int, _19: Int, _20: Int, +_21: Int, _22: Int, _23: Int, _24: Int, _25: Int, _26: Int, _27: Int, _28: Int, _29: Int, _30: Int, +_31: Int, _32: Int, _33: Int, _34: Int, _35: Int, _36: Int, _37: Int, _38: Int, _39: Int, _40: Int, +_41: Int, _42: Int, _43: Int, _44: Int, _45: Int, _46: Int, _47: Int, _48: Int, _49: Int, _50: Int, +_51: Int, _52: Int, _53: Int, _54: Int, _55: Int, _56: Int, _57: Int, _58: Int, _59: Int, _60: Int, +_61: Int, _62: Int, _63: Int, _64: Int, _65: Int, _66: Int, _67: Int, _68: Int, _69: Int, _70: Int, +_71: Int, _72: Int, _73: Int, _74: Int, _75: Int, _76: Int, _77: Int, _78: Int, _79: Int, _80: Int, +_81: Int, _82: Int, _83: Int, _84: Int, _85: Int, _86: Int, _87: Int, _88: Int, _89: Int, _90: Int, +_91: Int, _92: Int, _93: Int, _94: Int, _95: Int, _96: Int, _97: Int, _98: Int, _99: Int, _100: Int, +_101: Int, _102: Int, _103: Int, _104: Int, _105: Int, _106: Int, _107: Int, _108: Int, _109: Int, _110: Int, +_111: Int, _112: Int, _113: Int, _114: Int, _115: Int, _116: Int, _117: Int, _118: Int, _119: Int, _120: Int, +_121: Int, _122: Int, _123: Int, _124: Int, _125: Int, _126: Int, _127: Int, _128: Int, _129: Int, _130: Int, +_131: Int, _132: Int, _133: Int, _134: Int, _135: Int, _136: Int, _137: Int, _138: Int, _139: Int, _140: Int, +_141: Int, _142: Int, _143: Int, _144: Int, _145: Int, _146: Int, _147: Int, _148: Int, _149: Int, _150: Int, +_151: Int, _152: Int, _153: Int, _154: Int, _155: Int, _156: Int, _157: Int, _158: Int, _159: Int, _160: Int, +_161: Int, _162: Int, _163: Int, _164: Int, _165: Int, _166: Int, _167: Int, _168: Int, _169: Int, _170: Int, +_171: Int, _172: Int, _173: Int, _174: Int, _175: Int, _176: Int, _177: Int, _178: Int, _179: Int, _180: Int, +_181: Int, _182: Int, _183: Int, _184: Int, _185: Int, _186: Int, _187: Int, _188: Int, _189: Int, _190: Int, +_191: Int, _192: Int, _193: Int, _194: Int, _195: Int, _196: Int, _197: Int, _198: Int, _199: Int, _200: Int, +_201: Int, _202: Int, _203: Int, _204: Int, _205: Int, _206: Int, _207: Int, _208: Int, _209: Int, _210: Int, +_211: Int, _212: Int, _213: Int, _214: Int, _215: Int, _216: Int, _217: Int, _218: Int, _219: Int, _220: Int, +_221: Int, _222: Int, _223: Int, _224: Int, _225: Int, _226: Int, _227: Int, _228: Int, _229: Int, _230: Int, +_231: Int, _232: Int, _233: Int, _234: Int, _235: Int, _236: Int, _237: Int, _238: Int, _239: Int, _240: Int, +_241: Int, _242: Int, _243: Int, _244: Int, _245: Int, _246: Int, _247: Int, _248: Int, _249: Int, _250: Int, +_251: Int, _252: Int, _253: Int, _254: Int) diff --git a/tests/untried/neg/t7325.check b/tests/untried/neg/t7325.check new file mode 100644 index 000000000000..61c33f99b154 --- /dev/null +++ b/tests/untried/neg/t7325.check @@ -0,0 +1,19 @@ +t7325.scala:2: error: Missing conversion operator in '%'; use %% for literal %, %n for newline + println(f"%") + ^ +t7325.scala:4: error: Missing conversion operator in '%'; use %% for literal %, %n for newline + println(f"%%%") + ^ +t7325.scala:6: error: Missing conversion operator in '%'; use %% for literal %, %n for newline + println(f"%%%%%") + ^ +t7325.scala:16: error: Missing conversion operator in '%'; use %% for literal %, %n for newline + println(f"${0}%") + ^ +t7325.scala:19: error: conversions must follow a splice; use %% for literal %, %n for newline + println(f"${0}%%%d") + ^ +t7325.scala:21: error: conversions must follow a splice; use %% for literal %, %n for newline + println(f"${0}%%%%%d") + ^ +6 errors found diff --git a/tests/untried/neg/t7325.scala b/tests/untried/neg/t7325.scala new file mode 100644 index 000000000000..45a726d705a1 --- /dev/null +++ b/tests/untried/neg/t7325.scala @@ -0,0 +1,25 @@ +object Test extends App { + println(f"%") + println(f"%%") + println(f"%%%") + println(f"%%%%") + println(f"%%%%%") + println(f"%%%%%%") + + println(f"%%n") + println(f"%%%n") + println(f"%%%%n") + println(f"%%%%%n") + println(f"%%%%%%n") + println(f"%%%%%%%n") + + println(f"${0}%") + println(f"${0}%d") + println(f"${0}%%d") + println(f"${0}%%%d") + println(f"${0}%%%%d") + println(f"${0}%%%%%d") + + println(f"${0}%n") + println(f"${0}%d%n") +} diff --git a/tests/untried/neg/t7330.check b/tests/untried/neg/t7330.check new file mode 100644 index 000000000000..b96d656d2bb6 --- /dev/null +++ b/tests/untried/neg/t7330.check @@ -0,0 +1,5 @@ +t7330.scala:4: error: pattern must be a value: Y[_] +Note: if you intended to match against the class, try `case _: Y[_]` + 0 match { case Y[_] => } + ^ +one error found diff --git a/tests/untried/neg/t7330.scala b/tests/untried/neg/t7330.scala new file mode 100644 index 000000000000..2d1660fad1ec --- /dev/null +++ b/tests/untried/neg/t7330.scala @@ -0,0 +1,5 @@ +class Y[T] +class Test { + // TypeTree is not a valid tree for a pattern + 0 match { case Y[_] => } +} diff --git a/tests/untried/neg/t7369.check b/tests/untried/neg/t7369.check new file mode 100644 index 000000000000..a4e99f496e1d --- /dev/null +++ b/tests/untried/neg/t7369.check @@ -0,0 +1,15 @@ +t7369.scala:6: warning: unreachable code + case Tuple1(X) => // unreachable + ^ +t7369.scala:13: warning: unreachable code + case Tuple1(true) => // unreachable + ^ +t7369.scala:31: warning: unreachable code + case Tuple1(X) => // unreachable + ^ +t7369.scala:40: warning: unreachable code + case Tuple1(null) => // unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t7369.flags b/tests/untried/neg/t7369.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7369.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7369.scala b/tests/untried/neg/t7369.scala new file mode 100644 index 000000000000..87ddfe98b7aa --- /dev/null +++ b/tests/untried/neg/t7369.scala @@ -0,0 +1,43 @@ +object Test { + val X, Y = true + (null: Tuple1[Boolean]) match { + case Tuple1(X) => + case Tuple1(Y) => + case Tuple1(X) => // unreachable + case _ => + } + + (null: Tuple1[Boolean]) match { + case Tuple1(true) => + case Tuple1(false) => + case Tuple1(true) => // 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) => + case Tuple1(X) => // unreachable + case _ => + } +} + +object Test3 { + (null: Tuple1[B]) match { + case Tuple1(null) => + case Tuple1(True) => + case Tuple1(null) => // unreachable + case _ => + } +} diff --git a/tests/untried/neg/t7385.check b/tests/untried/neg/t7385.check new file mode 100644 index 000000000000..70d3c3fb61ae --- /dev/null +++ b/tests/untried/neg/t7385.check @@ -0,0 +1,10 @@ +t7385.scala:2: error: '(' expected but identifier found. + do { println("bippy") } while i<10 + ^ +t7385.scala:6: error: '(' expected but identifier found. + while i<10 { () } + ^ +t7385.scala:7: error: illegal start of simple expression +} +^ +three errors found diff --git a/tests/untried/neg/t7385.scala b/tests/untried/neg/t7385.scala new file mode 100644 index 000000000000..a7f801098bf6 --- /dev/null +++ b/tests/untried/neg/t7385.scala @@ -0,0 +1,7 @@ +object Bar { + do { println("bippy") } while i<10 +} + +object Foo { + while i<10 { () } +} diff --git a/tests/untried/neg/t7388.check b/tests/untried/neg/t7388.check new file mode 100644 index 000000000000..0a29e04896de --- /dev/null +++ b/tests/untried/neg/t7388.check @@ -0,0 +1,4 @@ +t7388.scala:1: error: doesnotexist is not an enclosing class +class Test private[doesnotexist]() + ^ +one error found diff --git a/tests/untried/neg/t7388.scala b/tests/untried/neg/t7388.scala new file mode 100644 index 000000000000..9ce9ea11b399 --- /dev/null +++ b/tests/untried/neg/t7388.scala @@ -0,0 +1 @@ +class Test private[doesnotexist]() diff --git a/tests/untried/neg/t742.check b/tests/untried/neg/t742.check new file mode 100644 index 000000000000..d35571544238 --- /dev/null +++ b/tests/untried/neg/t742.check @@ -0,0 +1,6 @@ +t742.scala:5: error: kinds of the type arguments (Crash._1,Crash._2,Any) do not conform to the expected kinds of the type parameters (type m,type n,type z). +Crash._1's type parameters do not match type m's expected parameters: +type s1 has one type parameter, but type n has two + type p = mul[_1, _2, Any] // mul[_1, _1, Any] needs -Yrecursion + ^ +one error found diff --git a/tests/untried/neg/t742.scala b/tests/untried/neg/t742.scala new file mode 100644 index 000000000000..cc0d7063c7ab --- /dev/null +++ b/tests/untried/neg/t742.scala @@ -0,0 +1,8 @@ +object Crash { + type mul[m[n[s[_], z], z], n[s[_], z], z] = m[n, z] + type _1[s1[_], z1] = s1[z1] + type _2[s1[_], z1] = s1[z1] + type p = mul[_1, _2, Any] // mul[_1, _1, Any] needs -Yrecursion + // _1[_2, Zero] + // _2[Zero] +} diff --git a/tests/untried/neg/t7473.check b/tests/untried/neg/t7473.check new file mode 100644 index 000000000000..bc8c29d46377 --- /dev/null +++ b/tests/untried/neg/t7473.check @@ -0,0 +1,7 @@ +t7473.scala:6: error: '<-' expected but '=' found. + (for (x = Option(i); if x == j) yield 42) toList + ^ +t7473.scala:6: error: illegal start of simple expression + (for (x = Option(i); if x == j) yield 42) toList + ^ +two errors found diff --git a/tests/untried/neg/t7473.scala b/tests/untried/neg/t7473.scala new file mode 100644 index 000000000000..593231d5f28e --- /dev/null +++ b/tests/untried/neg/t7473.scala @@ -0,0 +1,7 @@ + +object Foo { + val i,j = 3 + //for (x = Option(i); if x == j) yield 42 //t7473.scala:4: error: '<-' expected but '=' found. + // evil postfix! + (for (x = Option(i); if x == j) yield 42) toList +} diff --git a/tests/untried/neg/t7475c.check b/tests/untried/neg/t7475c.check new file mode 100644 index 000000000000..472808131ac5 --- /dev/null +++ b/tests/untried/neg/t7475c.check @@ -0,0 +1,7 @@ +t7475c.scala:6: error: value a is not a member of A.this.B + println(this.a) // wait, what? + ^ +t7475c.scala:7: error: value b is not a member of A.this.B + println(this.b) // wait, what? + ^ +two errors found diff --git a/tests/untried/neg/t7475c.scala b/tests/untried/neg/t7475c.scala new file mode 100644 index 000000000000..cd4a8762ca41 --- /dev/null +++ b/tests/untried/neg/t7475c.scala @@ -0,0 +1,9 @@ +class A { + private val a: Int = 0 + private[this] val b: Int = 0 + class B extends A { + def foo(a: A) = a.a // okay + println(this.a) // wait, what? + println(this.b) // wait, what? + } +} diff --git a/tests/untried/neg/t7475d.check b/tests/untried/neg/t7475d.check new file mode 100644 index 000000000000..6bd1da0d4405 --- /dev/null +++ b/tests/untried/neg/t7475d.check @@ -0,0 +1,7 @@ +t7475d.scala:4: error: value priv is not a member of T.this.TT + (??? : TT).priv + ^ +t7475d.scala:10: error: value priv is not a member of U.this.UU + (??? : UU).priv + ^ +two errors found diff --git a/tests/untried/neg/t7475e.check b/tests/untried/neg/t7475e.check new file mode 100644 index 000000000000..48af2be51a09 --- /dev/null +++ b/tests/untried/neg/t7475e.check @@ -0,0 +1,4 @@ +t7475e.scala:8: error: value priv is not a member of Base.this.TT + (??? : TT).priv + ^ +one error found diff --git a/tests/untried/neg/t7475e.scala b/tests/untried/neg/t7475e.scala new file mode 100644 index 000000000000..e5c4877d6eb1 --- /dev/null +++ b/tests/untried/neg/t7475e.scala @@ -0,0 +1,12 @@ +trait U { +} + +trait Base { + private val priv = 0 + + type TT = U with T // should exclude `priv` + (??? : TT).priv +} + +trait T extends Base { +} diff --git a/tests/untried/neg/t7475f.check b/tests/untried/neg/t7475f.check new file mode 100644 index 000000000000..a07a4480e224 --- /dev/null +++ b/tests/untried/neg/t7475f.check @@ -0,0 +1,10 @@ +t7475f.scala:12: error: method c1 in class C cannot be accessed in C[T] + c1 // a member, but inaccessible. + ^ +t7475f.scala:13: error: not found: value c2 + c2 // a member, but inaccessible. + ^ +t7475f.scala:26: error: value d2 is not a member of D[Any] + other.d2 // not a member + ^ +three errors found diff --git a/tests/untried/neg/t7475f.scala b/tests/untried/neg/t7475f.scala new file mode 100644 index 000000000000..eaac4a2e1de3 --- /dev/null +++ b/tests/untried/neg/t7475f.scala @@ -0,0 +1,28 @@ +class C[T] extends D[T] { + private def c1 = 0 + private[this] def c2 = 0 +} + +trait D[T] { + self: C[T] => + + private def d1 = 0 + private[this] def d2 = 0 + + c1 // a member, but inaccessible. + c2 // a member, but inaccessible. + + d1 // okay + d2 // okay + + + class C { + d1 + d2 + } + + def x(other: D[Any]): Unit = { + other.d1 + other.d2 // not a member + } +} diff --git a/tests/untried/neg/t7494-after-terminal.check b/tests/untried/neg/t7494-after-terminal.check new file mode 100644 index 000000000000..096efe09cded --- /dev/null +++ b/tests/untried/neg/t7494-after-terminal.check @@ -0,0 +1,2 @@ +error: [phase assembly, after dependency on terminal phase not allowed: afterterminal => terminal] +one error found diff --git a/tests/untried/neg/t7494-after-terminal/ThePlugin.scala b/tests/untried/neg/t7494-after-terminal/ThePlugin.scala new file mode 100644 index 000000000000..e8de8132ec42 --- /dev/null +++ b/tests/untried/neg/t7494-after-terminal/ThePlugin.scala @@ -0,0 +1,31 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "afterterminal" + val description = "Declares one plugin that wants to be after the terminal phase" + val components = List[PluginComponent](thePhase) + + private object thePhase extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]("terminal") + + val phaseName = ThePlugin.this.name + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = ThePlugin.this.name + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7494-after-terminal/sample_2.flags b/tests/untried/neg/t7494-after-terminal/sample_2.flags new file mode 100644 index 000000000000..b8a476e361ce --- /dev/null +++ b/tests/untried/neg/t7494-after-terminal/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:afterterminal diff --git a/tests/untried/neg/t7494-after-terminal/sample_2.scala b/tests/untried/neg/t7494-after-terminal/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-after-terminal/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-after-terminal/scalac-plugin.xml b/tests/untried/neg/t7494-after-terminal/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7494-after-terminal/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7494-before-parser.check b/tests/untried/neg/t7494-before-parser.check new file mode 100644 index 000000000000..9a407923b1dd --- /dev/null +++ b/tests/untried/neg/t7494-before-parser.check @@ -0,0 +1,2 @@ +error: [phase assembly, before dependency on parser phase not allowed: parser => beforeparser] +one error found diff --git a/tests/untried/neg/t7494-before-parser/ThePlugin.scala b/tests/untried/neg/t7494-before-parser/ThePlugin.scala new file mode 100644 index 000000000000..bb335c9c9dcd --- /dev/null +++ b/tests/untried/neg/t7494-before-parser/ThePlugin.scala @@ -0,0 +1,32 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "beforeparser" + val description = "Declares one plugin that wants to be before the parser phase" + val components = List[PluginComponent](thePhase) + + private object thePhase extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]() + override val runsBefore = List[String]("parser") + + val phaseName = ThePlugin.this.name + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = ThePlugin.this.name + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7494-before-parser/sample_2.flags b/tests/untried/neg/t7494-before-parser/sample_2.flags new file mode 100644 index 000000000000..0c92fc8a06ea --- /dev/null +++ b/tests/untried/neg/t7494-before-parser/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:beforeparser diff --git a/tests/untried/neg/t7494-before-parser/sample_2.scala b/tests/untried/neg/t7494-before-parser/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-before-parser/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-before-parser/scalac-plugin.xml b/tests/untried/neg/t7494-before-parser/scalac-plugin.xml new file mode 100644 index 000000000000..90ff27dc2a3d --- /dev/null +++ b/tests/untried/neg/t7494-before-parser/scalac-plugin.xml @@ -0,0 +1,5 @@ + + beforeparser + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7494-multi-right-after.check b/tests/untried/neg/t7494-multi-right-after.check new file mode 100644 index 000000000000..151d17741484 --- /dev/null +++ b/tests/untried/neg/t7494-multi-right-after.check @@ -0,0 +1 @@ +error: Multiple phases want to run right after explicitouter; followers: erasure,multi-rafter; created phase-order.dot diff --git a/tests/untried/neg/t7494-multi-right-after/ThePlugin.scala b/tests/untried/neg/t7494-multi-right-after/ThePlugin.scala new file mode 100644 index 000000000000..cb9e86e90675 --- /dev/null +++ b/tests/untried/neg/t7494-multi-right-after/ThePlugin.scala @@ -0,0 +1,31 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "multi-rafter" + val description = "" + val components = List[PluginComponent](thePhase) + + private object thePhase extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]() + override val runsRightAfter = Some("explicitouter") + val phaseName = ThePlugin.this.name + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = ThePlugin.this.name + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7494-multi-right-after/sample_2.flags b/tests/untried/neg/t7494-multi-right-after/sample_2.flags new file mode 100644 index 000000000000..9273fb98d7bf --- /dev/null +++ b/tests/untried/neg/t7494-multi-right-after/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:multi-rafter diff --git a/tests/untried/neg/t7494-multi-right-after/sample_2.scala b/tests/untried/neg/t7494-multi-right-after/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-multi-right-after/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-multi-right-after/scalac-plugin.xml b/tests/untried/neg/t7494-multi-right-after/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7494-multi-right-after/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7494-no-options.check b/tests/untried/neg/t7494-no-options.check new file mode 100644 index 000000000000..e3316f590a68 --- /dev/null +++ b/tests/untried/neg/t7494-no-options.check @@ -0,0 +1,40 @@ +error: Error: ploogin takes no options + phase name id description + ---------- -- ----------- + parser 1 parse source into ASTs, perform simple desugaring + namer 2 resolve names, attach symbols to named trees +packageobjects 3 load package objects + typer 4 the meat and potatoes: type the trees + patmat 5 translate match expressions +superaccessors 6 add super accessors in traits and nested classes + extmethods 7 add extension methods for inline classes + pickler 8 serialize symbol tables + refchecks 9 reference/override checking, translate nested objects + uncurry 10 uncurry, translate function values to anonymous classes + tailcalls 11 replace tail calls by jumps + specialize 12 @specialized-driven class and method specialization + explicitouter 13 this refs to outer pointers + erasure 14 erase types, add interfaces for traits + posterasure 15 clean up erased inline classes + lazyvals 16 allocate bitmaps, translate lazy vals into lazified defs + lambdalift 17 move nested functions to top level + constructors 18 move field definitions into constructors + flatten 19 eliminate inner classes + mixin 20 mixin composition + cleanup 21 platform-specific cleanups, generate reflective calls + delambdafy 22 remove lambdas + icode 23 generate portable intermediate code +#partest !-optimise + jvm 24 generate JVM bytecode + ploogin 25 A sample phase that does so many things it's kind of hard... + terminal 26 the last phase during a compilation run +#partest -optimise + inliner 24 optimization: do inlining +inlinehandlers 25 optimization: inline exception handlers + closelim 26 optimization: eliminate uncalled closures + constopt 27 optimization: optimize null and other constants + dce 28 optimization: eliminate dead code + jvm 29 generate JVM bytecode + ploogin 30 A sample phase that does so many things it's kind of hard... + terminal 31 the last phase during a compilation run +#partest diff --git a/tests/untried/neg/t7494-no-options/ploogin_1.scala b/tests/untried/neg/t7494-no-options/ploogin_1.scala new file mode 100644 index 000000000000..dbf433f9a41d --- /dev/null +++ b/tests/untried/neg/t7494-no-options/ploogin_1.scala @@ -0,0 +1,31 @@ + +package t6446 + +import scala.tools.nsc.{ Global, Phase } +import scala.tools.nsc.plugins.{ Plugin, PluginComponent } +import scala.reflect.io.Path +import scala.reflect.io.File + +/** A test plugin. */ +class Ploogin(val global: Global) extends Plugin { + import global._ + + val name = "ploogin" + val description = "A sample plugin for testing." + val components = List[PluginComponent](TestComponent) + + private object TestComponent extends PluginComponent { + val global: Ploogin.this.global.type = Ploogin.this.global + //override val runsBefore = List("refchecks") + val runsAfter = List("jvm") + val phaseName = Ploogin.this.name + override def description = "A sample phase that does so many things it's kind of hard to describe briefly." + def newPhase(prev: Phase) = new TestPhase(prev) + class TestPhase(prev: Phase) extends StdPhase(prev) { + override def description = TestComponent.this.description + def apply(unit: CompilationUnit): Unit = { + // kewl kode + } + } + } +} diff --git a/tests/untried/neg/t7494-no-options/sample_2.flags b/tests/untried/neg/t7494-no-options/sample_2.flags new file mode 100644 index 000000000000..7f0f7afe4883 --- /dev/null +++ b/tests/untried/neg/t7494-no-options/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xshow-phases -P:ploogin:inploog diff --git a/tests/untried/neg/t7494-no-options/sample_2.scala b/tests/untried/neg/t7494-no-options/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-no-options/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-no-options/scalac-plugin.xml b/tests/untried/neg/t7494-no-options/scalac-plugin.xml new file mode 100644 index 000000000000..e849bb59197e --- /dev/null +++ b/tests/untried/neg/t7494-no-options/scalac-plugin.xml @@ -0,0 +1,4 @@ + +sample-plugin +t6446.Ploogin + diff --git a/tests/untried/neg/t7494-right-after-before.check b/tests/untried/neg/t7494-right-after-before.check new file mode 100644 index 000000000000..7e83daab4ade --- /dev/null +++ b/tests/untried/neg/t7494-right-after-before.check @@ -0,0 +1 @@ +error: Phase erasure can't follow explicitouter, created phase-order.dot diff --git a/tests/untried/neg/t7494-right-after-before/ThePlugin.scala b/tests/untried/neg/t7494-right-after-before/ThePlugin.scala new file mode 100644 index 000000000000..967c1fb30705 --- /dev/null +++ b/tests/untried/neg/t7494-right-after-before/ThePlugin.scala @@ -0,0 +1,31 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "rafter-before-1" + val description = "" + val components = List[PluginComponent](thePhase1) + + private object thePhase1 extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]("refchecks") + override val runsBefore = List[String]("erasure") + val phaseName = ThePlugin.this.name + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = ThePlugin.this.name + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7494-right-after-before/sample_2.flags b/tests/untried/neg/t7494-right-after-before/sample_2.flags new file mode 100644 index 000000000000..97d0f5b5f6f7 --- /dev/null +++ b/tests/untried/neg/t7494-right-after-before/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:rafter-before-1 diff --git a/tests/untried/neg/t7494-right-after-before/sample_2.scala b/tests/untried/neg/t7494-right-after-before/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-right-after-before/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-right-after-before/scalac-plugin.xml b/tests/untried/neg/t7494-right-after-before/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7494-right-after-before/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7494-right-after-terminal.check b/tests/untried/neg/t7494-right-after-terminal.check new file mode 100644 index 000000000000..6fe4f63c823a --- /dev/null +++ b/tests/untried/neg/t7494-right-after-terminal.check @@ -0,0 +1,2 @@ +error: [phase assembly, right after dependency on terminal phase not allowed: rightafterterminal => terminal] +one error found diff --git a/tests/untried/neg/t7494-right-after-terminal/ThePlugin.scala b/tests/untried/neg/t7494-right-after-terminal/ThePlugin.scala new file mode 100644 index 000000000000..7c4d084582de --- /dev/null +++ b/tests/untried/neg/t7494-right-after-terminal/ThePlugin.scala @@ -0,0 +1,32 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "rightafterterminal" + val description = "Declares one plugin that wants to be right after the terminal phase" + val components = List[PluginComponent](thePhase) + + private object thePhase extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]() + override val runsRightAfter = Some("terminal") + + val phaseName = ThePlugin.this.name + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = ThePlugin.this.name + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7494-right-after-terminal/sample_2.flags b/tests/untried/neg/t7494-right-after-terminal/sample_2.flags new file mode 100644 index 000000000000..da046ba5f170 --- /dev/null +++ b/tests/untried/neg/t7494-right-after-terminal/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:rightafterterminal diff --git a/tests/untried/neg/t7494-right-after-terminal/sample_2.scala b/tests/untried/neg/t7494-right-after-terminal/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7494-right-after-terminal/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7494-right-after-terminal/scalac-plugin.xml b/tests/untried/neg/t7494-right-after-terminal/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7494-right-after-terminal/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t750.check b/tests/untried/neg/t750.check new file mode 100644 index 000000000000..c17ca334e663 --- /dev/null +++ b/tests/untried/neg/t750.check @@ -0,0 +1,15 @@ +Test_2.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO_1.f(a) + ^ +Test_2.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO_1.f[Int](a) + ^ +two errors found diff --git a/tests/untried/neg/t750/AO_1.java b/tests/untried/neg/t750/AO_1.java new file mode 100644 index 000000000000..4c7360ec6fc6 --- /dev/null +++ b/tests/untried/neg/t750/AO_1.java @@ -0,0 +1,5 @@ +public class AO_1 { + public static void f(T[] ar0) { + System.out.println(ar0); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t750/Test_2.scala b/tests/untried/neg/t750/Test_2.scala new file mode 100644 index 000000000000..80977431c54e --- /dev/null +++ b/tests/untried/neg/t750/Test_2.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO_1.f(a) + AO_1.f[Int](a) +} diff --git a/tests/untried/neg/t7501.check b/tests/untried/neg/t7501.check new file mode 100644 index 000000000000..2ded07c7ed81 --- /dev/null +++ b/tests/untried/neg/t7501.check @@ -0,0 +1,7 @@ +t7501_2.scala:2: error: value name is not a member of A + def foo(a: A) = a.name + ^ +t7501_2.scala:4: error: not found: type X + type TP = X // already failed before this fix + ^ +two errors found diff --git a/tests/untried/neg/t7501/t7501_1.scala b/tests/untried/neg/t7501/t7501_1.scala new file mode 100644 index 000000000000..323c3276235e --- /dev/null +++ b/tests/untried/neg/t7501/t7501_1.scala @@ -0,0 +1,12 @@ +object Test2 { + def test[X](name: String) = 12 +} +class strangeTest(x: Int) extends scala.annotation.StaticAnnotation + +trait A { + // When picking the type of `test`, the value parameter + // `x` was pickled with the owner `trait A`. On unpickling, + // it was taken to be a member! + @strangeTest(Test2.test("test")) + def test(x: String): Unit +} diff --git a/tests/untried/neg/t7501/t7501_2.scala b/tests/untried/neg/t7501/t7501_2.scala new file mode 100644 index 000000000000..044caea3c35c --- /dev/null +++ b/tests/untried/neg/t7501/t7501_2.scala @@ -0,0 +1,5 @@ +object Test { + def foo(a: A) = a.name + + type TP = X // already failed before this fix +} diff --git a/tests/untried/neg/t7507.check b/tests/untried/neg/t7507.check new file mode 100644 index 000000000000..de30fc705737 --- /dev/null +++ b/tests/untried/neg/t7507.check @@ -0,0 +1,4 @@ +t7507.scala:6: error: not found: value bippy + locally(bippy) + ^ +one error found diff --git a/tests/untried/neg/t7507.scala b/tests/untried/neg/t7507.scala new file mode 100644 index 000000000000..1b4756d955b8 --- /dev/null +++ b/tests/untried/neg/t7507.scala @@ -0,0 +1,7 @@ +trait Cake extends Slice { + private[this] val bippy = () +} + +trait Slice { self: Cake => + locally(bippy) +} diff --git a/tests/untried/neg/t7509.check b/tests/untried/neg/t7509.check new file mode 100644 index 000000000000..eaa6303cf520 --- /dev/null +++ b/tests/untried/neg/t7509.check @@ -0,0 +1,12 @@ +t7509.scala:3: error: inferred type arguments [Int] do not conform to method crash's type parameter bounds [R <: AnyRef] + crash(42) + ^ +t7509.scala:3: error: type mismatch; + found : Int(42) + required: R + crash(42) + ^ +t7509.scala:3: error: could not find implicit value for parameter ev: R + crash(42) + ^ +three errors found diff --git a/tests/untried/neg/t7509.scala b/tests/untried/neg/t7509.scala new file mode 100644 index 000000000000..3cba801ea7cf --- /dev/null +++ b/tests/untried/neg/t7509.scala @@ -0,0 +1,4 @@ +object NMWE { + def crash[R <: AnyRef](f: R)(implicit ev: R): Any = ??? + crash(42) +} diff --git a/tests/untried/neg/t750b.check b/tests/untried/neg/t750b.check new file mode 100644 index 000000000000..72a249191ebe --- /dev/null +++ b/tests/untried/neg/t750b.check @@ -0,0 +1,15 @@ +Test.scala:4: error: type mismatch; + found : Array[Int] + required: Array[? with Object] +Note: Int >: ? with Object, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10) + AO.f(a) + ^ +Test.scala:5: error: type mismatch; + found : Array[Int] + required: Array[Int] +Note: Int >: Int, but class Array is invariant in type T. +You may wish to investigate a wildcard type such as `_ >: Int`. (SLS 3.2.10) + AO.f[Int](a) + ^ +two errors found diff --git a/tests/untried/neg/t750b/AO.java b/tests/untried/neg/t750b/AO.java new file mode 100644 index 000000000000..060baf9a3cf8 --- /dev/null +++ b/tests/untried/neg/t750b/AO.java @@ -0,0 +1,5 @@ +public class AO { + public static void f(T[] ar0) { + System.out.println(ar0); + } +} \ No newline at end of file diff --git a/tests/untried/neg/t750b/Test.scala b/tests/untried/neg/t750b/Test.scala new file mode 100644 index 000000000000..5f792a7be860 --- /dev/null +++ b/tests/untried/neg/t750b/Test.scala @@ -0,0 +1,6 @@ +// t750 +object Test extends App { + val a = Array(1, 2, 3) + AO.f(a) + AO.f[Int](a) +} diff --git a/tests/untried/neg/t7519-b.check b/tests/untried/neg/t7519-b.check new file mode 100644 index 000000000000..bc8500b2b875 --- /dev/null +++ b/tests/untried/neg/t7519-b.check @@ -0,0 +1,6 @@ +Use_2.scala:8: error: type mismatch; + found : String + required: Q + val x: Q = ex.Mac.mac("asdf") + ^ +one error found diff --git a/tests/untried/neg/t7519-b/Mac_1.scala b/tests/untried/neg/t7519-b/Mac_1.scala new file mode 100644 index 000000000000..55b583d24be7 --- /dev/null +++ b/tests/untried/neg/t7519-b/Mac_1.scala @@ -0,0 +1,14 @@ +// get expected error message without package declaration +package ex + +import scala.language.experimental.macros +import scala.reflect.macros._ + +object IW { + def foo(a: String): String = ??? +} +object Mac { + def mac(s: String): String = macro macImpl + def macImpl(c: Context)(s: c.Expr[String]): c.Expr[String] = + c.universe.reify(IW.foo(s.splice)) +} diff --git a/tests/untried/neg/t7519-b/Use_2.scala b/tests/untried/neg/t7519-b/Use_2.scala new file mode 100644 index 000000000000..0d63eeed5bde --- /dev/null +++ b/tests/untried/neg/t7519-b/Use_2.scala @@ -0,0 +1,10 @@ +import scala.language.implicitConversions + +trait Q +trait K + +object Use { + implicit def cd[T](p: T)(implicit ev: T => K): Q = ??? + val x: Q = ex.Mac.mac("asdf") +} + diff --git a/tests/untried/neg/t7519.check b/tests/untried/neg/t7519.check new file mode 100644 index 000000000000..df54abaa3e23 --- /dev/null +++ b/tests/untried/neg/t7519.check @@ -0,0 +1,11 @@ +t7519.scala:5: error: type mismatch; + found : Int(0) + required: String + locally(0 : String) // was: "value conversion is not a member of C.this.C" + ^ +t7519.scala:15: error: type mismatch; + found : Int(0) + required: String + locally(0 : String) // was: "value conversion is not a member of U" + ^ +two errors found diff --git a/tests/untried/neg/t7519.scala b/tests/untried/neg/t7519.scala new file mode 100644 index 000000000000..aea0f35d8ef2 --- /dev/null +++ b/tests/untried/neg/t7519.scala @@ -0,0 +1,18 @@ +class C { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + class C { // rename class to get correct error, can't find implicit: Nothing. + locally(0 : String) // was: "value conversion is not a member of C.this.C" + } +} + +object Test2 { + trait T; trait U + new T { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + new U { // nested anonymous classes also share a name. + locally(0 : String) // was: "value conversion is not a member of U" + } + } +} diff --git a/tests/untried/neg/t752.check b/tests/untried/neg/t752.check new file mode 100644 index 000000000000..a91bba46eaa5 --- /dev/null +++ b/tests/untried/neg/t752.check @@ -0,0 +1,6 @@ +t752.scala:6: error: type mismatch; + found : String => Unit + required: Int => Unit + f(g _) + ^ +one error found diff --git a/tests/untried/neg/t752.scala b/tests/untried/neg/t752.scala new file mode 100644 index 000000000000..00f45e323c89 --- /dev/null +++ b/tests/untried/neg/t752.scala @@ -0,0 +1,8 @@ +object Test +{ + def f(x : Int => Unit) : Unit = () + def g(x : String) : Unit = () + def main(argv : Array[String]) = { + f(g _) + } +} diff --git a/tests/untried/neg/t7605-deprecation.check b/tests/untried/neg/t7605-deprecation.check new file mode 100644 index 000000000000..6db94613a103 --- /dev/null +++ b/tests/untried/neg/t7605-deprecation.check @@ -0,0 +1,15 @@ +t7605-deprecation.scala:2: warning: Procedure syntax is deprecated. Convert procedure `bar` to method by adding `: Unit =`. + def bar {} + ^ +t7605-deprecation.scala:3: warning: Procedure syntax is deprecated. Convert procedure `baz` to method by adding `: Unit`. + def baz + ^ +t7605-deprecation.scala:4: warning: Procedure syntax is deprecated. Convert procedure `boo` to method by adding `: Unit`. + def boo(i: Int, l: Long) + ^ +t7605-deprecation.scala:5: warning: Procedure syntax is deprecated. Convert procedure `boz` to method by adding `: Unit =`. + def boz(i: Int, l: Long) {} + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/t7605-deprecation.flags b/tests/untried/neg/t7605-deprecation.flags new file mode 100644 index 000000000000..0a7cb7d20251 --- /dev/null +++ b/tests/untried/neg/t7605-deprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfuture -Xfatal-warnings diff --git a/tests/untried/neg/t7605-deprecation.scala b/tests/untried/neg/t7605-deprecation.scala new file mode 100644 index 000000000000..30cd21bd69bf --- /dev/null +++ b/tests/untried/neg/t7605-deprecation.scala @@ -0,0 +1,8 @@ +abstract class Foo { + def bar: Unit = {} + def baz + def boo(i: Int, l: Long) + def boz(i: Int, l: Long): Unit = {} + def this(i: Int) { this() } // Don't complain here! + def foz: Unit // Don't complain here! +} diff --git a/tests/untried/neg/t7622-cyclic-dependency.check b/tests/untried/neg/t7622-cyclic-dependency.check new file mode 100644 index 000000000000..3546964f5f68 --- /dev/null +++ b/tests/untried/neg/t7622-cyclic-dependency.check @@ -0,0 +1 @@ +error: Cycle in phase dependencies detected at cyclicdependency1, created phase-cycle.dot diff --git a/tests/untried/neg/t7622-cyclic-dependency/ThePlugin.scala b/tests/untried/neg/t7622-cyclic-dependency/ThePlugin.scala new file mode 100644 index 000000000000..8074966bb628 --- /dev/null +++ b/tests/untried/neg/t7622-cyclic-dependency/ThePlugin.scala @@ -0,0 +1,40 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "cyclicdependency" + val description = "Declares two phases that have a cyclic dependency" + val components = List[PluginComponent](thePhase1,thePhase2) + + private object thePhase1 extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]("tailcalls","cyclicdependency2") + + val phaseName = ThePlugin.this.name + "1" + + def newPhase(prev: Phase) = new ThePhase(prev, phaseName) + } + + private object thePhase2 extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]("dce","cyclicdependency1") + + val phaseName = ThePlugin.this.name + "2" + + def newPhase(prev: Phase) = new ThePhase(prev, phaseName) + } + + private class ThePhase(prev: Phase, val name: String) extends Phase(prev) { + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7622-cyclic-dependency/sample_2.flags b/tests/untried/neg/t7622-cyclic-dependency/sample_2.flags new file mode 100644 index 000000000000..db25b88a1297 --- /dev/null +++ b/tests/untried/neg/t7622-cyclic-dependency/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:cyclicdependency diff --git a/tests/untried/neg/t7622-cyclic-dependency/sample_2.scala b/tests/untried/neg/t7622-cyclic-dependency/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7622-cyclic-dependency/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7622-cyclic-dependency/scalac-plugin.xml b/tests/untried/neg/t7622-cyclic-dependency/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7622-cyclic-dependency/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7622-missing-dependency.check b/tests/untried/neg/t7622-missing-dependency.check new file mode 100644 index 000000000000..a0d0e308705a --- /dev/null +++ b/tests/untried/neg/t7622-missing-dependency.check @@ -0,0 +1,2 @@ +error: Phase 'myplugin' requires: List(missing) +one error found diff --git a/tests/untried/neg/t7622-missing-dependency/ThePlugin.scala b/tests/untried/neg/t7622-missing-dependency/ThePlugin.scala new file mode 100644 index 000000000000..0fcbc6309ad6 --- /dev/null +++ b/tests/untried/neg/t7622-missing-dependency/ThePlugin.scala @@ -0,0 +1,33 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "myplugin" + val description = "Declares one plugin with a missing requirement" + val components = List[PluginComponent](thePhase) + + private object thePhase extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]("typer") + + val phaseName = ThePlugin.this.name + + override val requires = List("missing") + + def newPhase(prev: Phase) = new ThePhase(prev) + } + + private class ThePhase(prev: Phase) extends Phase(prev) { + def name = thePhase.phaseName + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7622-missing-dependency/sample_2.flags b/tests/untried/neg/t7622-missing-dependency/sample_2.flags new file mode 100644 index 000000000000..d69035100e6b --- /dev/null +++ b/tests/untried/neg/t7622-missing-dependency/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:myplugin diff --git a/tests/untried/neg/t7622-missing-dependency/sample_2.scala b/tests/untried/neg/t7622-missing-dependency/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7622-missing-dependency/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7622-missing-dependency/scalac-plugin.xml b/tests/untried/neg/t7622-missing-dependency/scalac-plugin.xml new file mode 100644 index 000000000000..3c14061dce37 --- /dev/null +++ b/tests/untried/neg/t7622-missing-dependency/scalac-plugin.xml @@ -0,0 +1,5 @@ + + myplugin + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7622-missing-required.check b/tests/untried/neg/t7622-missing-required.check new file mode 100644 index 000000000000..5982178581c0 --- /dev/null +++ b/tests/untried/neg/t7622-missing-required.check @@ -0,0 +1,2 @@ +error: Missing required plugin: special-plugin +one error found diff --git a/tests/untried/neg/t7622-missing-required.flags b/tests/untried/neg/t7622-missing-required.flags new file mode 100644 index 000000000000..65deac6febd1 --- /dev/null +++ b/tests/untried/neg/t7622-missing-required.flags @@ -0,0 +1 @@ +-Xplugin-require:special-plugin diff --git a/tests/untried/neg/t7622-missing-required.scala b/tests/untried/neg/t7622-missing-required.scala new file mode 100644 index 000000000000..a0ba487b2442 --- /dev/null +++ b/tests/untried/neg/t7622-missing-required.scala @@ -0,0 +1,4 @@ + +// the amazing features of this trait +// are unlocked by compiling with a special plugin. +trait Amazing diff --git a/tests/untried/neg/t7622-multi-followers.check b/tests/untried/neg/t7622-multi-followers.check new file mode 100644 index 000000000000..d123853a5b7b --- /dev/null +++ b/tests/untried/neg/t7622-multi-followers.check @@ -0,0 +1 @@ +error: Multiple phases want to run right after parser; followers: multi1,multi2; created phase-order.dot diff --git a/tests/untried/neg/t7622-multi-followers/ThePlugin.scala b/tests/untried/neg/t7622-multi-followers/ThePlugin.scala new file mode 100644 index 000000000000..36ee84f94a3f --- /dev/null +++ b/tests/untried/neg/t7622-multi-followers/ThePlugin.scala @@ -0,0 +1,44 @@ +package scala.test.plugins + +import scala.tools.nsc +import nsc.Global +import nsc.Phase +import nsc.plugins.Plugin +import nsc.plugins.PluginComponent + +class ThePlugin(val global: Global) extends Plugin { + import global._ + + val name = "multi" + val description = "Declares two phases that both follow parser" + val components = List[PluginComponent](thePhase1,thePhase2) + + private object thePhase1 extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]() + + override val runsRightAfter = Some("parser") + + val phaseName = ThePlugin.this.name + "1" + + def newPhase(prev: Phase) = new ThePhase(prev, phaseName) + } + + private object thePhase2 extends PluginComponent { + val global = ThePlugin.this.global + + val runsAfter = List[String]() + + override val runsRightAfter = Some("parser") + + val phaseName = ThePlugin.this.name + "2" + + def newPhase(prev: Phase) = new ThePhase(prev, phaseName) + } + + private class ThePhase(prev: Phase, val name: String) extends Phase(prev) { + def run: Unit = {} + } +} + diff --git a/tests/untried/neg/t7622-multi-followers/sample_2.flags b/tests/untried/neg/t7622-multi-followers/sample_2.flags new file mode 100644 index 000000000000..d2e83e97230b --- /dev/null +++ b/tests/untried/neg/t7622-multi-followers/sample_2.flags @@ -0,0 +1 @@ +-Xplugin:. -Xplugin-require:multi diff --git a/tests/untried/neg/t7622-multi-followers/sample_2.scala b/tests/untried/neg/t7622-multi-followers/sample_2.scala new file mode 100644 index 000000000000..73cdc64e40fb --- /dev/null +++ b/tests/untried/neg/t7622-multi-followers/sample_2.scala @@ -0,0 +1,6 @@ + +package sample + +// just a sample that is compiled with the sample plugin enabled +object Sample extends App { +} diff --git a/tests/untried/neg/t7622-multi-followers/scalac-plugin.xml b/tests/untried/neg/t7622-multi-followers/scalac-plugin.xml new file mode 100644 index 000000000000..2558d6fd03d8 --- /dev/null +++ b/tests/untried/neg/t7622-multi-followers/scalac-plugin.xml @@ -0,0 +1,5 @@ + + ignored + scala.test.plugins.ThePlugin + + diff --git a/tests/untried/neg/t7629-view-bounds-deprecation.check b/tests/untried/neg/t7629-view-bounds-deprecation.check new file mode 100644 index 000000000000..ed77c15c547b --- /dev/null +++ b/tests/untried/neg/t7629-view-bounds-deprecation.check @@ -0,0 +1,11 @@ +t7629-view-bounds-deprecation.scala:2: warning: View bounds are deprecated. Use an implicit parameter instead. +Example: Instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`. + def f[A <% Int](a: A) = null + ^ +t7629-view-bounds-deprecation.scala:3: warning: View bounds are deprecated. Use an implicit parameter instead. +Example: Instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`. + def g[C, B <: C, A <% B : Numeric](a: A) = null + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/t7629-view-bounds-deprecation.flags b/tests/untried/neg/t7629-view-bounds-deprecation.flags new file mode 100644 index 000000000000..43a25d4ccc01 --- /dev/null +++ b/tests/untried/neg/t7629-view-bounds-deprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings -Xfuture diff --git a/tests/untried/neg/t7629-view-bounds-deprecation.scala b/tests/untried/neg/t7629-view-bounds-deprecation.scala new file mode 100644 index 000000000000..a6ede1fcc3dd --- /dev/null +++ b/tests/untried/neg/t7629-view-bounds-deprecation.scala @@ -0,0 +1,4 @@ +object Test { + def f[A <% Int](a: A) = null + def g[C, B <: C, A <% B : Numeric](a: A) = null +} diff --git a/tests/untried/neg/t7636.check b/tests/untried/neg/t7636.check new file mode 100644 index 000000000000..f70d50bee3c5 --- /dev/null +++ b/tests/untried/neg/t7636.check @@ -0,0 +1,10 @@ +t7636.scala:3: error: illegal inheritance; + self-type Main.C does not conform to Main.ResultTable[_$3]'s selftype Main.ResultTable[_$3] + class C extends ResultTable(Left(5):Either[_,_])(5) + ^ +t7636.scala:3: error: type mismatch; + found : Either[_$2,_$3(in constructor C)] where type _$3(in constructor C), type _$2 + required: Either[_, _$3(in object Main)] where type _$3(in object Main) + class C extends ResultTable(Left(5):Either[_,_])(5) + ^ +two errors found diff --git a/tests/untried/neg/t7636.scala b/tests/untried/neg/t7636.scala new file mode 100644 index 000000000000..e801beacc9fe --- /dev/null +++ b/tests/untried/neg/t7636.scala @@ -0,0 +1,7 @@ +object Main extends App{ + class ResultTable[E]( query : Either[_,E] )( columns : Int ) + class C extends ResultTable(Left(5):Either[_,_])(5) +} +// Inference of the existential type for the parent type argument +// E still fails. That looks tricky to fix, see the comments in SI-7636. +// But we at least prevent a cascading NPE. diff --git a/tests/untried/neg/t765.check b/tests/untried/neg/t765.check new file mode 100644 index 000000000000..5a5f60325242 --- /dev/null +++ b/tests/untried/neg/t765.check @@ -0,0 +1,4 @@ +t765.scala:3: error: not found: type Bar123 + val bar = new Bar123 + ^ +one error found diff --git a/tests/untried/neg/t765.scala b/tests/untried/neg/t765.scala new file mode 100644 index 000000000000..3e5371b5332e --- /dev/null +++ b/tests/untried/neg/t765.scala @@ -0,0 +1,7 @@ +object test { + for (e <- List()) { //required + val bar = new Bar123 + val res = bar.f //required + () + } +} diff --git a/tests/untried/neg/t766.check b/tests/untried/neg/t766.check new file mode 100644 index 000000000000..92039ed1ff48 --- /dev/null +++ b/tests/untried/neg/t766.check @@ -0,0 +1,4 @@ +t766.scala:5: error: not found: value badIdentifier + val p = badIdentifier + ^ +one error found diff --git a/tests/untried/neg/t766.scala b/tests/untried/neg/t766.scala new file mode 100644 index 000000000000..b4b04d9642c9 --- /dev/null +++ b/tests/untried/neg/t766.scala @@ -0,0 +1,9 @@ +object B +{ + def a = { + for (n <- Nil; m <- Nil) { + val p = badIdentifier + false + } + } +} diff --git a/tests/untried/neg/t7669.check b/tests/untried/neg/t7669.check new file mode 100644 index 000000000000..c090ed18cebe --- /dev/null +++ b/tests/untried/neg/t7669.check @@ -0,0 +1,7 @@ +t7669.scala:9: warning: match may not be exhaustive. +It would fail on the following input: NotHandled(_) + def exhausto(expr: Expr): Unit = expr match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7669.flags b/tests/untried/neg/t7669.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t7669.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t7669.scala b/tests/untried/neg/t7669.scala new file mode 100644 index 000000000000..12441ec05693 --- /dev/null +++ b/tests/untried/neg/t7669.scala @@ -0,0 +1,13 @@ +object Test { + + sealed abstract class Expr + // Change type of `arg` to `Any` and the exhaustiveness warning + // is issued below + case class Op(arg: Expr) extends Expr + case class NotHandled(num: Double) extends Expr + + def exhausto(expr: Expr): Unit = expr match { + case Op(Op(_)) => + case Op(_) => + } +} diff --git a/tests/untried/neg/t771.check b/tests/untried/neg/t771.check new file mode 100644 index 000000000000..c0d1e002f8aa --- /dev/null +++ b/tests/untried/neg/t771.check @@ -0,0 +1,4 @@ +t771.scala:4: error: trait Iterator is abstract; cannot be instantiated + def c[A](it:java.util.Iterator[A]) = new scala.Iterator[A] + ^ +one error found diff --git a/tests/untried/neg/t771.scala b/tests/untried/neg/t771.scala new file mode 100755 index 000000000000..26bf44164859 --- /dev/null +++ b/tests/untried/neg/t771.scala @@ -0,0 +1,5 @@ +class Foo { + def a = c(b) + def b[List[AnyRef]] = new java.util.Iterator[List[Object]] { } + def c[A](it:java.util.Iterator[A]) = new scala.Iterator[A] +} diff --git a/tests/untried/neg/t7715.check b/tests/untried/neg/t7715.check new file mode 100644 index 000000000000..4ee6b6c95dec --- /dev/null +++ b/tests/untried/neg/t7715.check @@ -0,0 +1,13 @@ +t7715.scala:8: error: error in interpolated string: identifier or block expected + days map s"On the $_th day of Christmas" foreach println + ^ +t7715.scala:10: error: error in interpolated string: identifier or block expected + val rf = (n: Int) => s"\\*{$_}"(n).r + ^ +t7715.scala:17: error: unbound placeholder parameter + days zip days map s"${_: Int} by ${_: Int}".tupled foreach println + ^ +t7715.scala:17: error: unbound placeholder parameter + days zip days map s"${_: Int} by ${_: Int}".tupled foreach println + ^ +four errors found diff --git a/tests/untried/neg/t7715.scala b/tests/untried/neg/t7715.scala new file mode 100644 index 000000000000..637ab8df6d81 --- /dev/null +++ b/tests/untried/neg/t7715.scala @@ -0,0 +1,18 @@ + +import PartialFunction.cond +import util._ + +object Test extends App { + val days = (1 to 12).toList + + days map s"On the $_th day of Christmas" foreach println + + val rf = (n: Int) => s"\\*{$_}"(n).r + def stars(n: Int)(s: String) = { + val r = rf(n) + cond(s) { case r(_*) => true } + } + Console println stars(5)("*****") + + days zip days map s"${_: Int} by ${_: Int}".tupled foreach println +} diff --git a/tests/untried/neg/t7721.check b/tests/untried/neg/t7721.check new file mode 100644 index 000000000000..ade1ca3b206c --- /dev/null +++ b/tests/untried/neg/t7721.check @@ -0,0 +1,27 @@ +t7721.scala:11: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Concrete => x.bippy + x.conco + ^ +t7721.scala:15: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Concrete with Foo => x.bippy + x.conco + ^ +t7721.scala:19: warning: abstract type pattern A.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Bar => x.bippy + x.barry + ^ +t7721.scala:19: warning: abstract type pattern A.this.Bar is unchecked since it is eliminated by erasure + case x: Foo with Bar => x.bippy + x.barry + ^ +t7721.scala:39: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Concrete => x.bippy + x.dingo + x.conco + ^ +t7721.scala:43: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Concrete with Foo => x.bippy + x.dingo + x.conco + ^ +t7721.scala:47: warning: abstract type pattern B.this.Foo is unchecked since it is eliminated by erasure + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + ^ +t7721.scala:47: warning: abstract type pattern B.this.Bar is unchecked since it is eliminated by erasure + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/t7721.flags b/tests/untried/neg/t7721.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7721.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7721.scala b/tests/untried/neg/t7721.scala new file mode 100644 index 000000000000..9ac7b60f0079 --- /dev/null +++ b/tests/untried/neg/t7721.scala @@ -0,0 +1,140 @@ +import scala.language.reflectiveCalls + +trait A { + trait Concrete { def conco: Int = 1 } + type Foo <: { def bippy: Int } + type Bar <: { def barry: Int } + + implicit def barTag: scala.reflect.ClassTag[Bar] + + def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.conco + case _ => -1 + } + def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.conco + case _ => -1 + } + def f3(x: Any) = x match { + case x: Foo with Bar => x.bippy + x.barry + case _ => -1 + } + def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy // warns, suppressed + case _ => -1 + } + def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +trait B extends A { + type Foo <: { def bippy: Int ; def dingo: Int } + type Bar <: { def barry: Int ; def bongo: Int } + + override implicit def barTag: scala.reflect.ClassTag[Bar] + + override def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f3(x: Any) = x match { + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + case _ => -1 + } + override def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy + x.dingo // warns, suppressed + case _ => -1 + } + override def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry + x.bongo // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +object Test { + abstract class Base extends A { + trait Foo { + def bippy = 2 + def dingo = 3 + } + trait Bar { + def barry = 2 + def bongo = 3 + } + implicit def barTag: scala.reflect.ClassTag[Bar] = scala.reflect.ClassTag(classOf[Bar]) + + def run(): Unit = { + println("f1") + wrap(f1(new Concrete {})) + wrap(f1(new Foo {})) + wrap(f1(new Bar {})) + wrap(f1(new Foo with Concrete {})) + wrap(f1(new Concrete with Foo {})) + + println("\nf2") + wrap(f2(new Concrete {})) + wrap(f2(new Foo {})) + wrap(f2(new Bar {})) + wrap(f2(new Foo with Concrete {})) + wrap(f2(new Concrete with Foo {})) + wrap(f2(new Bar with Concrete {})) + wrap(f2(new Concrete with Bar {})) + wrap(f2(new Concrete with Foo with Bar {})) + wrap(f2(new Foo with Bar with Concrete {})) + + println("\nf3") + wrap(f3(new Concrete {})) + wrap(f3(new Foo {})) + wrap(f3(new Bar {})) + wrap(f3(new Foo with Concrete {})) + wrap(f3(new Concrete with Foo {})) + wrap(f3(new Bar with Concrete {})) + wrap(f3(new Concrete with Bar {})) + wrap(f3(new Concrete with Foo with Bar {})) + wrap(f3(new Foo with Bar with Concrete {})) + + println("\nf4") + wrap(f4(new Concrete {})) + wrap(f4(new Foo {})) + wrap(f4(new Bar {})) + wrap(f4(new Foo with Concrete {})) + wrap(f4(new Concrete with Foo {})) + wrap(f4(new Bar with Concrete {})) + wrap(f4(new Concrete with Bar {})) + wrap(f4(new Concrete with Foo with Bar {})) + wrap(f4(new Foo with Bar with Concrete {})) + + println("\nf5") + wrap(f5(new Concrete {})) + wrap(f5(new Foo {})) + wrap(f5(new Bar {})) + wrap(f5(new Foo with Concrete {})) + wrap(f5(new Concrete with Foo {})) + wrap(f5(new Bar with Concrete {})) + wrap(f5(new Concrete with Bar {})) + wrap(f5(new Concrete with Foo with Bar {})) + wrap(f5(new Foo with Bar with Concrete {})) + } + } + + object ao extends Base + object bo extends Base with B + + private def wrap(body: => Any): Unit = { + try println(body) + catch { case ex: NoSuchMethodException => println(ex) } + } + + def main(args: Array[String]): Unit = { + ao.run() + bo.run() + } +} + +// java.lang.NoSuchMethodException: Test$$anon$1.bippy() diff --git a/tests/untried/neg/t7752.check b/tests/untried/neg/t7752.check new file mode 100644 index 000000000000..0a015d3f3785 --- /dev/null +++ b/tests/untried/neg/t7752.check @@ -0,0 +1,27 @@ +t7752.scala:25: error: overloaded method value foo with alternatives: + [A](heading: String, rows: A*)(A,) + [A, B](heading: (String, String), rows: (A, B)*)(A, B) + [A, B, C](heading: (String, String, String), rows: (A, B, C)*)(A, B, C) + [A, B, C, D](heading: (String, String, String, String), rows: (A, B, C, D)*)(A, B, C, D) + [A, B, C, D, E](heading: (String, String, String, String, String), rows: (A, B, C, D, E)*)(A, B, C, D, E) + [A, B, C, D, E, F](heading: (String, String, String, String, String, String), rows: (A, B, C, D, E, F)*)(A, B, C, D, E, F) + [A, B, C, D, E, F, G](heading: (String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G)*)(A, B, C, D, E, F, G) + [A, B, C, D, E, F, G, H](heading: (String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H)*)(A, B, C, D, E, F, G, H) + [A, B, C, D, E, F, G, H, I](heading: (String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I)*)(A, B, C, D, E, F, G, H, I) + [A, B, C, D, E, F, G, H, I, J](heading: (String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J)*)(A, B, C, D, E, F, G, H, I, J) + [A, B, C, D, E, F, G, H, I, J, K](heading: (String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K)*)(A, B, C, D, E, F, G, H, I, J, K) + [A, B, C, D, E, F, G, H, I, J, K, L](heading: (String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L)*)(A, B, C, D, E, F, G, H, I, J, K, L) + [A, B, C, D, E, F, G, H, I, J, K, L, M](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M)*)(A, B, C, D, E, F, G, H, I, J, K, L, M) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (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, T) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U) + [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)*)(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V) + cannot be applied to (Int) + foo((1)) + ^ +one error found diff --git a/tests/untried/neg/t7752.scala b/tests/untried/neg/t7752.scala new file mode 100644 index 000000000000..342a2ca34963 --- /dev/null +++ b/tests/untried/neg/t7752.scala @@ -0,0 +1,26 @@ +object Test { + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)*): Tuple22[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)*): Tuple21[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)*): Tuple20[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)*): Tuple19[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)*): Tuple18[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)*): Tuple17[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)*): Tuple16[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)*): Tuple15[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M, N](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N)*): Tuple14[A,B,C,D,E,F,G,H,I,J,K,L,M,N] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L, M](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M)*): Tuple13[A,B,C,D,E,F,G,H,I,J,K,L,M] = null + def foo[A, B, C, D, E, F, G, H, I, J, K, L](heading: (String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L)*): Tuple12[A,B,C,D,E,F,G,H,I,J,K,L] = null + def foo[A, B, C, D, E, F, G, H, I, J, K](heading: (String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K)*): Tuple11[A,B,C,D,E,F,G,H,I,J,K] = null + def foo[A, B, C, D, E, F, G, H, I, J](heading: (String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J)*): Tuple10[A,B,C,D,E,F,G,H,I,J] = null + def foo[A, B, C, D, E, F, G, H, I](heading: (String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I)*): Tuple9[A,B,C,D,E,F,G,H,I] = null + def foo[A, B, C, D, E, F, G, H](heading: (String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H)*): Tuple8[A,B,C,D,E,F,G,H] = null + def foo[A, B, C, D, E, F, G](heading: (String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G)*): Tuple7[A,B,C,D,E,F,G] = null + def foo[A, B, C, D, E, F](heading: (String, String, String, String, String, String), rows: (A, B, C, D, E, F)*): Tuple6[A,B,C,D,E,F] = null + def foo[A, B, C, D, E](heading: (String, String, String, String, String), rows: (A, B, C, D, E)*): Tuple5[A,B,C,D,E] = null + def foo[A, B, C, D](heading: (String, String, String, String), rows: (A, B, C, D)*): Tuple4[A,B,C,D] = null + def foo[A, B, C](heading: (String, String, String), rows: (A, B, C)*): Tuple3[A,B,C] = null + def foo[A, B](heading: (String, String), rows: (A, B)*): Tuple2[A,B] = null + def foo[A](heading: String, rows: A*): Tuple1[A] = null + + foo((1)) +} diff --git a/tests/untried/neg/t7756a.check b/tests/untried/neg/t7756a.check new file mode 100644 index 000000000000..8d42717e47e3 --- /dev/null +++ b/tests/untried/neg/t7756a.check @@ -0,0 +1,7 @@ +t7756a.scala:7: error: type arguments [Object] do not conform to trait TA's type parameter bounds [X <: CharSequence] + locally(null: TA[Object]) + ^ +t7756a.scala:7: error: type arguments [Object] do not conform to trait TA's type parameter bounds [X <: CharSequence] + locally(null: TA[Object]) + ^ +two errors found diff --git a/tests/untried/neg/t7756a.scala b/tests/untried/neg/t7756a.scala new file mode 100644 index 000000000000..4453e8496311 --- /dev/null +++ b/tests/untried/neg/t7756a.scala @@ -0,0 +1,11 @@ +object Test { + def test: Unit = { + trait TA[X <: CharSequence] + 0 match { + case _ => + // the bounds violation isn't reported. RefChecks seems to be too broadly disabled under virtpatmat: see 65340ed4ad2e + locally(null: TA[Object]) + () + } + } +} diff --git a/tests/untried/neg/t7756b.check b/tests/untried/neg/t7756b.check new file mode 100644 index 000000000000..2817a7e230d3 --- /dev/null +++ b/tests/untried/neg/t7756b.check @@ -0,0 +1,6 @@ +t7756b.scala:3: warning: comparing values of types Int and String using `==' will always yield false + case _ => 0 == "" + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7756b.flags b/tests/untried/neg/t7756b.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/t7756b.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/t7756b.scala b/tests/untried/neg/t7756b.scala new file mode 100644 index 000000000000..a2de29c8e7f0 --- /dev/null +++ b/tests/untried/neg/t7756b.scala @@ -0,0 +1,5 @@ +object Test { + 0 match { + case _ => 0 == "" + } +} diff --git a/tests/untried/neg/t7757a.check b/tests/untried/neg/t7757a.check new file mode 100644 index 000000000000..de24e23004d2 --- /dev/null +++ b/tests/untried/neg/t7757a.check @@ -0,0 +1,4 @@ +t7757a.scala:1: error: ';' expected but '@' found. +trait Foo @annot + ^ +one error found diff --git a/tests/untried/neg/t7757a.scala b/tests/untried/neg/t7757a.scala new file mode 100644 index 000000000000..77168b145b50 --- /dev/null +++ b/tests/untried/neg/t7757a.scala @@ -0,0 +1 @@ +trait Foo @annot diff --git a/tests/untried/neg/t7757b.check b/tests/untried/neg/t7757b.check new file mode 100644 index 000000000000..3e5a0f1fa672 --- /dev/null +++ b/tests/untried/neg/t7757b.check @@ -0,0 +1,4 @@ +t7757b.scala:2: error: expected start of definition +@annot2 + ^ +one error found diff --git a/tests/untried/neg/t7757b.scala b/tests/untried/neg/t7757b.scala new file mode 100644 index 000000000000..e9a537dba160 --- /dev/null +++ b/tests/untried/neg/t7757b.scala @@ -0,0 +1,2 @@ +trait Foo2 +@annot2 \ No newline at end of file diff --git a/tests/untried/neg/t7783.check b/tests/untried/neg/t7783.check new file mode 100644 index 000000000000..647cfee12152 --- /dev/null +++ b/tests/untried/neg/t7783.check @@ -0,0 +1,18 @@ +t7783.scala:1: warning: type D in object O is deprecated: +object O { class C; @deprecated("", "") type D = C; def foo: Seq[D] = Nil } + ^ +t7783.scala:11: warning: type D in object O is deprecated: + type T = O.D + ^ +t7783.scala:12: warning: type D in object O is deprecated: + locally(null: O.D) + ^ +t7783.scala:13: warning: type D in object O is deprecated: + val x: O.D = null + ^ +t7783.scala:14: warning: type D in object O is deprecated: + locally(null.asInstanceOf[O.D]) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +5 warnings found +one error found diff --git a/tests/untried/neg/t7783.flags b/tests/untried/neg/t7783.flags new file mode 100644 index 000000000000..d1b831ea87cd --- /dev/null +++ b/tests/untried/neg/t7783.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7783.scala b/tests/untried/neg/t7783.scala new file mode 100644 index 000000000000..995b644a09ad --- /dev/null +++ b/tests/untried/neg/t7783.scala @@ -0,0 +1,15 @@ +object O { class C; @deprecated("", "") type D = C; def foo: Seq[D] = Nil } + +object NoWarn { + O.foo // nowarn + O.foo +: Nil // nowarn + def bar(a: Any, b: Any) = () // nowarn + bar(b = O.foo, a = ()) // nowarn +} + +object Warn { + type T = O.D + locally(null: O.D) + val x: O.D = null + locally(null.asInstanceOf[O.D]) +} diff --git a/tests/untried/neg/t779.check b/tests/untried/neg/t779.check new file mode 100644 index 000000000000..65f463c192d6 --- /dev/null +++ b/tests/untried/neg/t779.check @@ -0,0 +1,4 @@ +t779.scala:6: error: method ast has return statement; needs result type + override def ast = return null + ^ +one error found diff --git a/tests/untried/neg/t779.scala b/tests/untried/neg/t779.scala new file mode 100644 index 000000000000..cc92f9062a33 --- /dev/null +++ b/tests/untried/neg/t779.scala @@ -0,0 +1,8 @@ +abstract class Foo { + trait Node { + def ast: AnyRef = null + } + trait Something extends Node { + override def ast = return null + } +} diff --git a/tests/untried/neg/t783.check b/tests/untried/neg/t783.check new file mode 100644 index 000000000000..37610a50ffbe --- /dev/null +++ b/tests/untried/neg/t783.check @@ -0,0 +1,6 @@ +t783.scala:12: error: type mismatch; + found : Contexts.this.Global#Template + required: Contexts.this.global.Template + globalInit0.Template(10, 20); + ^ +one error found diff --git a/tests/untried/neg/t783.scala b/tests/untried/neg/t783.scala new file mode 100644 index 000000000000..59f7c7f97df1 --- /dev/null +++ b/tests/untried/neg/t783.scala @@ -0,0 +1,29 @@ +package test; + +object Main extends App { + class Global { + case class Template(x : Int, y : Int) { + Console.println("outer: " + Global.this); + } + } + trait Contexts { self: Analyzer => + val xxx : global.Template = { + assert(globalInit0 != null); + globalInit0.Template(10, 20); + } + } + abstract class Analyzer extends Contexts { + type Global <: Main.Global; + final val global : Global = globalInit; + def globalInit : Global; + final def globalInit0 = globalInit.asInstanceOf[global.type]; + } + + object global0 extends Global { + object analyzer extends Analyzer { + type Global = global0.type; + override def globalInit = global0; + } + } + Console.println(global0.analyzer.xxx); +} diff --git a/tests/untried/neg/t7834neg.check b/tests/untried/neg/t7834neg.check new file mode 100644 index 000000000000..569df4b8ce12 --- /dev/null +++ b/tests/untried/neg/t7834neg.check @@ -0,0 +1,41 @@ +t7834neg.scala:48: error: type mismatch; + found : C.super.q.type (with underlying type M2) + required: C.super.q.type + x1 = x2 // fail + ^ +t7834neg.scala:50: error: type mismatch; + found : C.super.q.type (with underlying type M1) + required: C.super.q.type + x2 = x1 // fail + ^ +t7834neg.scala:53: error: type mismatch; + found : C.super.q.type (with underlying type M1) + required: C.this.q.type + x3 = x1 // fail + ^ +t7834neg.scala:54: error: type mismatch; + found : C.super.q.type (with underlying type M2) + required: C.this.q.type + x3 = x2 // fail + ^ +t7834neg.scala:69: error: type mismatch; + found : C.super.q.type (with underlying type M2) + required: C.super.q.type + x1 = super[S2].q // fail + ^ +t7834neg.scala:71: error: type mismatch; + found : C.super.q.type (with underlying type M1) + required: C.super.q.type + x2 = super[S1].q // fail + ^ +t7834neg.scala:74: error: type mismatch; + found : C.super.q.type (with underlying type M1) + required: C.this.q.type + x3 = super[S1].q // fail + ^ +t7834neg.scala:75: error: type mismatch; + found : C.super.q.type (with underlying type M2) + required: C.this.q.type + x3 = super[S2].q // fail + ^ +8 errors found diff --git a/tests/untried/neg/t7834neg.scala b/tests/untried/neg/t7834neg.scala new file mode 100644 index 000000000000..d35a84eadda8 --- /dev/null +++ b/tests/untried/neg/t7834neg.scala @@ -0,0 +1,76 @@ +class M1 +class M2 extends M1 +class M3 extends M2 + +trait S1 { val q = new M1 ; val q1: q.type = q } +trait S2 { val q = new M2 ; val q2: q.type = q } + +class B extends S1 with S2 { + override val q = new M3 + val q3: q.type = q + + var x1: B.super[S1].q1.type = null + var x2: B.super[S2].q2.type = null + var x3: B.this.q3.type = null + + x1 = x1 + x1 = x2 + x1 = x3 + x2 = x1 + x2 = x2 + x2 = x3 + x3 = x1 + x3 = x2 + x3 = x3 + + x1 = q1 + x1 = q2 + x1 = q3 + x2 = q1 + x2 = q2 + x2 = q3 + x3 = q1 + x3 = q2 + x3 = x3 +} + +class C extends S1 with S2 { + override val q = new M3 + val q3: q.type = q + + // x1's type and x2's type are incompatible + // x3's is assignable to x1 or x2, but not vice versa + var x1: C.super[S1].q.type = null + var x2: C.super[S2].q.type = null + var x3: C.this.q.type = null + + x1 = x1 + x1 = x2 // fail + x1 = x3 + x2 = x1 // fail + x2 = x2 + x2 = x3 + x3 = x1 // fail + x3 = x2 // fail + x3 = x3 + + x1 = q1 + x1 = q2 + x1 = q3 + x2 = q1 + x2 = q2 + x2 = q3 + x3 = q1 + x3 = q2 + x3 = x3 + + x1 = q + x1 = super[S1].q + x1 = super[S2].q // fail + x2 = q + x2 = super[S1].q // fail + x2 = super[S2].q + x3 = q + x3 = super[S1].q // fail + x3 = super[S2].q // fail +} diff --git a/tests/untried/neg/t7848-interp-warn.check b/tests/untried/neg/t7848-interp-warn.check new file mode 100644 index 000000000000..b7df6d8ce252 --- /dev/null +++ b/tests/untried/neg/t7848-interp-warn.check @@ -0,0 +1,12 @@ +t7848-interp-warn.scala:8: warning: `$foo` looks like an interpolated identifier! Did you forget the interpolator? + "An important $foo message!" + ^ +t7848-interp-warn.scala:12: warning: That looks like an interpolated expression! Did you forget the interpolator? + "A doubly important ${foo * 2} message!" + ^ +t7848-interp-warn.scala:16: warning: `$bar` looks like an interpolated identifier! Did you forget the interpolator? + def j = s"Try using '${ "something like $bar" }' instead." // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t7848-interp-warn.flags b/tests/untried/neg/t7848-interp-warn.flags new file mode 100644 index 000000000000..7949c2afa212 --- /dev/null +++ b/tests/untried/neg/t7848-interp-warn.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/untried/neg/t7848-interp-warn.scala b/tests/untried/neg/t7848-interp-warn.scala new file mode 100644 index 000000000000..3887aff8de3b --- /dev/null +++ b/tests/untried/neg/t7848-interp-warn.scala @@ -0,0 +1,18 @@ + +package test + +object Test { + def bar = "bar" + def f = { + val foo = "bar" + "An important $foo message!" + } + def g = { + val foo = "bar" + "A doubly important ${foo * 2} message!" + } + def h = s"Try using '$$bar' instead." // no warn + def i = s"Try using '${ "$bar" }' instead." // no warn on space test + def j = s"Try using '${ "something like $bar" }' instead." // warn + def k = f"Try using '$bar' instead." // no warn on other std interps +} diff --git a/tests/untried/neg/t7850.check b/tests/untried/neg/t7850.check new file mode 100644 index 000000000000..317be2bbceed --- /dev/null +++ b/tests/untried/neg/t7850.check @@ -0,0 +1,7 @@ +t7850.scala:11: error: an unapply result must have a member `def isEmpty: Boolean (found: def isEmpty: Casey) + val Casey(x1) = new Casey(1) + ^ +t7850.scala:12: error: an unapply result must have a member `def isEmpty: Boolean + val Dingy(x2) = new Dingy(1) + ^ +two errors found diff --git a/tests/untried/neg/t7850.scala b/tests/untried/neg/t7850.scala new file mode 100644 index 000000000000..794ce2eb00da --- /dev/null +++ b/tests/untried/neg/t7850.scala @@ -0,0 +1,16 @@ +// isEmpty returns non-boolean +class Casey(a: Int) { def isEmpty = this; def get = this } +object Casey { def unapply(a: Casey) = a } + +// no isEmpty method at all +class Dingy(a: Int) { def get = this } +object Dingy { def unapply(a: Dingy) = a } + +object Test { + def main(args: Array[String]): Unit = { + val Casey(x1) = new Casey(1) + val Dingy(x2) = new Dingy(1) + println(s"$x1 $x2") + } +} + diff --git a/tests/untried/neg/t7859.check b/tests/untried/neg/t7859.check new file mode 100644 index 000000000000..5789e2a1228c --- /dev/null +++ b/tests/untried/neg/t7859.check @@ -0,0 +1,19 @@ +B_2.scala:6: error: not found: value x + new p1.A(x).x + ^ +B_2.scala:6: error: value x in class A cannot be accessed in p1.A + new p1.A(x).x + ^ +B_2.scala:7: error: not found: value x + new B(x).x + ^ +B_2.scala:7: error: value x is not a member of B + new B(x).x + ^ +B_2.scala:8: error: not found: value x + new C(x).x + ^ +B_2.scala:8: error: value x in class C cannot be accessed in C + new C(x).x + ^ +6 errors found diff --git a/tests/untried/neg/t7859/A_1.scala b/tests/untried/neg/t7859/A_1.scala new file mode 100644 index 000000000000..e5b32d1c9676 --- /dev/null +++ b/tests/untried/neg/t7859/A_1.scala @@ -0,0 +1,5 @@ +package p1 { + class A(private[p1] val x: Any) extends AnyVal +} +class B(private val x: Any) extends AnyVal + diff --git a/tests/untried/neg/t7859/B_2.scala b/tests/untried/neg/t7859/B_2.scala new file mode 100644 index 000000000000..2e0556bc7b1e --- /dev/null +++ b/tests/untried/neg/t7859/B_2.scala @@ -0,0 +1,9 @@ +class C(private val x: Any) extends AnyVal + +// Checking that makeNotPrivate(paramAccessor) doesn't make this visible during typer. +// The output is identical with/without `extends AnyVal`. +object Test { + new p1.A(x).x + new B(x).x + new C(x).x +} diff --git a/tests/untried/neg/t7870.check b/tests/untried/neg/t7870.check new file mode 100644 index 000000000000..d9db911ac1ce --- /dev/null +++ b/tests/untried/neg/t7870.check @@ -0,0 +1,4 @@ +t7870.scala:1: error: in class C, multiple overloaded alternatives of constructor C define default arguments. +class C(a: Int = 0, b: Any) { + ^ +one error found diff --git a/tests/untried/neg/t7870.scala b/tests/untried/neg/t7870.scala new file mode 100644 index 000000000000..5d48d43b3a7c --- /dev/null +++ b/tests/untried/neg/t7870.scala @@ -0,0 +1,3 @@ +class C(a: Int = 0, b: Any) { + def this(a: Int = 0) = this(???, ???) +} diff --git a/tests/untried/neg/t7872.check b/tests/untried/neg/t7872.check new file mode 100644 index 000000000000..57d9772abc5d --- /dev/null +++ b/tests/untried/neg/t7872.check @@ -0,0 +1,10 @@ +t7872.scala:6: error: contravariant type a occurs in covariant position in type [-a]Cov[a] of type l + type x = {type l[-a] = Cov[a]} + ^ +t7872.scala:8: error: covariant type a occurs in contravariant position in type [+a]Inv[a] of type l + foo[({type l[+a] = Inv[a]})#l] + ^ +t7872.scala:5: error: contravariant type a occurs in covariant position in type [-a]Cov[a] of type l + type l[-a] = Cov[a] + ^ +three errors found diff --git a/tests/untried/neg/t7872.scala b/tests/untried/neg/t7872.scala new file mode 100644 index 000000000000..66d22a071507 --- /dev/null +++ b/tests/untried/neg/t7872.scala @@ -0,0 +1,9 @@ +trait Cov[+A] +trait Inv[-A] + +object varianceExploit { + type l[-a] = Cov[a] + type x = {type l[-a] = Cov[a]} + def foo[M[_]] = () + foo[({type l[+a] = Inv[a]})#l] +} diff --git a/tests/untried/neg/t7872b.check b/tests/untried/neg/t7872b.check new file mode 100644 index 000000000000..0dc4e76301a4 --- /dev/null +++ b/tests/untried/neg/t7872b.check @@ -0,0 +1,7 @@ +t7872b.scala:8: error: contravariant type a occurs in covariant position in type [-a]List[a] of type l + def oops1 = down[({type l[-a] = List[a]})#l](List('whatever: Object)).head + "oops" + ^ +t7872b.scala:19: error: covariant type a occurs in contravariant position in type [+a]coinv.Stringer[a] of type l + def oops2 = up[({type l[+a] = Stringer[a]})#l]("printed: " + _) + ^ +two errors found diff --git a/tests/untried/neg/t7872b.scala b/tests/untried/neg/t7872b.scala new file mode 100644 index 000000000000..307a1470c58f --- /dev/null +++ b/tests/untried/neg/t7872b.scala @@ -0,0 +1,23 @@ +object coinv { + def up[F[+_]](fa: F[String]): F[Object] = fa + def down[F[-_]](fa: F[Object]): F[String] = fa + + up(List("hi")) + + // should not compile; `l' is unsound + def oops1 = down[({type l[-a] = List[a]})#l](List('whatever: Object)).head + "oops" + // scala> oops1 + // java.lang.ClassCastException: scala.Symbol cannot be cast to java.lang.String + // at com.nocandysw.coinv$.oops1(coinv.scala:12) + + type Stringer[-A] = A => String + down[Stringer](_.toString) + // [error] type A is contravariant, but type _ is declared covariant + // up[Stringer]("printed: " + _) + + // should not compile; `l' is unsound + def oops2 = up[({type l[+a] = Stringer[a]})#l]("printed: " + _) + // scala> oops2(Some(33)) + // java.lang.ClassCastException: scala.Some cannot be cast to java.lang.String + // at com.nocandysw.coinv$$anonfun$oops2$1.apply(coinv.scala:20) +} diff --git a/tests/untried/neg/t7872c.check b/tests/untried/neg/t7872c.check new file mode 100644 index 000000000000..469449dbd5bb --- /dev/null +++ b/tests/untried/neg/t7872c.check @@ -0,0 +1,11 @@ +t7872c.scala:7: error: inferred kinds of the type arguments (List) do not conform to the expected kinds of the type parameters (type F). +List's type parameters do not match type F's expected parameters: +type A is covariant, but type _ is declared contravariant + down(List('whatever: Object)) + ^ +t7872c.scala:7: error: type mismatch; + found : List[Object] + required: F[Object] + down(List('whatever: Object)) + ^ +two errors found diff --git a/tests/untried/neg/t7872c.scala b/tests/untried/neg/t7872c.scala new file mode 100644 index 000000000000..fa12a523b5f8 --- /dev/null +++ b/tests/untried/neg/t7872c.scala @@ -0,0 +1,8 @@ +object coinv { + def up[F[+_]](fa: F[String]): F[Object] = fa + def down[F[-_]](fa: F[Object]): F[String] = fa + + up(List("hi")) + // [error] type A is covariant, but type _ is declared contravariant + down(List('whatever: Object)) +} diff --git a/tests/untried/neg/t7877.check b/tests/untried/neg/t7877.check new file mode 100644 index 000000000000..7f7f832463a0 --- /dev/null +++ b/tests/untried/neg/t7877.check @@ -0,0 +1,7 @@ +t7877.scala:6: error: not found: value Y + case Y() => () // not allowed + ^ +t7877.scala:7: error: OnNext[Any] does not take parameters + case OnNext[Any]() => () // should *not* be allowed, but was. + ^ +two errors found diff --git a/tests/untried/neg/t7877.scala b/tests/untried/neg/t7877.scala new file mode 100644 index 000000000000..52e167f3b8e0 --- /dev/null +++ b/tests/untried/neg/t7877.scala @@ -0,0 +1,13 @@ +class Test { + val X: OnNext[Any] = null + def Y: OnNext[Any] = null + (null: Any) match { + case X() => () // allowed + case Y() => () // not allowed + case OnNext[Any]() => () // should *not* be allowed, but was. + } +} + +class OnNext[+T] { + def unapply(x: Any) = false +} diff --git a/tests/untried/neg/t7895.check b/tests/untried/neg/t7895.check new file mode 100644 index 000000000000..1a58e24b77f7 --- /dev/null +++ b/tests/untried/neg/t7895.check @@ -0,0 +1,4 @@ +t7895.scala:4: error: not found: value Goop + case Goop(a, b, c) => Tuple2(a, b) + ^ +one error found diff --git a/tests/untried/neg/t7895.scala b/tests/untried/neg/t7895.scala new file mode 100644 index 000000000000..87a586a82d83 --- /dev/null +++ b/tests/untried/neg/t7895.scala @@ -0,0 +1,6 @@ +class A { + (null: Any) match { + // We don't want "symbol not found errors" for `a` and `b` in the case body. + case Goop(a, b, c) => Tuple2(a, b) + } +} diff --git a/tests/untried/neg/t7895b.check b/tests/untried/neg/t7895b.check new file mode 100644 index 000000000000..87ea72704e2d --- /dev/null +++ b/tests/untried/neg/t7895b.check @@ -0,0 +1,7 @@ +t7895b.scala:4: error: not found: value a + foo(a, b) + ^ +t7895b.scala:4: error: not found: value b + foo(a, b) + ^ +two errors found diff --git a/tests/untried/neg/t7895b.scala b/tests/untried/neg/t7895b.scala new file mode 100644 index 000000000000..1603027446e0 --- /dev/null +++ b/tests/untried/neg/t7895b.scala @@ -0,0 +1,5 @@ +object Test { + def foo(a: Any*) = () + + foo(a, b) +} diff --git a/tests/untried/neg/t7895c.check b/tests/untried/neg/t7895c.check new file mode 100644 index 000000000000..d4745b1f4be7 --- /dev/null +++ b/tests/untried/neg/t7895c.check @@ -0,0 +1,13 @@ +t7895c.scala:2: error: not found: value bong + def booboo = bong + booble + bippity - bazingo + ^ +t7895c.scala:2: error: not found: value booble + def booboo = bong + booble + bippity - bazingo + ^ +t7895c.scala:2: error: not found: value bippity + def booboo = bong + booble + bippity - bazingo + ^ +t7895c.scala:2: error: not found: value bazingo + def booboo = bong + booble + bippity - bazingo + ^ +four errors found diff --git a/tests/untried/neg/t7895c.scala b/tests/untried/neg/t7895c.scala new file mode 100644 index 000000000000..53d2a8672e38 --- /dev/null +++ b/tests/untried/neg/t7895c.scala @@ -0,0 +1,3 @@ +class A { + def booboo = bong + booble + bippity - bazingo +} diff --git a/tests/untried/neg/t7897.check b/tests/untried/neg/t7897.check new file mode 100644 index 000000000000..48eff511c7b1 --- /dev/null +++ b/tests/untried/neg/t7897.check @@ -0,0 +1,4 @@ +t7897.scala:19: error: value length is not a member of p0.Single + case p0.Single(x) => println(s"`$x` has ${x.length} chars") + ^ +one error found diff --git a/tests/untried/neg/t7897.scala b/tests/untried/neg/t7897.scala new file mode 100644 index 000000000000..87c966b1e097 --- /dev/null +++ b/tests/untried/neg/t7897.scala @@ -0,0 +1,23 @@ +package p0 { + class Single(val x: Any) extends AnyRef with Product1[String] { + private def s = "" + x + override def canEqual(x: Any) = this eq x.asInstanceOf[AnyRef] + def isEmpty = false + def get = this + def _1 = s + " only" + + override def toString = s"Single(${_1})" + } + + object Single { + def unapply(x: Any): Single = new Single(x) + } +} +object Test { + def main(args: Array[String]): Unit = { + "catdog" match { + case p0.Single(x) => println(s"`$x` has ${x.length} chars") + case x => println("fail: " + x) + } + } +} diff --git a/tests/untried/neg/t7899.check b/tests/untried/neg/t7899.check new file mode 100644 index 000000000000..febfe76b8a1d --- /dev/null +++ b/tests/untried/neg/t7899.check @@ -0,0 +1,6 @@ +t7899.scala:5: error: type mismatch; + found : Int => Int + required: (=> Int) => ? + foo(identity)() + ^ +one error found diff --git a/tests/untried/neg/t7899.scala b/tests/untried/neg/t7899.scala new file mode 100644 index 000000000000..279f24b9cf69 --- /dev/null +++ b/tests/untried/neg/t7899.scala @@ -0,0 +1,7 @@ +object Test { + def foo[B](f: (=> Int) => B): () => B = () => f(0) + + def main(args: Array[String]): Unit = { + foo(identity)() + } +} diff --git a/tests/untried/neg/t7967.check b/tests/untried/neg/t7967.check new file mode 100644 index 000000000000..cde950dcdf6b --- /dev/null +++ b/tests/untried/neg/t7967.check @@ -0,0 +1,9 @@ +t7967.scala:6: error: illegal inheritance; + self-type C does not conform to C's selftype C with B + new C {} // fails + ^ +t7967.scala:8: error: illegal inheritance; + self-type Test.CC does not conform to Test.CC's selftype Test.CC + new CC {} // should fail, doesn't + ^ +two errors found diff --git a/tests/untried/neg/t7967.scala b/tests/untried/neg/t7967.scala new file mode 100644 index 000000000000..4f133479487e --- /dev/null +++ b/tests/untried/neg/t7967.scala @@ -0,0 +1,9 @@ + +trait B +trait C {self: B =>} + +object Test { + new C {} // fails + type CC = C + new CC {} // should fail, doesn't +} diff --git a/tests/untried/neg/t798.check b/tests/untried/neg/t798.check new file mode 100644 index 000000000000..b120f3a40395 --- /dev/null +++ b/tests/untried/neg/t798.check @@ -0,0 +1,4 @@ +t798.scala:2: error: cyclic aliasing or subtyping involving type Bracks +trait Test[Bracks <: Bracks] { + ^ +one error found diff --git a/tests/untried/neg/t798.scala b/tests/untried/neg/t798.scala new file mode 100644 index 000000000000..a2bf66d19be6 --- /dev/null +++ b/tests/untried/neg/t798.scala @@ -0,0 +1,8 @@ +package test; +trait Test[Bracks <: Bracks] { + def f(list : Any) = null; + class C[T] + val bracks : Bracks; + val singletons = f(bracks); + +} diff --git a/tests/untried/neg/t7980.check b/tests/untried/neg/t7980.check new file mode 100644 index 000000000000..031c23dbeb5a --- /dev/null +++ b/tests/untried/neg/t7980.check @@ -0,0 +1,4 @@ +t7980.scala:7: error: Can't unquote Nothing, bottom type values often indicate programmer mistake + println(q"class ${Name(X)} { }") + ^ +one error found diff --git a/tests/untried/neg/t7980.scala b/tests/untried/neg/t7980.scala new file mode 100644 index 000000000000..b21907de5499 --- /dev/null +++ b/tests/untried/neg/t7980.scala @@ -0,0 +1,8 @@ +object Test extends App { + import scala.reflect.runtime.universe._ + def Name[T:TypeTag](name:String): T = implicitly[TypeTag[T]] match { + case t => newTypeName(name).asInstanceOf[T] + } + val X = "ASDF" + println(q"class ${Name(X)} { }") +} diff --git a/tests/untried/neg/t7984.check b/tests/untried/neg/t7984.check new file mode 100644 index 000000000000..0cfd7d16198c --- /dev/null +++ b/tests/untried/neg/t7984.check @@ -0,0 +1,6 @@ +t7984.scala:4: warning: non-variable type argument Int in type pattern List[Int] (the underlying of Test.this.ListInt) is unchecked since it is eliminated by erasure + case is: ListInt => is.head + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t7984.flags b/tests/untried/neg/t7984.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/t7984.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/t7984.scala b/tests/untried/neg/t7984.scala new file mode 100644 index 000000000000..ca09a89fc71c --- /dev/null +++ b/tests/untried/neg/t7984.scala @@ -0,0 +1,7 @@ +class Test { + type ListInt = List[Int] + List[Any]("") match { + case is: ListInt => is.head + case _ => + } +} diff --git a/tests/untried/neg/t800.check b/tests/untried/neg/t800.check new file mode 100644 index 000000000000..8ba95fddde45 --- /dev/null +++ b/tests/untried/neg/t800.check @@ -0,0 +1,16 @@ +t800.scala:4: error: qualification is already defined as value qualification + val qualification = false; + ^ +t800.scala:8: error: method qualification is defined twice + conflicting symbols both originated in file 't800.scala' + val qualification = false; + ^ +t800.scala:12: error: value qualification is defined twice + conflicting symbols both originated in file 't800.scala' + var qualification = false; + ^ +t800.scala:16: error: method qualification is defined twice + conflicting symbols both originated in file 't800.scala' + var qualification = false; + ^ +four errors found diff --git a/tests/untried/neg/t800.scala b/tests/untried/neg/t800.scala new file mode 100644 index 000000000000..388574d42d61 --- /dev/null +++ b/tests/untried/neg/t800.scala @@ -0,0 +1,17 @@ +package test; +trait Test1 { + val qualification : String; + val qualification = false; +} +trait Test2 { + var qualification : String; + val qualification = false; +} +trait Test3 { + val qualification : String; + var qualification = false; +} +trait Test4 { + var qualification : String; + var qualification = false; +} diff --git a/tests/untried/neg/t8006.check b/tests/untried/neg/t8006.check new file mode 100644 index 000000000000..fbac26e3ad9c --- /dev/null +++ b/tests/untried/neg/t8006.check @@ -0,0 +1,6 @@ +t8006.scala:3: error: too many arguments for method applyDynamicNamed: (value: (String, Any))String +error after rewriting to X.this.d.applyDynamicNamed("meth")(scala.Tuple2("value1", 10), scala.Tuple2("value2", 100)) +possible cause: maybe a wrong Dynamic method signature? + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed + ^ +one error found diff --git a/tests/untried/neg/t8006.scala b/tests/untried/neg/t8006.scala new file mode 100644 index 000000000000..8dc60697dcb9 --- /dev/null +++ b/tests/untried/neg/t8006.scala @@ -0,0 +1,8 @@ +object X { + val d = new D + d.meth(value1 = 10, value2 = 100) // two arguments here, but only one is allowed +} +import language.dynamics +class D extends Dynamic { + def applyDynamicNamed(name: String)(value: (String, Any)) = name +} diff --git a/tests/untried/neg/t8015-ffa.check b/tests/untried/neg/t8015-ffa.check new file mode 100644 index 000000000000..0f28be7fe7b7 --- /dev/null +++ b/tests/untried/neg/t8015-ffa.check @@ -0,0 +1,6 @@ +t8015-ffa.scala:7: error: type mismatch; + found : String("3") + required: Int + val i: Int = "3" // error line 7 (was 8) + ^ +one error found diff --git a/tests/untried/neg/t8015-ffa.scala b/tests/untried/neg/t8015-ffa.scala new file mode 100644 index 000000000000..60876d91393f --- /dev/null +++ b/tests/untried/neg/t8015-ffa.scala @@ -0,0 +1,8 @@ + +package foo + +//------- object Next + +trait F { + val i: Int = "3" // error line 7 (was 8) +} diff --git a/tests/untried/neg/t8015-ffb.check b/tests/untried/neg/t8015-ffb.check new file mode 100644 index 000000000000..9b2171ea471a --- /dev/null +++ b/tests/untried/neg/t8015-ffb.check @@ -0,0 +1,6 @@ +t8015-ffb.scala:10: warning: side-effecting nullary methods are discouraged: suggest defining as `def w()` instead + def w = { x\u000c() } // ^L is colored blue on this screen, hardly visible + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/t8015-ffb.flags b/tests/untried/neg/t8015-ffb.flags new file mode 100644 index 000000000000..7949c2afa212 --- /dev/null +++ b/tests/untried/neg/t8015-ffb.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/tests/untried/neg/t8015-ffb.scala b/tests/untried/neg/t8015-ffb.scala new file mode 100644 index 000000000000..dbdd94255511 --- /dev/null +++ b/tests/untried/neg/t8015-ffb.scala @@ -0,0 +1,11 @@ + +trait G { + val c: Char = '\u000a' // disallowed! + def x\u000d\u000a = 9 // as nl + def y() = x + def z() = { + y()\u000a() // was Int does not take parameters + } + def v = y()\u000c() // was Int does not take parameters + def w = { x () } // ^L is colored blue on this screen, hardly visible +} diff --git a/tests/untried/neg/t8024.check b/tests/untried/neg/t8024.check new file mode 100644 index 000000000000..bd551aa59173 --- /dev/null +++ b/tests/untried/neg/t8024.check @@ -0,0 +1,6 @@ +t8024.scala:13: error: reference to sqrt is ambiguous; +it is both defined in package object p and imported subsequently by +import java.lang.Math.sqrt + sqrt(0d) + ^ +one error found diff --git a/tests/untried/neg/t8024.scala b/tests/untried/neg/t8024.scala new file mode 100644 index 000000000000..b4c2c5ebb98b --- /dev/null +++ b/tests/untried/neg/t8024.scala @@ -0,0 +1,14 @@ +package p + +trait NRoot[A] + +object `package` { + final def sqrt(x: Double): Double = Math.sqrt(x) + final def sqrt[A](a: A)(implicit ev: NRoot[A]): A = ??? +} + +object FastComplex { + import java.lang.Math.sqrt + + sqrt(0d) +} diff --git a/tests/untried/neg/t8024b.check b/tests/untried/neg/t8024b.check new file mode 100644 index 000000000000..9cd89bca535c --- /dev/null +++ b/tests/untried/neg/t8024b.check @@ -0,0 +1,6 @@ +t8024b.scala:15: error: reference to sqrt is ambiguous; +it is both defined in object FastComplex and imported subsequently by +import java.lang.Math.sqrt + sqrt(0d) + ^ +one error found diff --git a/tests/untried/neg/t8024b.scala b/tests/untried/neg/t8024b.scala new file mode 100644 index 000000000000..cf3d4963657a --- /dev/null +++ b/tests/untried/neg/t8024b.scala @@ -0,0 +1,17 @@ +package p + +trait NRoot[A] + +object FastComplex { + final def sqrt(x: Double): Double = Math.sqrt(x) + final def sqrt[A](a: A)(implicit ev: NRoot[A]): A = ??? + + object Inner { + import java.lang.Math.sqrt + + // wrong message: + // error: reference to sqrt is ambiguous; + // it is both defined in object FastComplex and imported subsequently by + sqrt(0d) + } +} diff --git a/tests/untried/neg/t8035-deprecated.check b/tests/untried/neg/t8035-deprecated.check new file mode 100644 index 000000000000..01f27e5310e4 --- /dev/null +++ b/tests/untried/neg/t8035-deprecated.check @@ -0,0 +1,21 @@ +t8035-deprecated.scala:2: warning: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want. + signature: GenSetLike.apply(elem: A): Boolean + given arguments: + after adaptation: GenSetLike((): Unit) + List(1,2,3).toSet() + ^ +t8035-deprecated.scala:5: warning: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want. + signature: A(x: T): Foo.A[T] + given arguments: + after adaptation: new A((): Unit) + new A + ^ +t8035-deprecated.scala:9: warning: Adaptation of argument list by inserting () has been deprecated: leaky (Object-receiving) target makes this especially dangerous. + signature: Format.format(x$1: Any): String + given arguments: + after adaptation: Format.format((): Unit) + sdf.format() + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/t8035-deprecated.flags b/tests/untried/neg/t8035-deprecated.flags new file mode 100644 index 000000000000..c6bfaf1f64a4 --- /dev/null +++ b/tests/untried/neg/t8035-deprecated.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/tests/untried/neg/t8035-deprecated.scala b/tests/untried/neg/t8035-deprecated.scala new file mode 100644 index 000000000000..6423157530db --- /dev/null +++ b/tests/untried/neg/t8035-deprecated.scala @@ -0,0 +1,10 @@ +object Foo { + List(1,2,3).toSet() + + class A[T](val x: T) + new A + + import java.text.SimpleDateFormat + val sdf = new SimpleDateFormat("yyyyMMdd-HH0000") + sdf.format() +} diff --git a/tests/untried/neg/t8035-removed.check b/tests/untried/neg/t8035-removed.check new file mode 100644 index 000000000000..e24a0b4e63d8 --- /dev/null +++ b/tests/untried/neg/t8035-removed.check @@ -0,0 +1,16 @@ +t8035-removed.scala:2: error: Adaptation of argument list by inserting () has been removed. + signature: GenSetLike.apply(elem: A): Boolean + given arguments: + List(1,2,3).toSet() + ^ +t8035-removed.scala:5: error: Adaptation of argument list by inserting () has been removed. + signature: A(x: T): Foo.A[T] + given arguments: + new A + ^ +t8035-removed.scala:9: error: Adaptation of argument list by inserting () has been removed. + signature: Format.format(x$1: Any): String + given arguments: + sdf.format() + ^ +three errors found diff --git a/tests/untried/neg/t8035-removed.flags b/tests/untried/neg/t8035-removed.flags new file mode 100644 index 000000000000..29f4ede37ab4 --- /dev/null +++ b/tests/untried/neg/t8035-removed.flags @@ -0,0 +1 @@ +-Xfuture diff --git a/tests/untried/neg/t8035-removed.scala b/tests/untried/neg/t8035-removed.scala new file mode 100644 index 000000000000..6423157530db --- /dev/null +++ b/tests/untried/neg/t8035-removed.scala @@ -0,0 +1,10 @@ +object Foo { + List(1,2,3).toSet() + + class A[T](val x: T) + new A + + import java.text.SimpleDateFormat + val sdf = new SimpleDateFormat("yyyyMMdd-HH0000") + sdf.format() +} diff --git a/tests/untried/neg/t8072.check b/tests/untried/neg/t8072.check new file mode 100644 index 000000000000..92670101353c --- /dev/null +++ b/tests/untried/neg/t8072.check @@ -0,0 +1,4 @@ +t8072.scala:4: error: value ifParSeq is not a member of List[Int] + val y = x.ifParSeq[Int](throw new Exception).otherwise(0) // Shouldn't compile + ^ +one error found diff --git a/tests/untried/neg/t8072.scala b/tests/untried/neg/t8072.scala new file mode 100644 index 000000000000..dddb8c5f207a --- /dev/null +++ b/tests/untried/neg/t8072.scala @@ -0,0 +1,6 @@ +class NoIfParSeq { + import collection.parallel._ + val x = List(1,2) + val y = x.ifParSeq[Int](throw new Exception).otherwise(0) // Shouldn't compile + val z = x.toParArray +} diff --git a/tests/untried/neg/t8104.check b/tests/untried/neg/t8104.check new file mode 100644 index 000000000000..69b3461bd52e --- /dev/null +++ b/tests/untried/neg/t8104.check @@ -0,0 +1,4 @@ +Test_2.scala:20: error: could not find implicit value for parameter e: Generic.Aux[Test.C,(Int, Int)] + implicitly[Generic.Aux[C, (Int, Int)]] + ^ +one error found diff --git a/tests/untried/neg/t8104/Macros_1.scala b/tests/untried/neg/t8104/Macros_1.scala new file mode 100644 index 000000000000..129c8db16f6a --- /dev/null +++ b/tests/untried/neg/t8104/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox.Context + +object Macros { + def impl[T](c: Context)(implicit T: c.WeakTypeTag[T]) = { + import c.universe._ + import definitions._ + val fields = T.tpe.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + val Repr = appliedType(TupleClass(fields.length).asType.toType, fields.map(_.info)) + q"new Generic[$T]{ type Repr = $Repr }" + } +} diff --git a/tests/untried/neg/t8104/Test_2.scala b/tests/untried/neg/t8104/Test_2.scala new file mode 100644 index 000000000000..a3bd940188fc --- /dev/null +++ b/tests/untried/neg/t8104/Test_2.scala @@ -0,0 +1,21 @@ +trait Generic[T] { type Repr } +object Generic { + type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 } + import scala.language.experimental.macros + implicit def materializeGeneric[T]: Generic[T] = macro Macros.impl[T] +} + +object Test extends App { + case class C(x: Int, y: Int) + + import scala.reflect.runtime.universe._ + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = println(tag) + reprify(C(40, 2)) + + // this is a compilation error at the moment as explained in SI-8104 + // because matchesPt in implicit search says that depoly() isn't a subtype of Generic.Aux[C, (Int, Int)] + // which is rightfully so, because depoly only replaces type parameters, not type members with wildcard types + // however in the future we might want to relax the matchesPt check, so this might start compiling + // therefore, if you've broken this test, then you should be happy, because most likely you've just enabled an interesting use case! + implicitly[Generic.Aux[C, (Int, Int)]] +} diff --git a/tests/untried/neg/t8143a.check b/tests/untried/neg/t8143a.check new file mode 100644 index 000000000000..4e11000a2a53 --- /dev/null +++ b/tests/untried/neg/t8143a.check @@ -0,0 +1,5 @@ +t8143a.scala:2: error: overriding method f in class Foo of type => Int; + method f has weaker access privileges; it should not be private +class Bar extends Foo { private def f = 10 } + ^ +one error found diff --git a/tests/untried/neg/t8143a.scala b/tests/untried/neg/t8143a.scala new file mode 100644 index 000000000000..6abe35e335c4 --- /dev/null +++ b/tests/untried/neg/t8143a.scala @@ -0,0 +1,15 @@ +class Foo { def f = 5 } +class Bar extends Foo { private def f = 10 } + + +class Foo1 { private def f = 5 } +class Bar1 extends Foo1 { def f = 10 } // okay + +class Foo2 { private def f = 5 } +class Bar2 extends Foo2 { private def f = 10 } // okay + +class Foo3 { private[this] def f = 5 } +class Bar3 extends Foo3 { private def f = 10 } // okay + +class Foo4 { private def f = 5 } +class Bar4 extends Foo4 { private[this] def f = 10 } // okay diff --git a/tests/untried/neg/t8146-non-finitary-2.check b/tests/untried/neg/t8146-non-finitary-2.check new file mode 100644 index 000000000000..8c2e1436c2dd --- /dev/null +++ b/tests/untried/neg/t8146-non-finitary-2.check @@ -0,0 +1,9 @@ +t8146-non-finitary-2.scala:5: error: class graph is not finitary because type parameter X is expansively recursive +trait C[X] extends N[N[C[D[X]]]] + ^ +t8146-non-finitary-2.scala:7: error: type mismatch; + found : C[Int] + required: N[C[Int]] + def foo(c: C[Int]): N[C[Int]] = c + ^ +two errors found diff --git a/tests/untried/neg/t8146-non-finitary-2.scala b/tests/untried/neg/t8146-non-finitary-2.scala new file mode 100644 index 000000000000..c12f5f8f497e --- /dev/null +++ b/tests/untried/neg/t8146-non-finitary-2.scala @@ -0,0 +1,8 @@ +// Example 3 from "On Decidability of Nominal Subtyping with Variance" (Pierce, Kennedy) +// http://research.microsoft.com/pubs/64041/fool2007.pdf +trait N[-Z] +trait D[Y] +trait C[X] extends N[N[C[D[X]]]] +object Test { + def foo(c: C[Int]): N[C[Int]] = c +} diff --git a/tests/untried/neg/t8146-non-finitary.check b/tests/untried/neg/t8146-non-finitary.check new file mode 100644 index 000000000000..8363b750caf3 --- /dev/null +++ b/tests/untried/neg/t8146-non-finitary.check @@ -0,0 +1,9 @@ +t8146-non-finitary.scala:4: error: class graph is not finitary because type parameter A is expansively recursive +trait C[A] extends N[N[C[C[A]]]] + ^ +t8146-non-finitary.scala:6: error: type mismatch; + found : C[Int] + required: N[C[Int]] + def foo(c: C[Int]): N[C[Int]] = c + ^ +two errors found diff --git a/tests/untried/neg/t8146-non-finitary.scala b/tests/untried/neg/t8146-non-finitary.scala new file mode 100644 index 000000000000..3d8a3074c76a --- /dev/null +++ b/tests/untried/neg/t8146-non-finitary.scala @@ -0,0 +1,7 @@ +// Example 3 from "On Decidability of Nominal Subtyping with Variance" (Pierce, Kennedy) +// http://research.microsoft.com/pubs/64041/fool2007.pdf +trait N[-A] +trait C[A] extends N[N[C[C[A]]]] +object Test { + def foo(c: C[Int]): N[C[Int]] = c +} diff --git a/tests/untried/neg/t8157.check b/tests/untried/neg/t8157.check new file mode 100644 index 000000000000..9a21a49a0771 --- /dev/null +++ b/tests/untried/neg/t8157.check @@ -0,0 +1,4 @@ +t8157.scala:1: error: in object Test, multiple overloaded alternatives of method foo define default arguments. +object Test { + ^ +one error found diff --git a/tests/untried/neg/t8157.scala b/tests/untried/neg/t8157.scala new file mode 100644 index 000000000000..462d4fa3f1ac --- /dev/null +++ b/tests/untried/neg/t8157.scala @@ -0,0 +1,4 @@ +object Test { + def foo(printer: Any, question: => String, show: Boolean = false)(op: => Any): Any = ??? + def foo[T](question: => String, show: Boolean)(op: => Any = ()): Any = ??? +} diff --git a/tests/untried/neg/t8158.check b/tests/untried/neg/t8158.check new file mode 100644 index 000000000000..fa6b744ba5a5 --- /dev/null +++ b/tests/untried/neg/t8158.check @@ -0,0 +1,4 @@ +Test_2.scala:10: error: not enough patterns for <$anon: AnyRef> offering AnyRef{def isEmpty: Boolean; def get: $anon; def unapply(x: String): $anon}: expected 1, found 0 + case X() => + ^ +one error found diff --git a/tests/untried/neg/t8158/Macros_1.scala b/tests/untried/neg/t8158/Macros_1.scala new file mode 100644 index 000000000000..b84e3ed8d31d --- /dev/null +++ b/tests/untried/neg/t8158/Macros_1.scala @@ -0,0 +1,34 @@ +import scala.language.experimental.macros +import scala.reflect.macros.whitebox.Context + +object Max { + def impl(c: Context)(any: c.Expr[Any]): c.Expr[Any] = { + import c.universe._ + def fail(msg: String) = c.abort(c.enclosingPosition, msg) + val t = c.macroApplication match { + case q"$_.unapply($unargs)" => + /* hangs + */ + q""" + new { + def isEmpty = false + def get = this + def unapply(x: String) = this + }.unapply($unargs) + """ + /* + if get returns Unit or Boolean: + wrong number of patterns for <$anon: AnyRef> offering Unit: expected 1, found 0 + */ + /* straightforward + q""" + new { + def unapply(x: String) = true + }.unapply($unargs) + """ + */ + case _ => fail("bad appl") + } + c.Expr[Any](t) + } +} \ No newline at end of file diff --git a/tests/untried/neg/t8158/Test_2.scala b/tests/untried/neg/t8158/Test_2.scala new file mode 100644 index 000000000000..f5ac6616bb2c --- /dev/null +++ b/tests/untried/neg/t8158/Test_2.scala @@ -0,0 +1,14 @@ +import scala.language.experimental.macros + +object X { + def unapply(any: Any): Any = macro Max.impl +} + +class BugTest { + def bug(): Unit = { + "any" match { + case X() => + case _ => ??? + } + } +} \ No newline at end of file diff --git a/tests/untried/neg/t8177a.check b/tests/untried/neg/t8177a.check new file mode 100644 index 000000000000..0d01206e0c2f --- /dev/null +++ b/tests/untried/neg/t8177a.check @@ -0,0 +1,6 @@ +t8177a.scala:5: error: type mismatch; + found : A{type Result = Int} + required: A{type Result = String} + : A { type Result = String} = x + ^ +one error found diff --git a/tests/untried/neg/t8177a.scala b/tests/untried/neg/t8177a.scala new file mode 100644 index 000000000000..0347541eaf39 --- /dev/null +++ b/tests/untried/neg/t8177a.scala @@ -0,0 +1,6 @@ +trait A { type Result } + +class PolyTests { + def wrong(x: A { type Result = Int }) + : A { type Result = String} = x +} diff --git a/tests/untried/neg/t8182.check b/tests/untried/neg/t8182.check new file mode 100644 index 000000000000..a156d70883a8 --- /dev/null +++ b/tests/untried/neg/t8182.check @@ -0,0 +1,22 @@ +t8182.scala:4: error: illegal start of simple pattern +} +^ +t8182.scala:7: error: illegal start of simple pattern +} +^ +t8182.scala:6: error: type application is not allowed in pattern + val a b[B] // error then continue as for X + ^ +t8182.scala:10: error: illegal start of simple pattern + case a b[B] => // bumpy recovery + ^ +t8182.scala:10: error: type application is not allowed in pattern + case a b[B] => // bumpy recovery + ^ +t8182.scala:11: error: '=>' expected but '}' found. + } + ^ +t8182.scala:16: error: type application is not allowed in pattern + case a B[T] b => + ^ +7 errors found diff --git a/tests/untried/neg/t8182.scala b/tests/untried/neg/t8182.scala new file mode 100644 index 000000000000..1b3bc9821f4a --- /dev/null +++ b/tests/untried/neg/t8182.scala @@ -0,0 +1,18 @@ + +trait X { + val a b // something missing +} +trait Y { + val a b[B] // error then continue as for X +} +trait Z { + (null: Any) match { + case a b[B] => // bumpy recovery + } +} +object B { def unapply[W](a: Any) = Some((1,2)) } +trait Z { + (null: Any) match { + case a B[T] b => + } +} diff --git a/tests/untried/neg/t8207.check b/tests/untried/neg/t8207.check new file mode 100644 index 000000000000..59facd897aa3 --- /dev/null +++ b/tests/untried/neg/t8207.check @@ -0,0 +1,7 @@ +t8207.scala:1: error: '.' expected but '}' found. +class C { import C.this.toString } + ^ +t8207.scala:3: error: '.' expected but '}' found. +class D { import D.this.toString } + ^ +two errors found diff --git a/tests/untried/neg/t8207.scala b/tests/untried/neg/t8207.scala new file mode 100644 index 000000000000..738ce381f4c8 --- /dev/null +++ b/tests/untried/neg/t8207.scala @@ -0,0 +1,3 @@ +class C { import C.this.toString } + +class D { import D.this.toString } diff --git a/tests/untried/neg/t8219-any-any-ref-equals.check b/tests/untried/neg/t8219-any-any-ref-equals.check new file mode 100644 index 000000000000..95d2536fba06 --- /dev/null +++ b/tests/untried/neg/t8219-any-any-ref-equals.check @@ -0,0 +1,10 @@ +t8219-any-any-ref-equals.scala:5: error: method ==: (x$1: Any)Boolean does not take type parameters. + "".==[Int] + ^ +t8219-any-any-ref-equals.scala:6: error: method ==: (x$1: Any)Boolean does not take type parameters. + ("": AnyRef).==[Int] + ^ +t8219-any-any-ref-equals.scala:7: error: method ==: (x$1: Any)Boolean does not take type parameters. + ("": Object).==[Int] + ^ +three errors found diff --git a/tests/untried/neg/t8219-any-any-ref-equals.scala b/tests/untried/neg/t8219-any-any-ref-equals.scala new file mode 100644 index 000000000000..f1b81fa734c1 --- /dev/null +++ b/tests/untried/neg/t8219-any-any-ref-equals.scala @@ -0,0 +1,8 @@ +object Test { + // The error message tells us that AnyRef#== and Any#== are overloaded. + // A real class couldn't define such an overload, why do we allow AnyRef + // to do so? + "".==[Int] + ("": AnyRef).==[Int] + ("": Object).==[Int] +} diff --git a/tests/untried/neg/t8228.check b/tests/untried/neg/t8228.check new file mode 100644 index 000000000000..02eff4b1b714 --- /dev/null +++ b/tests/untried/neg/t8228.check @@ -0,0 +1,4 @@ +t8228.scala:4: error: recursive value foo needs type + val foo = foo(null) + ^ +one error found diff --git a/tests/untried/neg/t8228.scala b/tests/untried/neg/t8228.scala new file mode 100644 index 000000000000..19d71aeab478 --- /dev/null +++ b/tests/untried/neg/t8228.scala @@ -0,0 +1,7 @@ +object X { + def bar = { + def foo(x: Any) = "" + val foo = foo(null) + foo(null) // cycle in isApplicableBasedOnArity + } +} diff --git a/tests/untried/neg/t8229.check b/tests/untried/neg/t8229.check new file mode 100644 index 000000000000..cc504fa34e25 --- /dev/null +++ b/tests/untried/neg/t8229.check @@ -0,0 +1,4 @@ +t8229.scala:5: error: value + is not a member of Object + o + "" + ^ +one error found diff --git a/tests/untried/neg/t8229.scala b/tests/untried/neg/t8229.scala new file mode 100644 index 000000000000..91966311e2d0 --- /dev/null +++ b/tests/untried/neg/t8229.scala @@ -0,0 +1,6 @@ +import Predef.{any2stringadd => _, _} + +object Test { + val o = new Object() + o + "" +} diff --git a/tests/untried/neg/t8237-default.check b/tests/untried/neg/t8237-default.check new file mode 100644 index 000000000000..59fe21ed0390 --- /dev/null +++ b/tests/untried/neg/t8237-default.check @@ -0,0 +1,13 @@ +t8237-default.scala:5: error: no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int]) + --- because --- +argument expression's type is not compatible with formal parameter type; + found : List[Int] + required: ?T[?T[List[?T[X forSome { type X }]]]] + test4(test4$default$1) + ^ +t8237-default.scala:5: error: type mismatch; + found : List[Int] + required: T[T[List[T[X forSome { type X }]]]] + test4(test4$default$1) + ^ +two errors found diff --git a/tests/untried/neg/t8237-default.scala b/tests/untried/neg/t8237-default.scala new file mode 100644 index 000000000000..f695aa523fec --- /dev/null +++ b/tests/untried/neg/t8237-default.scala @@ -0,0 +1,29 @@ +// This test case was extracte from `names-defaults-neg.scala` +// It pinpoints an improvement an error message that results from +// a type inference failure +object Test extends App { + test4(test4$default$1) + + def test4[T[P]](x: T[T[List[T[X forSome { type X }]]]]) = ??? + def test4$default$1[T[P]]: List[Int] = ??? +} + +/* +OLD: + no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int]) + --- because --- +argument expression's type is not compatible with formal parameter type; + found : List[Int] + required: ?T + test4(test4$default$1) + ^ + +NEW: + +no type parameters for method test4: (x: T[T[List[T[X forSome { type X }]]]])Nothing exist so that it can be applied to arguments (List[Int]) + --- because --- +argument expression's type is not compatible with formal parameter type; + found : List[Int] + required: ?T[?T[List[?T[X forSome { type X }]]] + test4(test4$default$1) +*/ diff --git a/tests/untried/neg/t8244.check b/tests/untried/neg/t8244.check new file mode 100644 index 000000000000..90b2bf6f4645 --- /dev/null +++ b/tests/untried/neg/t8244.check @@ -0,0 +1,4 @@ +Test_2.scala:9: error: value exxx is not a member of ?0 + raw.t.exxx // java.lang.ClassCastException: java.lang.String cannot be cast to X + ^ +one error found diff --git a/tests/untried/neg/t8244/Raw_1.java b/tests/untried/neg/t8244/Raw_1.java new file mode 100644 index 000000000000..0c667f1106d0 --- /dev/null +++ b/tests/untried/neg/t8244/Raw_1.java @@ -0,0 +1,4 @@ +public abstract class Raw_1{ + public Raw_1 raw() { return new Raw_1() { public String t() { return ""; } }; } + public abstract T t(); +} diff --git a/tests/untried/neg/t8244/Test_2.scala b/tests/untried/neg/t8244/Test_2.scala new file mode 100644 index 000000000000..152bb0b870d1 --- /dev/null +++ b/tests/untried/neg/t8244/Test_2.scala @@ -0,0 +1,12 @@ +class X extends Raw_1[X] { + override def t = this + def exxx = 0 +} + +object Test extends App { + def c(s: X) = { + val raw = s.raw + raw.t.exxx // java.lang.ClassCastException: java.lang.String cannot be cast to X + } + c(new X()) +} diff --git a/tests/untried/neg/t8244b.check b/tests/untried/neg/t8244b.check new file mode 100644 index 000000000000..f6cbf99eb596 --- /dev/null +++ b/tests/untried/neg/t8244b.check @@ -0,0 +1,4 @@ +t8244b.scala:15: error: value exxx is not a member of _$1 + raw.t.exxx + ^ +one error found diff --git a/tests/untried/neg/t8244b.scala b/tests/untried/neg/t8244b.scala new file mode 100644 index 000000000000..2fb4f451a1dd --- /dev/null +++ b/tests/untried/neg/t8244b.scala @@ -0,0 +1,18 @@ +class Raw_1[T]{ + def raw(): Raw_1[_] = { new Raw_1[String] { def t() = "" } } + def t(): T +} + + +class X extends Raw_1[X] { + override def t = this + def exxx = 0 +} + +object Test extends App { + def c(s: X) = { + val raw = s.raw + raw.t.exxx + } + c(new X()) +} diff --git a/tests/untried/neg/t8244c.check b/tests/untried/neg/t8244c.check new file mode 100644 index 000000000000..fd58a5847c2e --- /dev/null +++ b/tests/untried/neg/t8244c.check @@ -0,0 +1,4 @@ +t8244c.scala:15: error: value exxx is not a member of _$1 + raw.t.exxx + ^ +one error found diff --git a/tests/untried/neg/t8244c.scala b/tests/untried/neg/t8244c.scala new file mode 100644 index 000000000000..2fb4f451a1dd --- /dev/null +++ b/tests/untried/neg/t8244c.scala @@ -0,0 +1,18 @@ +class Raw_1[T]{ + def raw(): Raw_1[_] = { new Raw_1[String] { def t() = "" } } + def t(): T +} + + +class X extends Raw_1[X] { + override def t = this + def exxx = 0 +} + +object Test extends App { + def c(s: X) = { + val raw = s.raw + raw.t.exxx + } + c(new X()) +} diff --git a/tests/untried/neg/t8244e.check b/tests/untried/neg/t8244e.check new file mode 100644 index 000000000000..ebd74036e5f6 --- /dev/null +++ b/tests/untried/neg/t8244e.check @@ -0,0 +1,4 @@ +Test.scala:9: error: value exxx is not a member of ?0 + raw.t.exxx // java.lang.ClassCastException: java.lang.String cannot be cast to X + ^ +one error found diff --git a/tests/untried/neg/t8244e/Raw.java b/tests/untried/neg/t8244e/Raw.java new file mode 100644 index 000000000000..53202e319d32 --- /dev/null +++ b/tests/untried/neg/t8244e/Raw.java @@ -0,0 +1,4 @@ +public abstract class Raw{ + public Raw raw() { return new Raw() { public String t() { return ""; } }; } + public abstract T t(); +} diff --git a/tests/untried/neg/t8244e/Test.scala b/tests/untried/neg/t8244e/Test.scala new file mode 100644 index 000000000000..ca2a90583f63 --- /dev/null +++ b/tests/untried/neg/t8244e/Test.scala @@ -0,0 +1,12 @@ +class X extends Raw[X] { + override def t = this + def exxx = 0 +} + +object Test extends App { + def c(s: X) = { + val raw = s.raw + raw.t.exxx // java.lang.ClassCastException: java.lang.String cannot be cast to X + } + c(new X()) +} diff --git a/tests/untried/neg/t8266-invalid-interp.check b/tests/untried/neg/t8266-invalid-interp.check new file mode 100644 index 000000000000..70dd4081b017 --- /dev/null +++ b/tests/untried/neg/t8266-invalid-interp.check @@ -0,0 +1,10 @@ +t8266-invalid-interp.scala:4: error: Trailing '\' escapes nothing. + f"a\", + ^ +t8266-invalid-interp.scala:5: error: invalid escape character at index 1 in "a\xc" + f"a\xc", + ^ +t8266-invalid-interp.scala:7: error: invalid escape character at index 1 in "a\vc" + f"a\vc" + ^ +three errors found diff --git a/tests/untried/neg/t8266-invalid-interp.scala b/tests/untried/neg/t8266-invalid-interp.scala new file mode 100644 index 000000000000..4b26546880a3 --- /dev/null +++ b/tests/untried/neg/t8266-invalid-interp.scala @@ -0,0 +1,9 @@ + +trait X { + def f = Seq( + f"a\", + f"a\xc", + // following could suggest \u000b for vertical tab, similar for \a alert + f"a\vc" + ) +} diff --git a/tests/untried/neg/t8300-overloading.check b/tests/untried/neg/t8300-overloading.check new file mode 100644 index 000000000000..edd34d44bd6c --- /dev/null +++ b/tests/untried/neg/t8300-overloading.check @@ -0,0 +1,7 @@ +t8300-overloading.scala:15: error: double definition: +def foo(name: Test.u.Name): Nothing at line 14 and +def foo(name: Test.u.TermName): Nothing at line 15 +have same type after erasure: (name: Universe#NameApi)Nothing + def foo(name: TermName) = ??? + ^ +one error found diff --git a/tests/untried/neg/t8300-overloading.scala b/tests/untried/neg/t8300-overloading.scala new file mode 100644 index 000000000000..0f4eee7b4211 --- /dev/null +++ b/tests/untried/neg/t8300-overloading.scala @@ -0,0 +1,16 @@ +// cf. pos/t8300-overloading.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._ + + def foo(name: Name) = ??? + def foo(name: TermName) = ??? +} diff --git a/tests/untried/neg/t835.check b/tests/untried/neg/t835.check new file mode 100644 index 000000000000..6ad18d30284f --- /dev/null +++ b/tests/untried/neg/t835.check @@ -0,0 +1,9 @@ +t835.scala:2: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + Console.println(List(List(1, 2, 3) : _*, List(4, 5, 6) : _*)) + ^ +t835.scala:2: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + Console.println(List(List(1, 2, 3) : _*, List(4, 5, 6) : _*)) + ^ +two errors found diff --git a/tests/untried/neg/t835.scala b/tests/untried/neg/t835.scala new file mode 100644 index 000000000000..553d2c1be4f5 --- /dev/null +++ b/tests/untried/neg/t835.scala @@ -0,0 +1,3 @@ +object Test extends App { + Console.println(List(List(1, 2, 3) : _*, List(4, 5, 6) : _*)) +} diff --git a/tests/untried/neg/t836.check b/tests/untried/neg/t836.check new file mode 100644 index 000000000000..cf2faf926fd8 --- /dev/null +++ b/tests/untried/neg/t836.check @@ -0,0 +1,7 @@ +t836.scala:9: error: type mismatch; + found : Any + required: A.this.S + (which expands to) A.this.MyObj#S + val some: S = any // compiles => type X is set to scala.Any + ^ +one error found diff --git a/tests/untried/neg/t836.scala b/tests/untried/neg/t836.scala new file mode 100644 index 000000000000..3633b816c6a1 --- /dev/null +++ b/tests/untried/neg/t836.scala @@ -0,0 +1,16 @@ +abstract class Obj { type S } +class ObjImpl extends Obj { type S = String } + +abstract class A { + type MyObj <: Obj + type S = MyObj#S + + val any: Any = 0 + val some: S = any // compiles => type X is set to scala.Any +} + +class B extends A { + type MyObj = ObjImpl + val myString: S = "hello" + val realString: String = myString // error: type missmatch +} diff --git a/tests/untried/neg/t8372.check b/tests/untried/neg/t8372.check new file mode 100644 index 000000000000..6a6424a834b0 --- /dev/null +++ b/tests/untried/neg/t8372.check @@ -0,0 +1,7 @@ +t8372.scala:7: error: No ClassTag available for T1 + def unzip[T1, T2](a: Array[(T1, T2)]) = a.unzip + ^ +t8372.scala:9: error: No ClassTag available for T1 + def unzip3[T1, T2, T3](a: Array[(T1, T2, T3)]): (Array[T1], Array[T2], Array[T3]) = a.unzip3 + ^ +two errors found diff --git a/tests/untried/neg/t8372.scala b/tests/untried/neg/t8372.scala new file mode 100644 index 000000000000..60a674f4d851 --- /dev/null +++ b/tests/untried/neg/t8372.scala @@ -0,0 +1,10 @@ +class t8372 { + // failed with "error: tpe T1 is an unresolved spliceable type"; that was caused by + // misguided type inference of type parameters in ArrayOps.unzip + // the type inference failed because the order of implicit arguments was wrong + // the evidence that T <: (T1, T2) came as last argument so it couldn't guide the + // type inference early enough + def unzip[T1, T2](a: Array[(T1, T2)]) = a.unzip + // the same as above + def unzip3[T1, T2, T3](a: Array[(T1, T2, T3)]): (Array[T1], Array[T2], Array[T3]) = a.unzip3 +} diff --git a/tests/untried/neg/t8376.check b/tests/untried/neg/t8376.check new file mode 100644 index 000000000000..22ed942d51a3 --- /dev/null +++ b/tests/untried/neg/t8376.check @@ -0,0 +1,7 @@ +S.scala:2: error: overloaded method value m with alternatives: + (a: J*)Unit + (a: String*)Unit + cannot be applied to (Int) + J.m(0) + ^ +one error found diff --git a/tests/untried/neg/t8376/J.java b/tests/untried/neg/t8376/J.java new file mode 100644 index 000000000000..29aa23da8421 --- /dev/null +++ b/tests/untried/neg/t8376/J.java @@ -0,0 +1,4 @@ +class J { + public static void m(String... a) { } + public static void m(J... a) { } +} diff --git a/tests/untried/neg/t8376/S.scala b/tests/untried/neg/t8376/S.scala new file mode 100644 index 000000000000..a19f0d3c067c --- /dev/null +++ b/tests/untried/neg/t8376/S.scala @@ -0,0 +1,4 @@ +object S { + J.m(0) + // the error message should show `T*` in the method signatures rather than `[T]` +} diff --git a/tests/untried/neg/t845.check b/tests/untried/neg/t845.check new file mode 100644 index 000000000000..07ed7e417b8d --- /dev/null +++ b/tests/untried/neg/t845.check @@ -0,0 +1,4 @@ +t845.scala:4: error: only classes can have declared but undefined members + type Bar; + ^ +one error found diff --git a/tests/untried/neg/t845.scala b/tests/untried/neg/t845.scala new file mode 100644 index 000000000000..ddf6a16f326a --- /dev/null +++ b/tests/untried/neg/t845.scala @@ -0,0 +1,16 @@ +package test; + +object Test extends App { + type Bar; + trait FooImpl; + + trait Bob { + def bar : Bar with FooImpl; + } + def ifn[A,B](a : A)(f : A => B) = + if (a != null) f(a) else null; + + val bob : Bob = null; + val bar = ifn(bob)(_.bar); + assert(bar == null); +} diff --git a/tests/untried/neg/t846.check b/tests/untried/neg/t846.check new file mode 100644 index 000000000000..242a8001ff3c --- /dev/null +++ b/tests/untried/neg/t846.check @@ -0,0 +1,6 @@ +t846.scala:9: error: type mismatch; + found : Null(null) + required: B + if (a != null) f(a) else null + ^ +one error found diff --git a/tests/untried/neg/t846.scala b/tests/untried/neg/t846.scala new file mode 100644 index 000000000000..acf8462030e2 --- /dev/null +++ b/tests/untried/neg/t846.scala @@ -0,0 +1,13 @@ +package test; +trait Test { + type Bar; + trait FooImpl; + trait Bob { + def bar : Bar with FooImpl; + } + def ifn[A,B](a : A)(f : A => B): B = + if (a != null) f(a) else null + val bob : Bob = null; + val bar = ifn(bob)(_.bar); + assert(bar == null); +} diff --git a/tests/untried/neg/t856.check b/tests/untried/neg/t856.check new file mode 100644 index 000000000000..fb93f96d9f30 --- /dev/null +++ b/tests/untried/neg/t856.check @@ -0,0 +1,14 @@ +t856.scala:3: error: class ComplexRect needs to be abstract, since: +it has 2 unimplemented members. +/** As seen from class ComplexRect, the missing signatures are as follows. + * For convenience, these are usable as stub implementations. + */ + // Members declared in scala.Equals + def canEqual(that: Any): Boolean = ??? + + // Members declared in scala.Product2 + def _2: Double = ??? + +class ComplexRect(val _1:Double, _2:Double) extends Complex { + ^ +one error found diff --git a/tests/untried/neg/t856.scala b/tests/untried/neg/t856.scala new file mode 100644 index 000000000000..fea216bfad05 --- /dev/null +++ b/tests/untried/neg/t856.scala @@ -0,0 +1,11 @@ +trait Complex extends Product2[Double,Double] + +class ComplexRect(val _1:Double, _2:Double) extends Complex { + override def toString = "ComplexRect("+_1+","+_2+")" +} + +object Test { + def main(args:Array[String]) = { + new ComplexRect(1,1)._2 + } +} diff --git a/tests/untried/neg/t875.check b/tests/untried/neg/t875.check new file mode 100644 index 000000000000..406edcf50702 --- /dev/null +++ b/tests/untried/neg/t875.check @@ -0,0 +1,17 @@ +t875.scala:3: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + val ys = List(1, 2, 3, xs: _*) + ^ +t875.scala:6: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + mkList1(xs: _*) + ^ +t875.scala:15: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + f(true, 1, xs: _*) + ^ +t875.scala:16: error: no `: _*' annotation allowed here +(such annotations are only allowed in arguments to *-parameters) + g(1, xs:_*) + ^ +four errors found diff --git a/tests/untried/neg/t875.scala b/tests/untried/neg/t875.scala new file mode 100644 index 000000000000..841b2aec3f57 --- /dev/null +++ b/tests/untried/neg/t875.scala @@ -0,0 +1,18 @@ +object Test extends App { + val xs = List(4, 5, 6) + val ys = List(1, 2, 3, xs: _*) + def mkList1(x: Int) = List(x) + def mkList2(x: Boolean) = List(x) + mkList1(xs: _*) + + + def f(x: Int*) = List(x: _*) + + def f(x: Boolean, y: Int*) = List(y: _*) + + def g[a](x: a*) = List(x: _*) + + f(true, 1, xs: _*) + g(1, xs:_*) + +} diff --git a/tests/untried/neg/t876.check b/tests/untried/neg/t876.check new file mode 100644 index 000000000000..04c5c8f22e97 --- /dev/null +++ b/tests/untried/neg/t876.check @@ -0,0 +1,4 @@ +t876.scala:25: error: too many arguments for method apply: (key: AssertionError.A)manager.B in class HashMap + assert(manager.map(A2) == List(manager.map(A2, A1))) + ^ +one error found diff --git a/tests/untried/neg/t876.scala b/tests/untried/neg/t876.scala new file mode 100644 index 000000000000..981d48d8bad6 --- /dev/null +++ b/tests/untried/neg/t876.scala @@ -0,0 +1,28 @@ +import scala.collection.mutable.HashMap + +object AssertionError extends AnyRef with App +{ + abstract class A {} + + object A1 extends A {} + + object A2 extends A {} + + class Manager + { + final class B {} + + val map = new HashMap[A, B] + } + + + def test[T](f: => T): Unit = { f } + + test { + val manager = new Manager + + // This line is illegal and causes a compiler crash with Scala 2.3.1 + assert(manager.map(A2) == List(manager.map(A2, A1))) + } + +} diff --git a/tests/untried/neg/t877.check b/tests/untried/neg/t877.check new file mode 100644 index 000000000000..c3d4ab658478 --- /dev/null +++ b/tests/untried/neg/t877.check @@ -0,0 +1,7 @@ +t877.scala:3: error: Invalid literal number +trait Foo extends A(22A, Bug!) {} + ^ +t877.scala:3: error: ')' expected but eof found. +trait Foo extends A(22A, Bug!) {} + ^ +two errors found diff --git a/tests/untried/neg/t877.scala b/tests/untried/neg/t877.scala new file mode 100644 index 000000000000..5e132a1dd4c5 --- /dev/null +++ b/tests/untried/neg/t877.scala @@ -0,0 +1,3 @@ +class A + +trait Foo extends A(22A, Bug!) {} diff --git a/tests/untried/neg/t882.check b/tests/untried/neg/t882.check new file mode 100644 index 000000000000..a906778a1a41 --- /dev/null +++ b/tests/untried/neg/t882.check @@ -0,0 +1,4 @@ +t882.scala:2: error: traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...' +trait SortedSet[A <% Ordered[A]] { + ^ +one error found diff --git a/tests/untried/neg/t882.scala b/tests/untried/neg/t882.scala new file mode 100644 index 000000000000..5a8908befc5c --- /dev/null +++ b/tests/untried/neg/t882.scala @@ -0,0 +1,6 @@ +package test; +trait SortedSet[A <% Ordered[A]] { + def first : A; + def last : A; + assert(first.compare(last) < 0); +} diff --git a/tests/untried/neg/t900.check b/tests/untried/neg/t900.check new file mode 100644 index 000000000000..6fe26a31acdc --- /dev/null +++ b/tests/untried/neg/t900.check @@ -0,0 +1,9 @@ +t900.scala:4: error: type mismatch; + found : Foo.this.x.type (with underlying type Foo.this.bar) + required: AnyRef +Note that bar is unbounded, which means AnyRef is not a known parent. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + def break(): x.type + ^ +one error found diff --git a/tests/untried/neg/t900.scala b/tests/untried/neg/t900.scala new file mode 100644 index 000000000000..2d2c85757523 --- /dev/null +++ b/tests/untried/neg/t900.scala @@ -0,0 +1,5 @@ +trait Foo { + type bar + val x : bar + def break(): x.type +} diff --git a/tests/untried/neg/t908.check b/tests/untried/neg/t908.check new file mode 100644 index 000000000000..2c723a700bc2 --- /dev/null +++ b/tests/untried/neg/t908.check @@ -0,0 +1,4 @@ +t908.scala:8: error: not found: value makeA + this(makeA) + ^ +one error found diff --git a/tests/untried/neg/t908.scala b/tests/untried/neg/t908.scala new file mode 100644 index 000000000000..97f3c5058639 --- /dev/null +++ b/tests/untried/neg/t908.scala @@ -0,0 +1,11 @@ +abstract class A[T <% Ordered[T]] { + def makeA = new Object +// case object default extends Object +} + +class C[T <% Ordered[T]](foo: Object) extends A[T] { + def this() = { + this(makeA) + // this(default) + } +} diff --git a/tests/untried/neg/t909.check b/tests/untried/neg/t909.check new file mode 100644 index 000000000000..e7a42bd246b7 --- /dev/null +++ b/tests/untried/neg/t909.check @@ -0,0 +1,6 @@ +t909.scala:6: error: type mismatch; + found : String("Hello") + required: Int + case Foo("Hello") => + ^ +one error found diff --git a/tests/untried/neg/t909.scala b/tests/untried/neg/t909.scala new file mode 100644 index 000000000000..63dd88adf20e --- /dev/null +++ b/tests/untried/neg/t909.scala @@ -0,0 +1,9 @@ +case class Foo(x:Int) + +object Bar { + def main(args:Array[String]): Unit = { + Foo(2) match { + case Foo("Hello") => + } + } +} diff --git a/tests/untried/neg/t910.check b/tests/untried/neg/t910.check new file mode 100644 index 000000000000..45420f8e3545 --- /dev/null +++ b/tests/untried/neg/t910.check @@ -0,0 +1,6 @@ +t910.scala:4: error: type mismatch; + found : Seq[Char] + required: Seq[Int] + val y: Seq[Int] = rest + ^ +one error found diff --git a/tests/untried/neg/t910.scala b/tests/untried/neg/t910.scala new file mode 100644 index 000000000000..cc47104d14f9 --- /dev/null +++ b/tests/untried/neg/t910.scala @@ -0,0 +1,7 @@ +object RegExpTest1 extends App { + def co(x: Seq[Char]) = x match { + case Seq('s','c','a','l','a', rest @ _*) => + val y: Seq[Int] = rest + y + } +} diff --git a/tests/untried/neg/t935.check b/tests/untried/neg/t935.check new file mode 100644 index 000000000000..af634a2630f2 --- /dev/null +++ b/tests/untried/neg/t935.check @@ -0,0 +1,7 @@ +t935.scala:7: error: type arguments [Test3.B] do not conform to class E's type parameter bounds [T <: String] + @E[B](new B) val b = "hi" + ^ +t935.scala:13: error: type arguments [Test4.B] do not conform to class E's type parameter bounds [T <: String] + val b: String @E[B](new B) = "hi" + ^ +two errors found diff --git a/tests/untried/neg/t935.scala b/tests/untried/neg/t935.scala new file mode 100644 index 000000000000..299062adb883 --- /dev/null +++ b/tests/untried/neg/t935.scala @@ -0,0 +1,14 @@ +import annotation.Annotation + +object Test3 { + class E[T >: Nothing <: String](s: T) extends Annotation + class B + // val a = new E[B](new B) + @E[B](new B) val b = "hi" +} + +object Test4 { + class E[T <: String](s: T) extends Annotation + class B + val b: String @E[B](new B) = "hi" +} diff --git a/tests/untried/neg/t944.check b/tests/untried/neg/t944.check new file mode 100644 index 000000000000..1fc0a12208cd --- /dev/null +++ b/tests/untried/neg/t944.check @@ -0,0 +1,4 @@ +t944.scala:5: error: implementation restricts functions to 22 parameters + a23:Int) => 1 + ^ +one error found diff --git a/tests/untried/neg/t944.scala b/tests/untried/neg/t944.scala new file mode 100644 index 000000000000..dc80e5f49f89 --- /dev/null +++ b/tests/untried/neg/t944.scala @@ -0,0 +1,6 @@ +object TooManyArgsFunction { + val f = (a1:Int, a2:Int, a3:Int, a4:Int, a5:Int, a6:Int, a7:Int, a8:Int, + a9:Int, a10:Int, a11:Int, a12:Int, a13:Int, a14:Int, a15:Int, + a16:Int, a17:Int, a18:Int, a19:Int, a20:Int, a21:Int, a22:Int, + a23:Int) => 1 +} diff --git a/tests/untried/neg/t961.check b/tests/untried/neg/t961.check new file mode 100644 index 000000000000..14d39b0f4224 --- /dev/null +++ b/tests/untried/neg/t961.check @@ -0,0 +1,4 @@ +t961.scala:11: error: Temp.B.type does not take parameters + B() match { + ^ +one error found diff --git a/tests/untried/neg/t961.scala b/tests/untried/neg/t961.scala new file mode 100644 index 000000000000..088bddd7ee8d --- /dev/null +++ b/tests/untried/neg/t961.scala @@ -0,0 +1,14 @@ +object Temp { + abstract class A + object B { + private case class B_inner() extends A + def apply: A = B_inner() + def unapply(a: A) = a match { + case B_inner() => true + case _ => false + } + } + B() match { + case B() => Console.println("match") + } +} diff --git a/tests/untried/neg/t963.check b/tests/untried/neg/t963.check new file mode 100644 index 000000000000..4dc202c7bd14 --- /dev/null +++ b/tests/untried/neg/t963.check @@ -0,0 +1,12 @@ +t963.scala:14: error: stable identifier required, but Test.this.y3.x found. + val w3 : y3.x.type = y3.x + ^ +t963.scala:17: error: stable identifier required, but Test.this.y4.x found. + val w4 : y4.x.type = y4.x + ^ +t963.scala:10: error: type mismatch; + found : AnyRef{def x: Integer} + required: AnyRef{val x: Integer} + val y2 : { val x : java.lang.Integer } = new { def x = new java.lang.Integer(r.nextInt) } + ^ +three errors found diff --git a/tests/untried/neg/t963.scala b/tests/untried/neg/t963.scala new file mode 100644 index 000000000000..0cc203429924 --- /dev/null +++ b/tests/untried/neg/t963.scala @@ -0,0 +1,18 @@ +import scala.util.Random + +// Only y1 (val/val) should actually compile. +object Test { + val r = new Random() + + val y1 : { val x : java.lang.Integer } = new { val x = new java.lang.Integer(r.nextInt) } + val w1 : y1.x.type = y1.x + + val y2 : { val x : java.lang.Integer } = new { def x = new java.lang.Integer(r.nextInt) } + val w2 : y2.x.type = y2.x + + val y3 : { def x : java.lang.Integer } = new { val x = new java.lang.Integer(r.nextInt) } + val w3 : y3.x.type = y3.x + + val y4 : { def x : java.lang.Integer } = new { def x = new java.lang.Integer(r.nextInt) } + val w4 : y4.x.type = y4.x +} diff --git a/tests/untried/neg/t963b.check b/tests/untried/neg/t963b.check new file mode 100644 index 000000000000..9918a98c464c --- /dev/null +++ b/tests/untried/neg/t963b.check @@ -0,0 +1,6 @@ +t963b.scala:25: error: type mismatch; + found : B.type + required: AnyRef{val y: A} + B.f(B) + ^ +one error found diff --git a/tests/untried/neg/t963b.scala b/tests/untried/neg/t963b.scala new file mode 100644 index 000000000000..3442f46c4e5d --- /dev/null +++ b/tests/untried/neg/t963b.scala @@ -0,0 +1,26 @@ +// Soundness bug, at #963 and dup at #2079. +trait A { + type T + var v : T +} + +object B { + def f(x : { val y : A }): Unit = { x.y.v = x.y.v } + + var a : A = _ + var b : Boolean = false + def y : A = { + if(b) { + a = new A { type T = Int; var v = 1 } + a + } else { + a = new A { type T = String; var v = "" } + b = true + a + } + } +} + +object Test extends App { + B.f(B) +} diff --git a/tests/untried/neg/t987.check b/tests/untried/neg/t987.check new file mode 100644 index 000000000000..90ab70ba1ca0 --- /dev/null +++ b/tests/untried/neg/t987.check @@ -0,0 +1,19 @@ +t987.scala:15: error: illegal inheritance; + class E inherits different type instances of trait B: +B[D] and B[C] +class E extends D + ^ +t987.scala:20: error: illegal inheritance; + class F inherits different type instances of trait B: +B[D] and B[C] +class F extends D + ^ +t987.scala:25: error: illegal inheritance; + class D inherits different type instances of trait B: +B[D] and B[C] +abstract class D extends C with B[D] {} + ^ +t987.scala:25: error: type arguments [D] do not conform to trait B's type parameter bounds [T <: B[T]] +abstract class D extends C with B[D] {} + ^ +four errors found diff --git a/tests/untried/neg/t987.scala b/tests/untried/neg/t987.scala new file mode 100644 index 000000000000..1fedf12ebc85 --- /dev/null +++ b/tests/untried/neg/t987.scala @@ -0,0 +1,25 @@ +// tested using Scala compiler version 2.4.0-RC1 -- (c) 2002-2011 LAMP/EPFL + +// Many thanks to all at LAMP for the work that goes into Scala. + + +class A {} + +trait B[T <: B[T]] { self: T => } + +abstract class C extends A with B[C] +{ + protected val data: List[Int] +} + +class E extends D +{ + val data = Nil +} + +class F extends D +{ + val data = Nil +} + +abstract class D extends C with B[D] {} diff --git a/tests/untried/neg/t997.check b/tests/untried/neg/t997.check new file mode 100644 index 000000000000..b11879222929 --- /dev/null +++ b/tests/untried/neg/t997.check @@ -0,0 +1,4 @@ +t997.scala:13: error: too many patterns for object Foo offering (String, String): expected 2, found 3 +"x" match { case Foo(a, b, c) => Console.println((a,b,c)) } + ^ +one error found diff --git a/tests/untried/neg/t997.scala b/tests/untried/neg/t997.scala new file mode 100644 index 000000000000..1198738f2495 --- /dev/null +++ b/tests/untried/neg/t997.scala @@ -0,0 +1,15 @@ +// An extractor with 2 results +object Foo { def unapply(x : String) = Some((x, x)) } + +object Test extends App { + +// Prints '(x, x)'. Should compile as per SI-6111. +"x" match { case Foo(a) => Console.println(a) } + +// Prints '(x,x)' as expected. +"x" match { case Foo(a, b) => Console.println((a,b)) } + +// Gives confusing error 'not found: value c'. +"x" match { case Foo(a, b, c) => Console.println((a,b,c)) } + +} diff --git a/tests/untried/neg/tailrec-2.check b/tests/untried/neg/tailrec-2.check new file mode 100644 index 000000000000..1daad6922edc --- /dev/null +++ b/tests/untried/neg/tailrec-2.check @@ -0,0 +1,7 @@ +tailrec-2.scala:8: error: could not optimize @tailrec annotated method f: it contains a recursive call targeting a supertype + @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Super[A]).f(mem) + ^ +tailrec-2.scala:9: error: @tailrec annotated method contains no recursive calls + @annotation.tailrec final def f1[B >: A](mem: List[B]): List[B] = this.g(mem) + ^ +two errors found diff --git a/tests/untried/neg/tailrec-2.scala b/tests/untried/neg/tailrec-2.scala new file mode 100644 index 000000000000..d6b8b1355b01 --- /dev/null +++ b/tests/untried/neg/tailrec-2.scala @@ -0,0 +1,29 @@ +sealed abstract class Super[+A] { + def f[B >: A](mem: List[B]) : List[B] + def g(mem: List[_]) = ??? +} +// This one should fail, target is a supertype +class Bop1[+A](val element: A) extends Super[A] { + + @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Super[A]).f(mem) + @annotation.tailrec final def f1[B >: A](mem: List[B]): List[B] = this.g(mem) +} +// These succeed +class Bop2[+A](val element: A) extends Super[A] { + @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = (null: Bop2[A]).f(mem) +} +object Bop3 extends Super[Nothing] { + @annotation.tailrec final def f[B](mem: List[B]): List[B] = (null: Bop3.type).f(mem) +} +class Bop4[+A](val element: A) extends Super[A] { + @annotation.tailrec final def f[B >: A](mem: List[B]): List[B] = Other.f[A].f(mem) +} + +object Other { + def f[T] : Bop4[T] = sys.error("") +} + +object Bop { + def m1[A] : Super[A] = sys.error("") + def m2[A] : Bop2[A] = sys.error("") +} diff --git a/tests/untried/neg/tailrec-3.check b/tests/untried/neg/tailrec-3.check new file mode 100644 index 000000000000..a3542fb56441 --- /dev/null +++ b/tests/untried/neg/tailrec-3.check @@ -0,0 +1,10 @@ +tailrec-3.scala:4: error: could not optimize @tailrec annotated method quux: it contains a recursive call not in tail position + @tailrec private def quux(xs: List[String]): List[String] = quux(quux(xs)) + ^ +tailrec-3.scala:6: error: could not optimize @tailrec annotated method quux2: it contains a recursive call not in tail position + case x1 :: x2 :: rest => quux2(x1 :: quux2(rest)) + ^ +tailrec-3.scala:10: error: could not optimize @tailrec annotated method quux3: it contains a recursive call not in tail position + case x :: xs if quux3(List("abc")) => quux3(xs) + ^ +three errors found diff --git a/tests/untried/neg/tailrec-3.scala b/tests/untried/neg/tailrec-3.scala new file mode 100644 index 000000000000..20361658eace --- /dev/null +++ b/tests/untried/neg/tailrec-3.scala @@ -0,0 +1,14 @@ +import annotation.tailrec + +object Test { + @tailrec private def quux(xs: List[String]): List[String] = quux(quux(xs)) + @tailrec private def quux2(xs: List[String]): List[String] = xs match { + case x1 :: x2 :: rest => quux2(x1 :: quux2(rest)) + case _ => Nil + } + @tailrec private def quux3(xs: List[String]): Boolean = xs match { + case x :: xs if quux3(List("abc")) => quux3(xs) + case _ => false + } +} + diff --git a/tests/untried/neg/tailrec.check b/tests/untried/neg/tailrec.check new file mode 100644 index 000000000000..946d3421e689 --- /dev/null +++ b/tests/untried/neg/tailrec.check @@ -0,0 +1,16 @@ +tailrec.scala:45: error: could not optimize @tailrec annotated method facfail: it contains a recursive call not in tail position + else n * facfail(n - 1) + ^ +tailrec.scala:50: error: could not optimize @tailrec annotated method fail1: it is neither private nor final so can be overridden + @tailrec def fail1(x: Int): Int = fail1(x) + ^ +tailrec.scala:53: error: could not optimize @tailrec annotated method fail2: it contains a recursive call not in tail position + @tailrec final def fail2[T](xs: List[T]): List[T] = xs match { + ^ +tailrec.scala:59: error: could not optimize @tailrec annotated method fail3: it is called recursively with different type arguments + @tailrec final def fail3[T](x: Int): Int = fail3(x - 1) + ^ +tailrec.scala:63: error: could not optimize @tailrec annotated method fail4: it changes type of 'this' on a polymorphic recursive call + @tailrec final def fail4[U](other: Tom[U], x: Int): Int = other.fail4[U](other, x - 1) + ^ +5 errors found diff --git a/tests/untried/neg/tailrec.scala b/tests/untried/neg/tailrec.scala new file mode 100644 index 000000000000..83a0c1a9e609 --- /dev/null +++ b/tests/untried/neg/tailrec.scala @@ -0,0 +1,65 @@ +import scala.annotation.tailrec + +// putting @tailrec through the paces +object Winners { + @tailrec + def facsucc(n: Int, acc: Int): Int = + if (n == 0) acc + else facsucc(n - 1, n * acc) + + @tailrec def loopsucc1(x: Int): Int = loopsucc1(x - 1) + @tailrec def loopsucc2[T](x: Int): Int = loopsucc2[T](x - 1) + + def ding(): Unit = { + object dong { + @tailrec def loopsucc3(x: Int): Int = loopsucc3(x) + } + () + } + + def inner(q: Int) = { + @tailrec + def loopsucc4(x: Int): Int = loopsucc4(x + 1) + + loopsucc4(q) + } + + object innerBob { + @tailrec def loopsucc5(x: Int): Int = loopsucc5(x) + } +} + +class Winners { + @tailrec private def succ1(x: Int): Int = succ1(x) + @tailrec final def succ2(x: Int): Int = succ2(x) + @tailrec final def succ3[T](in: List[T], acc: List[T]): List[T] = in match { + case Nil => Nil + case x :: xs => succ3(xs, x :: acc) + } +} + +object Failures { + @tailrec + def facfail(n: Int): Int = + if (n == 0) 1 + else n * facfail(n - 1) +} + +class Failures { + // not private, not final + @tailrec def fail1(x: Int): Int = fail1(x) + + // a typical between-chair-and-keyboard error + @tailrec final def fail2[T](xs: List[T]): List[T] = xs match { + case Nil => Nil + case x :: xs => x :: fail2[T](xs) + } + + // unsafe + @tailrec final def fail3[T](x: Int): Int = fail3(x - 1) + + // unsafe + class Tom[T](x: Int) { + @tailrec final def fail4[U](other: Tom[U], x: Int): Int = other.fail4[U](other, x - 1) + } +} diff --git a/tests/untried/neg/tcpoly_bounds.check b/tests/untried/neg/tcpoly_bounds.check new file mode 100644 index 000000000000..8b65c8d7fe63 --- /dev/null +++ b/tests/untried/neg/tcpoly_bounds.check @@ -0,0 +1,4 @@ +tcpoly_bounds.scala:3: error: type arguments [List] do not conform to class A's type parameter bounds [m[x] <: Option[x]] +object b extends A[List] + ^ +one error found diff --git a/tests/untried/neg/tcpoly_bounds.scala b/tests/untried/neg/tcpoly_bounds.scala new file mode 100644 index 000000000000..b444c59b3edb --- /dev/null +++ b/tests/untried/neg/tcpoly_bounds.scala @@ -0,0 +1,3 @@ +class A[m[x] <: Option[x]] +object a extends A[Some] +object b extends A[List] diff --git a/tests/untried/neg/tcpoly_infer_ticket1162.check b/tests/untried/neg/tcpoly_infer_ticket1162.check new file mode 100644 index 000000000000..67b79e7f3c5d --- /dev/null +++ b/tests/untried/neg/tcpoly_infer_ticket1162.check @@ -0,0 +1,4 @@ +tcpoly_infer_ticket1162.scala:6: error: wrong number of type parameters for method apply: [A, B, F[_]]()Test.Lift[A,B,F] in object Lift + def simplify[A,B]: Expression[A,B] = Lift[A,B]() + ^ +one error found diff --git a/tests/untried/neg/tcpoly_infer_ticket1162.scala b/tests/untried/neg/tcpoly_infer_ticket1162.scala new file mode 100644 index 000000000000..0552b42a22a1 --- /dev/null +++ b/tests/untried/neg/tcpoly_infer_ticket1162.scala @@ -0,0 +1,8 @@ +object Test { + trait Expression[A,B] + + case class Lift[A,B,F[_]]() extends Expression[F[A],F[B]] + + def simplify[A,B]: Expression[A,B] = Lift[A,B]() +} + diff --git a/tests/untried/neg/tcpoly_override.check b/tests/untried/neg/tcpoly_override.check new file mode 100644 index 000000000000..dbc3ff946157 --- /dev/null +++ b/tests/untried/neg/tcpoly_override.check @@ -0,0 +1,6 @@ +tcpoly_override.scala:9: error: The kind of type T does not conform to the expected kind of type T[_] in trait A. +C.this.T's type parameters do not match type T's expected parameters: +type T (in class C) has no type parameters, but type T (in trait A) has one + type T = B // This compiles well (@M: ... but it shouldn't) + ^ +one error found diff --git a/tests/untried/neg/tcpoly_override.scala b/tests/untried/neg/tcpoly_override.scala new file mode 100644 index 000000000000..dd043b47edd6 --- /dev/null +++ b/tests/untried/neg/tcpoly_override.scala @@ -0,0 +1,10 @@ +// t1231: reported by Vladimir Reshetnikov on 19 July 2007 +trait A { + type T[_] +} + +trait B // First-order type + +class C extends A { + type T = B // This compiles well (@M: ... but it shouldn't) +} diff --git a/tests/untried/neg/tcpoly_ticket2101.check b/tests/untried/neg/tcpoly_ticket2101.check new file mode 100644 index 000000000000..ad0fd8bda26a --- /dev/null +++ b/tests/untried/neg/tcpoly_ticket2101.check @@ -0,0 +1,4 @@ +tcpoly_ticket2101.scala:2: error: type arguments [T2,X] do not conform to class T's type parameter bounds [A[Y] <: T[A,B],B] +class T2[X] extends T[T2, X] // ill-typed + ^ +one error found diff --git a/tests/untried/neg/tcpoly_ticket2101.scala b/tests/untried/neg/tcpoly_ticket2101.scala new file mode 100644 index 000000000000..68f061ce7020 --- /dev/null +++ b/tests/untried/neg/tcpoly_ticket2101.scala @@ -0,0 +1,28 @@ +class T[A[Y] <: T[A, B], B] +class T2[X] extends T[T2, X] // ill-typed +// because this bound is not met: +// Forall Y. T2[Y] <: T[T2, X] + +// debugging before fix: +// def isSubType0 --> +// case (PolyType(tparams1, res1), PolyType(tparams2, res2)) => println("<: p2.info.substSym(tparams2, tparams1) <:< p1.info) && +// res1 <:< res2.substSym(tparams2, tparams1)) + +// generates output: +// <: println("<: p2.info.substSym(tparams2, tpsFresh) <:< p1.info.substSym(tparams1, tpsFresh)) && +// res1.substSym(tparams1, tpsFresh) <:< res2.substSym(tparams2, tpsFresh) +// }) diff --git a/tests/untried/neg/tcpoly_typealias.check b/tests/untried/neg/tcpoly_typealias.check new file mode 100644 index 000000000000..4beac0e44071 --- /dev/null +++ b/tests/untried/neg/tcpoly_typealias.check @@ -0,0 +1,16 @@ +tcpoly_typealias.scala:37: error: The kind of type m does not conform to the expected kind of type m[+x] in trait A. +BInv.this.m's type parameters do not match type m's expected parameters: +type x (in trait BInv) is invariant, but type x (in trait A) is declared covariant + type m[x] = FooCov[x] // error: invariant x in alias def + ^ +tcpoly_typealias.scala:41: error: The kind of type m does not conform to the expected kind of type m[+x] in trait A. +BCon.this.m's type parameters do not match type m's expected parameters: +type x (in trait BCon) is contravariant, but type x (in trait A) is declared covariant + type m[-x] = FooCon[x] // error: contravariant x + ^ +tcpoly_typealias.scala:45: error: The kind of type m does not conform to the expected kind of type m[+x] in trait A. +BBound.this.m's type parameters do not match type m's expected parameters: +type x (in trait BBound)'s bounds <: String are stricter than type x (in trait A)'s declared bounds >: Nothing <: Any + type m[+x <: String] = FooBound[x] // error: x with stricter bound + ^ +three errors found diff --git a/tests/untried/neg/tcpoly_typealias.scala b/tests/untried/neg/tcpoly_typealias.scala new file mode 100644 index 000000000000..6c7f80cc0bdf --- /dev/null +++ b/tests/untried/neg/tcpoly_typealias.scala @@ -0,0 +1,47 @@ +trait A { + type m[+x] +} + +trait A2 { + type m[+x <: String] +} + +trait A3 { + type m[x] +} + +trait FooCov[+x] +trait FooCon[-x] +trait FooBound[+x <: String] + +trait BOk1 extends A { + type m[+x] = FooCov[x] +} + +trait BOk2 extends A2 { + type m[+x <: String] = FooBound[x] +} + +trait BOk3 extends A2 { + type m[+x] = FooCov[x] // weaker bound +} + +trait BOk4 extends A3 { + type m[+x] = FooCov[x] // weaker variance +} + +// there are two aspects to check: + // does type alias signature (not considering RHS) correspond to abstract type member in super class + // does RHS correspond to the type alias sig +trait BInv extends A{ + type m[x] = FooCov[x] // error: invariant x in alias def +} + +trait BCon extends A{ + type m[-x] = FooCon[x] // error: contravariant x +} + +trait BBound extends A{ + type m[+x <: String] = FooBound[x] // error: x with stricter bound +} + diff --git a/tests/untried/neg/tcpoly_variance.check b/tests/untried/neg/tcpoly_variance.check new file mode 100644 index 000000000000..c0dfcac2dd7c --- /dev/null +++ b/tests/untried/neg/tcpoly_variance.check @@ -0,0 +1,5 @@ +tcpoly_variance.scala:6: error: overriding method str in class A of type => m[Object]; + method str has incompatible type + override def str: m[String] = sys.error("foo") // since x in m[x] is invariant, ! m[String] <: m[Object] + ^ +one error found diff --git a/tests/untried/neg/tcpoly_variance.scala b/tests/untried/neg/tcpoly_variance.scala new file mode 100644 index 000000000000..4b9bd50e0850 --- /dev/null +++ b/tests/untried/neg/tcpoly_variance.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") // since x in m[x] is invariant, ! m[String] <: m[Object] +} diff --git a/tests/untried/neg/tcpoly_variance_enforce.check b/tests/untried/neg/tcpoly_variance_enforce.check new file mode 100644 index 000000000000..3299cc343518 --- /dev/null +++ b/tests/untried/neg/tcpoly_variance_enforce.check @@ -0,0 +1,57 @@ +tcpoly_variance_enforce.scala:15: error: kinds of the type arguments (FooInvar) do not conform to the expected kinds of the type parameters (type m) in trait coll. +FooInvar's type parameters do not match type m's expected parameters: +type x (in class FooInvar) is invariant, but type x is declared covariant +object fcollinv extends coll[FooInvar] // error + ^ +tcpoly_variance_enforce.scala:16: error: kinds of the type arguments (FooContra) do not conform to the expected kinds of the type parameters (type m) in trait coll. +FooContra's type parameters do not match type m's expected parameters: +type x (in class FooContra) is contravariant, but type x is declared covariant +object fcollcon extends coll[FooContra] // error + ^ +tcpoly_variance_enforce.scala:17: error: kinds of the type arguments (FooString) do not conform to the expected kinds of the type parameters (type m) in trait coll. +FooString's type parameters do not match type m's expected parameters: +type x (in class FooString)'s bounds <: String are stricter than type x's declared bounds >: Nothing <: Any +object fcollwb extends coll[FooString] // error + ^ +tcpoly_variance_enforce.scala:19: error: kinds of the type arguments (FooCov) do not conform to the expected kinds of the type parameters (type m) in trait coll2. +FooCov's type parameters do not match type m's expected parameters: +type x (in class FooCov) is covariant, but type x is declared contravariant +object fcoll2ok extends coll2[FooCov] // error + ^ +tcpoly_variance_enforce.scala:20: error: kinds of the type arguments (FooInvar) do not conform to the expected kinds of the type parameters (type m) in trait coll2. +FooInvar's type parameters do not match type m's expected parameters: +type x (in class FooInvar) is invariant, but type x is declared contravariant +object fcoll2inv extends coll2[FooInvar] // error + ^ +tcpoly_variance_enforce.scala:22: error: kinds of the type arguments (FooString) do not conform to the expected kinds of the type parameters (type m) in trait coll2. +FooString's type parameters do not match type m's expected parameters: +type x (in class FooString) is covariant, but type x is declared contravariant +type x (in class FooString)'s bounds <: String are stricter than type x's declared bounds >: Nothing <: Any +object fcoll2wb extends coll2[FooString] // error + ^ +tcpoly_variance_enforce.scala:27: error: kinds of the type arguments (FooString) do not conform to the expected kinds of the type parameters (type m) in trait coll3. +FooString's type parameters do not match type m's expected parameters: +type x (in class FooString)'s bounds <: String are stricter than type x's declared bounds >: Nothing <: Any +object fcoll3wb extends coll3[FooString] // error + ^ +tcpoly_variance_enforce.scala:30: error: kinds of the type arguments (FooString,Int) do not conform to the expected kinds of the type parameters (type m,type y) in trait coll4. +FooString's type parameters do not match type m's expected parameters: +type x (in class FooString)'s bounds <: String are stricter than type x's declared bounds <: y +object fcoll4_1 extends coll4[FooString, Int] // error + ^ +tcpoly_variance_enforce.scala:31: error: kinds of the type arguments (FooString,Any) do not conform to the expected kinds of the type parameters (type m,type y) in trait coll4. +FooString's type parameters do not match type m's expected parameters: +type x (in class FooString)'s bounds <: String are stricter than type x's declared bounds <: y +object fcoll4_2 extends coll4[FooString, Any] // error + ^ +tcpoly_variance_enforce.scala:37: error: kinds of the type arguments (FooInvar) do not conform to the expected kinds of the type parameters (type m) in trait coll. +FooInvar's type parameters do not match type m's expected parameters: +type x (in class FooInvar) is invariant, but type x is declared covariant + def x: coll[FooInvar] = sys.error("foo") // error + ^ +tcpoly_variance_enforce.scala:38: error: kinds of the type arguments (FooContra) do not conform to the expected kinds of the type parameters (type m) in trait coll. +FooContra's type parameters do not match type m's expected parameters: +type x (in class FooContra) is contravariant, but type x is declared covariant + def y: coll[FooContra] = sys.error("foo") // error + ^ +11 errors found diff --git a/tests/untried/neg/tcpoly_variance_enforce.scala b/tests/untried/neg/tcpoly_variance_enforce.scala new file mode 100644 index 000000000000..ddff0e9f9438 --- /dev/null +++ b/tests/untried/neg/tcpoly_variance_enforce.scala @@ -0,0 +1,42 @@ +trait coll[m[+x]] + +trait coll2[m[-x]] + +trait coll3[m[x]] + +trait coll4[m[x <: y], y] + +class FooInvar[x] +class FooContra[-x] +class FooCov[+x] +class FooString[+x <: String] + +object fcollok extends coll[FooCov] +object fcollinv extends coll[FooInvar] // error +object fcollcon extends coll[FooContra] // error +object fcollwb extends coll[FooString] // error + +object fcoll2ok extends coll2[FooCov] // error +object fcoll2inv extends coll2[FooInvar] // error +object fcoll2con extends coll2[FooContra] +object fcoll2wb extends coll2[FooString] // error + +object fcoll3ok extends coll3[FooCov] +object fcoll3inv extends coll3[FooInvar] +object fcoll3con extends coll3[FooContra] +object fcoll3wb extends coll3[FooString] // error + +object fcoll4ok extends coll4[FooString, String] +object fcoll4_1 extends coll4[FooString, Int] // error +object fcoll4_2 extends coll4[FooString, Any] // error + + +object test { + var ok: coll[FooCov] = _ + + def x: coll[FooInvar] = sys.error("foo") // error + def y: coll[FooContra] = sys.error("foo") // error +} + + +// TODO: need test for rank N with N >: 2 diff --git a/tests/untried/neg/ticket513.check b/tests/untried/neg/ticket513.check new file mode 100644 index 000000000000..8994269262f0 --- /dev/null +++ b/tests/untried/neg/ticket513.check @@ -0,0 +1,4 @@ +ticket513.scala:6: error: type arguments [NotThatBound] do not conform to trait T's type parameter bounds [A <: Bound] +object Wrong extends Wrap[T[NotThatBound]] + ^ +one error found diff --git a/tests/untried/neg/ticket513.scala b/tests/untried/neg/ticket513.scala new file mode 100644 index 000000000000..5aecc7a05f30 --- /dev/null +++ b/tests/untried/neg/ticket513.scala @@ -0,0 +1,6 @@ +class Bound +class NotThatBound +trait T[A <: Bound] +trait Wrap[X] + +object Wrong extends Wrap[T[NotThatBound]] diff --git a/tests/untried/neg/type-diagnostics.check b/tests/untried/neg/type-diagnostics.check new file mode 100644 index 000000000000..c5e6dec3f80e --- /dev/null +++ b/tests/untried/neg/type-diagnostics.check @@ -0,0 +1,21 @@ +type-diagnostics.scala:4: error: type mismatch; + found : scala.collection.Set[String] + required: scala.collection.immutable.Set[String] + def f = Calculator("Hello", binding.keySet: collection.Set[String]) + ^ +type-diagnostics.scala:13: error: type mismatch; + found : List[a(in method f2)] + required: List[a(in method f1)] + y match { case y1: List[a] => f3(x, y1) } + ^ +type-diagnostics.scala:17: error: type mismatch; + found : String(in method f2) + required: java.lang.String + def f2[String](s: String) = strings(List(s)) + ^ +type-diagnostics.scala:21: error: missing parameter type for expanded function +The argument types of an anonymous function must be fully known. (SLS 8.5) +Expected type was: ? + val f = { case 5 => 10 } + ^ +four errors found diff --git a/tests/untried/neg/type-diagnostics.scala b/tests/untried/neg/type-diagnostics.scala new file mode 100644 index 000000000000..366e6e7acfb1 --- /dev/null +++ b/tests/untried/neg/type-diagnostics.scala @@ -0,0 +1,22 @@ +object SetVsSet { + case class Calculator[+T](name: String, parameters: Set[String]) + val binding = Map.empty[String, String] + def f = Calculator("Hello", binding.keySet: collection.Set[String]) +} + +object TParamConfusion { + def strings(xs: List[String]) = xs + + def f1[a <% Ordered[a]](x: List[a]) = { + def f2[b >: List[a] <% Ordered[b]](x: List[a], y: b): Int = { + def f3(xs: List[a], ys: List[a]) = -1 + y match { case y1: List[a] => f3(x, y1) } + } + } + + def f2[String](s: String) = strings(List(s)) +} + +object PartialInfer { + val f = { case 5 => 10 } +} diff --git a/tests/untried/neg/typeerror.check b/tests/untried/neg/typeerror.check new file mode 100644 index 000000000000..f117e702f0d7 --- /dev/null +++ b/tests/untried/neg/typeerror.check @@ -0,0 +1,11 @@ +typeerror.scala:6: error: type mismatch; + found : Long(in method add) + required: scala.Long + else add2(x.head, y.head) :: add(x.tail, y.tail) + ^ +typeerror.scala:6: error: type mismatch; + found : Long(in method add) + required: scala.Long + else add2(x.head, y.head) :: add(x.tail, y.tail) + ^ +two errors found diff --git a/tests/untried/neg/typeerror.scala b/tests/untried/neg/typeerror.scala new file mode 100644 index 000000000000..158ad179369a --- /dev/null +++ b/tests/untried/neg/typeerror.scala @@ -0,0 +1,7 @@ +object Test { + def add2(x:Long,y:Long): Long = x + y + + def add[Long](x: List[Long], y: List[Long]): List[Long] = + if (x.isEmpty || y.isEmpty) Nil + else add2(x.head, y.head) :: add(x.tail, y.tail) +} diff --git a/tests/untried/neg/unchecked-abstract.check b/tests/untried/neg/unchecked-abstract.check new file mode 100644 index 000000000000..72019082acbe --- /dev/null +++ b/tests/untried/neg/unchecked-abstract.check @@ -0,0 +1,27 @@ +unchecked-abstract.scala:16: warning: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Contravariant[H]]) + ^ +unchecked-abstract.scala:21: warning: abstract type H in type Contravariant[M.this.H] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Contravariant[H]]) + ^ +unchecked-abstract.scala:27: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[T]]) + ^ +unchecked-abstract.scala:28: warning: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[L]]) + ^ +unchecked-abstract.scala:31: warning: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[H]]) + ^ +unchecked-abstract.scala:33: warning: abstract type L in type Invariant[M.this.L] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[L]]) + ^ +unchecked-abstract.scala:36: warning: abstract type H in type Invariant[M.this.H] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[H]]) + ^ +unchecked-abstract.scala:37: warning: abstract type T in type Invariant[M.this.T] is unchecked since it is eliminated by erasure + /* warn */ println(x.isInstanceOf[Invariant[T]]) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +8 warnings found +one error found diff --git a/tests/untried/neg/unchecked-abstract.flags b/tests/untried/neg/unchecked-abstract.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unchecked-abstract.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unchecked-abstract.scala b/tests/untried/neg/unchecked-abstract.scala new file mode 100644 index 000000000000..23c8281ca82d --- /dev/null +++ b/tests/untried/neg/unchecked-abstract.scala @@ -0,0 +1,93 @@ +trait Contravariant[-X] +trait Invariant[X] +trait Covariant[+X] + +abstract class M { + type H + type L <: H + type T >: L <: H + + def h1(x: Contravariant[H]) = { + /* nowarn */ println(x.isInstanceOf[Contravariant[H]]) + /* nowarn */ println(x.isInstanceOf[Contravariant[T]]) + /* nowarn */ println(x.isInstanceOf[Contravariant[L]]) + } + def h2(x: Contravariant[T]) = { + /* warn */ println(x.isInstanceOf[Contravariant[H]]) + /* nowarn */ println(x.isInstanceOf[Contravariant[T]]) + /* nowarn */ println(x.isInstanceOf[Contravariant[L]]) + } + def h3(x: Contravariant[L]) = { + /* warn */ println(x.isInstanceOf[Contravariant[H]]) + /* warn */ println(x.isInstanceOf[Contravariant[T]]) + /* nowarn */ println(x.isInstanceOf[Contravariant[L]]) + } + def h4(x: Invariant[H]) = { + /* nowarn */ println(x.isInstanceOf[Invariant[H]]) + /* warn */ println(x.isInstanceOf[Invariant[T]]) + /* warn */ println(x.isInstanceOf[Invariant[L]]) + } + def h5(x: Invariant[T]) = { + /* warn */ println(x.isInstanceOf[Invariant[H]]) + /* nowarn */ println(x.isInstanceOf[Invariant[T]]) + /* warn */ println(x.isInstanceOf[Invariant[L]]) + } + def h6(x: Invariant[L]) = { + /* warn */ println(x.isInstanceOf[Invariant[H]]) + /* warn */ println(x.isInstanceOf[Invariant[T]]) + /* nowarn */ println(x.isInstanceOf[Invariant[L]]) + } + def h7(x: Covariant[H]) = { + /* nowarn */ println(x.isInstanceOf[Covariant[H]]) + /* warn */ println(x.isInstanceOf[Covariant[T]]) + /* warn */ println(x.isInstanceOf[Covariant[L]]) + } + def h8(x: Covariant[T]) = { + /* nowarn */ println(x.isInstanceOf[Covariant[H]]) + /* nowarn */ println(x.isInstanceOf[Covariant[T]]) + /* warn */ println(x.isInstanceOf[Covariant[L]]) + } + def h9(x: Covariant[L]) = { + /* nowarn */ println(x.isInstanceOf[Covariant[H]]) + /* nowarn */ println(x.isInstanceOf[Covariant[T]]) + /* nowarn */ println(x.isInstanceOf[Covariant[L]]) + } +} + +object Test extends M { + type H = Any + type T = Int + type L = Nothing + + val conh = new Contravariant[H] { } + val cont = new Contravariant[T] { } + val conl = new Contravariant[L] { } + + val invh = new Invariant[H] { } + val invt = new Invariant[T] { } + val invl = new Invariant[L] { } + + val covh = new Covariant[H] { } + val covt = new Covariant[T] { } + val covl = new Covariant[L] { } + + def main(args: Array[String]): Unit = { + h1(conh) + h2(conh) + h2(cont) + h3(conh) + h3(cont) + h3(conl) + + h4(invh) + h5(invt) + h6(invl) + + h7(covh) + h7(covt) + h7(covl) + h8(covt) + h8(covl) + h9(covl) + } +} diff --git a/tests/untried/neg/unchecked-impossible.check b/tests/untried/neg/unchecked-impossible.check new file mode 100644 index 000000000000..d150a5a853f6 --- /dev/null +++ b/tests/untried/neg/unchecked-impossible.check @@ -0,0 +1,10 @@ +unchecked-impossible.scala:5: warning: fruitless type test: a value of type T2[Int,Int] cannot also be a Seq[A] + case Seq(x) => + ^ +unchecked-impossible.scala:5: error: pattern type is incompatible with expected type; + found : Seq[A] + required: T2[Int,Int] + case Seq(x) => + ^ +one warning found +one error found diff --git a/tests/untried/neg/unchecked-impossible.flags b/tests/untried/neg/unchecked-impossible.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unchecked-impossible.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unchecked-impossible.scala b/tests/untried/neg/unchecked-impossible.scala new file mode 100644 index 000000000000..985a2d0b0841 --- /dev/null +++ b/tests/untried/neg/unchecked-impossible.scala @@ -0,0 +1,16 @@ +final case class T2[+A, +B](a: A, b: B) + +class A { + def f1 = T2(1, 2) match { + case Seq(x) => + case _ => + } + def f2 = T2(1, 2) match { + case _: T2[Int, Int] => /* nowarn */ + case _ => + } + def f3 = T2(1, 2) match { + case _: T2[_, Int] => /* nowarn */ + case _ => + } +} diff --git a/tests/untried/neg/unchecked-knowable.check b/tests/untried/neg/unchecked-knowable.check new file mode 100644 index 000000000000..327a5f202d47 --- /dev/null +++ b/tests/untried/neg/unchecked-knowable.check @@ -0,0 +1,9 @@ +unchecked-knowable.scala:18: warning: fruitless type test: a value of type Bippy cannot also be a A1 + /* warn */ (new Bippy).isInstanceOf[A1] + ^ +unchecked-knowable.scala:19: warning: fruitless type test: a value of type Bippy cannot also be a B1 + /* warn */ (new Bippy).isInstanceOf[B1] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/tests/untried/neg/unchecked-knowable.flags b/tests/untried/neg/unchecked-knowable.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unchecked-knowable.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unchecked-knowable.scala b/tests/untried/neg/unchecked-knowable.scala new file mode 100644 index 000000000000..21624c4fb459 --- /dev/null +++ b/tests/untried/neg/unchecked-knowable.scala @@ -0,0 +1,22 @@ +/** Knowable - only final leaves */ +sealed abstract class A1 +sealed abstract class A2 extends A1 +final class A3 extends A1 +final class A4 extends A2 + +/** Unknowable */ +sealed abstract class B1 +sealed abstract class B2 extends B1 +sealed trait B2B extends B1 +final class B3 extends B1 +trait B4 extends B2 + +class Bippy +trait Dingus + +class A { + /* warn */ (new Bippy).isInstanceOf[A1] + /* warn */ (new Bippy).isInstanceOf[B1] + /* nowarn */ (null: Dingus).isInstanceOf[B1] + /* nowarn */ ((new Bippy): Any).isInstanceOf[A1] +} diff --git a/tests/untried/neg/unchecked-refinement.check b/tests/untried/neg/unchecked-refinement.check new file mode 100644 index 000000000000..e85a51f44dad --- /dev/null +++ b/tests/untried/neg/unchecked-refinement.check @@ -0,0 +1,15 @@ +unchecked-refinement.scala:17: warning: abstract type U in type pattern Foo[U,U,V] is unchecked since it is eliminated by erasure + /* warn */ case _: Foo[U, U, V] if b => () + ^ +unchecked-refinement.scala:19: warning: non-variable type argument Any in type pattern Foo[Any,U,V] is unchecked since it is eliminated by erasure + /* warn */ case _: Foo[Any, U, V] if b => () + ^ +unchecked-refinement.scala:23: warning: a pattern match on a refinement type is unchecked + /* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy // this could/should do an instance check and not warn + ^ +unchecked-refinement.scala:24: warning: a pattern match on a refinement type is unchecked + /* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/unchecked-refinement.flags b/tests/untried/neg/unchecked-refinement.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unchecked-refinement.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unchecked-refinement.scala b/tests/untried/neg/unchecked-refinement.scala new file mode 100644 index 000000000000..79ed7f13c15b --- /dev/null +++ b/tests/untried/neg/unchecked-refinement.scala @@ -0,0 +1,27 @@ +// a.scala +// Thu Sep 27 09:42:16 PDT 2012 + +trait Bar[-T1, T2, +T3] { } +trait Foo[-T1, T2, +T3] extends Bar[T1, T2, T3] + +class A { + var b = true + + def f1(x: Foo[Int, Int, Int]) = x match { + /* nowarn */ case _: Foo[Nothing, Int, Any] => true + } + def f2[T, U, V](x: Foo[T, U, V]) = x match { + /* nowarn */ case _: Foo[Nothing, U, Any] => true + } + def f3[T, U, V](x: Foo[T, U, V]) = x match { + /* warn */ case _: Foo[U, U, V] if b => () + /* nowarn */ case _: Foo[Nothing, U, V] if b => () + /* warn */ case _: Foo[Any, U, V] if b => () + } + + def f4(xs: List[Int]) = xs match { + /* nowarn - todo */ case x: AnyRef { def bippy: Int } if b => x.bippy // this could/should do an instance check and not warn + /* nowarn - todo */ case x: AnyRef { def size: Int } if b => x.size // this could/should do a static conformance test and not warn + /* nowarn */ case x: ((AnyRef { def size: Int }) @unchecked) if b => x.size + } +} diff --git a/tests/untried/neg/unchecked-suppress.check b/tests/untried/neg/unchecked-suppress.check new file mode 100644 index 000000000000..d3dc86014ba5 --- /dev/null +++ b/tests/untried/neg/unchecked-suppress.check @@ -0,0 +1,12 @@ +unchecked-suppress.scala:4: warning: non-variable type argument Int in type pattern scala.collection.immutable.Set[Int] (the underlying of Set[Int]) is unchecked since it is eliminated by erasure + case xs: Set[Int] => xs.head // unchecked + ^ +unchecked-suppress.scala:5: warning: non-variable type argument String in type pattern scala.collection.immutable.Map[String @unchecked,String] (the underlying of Map[String @unchecked,String]) is unchecked since it is eliminated by erasure + case xs: Map[String @unchecked, String] => xs.head // one unchecked, one okay + ^ +unchecked-suppress.scala:7: warning: non-variable type argument Int in type pattern (Int, Int) => Int is unchecked since it is eliminated by erasure + case f: ((Int, Int) => Int) => // unchecked + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/unchecked-suppress.flags b/tests/untried/neg/unchecked-suppress.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/unchecked-suppress.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/unchecked-suppress.scala b/tests/untried/neg/unchecked-suppress.scala new file mode 100644 index 000000000000..7bd61a2a4d98 --- /dev/null +++ b/tests/untried/neg/unchecked-suppress.scala @@ -0,0 +1,10 @@ +class A { + def f(x: Any) = x match { + case xs: List[String @unchecked] => xs.head // okay + case xs: Set[Int] => xs.head // unchecked + case xs: Map[String @unchecked, String] => xs.head // one unchecked, one okay + case f: ((Int @unchecked) => (Int @unchecked)) => f(5) // okay + case f: ((Int, Int) => Int) => // unchecked + case _ => "" + } +} diff --git a/tests/untried/neg/unchecked.check b/tests/untried/neg/unchecked.check new file mode 100644 index 000000000000..033cffb18f59 --- /dev/null +++ b/tests/untried/neg/unchecked.check @@ -0,0 +1,21 @@ +unchecked.scala:18: warning: non-variable type argument String in type pattern Iterable[String] (the underlying of Iterable[String]) is unchecked since it is eliminated by erasure + case xs: Iterable[String] => xs.head // unchecked + ^ +unchecked.scala:22: warning: non-variable type argument Any in type pattern scala.collection.immutable.Set[Any] (the underlying of Set[Any]) is unchecked since it is eliminated by erasure + case xs: Set[Any] => xs.head // unchecked + ^ +unchecked.scala:26: warning: non-variable type argument Any in type pattern scala.collection.immutable.Map[Any,Any] (the underlying of Map[Any,Any]) is unchecked since it is eliminated by erasure + case xs: Map[Any, Any] => xs.head // unchecked + ^ +unchecked.scala:35: warning: non-variable type argument List[Nothing] in type pattern Test.Contra[List[Nothing]] is unchecked since it is eliminated by erasure + case xs: Contra[List[Nothing]] => xs.head // unchecked + ^ +unchecked.scala:50: warning: non-variable type argument String in type pattern Test.Exp[String] is unchecked since it is eliminated by erasure + case ArrayApply(x: Exp[Array[T]], _, j: Exp[String]) => x // unchecked + ^ +unchecked.scala:55: warning: non-variable type argument Array[T] in type pattern Test.Exp[Array[T]] is unchecked since it is eliminated by erasure + case ArrayApply(x: Exp[Array[T]], _, _) => x // unchecked + ^ +error: No warnings can be incurred under -Xfatal-warnings. +6 warnings found +one error found diff --git a/tests/untried/neg/unchecked.flags b/tests/untried/neg/unchecked.flags new file mode 100644 index 000000000000..464cc20ea684 --- /dev/null +++ b/tests/untried/neg/unchecked.flags @@ -0,0 +1 @@ +-Xfatal-warnings -unchecked \ No newline at end of file diff --git a/tests/untried/neg/unchecked.scala b/tests/untried/neg/unchecked.scala new file mode 100644 index 000000000000..e491b253ba9d --- /dev/null +++ b/tests/untried/neg/unchecked.scala @@ -0,0 +1,74 @@ +import language.existentials + +object Test { + class Def[T] + class Exp[T] + class Contra[-T] { def head[T1 <: T] : T1 = ??? } + class Cov[+T] { } + + case class ArrayApply[T](x: Exp[Array[T]], i: Exp[Int], j: Exp[_]) extends Def[T] + + val IntArrayApply = ArrayApply[Int](new Exp[Array[Int]], new Exp[Int], new Exp[Int]) + + def f(x: Any) = x match { + case xs: Iterable[Any] => xs.head // okay + case _ => 0 + } + def f2(x: Any) = x match { + case xs: Iterable[String] => xs.head // unchecked + case _ => 0 + } + def f3(x: Any) = x match { + case xs: Set[Any] => xs.head // unchecked + case _ => 0 + } + def f4(x: Any) = x match { + case xs: Map[Any, Any] => xs.head // unchecked + case _ => 0 + } + + def cf1(x: Any) = x match { + case xs: Contra[Nothing] => xs.head // okay + case _ => 0 + } + def cf2(x: Any) = x match { + case xs: Contra[List[Nothing]] => xs.head // unchecked + case _ => 0 + } + + def co1(x: List[Cov[List[Int]]]) = x match { + case _: Seq[Cov[Seq[Any]]] => true // okay + case _ => false + } + + def g[T](x: Def[T]) = x match { + case ArrayApply(x: Exp[Array[T]], i: Exp[Int], _) => x // okay + case _ => 0 + } + + def g2[T](x: Def[T]) = x match { + case ArrayApply(x: Exp[Array[T]], _, j: Exp[String]) => x // unchecked + case _ => 0 + } + + def g3[T](x: Any) = x match { + case ArrayApply(x: Exp[Array[T]], _, _) => x // unchecked + case _ => 0 + } + + def g4 = IntArrayApply match { + case ArrayApply(x: Exp[Array[Int]], _, _) => x // okay + case _ => () + } + def g5[T](x: ArrayApply[Int]) = x match { + case ArrayApply(x: Exp[Array[Int]], _, _) => x // okay + case _ => 0 + } + + // Nope + // + // def g5 = IntArrayApply match { + // case ArrayApply(x: Exp[Array[String]], _, _) => x // nope + // case _ => () + // } +} diff --git a/tests/untried/neg/unchecked2.check b/tests/untried/neg/unchecked2.check new file mode 100644 index 000000000000..a7b83918565f --- /dev/null +++ b/tests/untried/neg/unchecked2.check @@ -0,0 +1,45 @@ +unchecked2.scala:4: warning: fruitless type test: a value of type Some[List[Int]] cannot also be a Option[List[String]] (but still might match its erasure) + /* warn */ Some(List(1)).isInstanceOf[Option[List[String]]] + ^ +unchecked2.scala:5: warning: non-variable type argument Option[_] in type Option[Option[_]] is unchecked since it is eliminated by erasure + /* warn */ Some(123).isInstanceOf[Option[Option[_]]] + ^ +unchecked2.scala:6: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String] (but still might match its erasure) + /* warn */ Some(123).isInstanceOf[Option[String]] + ^ +unchecked2.scala:7: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[String]] (but still might match its erasure) + /* warn */ Some(123).isInstanceOf[Option[List[String]]] + ^ +unchecked2.scala:8: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[List[Int => String]] (but still might match its erasure) + /* warn */ Some(123).isInstanceOf[Option[List[Int => String]]] + ^ +unchecked2.scala:9: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[(String, Double)] (but still might match its erasure) + /* warn */ Some(123).isInstanceOf[Option[(String, Double)]] + ^ +unchecked2.scala:10: warning: fruitless type test: a value of type Some[Int] cannot also be a Option[String => Double] (but still might match its erasure) + /* warn */ Some(123).isInstanceOf[Option[String => Double]] + ^ +unchecked2.scala:14: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure + /* warn */ (Some(List(1)): Any).isInstanceOf[Option[List[String]]] + ^ +unchecked2.scala:15: warning: non-variable type argument Int in type Option[Int] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[Int]] + ^ +unchecked2.scala:16: warning: non-variable type argument String in type Option[String] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[String]] + ^ +unchecked2.scala:17: warning: non-variable type argument List[String] in type Option[List[String]] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[List[String]]] + ^ +unchecked2.scala:18: warning: non-variable type argument List[Int => String] in type Option[List[Int => String]] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[List[Int => String]]] + ^ +unchecked2.scala:19: warning: non-variable type argument (String, Double) in type Option[(String, Double)] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[(String, Double)]] + ^ +unchecked2.scala:20: warning: non-variable type argument String => Double in type Option[String => Double] is unchecked since it is eliminated by erasure + /* warn */ (Some(123): Any).isInstanceOf[Option[String => Double]] + ^ +error: No warnings can be incurred under -Xfatal-warnings. +14 warnings found +one error found diff --git a/tests/untried/neg/unchecked2.flags b/tests/untried/neg/unchecked2.flags new file mode 100644 index 000000000000..144ddac9d3d8 --- /dev/null +++ b/tests/untried/neg/unchecked2.flags @@ -0,0 +1 @@ +-unchecked -Xfatal-warnings diff --git a/tests/untried/neg/unchecked2.scala b/tests/untried/neg/unchecked2.scala new file mode 100644 index 000000000000..616b05aad8b1 --- /dev/null +++ b/tests/untried/neg/unchecked2.scala @@ -0,0 +1,33 @@ +object Test { + // These warn because it can be statically shown they won't match. + + /* warn */ Some(List(1)).isInstanceOf[Option[List[String]]] + /* warn */ Some(123).isInstanceOf[Option[Option[_]]] + /* warn */ Some(123).isInstanceOf[Option[String]] + /* warn */ Some(123).isInstanceOf[Option[List[String]]] + /* warn */ Some(123).isInstanceOf[Option[List[Int => String]]] + /* warn */ Some(123).isInstanceOf[Option[(String, Double)]] + /* warn */ Some(123).isInstanceOf[Option[String => Double]] + + // These warn because you can't check at runtime. + + /* warn */ (Some(List(1)): Any).isInstanceOf[Option[List[String]]] + /* warn */ (Some(123): Any).isInstanceOf[Option[Int]] + /* warn */ (Some(123): Any).isInstanceOf[Option[String]] + /* warn */ (Some(123): Any).isInstanceOf[Option[List[String]]] + /* warn */ (Some(123): Any).isInstanceOf[Option[List[Int => String]]] + /* warn */ (Some(123): Any).isInstanceOf[Option[(String, Double)]] + /* warn */ (Some(123): Any).isInstanceOf[Option[String => Double]] + + // These don't warn. + + /* nowarn */ Some(List(1)).isInstanceOf[Option[List[Int]]] + /* nowarn */ Some(123).isInstanceOf[Option[Int]] + /* nowarn */ Some(123).isInstanceOf[Some[Int]] + /* nowarn */ Some(123).isInstanceOf[AnyRef] + + /* nowarn */ (Some(List(1)): Any).isInstanceOf[Option[_]] + /* nowarn */ (Some(123): Any).isInstanceOf[Option[_]] + /* nowarn */ (Some(123): Any).isInstanceOf[Some[_]] + /* nowarn */ (Some(123): Any).isInstanceOf[AnyRef] +} diff --git a/tests/untried/neg/unchecked3.check b/tests/untried/neg/unchecked3.check new file mode 100644 index 000000000000..0a526050fcb4 --- /dev/null +++ b/tests/untried/neg/unchecked3.check @@ -0,0 +1,42 @@ +unchecked3.scala:24: warning: non-variable type argument Double in type pattern E1[Double] is unchecked since it is eliminated by erasure + /* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true } + ^ +unchecked3.scala:25: warning: non-variable type argument Double in type pattern F1[Double] is unchecked since it is eliminated by erasure + /* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true } + ^ +unchecked3.scala:28: warning: non-variable type argument Int in type pattern A2[Int] is unchecked since it is eliminated by erasure + /* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true } + ^ +unchecked3.scala:32: warning: non-variable type argument Int in type pattern B2[_,Int] is unchecked since it is eliminated by erasure + /* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true } + ^ +unchecked3.scala:40: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[List[String]] => () + ^ +unchecked3.scala:43: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[Array[List[String]]] => () + ^ +unchecked3.scala:50: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[List[String]] => () + ^ +unchecked3.scala:53: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[Array[List[String]]] => () + ^ +unchecked3.scala:60: warning: non-variable type argument String in type pattern Array[List[String]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[List[String]] => () + ^ +unchecked3.scala:62: warning: non-variable type argument Array[String] in type pattern Array[List[Array[String]]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[List[Array[String]]] => () + ^ +unchecked3.scala:63: warning: non-variable type argument String in type pattern Array[Array[List[String]]] is unchecked since it is eliminated by erasure + /* warn */ case _: Array[Array[List[String]]] => () + ^ +unchecked3.scala:75: warning: abstract type A in type pattern scala.collection.immutable.Set[Q.this.A] (the underlying of Set[Q.this.A]) is unchecked since it is eliminated by erasure + /* warn */ case xs: Set[A] => xs.head + ^ +unchecked3.scala:62: warning: unreachable code + /* warn */ case _: Array[List[Array[String]]] => () + ^ +error: No warnings can be incurred under -Xfatal-warnings. +13 warnings found +one error found diff --git a/tests/untried/neg/unchecked3.flags b/tests/untried/neg/unchecked3.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unchecked3.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unchecked3.scala b/tests/untried/neg/unchecked3.scala new file mode 100644 index 000000000000..7b8c13e8f88f --- /dev/null +++ b/tests/untried/neg/unchecked3.scala @@ -0,0 +1,83 @@ +sealed trait A2[T1] +final class B2[T1, T2] extends A2[T1] + +sealed trait A[T] +final class B[T] extends A[T] + +sealed trait A1[T] +trait B1[T] extends A1[T] +trait C1[T] extends A1[T] +trait D1[T] extends A1[Int] +trait E1[T] extends B1[Int] +trait F1[T] extends B1[T] + +object MiscUnchecked { + /* nowarn */ def knownType1(x: A[Int]) = x match { case _: B[Int] if true => 1 } + /* nowarn */ def knownType2(x: B[Int]) = x match { case _: A[Int] if true => 1 } + /* nowarn */ def tparamLeakage1(x: Any) = x match { case Array() => 1 } + /* nowarn */ def tparamLeakage2(x: Any) = x match { case List() => 1 } + + // E1[Double] implies B1[Int], but B1[Int] does not imply E1[Double], even if .isInstanceOf[E1[_]] + // F1[Int] implies B1[Int], and B1[Int] implies F1[Int] + + /* nowarn */ def peerTypes1(x: B1[Int]) = x match { case _: C1[Int] => true } + /* warn */ def peerTypes2(x: B1[Int]) = x match { case _: E1[Double] => true } + /* warn */ def peerTypes3(x: B1[_]) = x match { case _: F1[Double] => true } + /* nowarn */ def peerTypes4(x: B1[Int]) = x match { case _: F1[Int] => true } + + /* warn */ def twotypes1[T](x: B2[T, Int]) = x match { case _: A2[Int] => true } + /* nowarn */ def twotypes2[T](x: B2[Int, T]) = x match { case _: A2[Int] => true } + /* nowarn */ def twotypes3(x: A2[Int]) = x match { case _: B2[Int, _] => true } + /* nowarn */ def twotypes4[T](x: A2[T]) = x match { case _: B2[T, _] => true } + /* warn */ def twotypes5[T](x: A2[T]) = x match { case _: B2[_, Int] => true } +} + +object Arrays { + def f1(x: Any) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* nowarn */ case _: Array[Array[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } + + def f2(x: Array[_]) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* nowarn */ case _: Array[Array[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } + + def f3[T](x: Array[T]) = x match { + /* nowarn */ case _: Array[Int] => () + /* nowarn */ case _: Array[Boolean] => () + /* nowarn */ case _: Array[String] => () + /* warn */ case _: Array[List[String]] => () + /* nowarn */ case _: Array[Array[String]] => () + /* warn */ case _: Array[List[Array[String]]] => () + /* warn */ case _: Array[Array[List[String]]] => () + } +} + +object Matching { + class Q { + type A + type B <: A + + def f(xs: Traversable[B]) = xs match { + /* nowarn */ case xs: List[A] => xs.head + /* nowarn */ case xs: Seq[B] => xs.head + /* warn */ case xs: Set[A] => xs.head + } + def f2[T <: B](xs: Traversable[T]) = xs match { + /* nowarn */ case xs: List[B with T] => xs.head + /* nowarn */ case xs: Seq[A] => xs.head + /* nowarn */ case xs: Set[T] => xs.head + } + } +} diff --git a/tests/untried/neg/unicode-unterminated-quote.check b/tests/untried/neg/unicode-unterminated-quote.check new file mode 100644 index 000000000000..166488710b2a --- /dev/null +++ b/tests/untried/neg/unicode-unterminated-quote.check @@ -0,0 +1,7 @@ +unicode-unterminated-quote.scala:2: error: unclosed string literal + val x = \u0022 + ^ +unicode-unterminated-quote.scala:2: error: '}' expected but eof found. + val x = \u0022 + ^ +two errors found diff --git a/tests/untried/neg/unicode-unterminated-quote.scala b/tests/untried/neg/unicode-unterminated-quote.scala new file mode 100644 index 000000000000..bb6eab667fb6 --- /dev/null +++ b/tests/untried/neg/unicode-unterminated-quote.scala @@ -0,0 +1,2 @@ +class A { + val x = \u0022 \ No newline at end of file diff --git a/tests/untried/neg/unit-returns-value.check b/tests/untried/neg/unit-returns-value.check new file mode 100644 index 000000000000..f30a506ebe50 --- /dev/null +++ b/tests/untried/neg/unit-returns-value.check @@ -0,0 +1,15 @@ +unit-returns-value.scala:4: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + if (b) return 5 + ^ +unit-returns-value.scala:4: warning: enclosing method f has result type Unit: return value discarded + if (b) return 5 + ^ +unit-returns-value.scala:22: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + i1 // warn + ^ +unit-returns-value.scala:23: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses + i2 // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/unit-returns-value.flags b/tests/untried/neg/unit-returns-value.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/unit-returns-value.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/unit-returns-value.scala b/tests/untried/neg/unit-returns-value.scala new file mode 100644 index 000000000000..1c125f0dae8c --- /dev/null +++ b/tests/untried/neg/unit-returns-value.scala @@ -0,0 +1,32 @@ +object Test { + def f: Unit = { + var b = false + if (b) return 5 + } + + // no warning + def g: Unit = { + return println("hello") + } +} + +class UnusedValues { + var i1 = 2 + val i2 = 2 + lazy val i3 = 2 + object i4 { } + def i5 = 2 + final def i6 = 2 + + def x = { + i1 // warn + i2 // warn + i3 // no warn + i4 // no warn + i5 // no warn + i6 // could warn someday, if i6 returned 2.type instead of Int + + 5 + } +} + diff --git a/tests/untried/neg/unit2anyref.check b/tests/untried/neg/unit2anyref.check new file mode 100644 index 000000000000..6d11461700bc --- /dev/null +++ b/tests/untried/neg/unit2anyref.check @@ -0,0 +1,6 @@ +unit2anyref.scala:2: error: type mismatch; + found : Unit + required: AnyRef + val x: AnyRef = () // this should not succeed. + ^ +one error found diff --git a/tests/untried/neg/unit2anyref.scala b/tests/untried/neg/unit2anyref.scala new file mode 100644 index 000000000000..1e9cdbf7831d --- /dev/null +++ b/tests/untried/neg/unit2anyref.scala @@ -0,0 +1,3 @@ +object Test { + val x: AnyRef = () // this should not succeed. +} diff --git a/tests/untried/neg/unreachablechar.check b/tests/untried/neg/unreachablechar.check new file mode 100644 index 000000000000..a621196c568c --- /dev/null +++ b/tests/untried/neg/unreachablechar.check @@ -0,0 +1,12 @@ +unreachablechar.scala:4: warning: patterns after a variable pattern cannot match (SLS 8.1.1) + case _ => println("stuff"); + ^ +unreachablechar.scala:5: warning: unreachable code due to variable pattern on line 4 + case 'f' => println("not stuff?"); + ^ +unreachablechar.scala:5: warning: unreachable code + case 'f' => println("not stuff?"); + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/unreachablechar.flags b/tests/untried/neg/unreachablechar.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/unreachablechar.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/unreachablechar.scala b/tests/untried/neg/unreachablechar.scala new file mode 100644 index 000000000000..ed04c5cd3584 --- /dev/null +++ b/tests/untried/neg/unreachablechar.scala @@ -0,0 +1,8 @@ +object Foo extends App{ + 'f' match { + case 'o'|'c'|'b' => println("Oooo"); + case _ => println("stuff"); + case 'f' => println("not stuff?"); + } + +} diff --git a/tests/untried/neg/valueclasses-doubledefs.check b/tests/untried/neg/valueclasses-doubledefs.check new file mode 100644 index 000000000000..ec513aca6b9e --- /dev/null +++ b/tests/untried/neg/valueclasses-doubledefs.check @@ -0,0 +1,7 @@ +valueclasses-doubledefs.scala:5: error: double definition: +def apply(x: Double): String at line 4 and +def apply(x: Meter): String at line 5 +have same type after erasure: (x: Double)String + def apply(x: Meter) = x.toString + ^ +one error found diff --git a/tests/untried/neg/valueclasses-doubledefs.scala b/tests/untried/neg/valueclasses-doubledefs.scala new file mode 100644 index 000000000000..87bcf8fee3bc --- /dev/null +++ b/tests/untried/neg/valueclasses-doubledefs.scala @@ -0,0 +1,6 @@ +class Meter(val x: Double) extends AnyVal + +class Foo { + def apply(x: Double) = x.toString + def apply(x: Meter) = x.toString +} diff --git a/tests/untried/neg/valueclasses-impl-restrictions.check b/tests/untried/neg/valueclasses-impl-restrictions.check new file mode 100644 index 000000000000..0af9173f74fc --- /dev/null +++ b/tests/untried/neg/valueclasses-impl-restrictions.check @@ -0,0 +1,13 @@ +valueclasses-impl-restrictions.scala:3: error: implementation restriction: nested object is not allowed in value class +This restriction is planned to be removed in subsequent releases. + object X + ^ +valueclasses-impl-restrictions.scala:9: error: implementation restriction: nested trait is not allowed in value class +This restriction is planned to be removed in subsequent releases. + trait I2 { + ^ +valueclasses-impl-restrictions.scala:23: error: implementation restriction: nested class is not allowed in value class +This restriction is planned to be removed in subsequent releases. + private[this] class I2(val q: String) + ^ +three errors found diff --git a/tests/untried/neg/valueclasses-impl-restrictions.scala b/tests/untried/neg/valueclasses-impl-restrictions.scala new file mode 100644 index 000000000000..f0577a94aa9c --- /dev/null +++ b/tests/untried/neg/valueclasses-impl-restrictions.scala @@ -0,0 +1,29 @@ +class M(val t: Int) extends AnyVal { + def lazyString = { + object X + () => X + } +} + +class X1(val s: String) extends AnyVal { + trait I2 { + val q: String + def z = s + q + } + + def y(x: X1) = { + val i2 = new I2 { val q = x.s } // allowed as of SI-7571 + i2.z + + { case x => x } : PartialFunction[Int, Int] // allowed + } +} + +class X2(val s: String) extends AnyVal { + private[this] class I2(val q: String) + + def y(i: Int) = { + val i2 = new I2(i.toString) + i2.q + s + } +} diff --git a/tests/untried/neg/valueclasses-pavlov.check b/tests/untried/neg/valueclasses-pavlov.check new file mode 100644 index 000000000000..17102a0c68d8 --- /dev/null +++ b/tests/untried/neg/valueclasses-pavlov.check @@ -0,0 +1,7 @@ +valueclasses-pavlov.scala:8: error: double definition: +def foo(x: String): String at line 7 and +def foo(x: Box2): String at line 8 +have same type after erasure: (x: String)String + def foo(x: Box2) = "foo(Box2): ok" + ^ +one error found diff --git a/tests/untried/neg/valueclasses-pavlov.scala b/tests/untried/neg/valueclasses-pavlov.scala new file mode 100644 index 000000000000..d0c1ed59ba10 --- /dev/null +++ b/tests/untried/neg/valueclasses-pavlov.scala @@ -0,0 +1,23 @@ +trait Foo[T <: AnyVal] extends Any { + def foo(x: String): String + def foo(x: T): String +} + +class Box1(val value: String) extends AnyVal with Foo[Box2] { + def foo(x: String) = "foo(String): ok" + def foo(x: Box2) = "foo(Box2): ok" +} + +class Box2(val value: String) extends AnyVal + + +object test2a { + + def main(args: Array[String]): Unit = { + val b1 = new Box1(null) + val b2 = new Box2(null) + val f: Foo[Box2] = b1 + println(f.foo("")) + println(f.foo(b2)) + } +} diff --git a/tests/untried/neg/valueclasses.check b/tests/untried/neg/valueclasses.check new file mode 100644 index 000000000000..35d38aae6082 --- /dev/null +++ b/tests/untried/neg/valueclasses.check @@ -0,0 +1,46 @@ +valueclasses.scala:3: error: only classes (not traits) are allowed to extend AnyVal +trait T extends AnyVal // fail + ^ +valueclasses.scala:6: error: value class may not be a member of another class + class Bar(x: Int) extends AnyVal // fail + ^ +valueclasses.scala:6: error: value class parameter must be a val and not be private[this] + class Bar(x: Int) extends AnyVal // fail + ^ +valueclasses.scala:8: error: value class may not be a local class + class Baz(x: Int) extends AnyVal // fail + ^ +valueclasses.scala:8: error: value class parameter must be a val and not be private[this] + class Baz(x: Int) extends AnyVal // fail + ^ +valueclasses.scala:12: error: value class needs to have exactly one val parameter +class V1 extends AnyVal // fail + ^ +valueclasses.scala:19: error: value class needs to have exactly one val parameter +class V6(val x: Int, val y: String) extends AnyVal // fail + ^ +valueclasses.scala:20: error: value class needs to have exactly one val parameter +class V7(val x: Int, private[this] val y: String) extends AnyVal // fail + ^ +valueclasses.scala:21: error: value class parameter must not be a var +class V8(var x: Int) extends AnyVal // fail + ^ +valueclasses.scala:24: error: field definition is not allowed in value class + val y = x // fail + ^ +valueclasses.scala:29: error: type parameter of value class may not be specialized +class V12[@specialized T, U](val x: (T, U)) extends AnyVal // fail + ^ +valueclasses.scala:31: error: value class parameter must be a val and not be private[this] +class V13(x: Int) extends AnyVal // fail + ^ +valueclasses.scala:33: error: value class parameter must be a val and not be private[this] +class V14(private[this] val x: Int) extends AnyVal // fail + ^ +valueclasses.scala:34: error: value class parameter must not be protected[this] +class V15(protected[this] val x: Int) extends AnyVal // fail + ^ +valueclasses.scala:36: error: value class needs to have exactly one val parameter +class V16()(val a: Any) extends AnyVal // fail, was allowed 2.10.x + ^ +15 errors found diff --git a/tests/untried/neg/valueclasses.scala b/tests/untried/neg/valueclasses.scala new file mode 100644 index 000000000000..7ccf9680f9d9 --- /dev/null +++ b/tests/untried/neg/valueclasses.scala @@ -0,0 +1,36 @@ +package test + +trait T extends AnyVal // fail + +class Foo { + class Bar(x: Int) extends AnyVal // fail + def foo(): Unit = { + class Baz(x: Int) extends AnyVal // fail + } +} + +class V1 extends AnyVal // fail + +class V2(private[test] val x: Int) extends AnyVal // okay, wasn't allowed in 2.10.x +class V3(protected[test] val x: Int) extends AnyVal // okay, wasn't allowed in 2.10.x +class V4(protected val x: Int) extends AnyVal // okay, wasn't allowed in 2.10.x +class V5(private val x: Int) extends AnyVal // okay, wasn't allowed in 2.10.x + +class V6(val x: Int, val y: String) extends AnyVal // fail +class V7(val x: Int, private[this] val y: String) extends AnyVal // fail +class V8(var x: Int) extends AnyVal // fail + +class V9(val x: Int) extends AnyVal { + val y = x // fail +} + +class V10[T](val x: T) extends AnyVal // ok +class V11[T](val x: List[T]) extends AnyVal // ok +class V12[@specialized T, U](val x: (T, U)) extends AnyVal // fail + +class V13(x: Int) extends AnyVal // fail + +class V14(private[this] val x: Int) extends AnyVal // fail +class V15(protected[this] val x: Int) extends AnyVal // fail + +class V16()(val a: Any) extends AnyVal // fail, was allowed 2.10.x diff --git a/tests/untried/neg/varargs.check b/tests/untried/neg/varargs.check new file mode 100644 index 000000000000..424e24403c51 --- /dev/null +++ b/tests/untried/neg/varargs.check @@ -0,0 +1,10 @@ +varargs.scala:16: error: A method with a varargs annotation produces a forwarder method with the same signature (a: Int, b: Array[String])Int as an existing method. + @varargs def v1(a: Int, b: String*) = a + b.length + ^ +varargs.scala:19: error: A method without repeated parameters cannot be annotated with the `varargs` annotation. + @varargs def nov(a: Int) = 0 + ^ +varargs.scala:21: error: A method with a varargs annotation produces a forwarder method with the same signature (a: Int, b: Array[String])Int as an existing method. + @varargs def v2(a: Int, b: String*) = 0 + ^ +three errors found diff --git a/tests/untried/neg/varargs.scala b/tests/untried/neg/varargs.scala new file mode 100644 index 000000000000..ce7f0d71fee8 --- /dev/null +++ b/tests/untried/neg/varargs.scala @@ -0,0 +1,27 @@ + + + +import annotation.varargs + + + +// Failing varargs annotation +object Test { + + trait A { + def v1(a: Int, b: Array[String]) = a + } + + trait B extends A { + @varargs def v1(a: Int, b: String*) = a + b.length + } + + @varargs def nov(a: Int) = 0 + @varargs def v(a: Int, b: String*) = a + b.length + @varargs def v2(a: Int, b: String*) = 0 + def v2(a: Int, b: Array[String]) = 0 + + def main(args: Array[String]): Unit = { + } + +} diff --git a/tests/untried/neg/variances-refinement.check b/tests/untried/neg/variances-refinement.check new file mode 100644 index 000000000000..2bed3ffa6b0b --- /dev/null +++ b/tests/untried/neg/variances-refinement.check @@ -0,0 +1,22 @@ +variances-refinement.scala:17: error: contravariant type A occurs in covariant position in type ()AnyRef{def f0(x: A): A} of method fail1 + def fail1() = { object O { def f0(x: A): A = ??? } ; O } // fail + ^ +variances-refinement.scala:18: error: covariant type B occurs in contravariant position in type ()AnyRef{def f0(x: B): A} of method fail2 + def fail2() = { object O { def f0(x: B): A = ??? } ; O } // fail + ^ +variances-refinement.scala:19: error: covariant type B occurs in contravariant position in type ()AnyRef{def f0(x: B): B} of method fail3 + def fail3() = { object O { def f0(x: B): B = ??? } ; O } // fail + ^ +variances-refinement.scala:20: error: covariant type B occurs in contravariant position in type ()AnyRef{def f0(x: B): C} of method fail4 + def fail4() = { object O { def f0(x: B): C = ??? } ; O } // fail + ^ +variances-refinement.scala:21: error: contravariant type A occurs in covariant position in type ()AnyRef{def f0(x: C): A} of method fail5 + def fail5() = { object O { def f0(x: C): A = ??? } ; O } // fail + ^ +variances-refinement.scala:23: error: contravariant type A occurs in covariant position in type ()O1.type forSome { val O1: AnyRef with O0; type O0 <: AnyRef{def f0(x: A): A; def f1(x: A): B; def f2(x: A): C} } of method fail6 + def fail6() = { // fail + ^ +variances-refinement.scala:32: error: contravariant type A occurs in covariant position in type ()AnyRef{def f0(x: A): A; def f1(x: A): B; def f2(x: A): C} of method fail7 + def fail7() = { // fail + ^ +7 errors found diff --git a/tests/untried/neg/variances-refinement.scala b/tests/untried/neg/variances-refinement.scala new file mode 100644 index 000000000000..6bfd336ce057 --- /dev/null +++ b/tests/untried/neg/variances-refinement.scala @@ -0,0 +1,40 @@ +trait Trait[-A, +B, C] { + def ok() = { // ok + object O { + private def f0(x: A): A = ??? + def f1(x: A): B = ??? + def f2(x: A): C = ??? + private def f3(x: B): A = ??? + private def f4(x: B): B = ??? + private def f5(x: B): C = ??? + private def f6(x: C): A = ??? + def f7(x: C): B = ??? + def f8(x: C): C = ??? + } + O + } + + def fail1() = { object O { def f0(x: A): A = ??? } ; O } // fail + def fail2() = { object O { def f0(x: B): A = ??? } ; O } // fail + def fail3() = { object O { def f0(x: B): B = ??? } ; O } // fail + def fail4() = { object O { def f0(x: B): C = ??? } ; O } // fail + def fail5() = { object O { def f0(x: C): A = ??? } ; O } // fail + + def fail6() = { // fail + trait O0 { + def f0(x: A): A = ??? + def f1(x: A): B = ??? + def f2(x: A): C = ??? + } + object O1 extends O0 + O1 + } + def fail7() = { // fail + trait O0 { + def f0(x: A): A = ??? + def f1(x: A): B = ??? + def f2(x: A): C = ??? + } + new O0 { } + } +} diff --git a/tests/untried/neg/variances.check b/tests/untried/neg/variances.check new file mode 100644 index 000000000000..cb1a60a6323c --- /dev/null +++ b/tests/untried/neg/variances.check @@ -0,0 +1,25 @@ +variances.scala:4: error: covariant type A occurs in contravariant position in type test.Vector[A] of value x + def append(x: Vector[A]): Vector[A] + ^ +variances.scala:75: error: covariant type A occurs in contravariant position in type => A => A of value m + val m: A => A + ^ +variances.scala:18: error: covariant type A occurs in contravariant position in type A of value a + private def setA3(a : A) = this.a = a + ^ +variances.scala:19: error: covariant type A occurs in contravariant position in type A of value a + protected def setA4(a : A) = this.a = a + ^ +variances.scala:21: error: covariant type A occurs in invariant position in supertype test.C[A] of object Baz + object Baz extends C[A] + ^ +variances.scala:74: error: covariant type A occurs in contravariant position in type => test.Covariant.T[A]{val m: A => A} of value x + val x: T[A] { + ^ +variances.scala:89: error: covariant type T occurs in invariant position in type T of type A + type A = T + ^ +variances.scala:90: error: covariant type T occurs in contravariant position in type => test.TestAlias.B[C.this.A] of method foo + def foo: B[A] + ^ +8 errors found diff --git a/tests/untried/neg/variances.scala b/tests/untried/neg/variances.scala new file mode 100644 index 000000000000..01c95be04aff --- /dev/null +++ b/tests/untried/neg/variances.scala @@ -0,0 +1,92 @@ +package test + +trait Vector[+A] { + def append(x: Vector[A]): Vector[A] + private[this] def append3(x: Vector[A]): Vector[A] = append(x) +} + +class C[T] + +object Covariant { + class Foo[+A] { + private[this] var a : A = _ + def getA : A = a + // allowed + private[this] def setA1(a : A) = this.a = a + protected[this] def setA2(a : A) = this.a = a + // forbidden + private def setA3(a : A) = this.a = a + protected def setA4(a : A) = this.a = a + + object Baz extends C[A] + trait Convert[B] { + def b2a(b : B) : A + def doit1(b : B) = setA1(b2a(b)) + def doit2(b : B) = setA2(b2a(b)) + def doit3(b : B) = setA3(b2a(b)) + def doit4(b : B) = setA4(b2a(b)) + } + } + class Foo2[+A] { + private[this] var a : A = _ + def getA : A = a + private[this] def setA(a : A) = this.a = a + + { + trait Convert[B] { + def b2a(b : B) : A + def doit(b : B) = setA(b2a(b)) + } + println("") + } + } + class Foo3[+A] { + private[this] var a : A = _ + def getA : A = a + private[this] def setA(a : A) = this.a = a + + private[this] trait Convert[B] { + def b2a(b : B) : A + def doit(b : B) = setA(b2a(b)) + } + } + abstract class AbstractTest { + val a : Foo[AnyRef] + val c = new a.Convert[Int] { + def b2a(b : Int) : AnyRef = "hello" + } + val b : Int = 42 + } + class Test extends AbstractTest { + val a : Foo[java.lang.Character] = new Foo[java.lang.Character] + } + def main(args : Array[String]): Unit = { + val test = new Test + test.c.doit1(test.b) + test.c.doit2(test.b) + test.c.doit3(test.b) + test.c.doit4(test.b) + val x : java.lang.Character = test.a.getA + Console.println("XXX " + x) + } + + abstract class T[+A] { + val x: T[A] { + val m: A => A + } + } + object ST extends T[String] { + val x: T[String] { val m: String => String } = ST + val m: String => String = (_.substring(1)) + } + val t: T[Any] = ST + t.x.m(new Object) +} + +object TestAlias { + class B[-T] + trait C[+T] { + type A = T + def foo: B[A] + } +} diff --git a/tests/untried/neg/variances2.check b/tests/untried/neg/variances2.check new file mode 100644 index 000000000000..433cc125ad14 --- /dev/null +++ b/tests/untried/neg/variances2.check @@ -0,0 +1,229 @@ +variances2.scala:9: error: covariant type B occurs in contravariant position in type B of value x + def f1(x: B): Unit = () + ^ +variances2.scala:12: error: covariant type E occurs in contravariant position in type E of value x + def f4(x: E): Unit = () + ^ +variances2.scala:15: error: contravariant type A occurs in covariant position in type ()A of method f6 + def f6(): A = ??? + ^ +variances2.scala:18: error: contravariant type D occurs in covariant position in type ()D of method f9 + def f9(): D = ??? + ^ +variances2.scala:22: error: contravariant type A occurs in covariant position in type A => A of value f + def f12(f: A => A): Unit = () + ^ +variances2.scala:23: error: contravariant type A occurs in covariant position in type A => B of value f + def f13(f: A => B): Unit = () + ^ +variances2.scala:24: error: contravariant type A occurs in covariant position in type A => C of value f + def f14(f: A => C): Unit = () + ^ +variances2.scala:25: error: contravariant type A occurs in covariant position in type A => D of value f + def f15(f: A => D): Unit = () + ^ +variances2.scala:26: error: contravariant type A occurs in covariant position in type A => E of value f + def f16(f: A => E): Unit = () + ^ +variances2.scala:27: error: contravariant type A occurs in covariant position in type A => F of value f + def f17(f: A => F): Unit = () + ^ +variances2.scala:29: error: covariant type B occurs in contravariant position in type B => B of value f + def f19(f: B => B): Unit = () + ^ +variances2.scala:32: error: covariant type E occurs in contravariant position in type B => E of value f + def f22(f: B => E): Unit = () + ^ +variances2.scala:35: error: covariant type B occurs in contravariant position in type C => B of value f + def f25(f: C => B): Unit = () + ^ +variances2.scala:38: error: covariant type E occurs in contravariant position in type C => E of value f + def f28(f: C => E): Unit = () + ^ +variances2.scala:40: error: contravariant type D occurs in covariant position in type D => A of value f + def f30(f: D => A): Unit = () + ^ +variances2.scala:41: error: contravariant type D occurs in covariant position in type D => B of value f + def f31(f: D => B): Unit = () + ^ +variances2.scala:42: error: contravariant type D occurs in covariant position in type D => C of value f + def f32(f: D => C): Unit = () + ^ +variances2.scala:43: error: contravariant type D occurs in covariant position in type D => D of value f + def f33(f: D => D): Unit = () + ^ +variances2.scala:44: error: contravariant type D occurs in covariant position in type D => E of value f + def f34(f: D => E): Unit = () + ^ +variances2.scala:45: error: contravariant type D occurs in covariant position in type D => F of value f + def f35(f: D => F): Unit = () + ^ +variances2.scala:47: error: covariant type B occurs in contravariant position in type E => B of value f + def f37(f: E => B): Unit = () + ^ +variances2.scala:50: error: covariant type E occurs in contravariant position in type E => E of value f + def f40(f: E => E): Unit = () + ^ +variances2.scala:53: error: covariant type B occurs in contravariant position in type F => B of value f + def f43(f: F => B): Unit = () + ^ +variances2.scala:56: error: covariant type E occurs in contravariant position in type F => E of value f + def f46(f: F => E): Unit = () + ^ +variances2.scala:59: error: contravariant type A occurs in covariant position in type ()A => A of method f48 + def f48(): A => A = null + ^ +variances2.scala:62: error: contravariant type D occurs in covariant position in type ()A => D of method f51 + def f51(): A => D = null + ^ +variances2.scala:65: error: covariant type B occurs in contravariant position in type ()B => A of method f54 + def f54(): B => A = null + ^ +variances2.scala:66: error: covariant type B occurs in contravariant position in type ()B => B of method f55 + def f55(): B => B = null + ^ +variances2.scala:67: error: covariant type B occurs in contravariant position in type ()B => C of method f56 + def f56(): B => C = null + ^ +variances2.scala:68: error: covariant type B occurs in contravariant position in type ()B => D of method f57 + def f57(): B => D = null + ^ +variances2.scala:69: error: covariant type B occurs in contravariant position in type ()B => E of method f58 + def f58(): B => E = null + ^ +variances2.scala:70: error: covariant type B occurs in contravariant position in type ()B => F of method f59 + def f59(): B => F = null + ^ +variances2.scala:71: error: contravariant type A occurs in covariant position in type ()C => A of method f60 + def f60(): C => A = null + ^ +variances2.scala:74: error: contravariant type D occurs in covariant position in type ()C => D of method f63 + def f63(): C => D = null + ^ +variances2.scala:77: error: contravariant type A occurs in covariant position in type ()D => A of method f66 + def f66(): D => A = null + ^ +variances2.scala:80: error: contravariant type D occurs in covariant position in type ()D => D of method f69 + def f69(): D => D = null + ^ +variances2.scala:83: error: covariant type E occurs in contravariant position in type ()E => A of method f72 + def f72(): E => A = null + ^ +variances2.scala:84: error: covariant type E occurs in contravariant position in type ()E => B of method f73 + def f73(): E => B = null + ^ +variances2.scala:85: error: covariant type E occurs in contravariant position in type ()E => C of method f74 + def f74(): E => C = null + ^ +variances2.scala:86: error: covariant type E occurs in contravariant position in type ()E => D of method f75 + def f75(): E => D = null + ^ +variances2.scala:87: error: covariant type E occurs in contravariant position in type ()E => E of method f76 + def f76(): E => E = null + ^ +variances2.scala:88: error: covariant type E occurs in contravariant position in type ()E => F of method f77 + def f77(): E => F = null + ^ +variances2.scala:89: error: contravariant type A occurs in covariant position in type ()F => A of method f78 + def f78(): F => A = null + ^ +variances2.scala:92: error: contravariant type D occurs in covariant position in type ()F => D of method f81 + def f81(): F => D = null + ^ +variances2.scala:96: error: contravariant type A occurs in covariant position in type (x: A)A of method f84 + def f84(x: A): A = ??? + ^ +variances2.scala:99: error: contravariant type D occurs in covariant position in type (x: A)D of method f87 + def f87(x: A): D = ??? + ^ +variances2.scala:102: error: contravariant type A occurs in covariant position in type (x: B)A of method f90 + def f90(x: B): A = ??? + ^ +variances2.scala:102: error: covariant type B occurs in contravariant position in type B of value x + def f90(x: B): A = ??? + ^ +variances2.scala:103: error: covariant type B occurs in contravariant position in type B of value x + def f91(x: B): B = ??? + ^ +variances2.scala:104: error: covariant type B occurs in contravariant position in type B of value x + def f92(x: B): C = ??? + ^ +variances2.scala:105: error: contravariant type D occurs in covariant position in type (x: B)D of method f93 + def f93(x: B): D = ??? + ^ +variances2.scala:105: error: covariant type B occurs in contravariant position in type B of value x + def f93(x: B): D = ??? + ^ +variances2.scala:106: error: covariant type B occurs in contravariant position in type B of value x + def f94(x: B): E = ??? + ^ +variances2.scala:107: error: covariant type B occurs in contravariant position in type B of value x + def f95(x: B): F = ??? + ^ +variances2.scala:108: error: contravariant type A occurs in covariant position in type (x: C)A of method f96 + def f96(x: C): A = ??? + ^ +variances2.scala:111: error: contravariant type D occurs in covariant position in type (x: C)D of method f99 + def f99(x: C): D = ??? + ^ +variances2.scala:114: error: contravariant type A occurs in covariant position in type (x: D)A of method f102 + def f102(x: D): A = ??? + ^ +variances2.scala:117: error: contravariant type D occurs in covariant position in type (x: D)D of method f105 + def f105(x: D): D = ??? + ^ +variances2.scala:120: error: contravariant type A occurs in covariant position in type (x: E)A of method f108 + def f108(x: E): A = ??? + ^ +variances2.scala:120: error: covariant type E occurs in contravariant position in type E of value x + def f108(x: E): A = ??? + ^ +variances2.scala:121: error: covariant type E occurs in contravariant position in type E of value x + def f109(x: E): B = ??? + ^ +variances2.scala:122: error: covariant type E occurs in contravariant position in type E of value x + def f110(x: E): C = ??? + ^ +variances2.scala:123: error: contravariant type D occurs in covariant position in type (x: E)D of method f111 + def f111(x: E): D = ??? + ^ +variances2.scala:123: error: covariant type E occurs in contravariant position in type E of value x + def f111(x: E): D = ??? + ^ +variances2.scala:124: error: covariant type E occurs in contravariant position in type E of value x + def f112(x: E): E = ??? + ^ +variances2.scala:125: error: covariant type E occurs in contravariant position in type E of value x + def f113(x: E): F = ??? + ^ +variances2.scala:126: error: contravariant type A occurs in covariant position in type (x: F)A of method f114 + def f114(x: F): A = ??? + ^ +variances2.scala:129: error: contravariant type D occurs in covariant position in type (x: F)D of method f117 + def f117(x: F): D = ??? + ^ +variances2.scala:133: error: contravariant type A occurs in covariant position in supertype Cov[A] of object O1 + object O1 extends Cov[A] + ^ +variances2.scala:136: error: contravariant type D occurs in covariant position in supertype Cov[D] of object O4 + object O4 extends Cov[D] + ^ +variances2.scala:140: error: covariant type B occurs in contravariant position in supertype Con[B] of object O8 + object O8 extends Con[B] + ^ +variances2.scala:143: error: covariant type E occurs in contravariant position in supertype Con[E] of object O11 + object O11 extends Con[E] + ^ +variances2.scala:145: error: contravariant type A occurs in invariant position in supertype Inv[A] of object O13 + object O13 extends Inv[A] + ^ +variances2.scala:146: error: covariant type B occurs in invariant position in supertype Inv[B] of object O14 + object O14 extends Inv[B] + ^ +variances2.scala:148: error: contravariant type D occurs in invariant position in supertype Inv[D] of object O16 + object O16 extends Inv[D] + ^ +variances2.scala:149: error: covariant type E occurs in invariant position in supertype Inv[E] of object O17 + object O17 extends Inv[E] + ^ +76 errors found diff --git a/tests/untried/neg/variances2.scala b/tests/untried/neg/variances2.scala new file mode 100644 index 000000000000..0a57f8120dc2 --- /dev/null +++ b/tests/untried/neg/variances2.scala @@ -0,0 +1,303 @@ +trait Cov[+A] +trait Con[-A] +trait Inv[A] + +trait Trait[-A, +B, C] { + // trait Inner[-D <: C, +E >: C, F] { + trait Inner[-D <: C, +E >: C, F] { + def f0(x: A): Unit = () + def f1(x: B): Unit = () + def f2(x: C): Unit = () + def f3(x: D): Unit = () + def f4(x: E): Unit = () + def f5(x: F): Unit = () + + def f6(): A = ??? + def f7(): B = ??? + def f8(): C = ??? + def f9(): D = ??? + def f10(): E = ??? + def f11(): F = ??? + + def f12(f: A => A): Unit = () + def f13(f: A => B): Unit = () + def f14(f: A => C): Unit = () + def f15(f: A => D): Unit = () + def f16(f: A => E): Unit = () + def f17(f: A => F): Unit = () + def f18(f: B => A): Unit = () + def f19(f: B => B): Unit = () + def f20(f: B => C): Unit = () + def f21(f: B => D): Unit = () + def f22(f: B => E): Unit = () + def f23(f: B => F): Unit = () + def f24(f: C => A): Unit = () + def f25(f: C => B): Unit = () + def f26(f: C => C): Unit = () + def f27(f: C => D): Unit = () + def f28(f: C => E): Unit = () + def f29(f: C => F): Unit = () + def f30(f: D => A): Unit = () + def f31(f: D => B): Unit = () + def f32(f: D => C): Unit = () + def f33(f: D => D): Unit = () + def f34(f: D => E): Unit = () + def f35(f: D => F): Unit = () + def f36(f: E => A): Unit = () + def f37(f: E => B): Unit = () + def f38(f: E => C): Unit = () + def f39(f: E => D): Unit = () + def f40(f: E => E): Unit = () + def f41(f: E => F): Unit = () + def f42(f: F => A): Unit = () + def f43(f: F => B): Unit = () + def f44(f: F => C): Unit = () + def f45(f: F => D): Unit = () + def f46(f: F => E): Unit = () + def f47(f: F => F): Unit = () + + def f48(): A => A = null + def f49(): A => B = null + def f50(): A => C = null + def f51(): A => D = null + def f52(): A => E = null + def f53(): A => F = null + def f54(): B => A = null + def f55(): B => B = null + def f56(): B => C = null + def f57(): B => D = null + def f58(): B => E = null + def f59(): B => F = null + def f60(): C => A = null + def f61(): C => B = null + def f62(): C => C = null + def f63(): C => D = null + def f64(): C => E = null + def f65(): C => F = null + def f66(): D => A = null + def f67(): D => B = null + def f68(): D => C = null + def f69(): D => D = null + def f70(): D => E = null + def f71(): D => F = null + def f72(): E => A = null + def f73(): E => B = null + def f74(): E => C = null + def f75(): E => D = null + def f76(): E => E = null + def f77(): E => F = null + def f78(): F => A = null + def f79(): F => B = null + def f80(): F => C = null + def f81(): F => D = null + def f82(): F => E = null + def f83(): F => F = null + + def f84(x: A): A = ??? + def f85(x: A): B = ??? + def f86(x: A): C = ??? + def f87(x: A): D = ??? + def f88(x: A): E = ??? + def f89(x: A): F = ??? + def f90(x: B): A = ??? + def f91(x: B): B = ??? + def f92(x: B): C = ??? + def f93(x: B): D = ??? + def f94(x: B): E = ??? + def f95(x: B): F = ??? + def f96(x: C): A = ??? + def f97(x: C): B = ??? + def f98(x: C): C = ??? + def f99(x: C): D = ??? + def f100(x: C): E = ??? + def f101(x: C): F = ??? + def f102(x: D): A = ??? + def f103(x: D): B = ??? + def f104(x: D): C = ??? + def f105(x: D): D = ??? + def f106(x: D): E = ??? + def f107(x: D): F = ??? + def f108(x: E): A = ??? + def f109(x: E): B = ??? + def f110(x: E): C = ??? + def f111(x: E): D = ??? + def f112(x: E): E = ??? + def f113(x: E): F = ??? + def f114(x: F): A = ??? + def f115(x: F): B = ??? + def f116(x: F): C = ??? + def f117(x: F): D = ??? + def f118(x: F): E = ??? + def f119(x: F): F = ??? + + object O1 extends Cov[A] + object O2 extends Cov[B] + object O3 extends Cov[C] + object O4 extends Cov[D] + object O5 extends Cov[E] + object O6 extends Cov[F] + object O7 extends Con[A] + object O8 extends Con[B] + object O9 extends Con[C] + object O10 extends Con[D] + object O11 extends Con[E] + object O12 extends Con[F] + object O13 extends Inv[A] + object O14 extends Inv[B] + object O15 extends Inv[C] + object O16 extends Inv[D] + object O17 extends Inv[E] + object O18 extends Inv[F] + } +} + +trait Trait2[-A, +B, C] { + // trait Inner[-D <: C, +E >: C, F] { + def method[D <: A, E >: B, F](): Unit = { + def f0(x: A): Unit = () + def f1(x: B): Unit = () + def f2(x: C): Unit = () + def f3(x: D): Unit = () + def f4(x: E): Unit = () + def f5(x: F): Unit = () + + def f6(): A = ??? + def f7(): B = ??? + def f8(): C = ??? + def f9(): D = ??? + def f10(): E = ??? + def f11(): F = ??? + + def f12(f: A => A): Unit = () + def f13(f: A => B): Unit = () + def f14(f: A => C): Unit = () + def f15(f: A => D): Unit = () + def f16(f: A => E): Unit = () + def f17(f: A => F): Unit = () + def f18(f: B => A): Unit = () + def f19(f: B => B): Unit = () + def f20(f: B => C): Unit = () + def f21(f: B => D): Unit = () + def f22(f: B => E): Unit = () + def f23(f: B => F): Unit = () + def f24(f: C => A): Unit = () + def f25(f: C => B): Unit = () + def f26(f: C => C): Unit = () + def f27(f: C => D): Unit = () + def f28(f: C => E): Unit = () + def f29(f: C => F): Unit = () + def f30(f: D => A): Unit = () + def f31(f: D => B): Unit = () + def f32(f: D => C): Unit = () + def f33(f: D => D): Unit = () + def f34(f: D => E): Unit = () + def f35(f: D => F): Unit = () + def f36(f: E => A): Unit = () + def f37(f: E => B): Unit = () + def f38(f: E => C): Unit = () + def f39(f: E => D): Unit = () + def f40(f: E => E): Unit = () + def f41(f: E => F): Unit = () + def f42(f: F => A): Unit = () + def f43(f: F => B): Unit = () + def f44(f: F => C): Unit = () + def f45(f: F => D): Unit = () + def f46(f: F => E): Unit = () + def f47(f: F => F): Unit = () + + def f48(): A => A = null + def f49(): A => B = null + def f50(): A => C = null + def f51(): A => D = null + def f52(): A => E = null + def f53(): A => F = null + def f54(): B => A = null + def f55(): B => B = null + def f56(): B => C = null + def f57(): B => D = null + def f58(): B => E = null + def f59(): B => F = null + def f60(): C => A = null + def f61(): C => B = null + def f62(): C => C = null + def f63(): C => D = null + def f64(): C => E = null + def f65(): C => F = null + def f66(): D => A = null + def f67(): D => B = null + def f68(): D => C = null + def f69(): D => D = null + def f70(): D => E = null + def f71(): D => F = null + def f72(): E => A = null + def f73(): E => B = null + def f74(): E => C = null + def f75(): E => D = null + def f76(): E => E = null + def f77(): E => F = null + def f78(): F => A = null + def f79(): F => B = null + def f80(): F => C = null + def f81(): F => D = null + def f82(): F => E = null + def f83(): F => F = null + + def f84(x: A): A = ??? + def f85(x: A): B = ??? + def f86(x: A): C = ??? + def f87(x: A): D = ??? + def f88(x: A): E = ??? + def f89(x: A): F = ??? + def f90(x: B): A = ??? + def f91(x: B): B = ??? + def f92(x: B): C = ??? + def f93(x: B): D = ??? + def f94(x: B): E = ??? + def f95(x: B): F = ??? + def f96(x: C): A = ??? + def f97(x: C): B = ??? + def f98(x: C): C = ??? + def f99(x: C): D = ??? + def f100(x: C): E = ??? + def f101(x: C): F = ??? + def f102(x: D): A = ??? + def f103(x: D): B = ??? + def f104(x: D): C = ??? + def f105(x: D): D = ??? + def f106(x: D): E = ??? + def f107(x: D): F = ??? + def f108(x: E): A = ??? + def f109(x: E): B = ??? + def f110(x: E): C = ??? + def f111(x: E): D = ??? + def f112(x: E): E = ??? + def f113(x: E): F = ??? + def f114(x: F): A = ??? + def f115(x: F): B = ??? + def f116(x: F): C = ??? + def f117(x: F): D = ??? + def f118(x: F): E = ??? + def f119(x: F): F = ??? + + object O1 extends Cov[A] + object O2 extends Cov[B] + object O3 extends Cov[C] + object O4 extends Cov[D] + object O5 extends Cov[E] + object O6 extends Cov[F] + object O7 extends Con[A] + object O8 extends Con[B] + object O9 extends Con[C] + object O10 extends Con[D] + object O11 extends Con[E] + object O12 extends Con[F] + object O13 extends Inv[A] + object O14 extends Inv[B] + object O15 extends Inv[C] + object O16 extends Inv[D] + object O17 extends Inv[E] + object O18 extends Inv[F] + + () + } +} diff --git a/tests/untried/neg/viewtest.check b/tests/untried/neg/viewtest.check new file mode 100644 index 000000000000..21ed93a01cee --- /dev/null +++ b/tests/untried/neg/viewtest.check @@ -0,0 +1,6 @@ +viewtest.scala:43: error: type mismatch; + found : List[a(in method compareTo)] + required: List[a(in method view3)] + case y1: List[a] => compareLists(x, y1) + ^ +one error found diff --git a/tests/untried/neg/viewtest.scala b/tests/untried/neg/viewtest.scala new file mode 100644 index 000000000000..5e7d624d2307 --- /dev/null +++ b/tests/untried/neg/viewtest.scala @@ -0,0 +1,116 @@ +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[a] => compareLists(x, y1) + 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) + } + } + } + implicit def view4[a](x: a): a = x +} + +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]) = { + { + 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/neg/virtpatmat_reach_null.check b/tests/untried/neg/virtpatmat_reach_null.check new file mode 100644 index 000000000000..e0c36c8c5b3c --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_null.check @@ -0,0 +1,6 @@ +virtpatmat_reach_null.scala:13: warning: unreachable code + case _ => // unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/virtpatmat_reach_null.flags b/tests/untried/neg/virtpatmat_reach_null.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_null.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/virtpatmat_reach_null.scala b/tests/untried/neg/virtpatmat_reach_null.scala new file mode 100644 index 000000000000..6314a5b1d84a --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_null.scala @@ -0,0 +1,19 @@ +sealed abstract class Const { + final def excludes(other: Const) = + (this, other) match { + case (_, NullConst) => + case (NullConst, _) => + case (_: ValueConst, _: ValueConst) => + case (_: ValueConst, _: TypeConst) => + case (_: TypeConst, _: ValueConst) => + case (_: TypeConst, _: TypeConst) => + case (null, _) => + case (_, null) => + case null => + case _ => // unreachable + } +} + +sealed class TypeConst extends Const +sealed class ValueConst extends Const +case object NullConst extends Const diff --git a/tests/untried/neg/virtpatmat_reach_sealed_unsealed.check b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.check new file mode 100644 index 000000000000..064a12bcaa4b --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.check @@ -0,0 +1,16 @@ +virtpatmat_reach_sealed_unsealed.scala:16: warning: match may not be exhaustive. +It would fail on the following input: false + (true: Boolean) match { case true => } // not exhaustive, but reachable + ^ +virtpatmat_reach_sealed_unsealed.scala:18: warning: unreachable code + (true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable + ^ +virtpatmat_reach_sealed_unsealed.scala:19: warning: unreachable code + (true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable + ^ +virtpatmat_reach_sealed_unsealed.scala:20: warning: unreachable code + (true: Boolean) match { case true => case false => case _: Any => } // exhaustive, last case is unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +four warnings found +one error found diff --git a/tests/untried/neg/virtpatmat_reach_sealed_unsealed.flags b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.flags @@ -0,0 +1 @@ +-Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/neg/virtpatmat_reach_sealed_unsealed.scala b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.scala new file mode 100644 index 000000000000..26ab5da71851 --- /dev/null +++ b/tests/untried/neg/virtpatmat_reach_sealed_unsealed.scala @@ -0,0 +1,21 @@ +sealed abstract class X +sealed case class A(x: Int) extends X + +// test reachability on mixed sealed / non-sealed matches +object Test extends App { + val B: X = A(0) + val C: X = A(1) + + // all cases are reachable and the match is exhaustive + (C: X) match { + case B => + case C => + case A(_) => + } + + (true: Boolean) match { case true => } // not exhaustive, but reachable + (true: Boolean) match { case true => case false => } // exhaustive, reachable + (true: Boolean) match { case true => case false => case _ => } // exhaustive, last case is unreachable + (true: Boolean) match { case true => case false => case _: Boolean => } // exhaustive, last case is unreachable + (true: Boolean) match { case true => case false => case _: Any => } // exhaustive, last case is unreachable +} diff --git a/tests/untried/neg/virtpatmat_unreach_select.check b/tests/untried/neg/virtpatmat_unreach_select.check new file mode 100644 index 000000000000..4fc78cd4122d --- /dev/null +++ b/tests/untried/neg/virtpatmat_unreach_select.check @@ -0,0 +1,6 @@ +virtpatmat_unreach_select.scala:10: warning: unreachable code + case WARNING.id => // unreachable + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/tests/untried/neg/virtpatmat_unreach_select.flags b/tests/untried/neg/virtpatmat_unreach_select.flags new file mode 100644 index 000000000000..85d8eb2ba295 --- /dev/null +++ b/tests/untried/neg/virtpatmat_unreach_select.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/tests/untried/neg/virtpatmat_unreach_select.scala b/tests/untried/neg/virtpatmat_unreach_select.scala new file mode 100644 index 000000000000..c46ff15453de --- /dev/null +++ b/tests/untried/neg/virtpatmat_unreach_select.scala @@ -0,0 +1,12 @@ +class Test { + object severity extends Enumeration + class Severity(val id: Int) extends severity.Value + val INFO = new Severity(0) + val WARNING = new Severity(1) + + (0: Int) match { + case WARNING.id => + case INFO.id => // reachable + case WARNING.id => // unreachable + } +} diff --git a/tests/untried/neg/volatile-intersection.check b/tests/untried/neg/volatile-intersection.check new file mode 100644 index 000000000000..ef983994ab41 --- /dev/null +++ b/tests/untried/neg/volatile-intersection.check @@ -0,0 +1,4 @@ +volatile-intersection.scala:8: error: illegal type selection from volatile type C.this.D with C.this.U + val y: (D with U)#T = new B { } + ^ +one error found diff --git a/tests/untried/neg/volatile-intersection.scala b/tests/untried/neg/volatile-intersection.scala new file mode 100644 index 000000000000..209d13baef33 --- /dev/null +++ b/tests/untried/neg/volatile-intersection.scala @@ -0,0 +1,21 @@ +object Test extends App { + trait A + trait B extends A + + trait C { + type U + trait D { type T >: B <: A } + val y: (D with U)#T = new B { } + } + + class D extends C { + trait E + trait F { type T = E } + type U = F + def frob(arg : E) : E = arg + frob(y) + } + + new D +} + diff --git a/tests/untried/neg/volatile.check b/tests/untried/neg/volatile.check new file mode 100644 index 000000000000..b904284125e3 --- /dev/null +++ b/tests/untried/neg/volatile.check @@ -0,0 +1,7 @@ +volatile.scala:11: error: Inferred type C.this.D with C.this.E#T contains type selection from volatile type C.this.D with C.this.E + var sneak = { () => y.x } + ^ +volatile.scala:11: error: Inferred type () => C.this.D with C.this.E#T contains type selection from volatile type C.this.D with C.this.E + var sneak = { () => y.x } + ^ +two errors found diff --git a/tests/untried/neg/volatile.scala b/tests/untried/neg/volatile.scala new file mode 100644 index 000000000000..8292863152aa --- /dev/null +++ b/tests/untried/neg/volatile.scala @@ -0,0 +1,24 @@ +object Test extends App { + trait A + trait B extends A + + class C { + type D + trait E { type T >: B <: A; val x : T } + // This is currently correctly disallowed + // val y : (D with E)#T = y + val y : D with E = y + var sneak = { () => y.x } + sneak = { () => new B { } } + } + + class F extends C { + trait G + trait H { type T = G } + type D = H + def frob(arg : G) : G = arg + frob(sneak()) + } + + new F +} diff --git a/tests/untried/neg/volatile_no_override.check b/tests/untried/neg/volatile_no_override.check new file mode 100644 index 000000000000..a9a60ab697b3 --- /dev/null +++ b/tests/untried/neg/volatile_no_override.check @@ -0,0 +1,5 @@ +volatile_no_override.scala:13: error: overriding value x in class A of type Volatile.this.D; + value x has a volatile type; cannot override a member with non-volatile type + val x: A with D = null + ^ +one error found diff --git a/tests/untried/neg/volatile_no_override.scala b/tests/untried/neg/volatile_no_override.scala new file mode 100644 index 000000000000..9fad082a90cc --- /dev/null +++ b/tests/untried/neg/volatile_no_override.scala @@ -0,0 +1,14 @@ +class B +class C(x: String) extends B + +abstract class A { + class D { type T >: C <: B } + val x: D + var y: x.T = new C("abc") +} + +class Volatile extends A { + type A >: Null + // test (1.4), pt 2 in RefChecks + val x: A with D = null +} diff --git a/tests/untried/neg/warn-inferred-any.check b/tests/untried/neg/warn-inferred-any.check new file mode 100644 index 000000000000..4628033e55ab --- /dev/null +++ b/tests/untried/neg/warn-inferred-any.check @@ -0,0 +1,12 @@ +warn-inferred-any.scala:8: warning: a type was inferred to be `Any`; this may indicate a programming error. + { List(1, 2, 3) contains "a" } // only this warns + ^ +warn-inferred-any.scala:16: warning: a type was inferred to be `AnyVal`; this may indicate a programming error. + { 1l to 5l contains 5 } + ^ +warn-inferred-any.scala:17: warning: a type was inferred to be `AnyVal`; this may indicate a programming error. + { 1l to 5l contains 5d } + ^ +error: No warnings can be incurred under -Xfatal-warnings. +three warnings found +one error found diff --git a/tests/untried/neg/warn-inferred-any.flags b/tests/untried/neg/warn-inferred-any.flags new file mode 100644 index 000000000000..a3127d392a24 --- /dev/null +++ b/tests/untried/neg/warn-inferred-any.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Ywarn-infer-any diff --git a/tests/untried/neg/warn-inferred-any.scala b/tests/untried/neg/warn-inferred-any.scala new file mode 100644 index 000000000000..b853e6e5a81a --- /dev/null +++ b/tests/untried/neg/warn-inferred-any.scala @@ -0,0 +1,19 @@ +trait Foo[-A <: AnyRef, +B <: AnyRef] { + def run[U](x: A)(action: B => U): Boolean = ??? + + { run(_: A)(_: B => String) } +} + +trait Xs[+A] { + { List(1, 2, 3) contains "a" } // only this warns + { List(1, 2, 3) contains 1 } + { identity(List(1, 2, 3) contains 1) } + { List("a") foreach println } +} + +trait Ys[+A] { + { 1 to 5 contains 5l } + { 1l to 5l contains 5 } + { 1l to 5l contains 5d } + { 1l to 5l contains 5l } +} diff --git a/tests/untried/neg/warn-unused-imports.check b/tests/untried/neg/warn-unused-imports.check new file mode 100644 index 000000000000..36c6dd03c38d --- /dev/null +++ b/tests/untried/neg/warn-unused-imports.check @@ -0,0 +1,33 @@ +warn-unused-imports.scala:57: warning: Unused import + import p1.A // warn + ^ +warn-unused-imports.scala:62: warning: Unused import + import p1.{ A, B } // warn on A + ^ +warn-unused-imports.scala:67: warning: Unused import + import p1.{ A, B } // warn on both + ^ +warn-unused-imports.scala:67: warning: Unused import + import p1.{ A, B } // warn on both + ^ +warn-unused-imports.scala:73: warning: Unused import + import c._ // warn + ^ +warn-unused-imports.scala:78: warning: Unused import + import p1._ // warn + ^ +warn-unused-imports.scala:85: warning: Unused import + import c._ // warn + ^ +warn-unused-imports.scala:91: warning: Unused import + import p1.c._ // warn + ^ +warn-unused-imports.scala:98: warning: Unused import + import p1._ // warn + ^ +warn-unused-imports.scala:118: warning: Unused import + import p1.A // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +10 warnings found +one error found diff --git a/tests/untried/neg/warn-unused-imports.flags b/tests/untried/neg/warn-unused-imports.flags new file mode 100644 index 000000000000..24db705df164 --- /dev/null +++ b/tests/untried/neg/warn-unused-imports.flags @@ -0,0 +1 @@ +-Xfatal-warnings -Ywarn-unused-import diff --git a/tests/untried/neg/warn-unused-imports.scala b/tests/untried/neg/warn-unused-imports.scala new file mode 100644 index 000000000000..b7a2f1c414ea --- /dev/null +++ b/tests/untried/neg/warn-unused-imports.scala @@ -0,0 +1,125 @@ +class Bippo { + def length: Int = 123 + class Tree +} + +package object p1 { + class A + implicit class B(val s: String) { def bippy = s } + val c: Bippo = new Bippo + type D = String +} +package object p2 { + class A + implicit class B(val s: String) { def bippy = s } + val c: Bippo = new Bippo + type D = Int +} + +trait NoWarn { + { + import p1._ // no warn + println("abc".bippy) + } + + { + import p1._ // no warn + println(new A) + } + + { + import p1.B // no warn + println("abc".bippy) + } + + { + import p1._ // no warn + import c._ // no warn + println(length) + } + + { + import p1._ // no warn + import c._ // no warn + val x: Tree = null + println(x) + } + + { + import p1.D // no warn + val x: D = null + println(x) + } +} + +trait Warn { + { + import p1.A // warn + println(123) + } + + { + import p1.{ A, B } // warn on A + println("abc".bippy) + } + + { + import p1.{ A, B } // warn on both + println(123) + } + + { + import p1._ // no warn (technically this could warn, but not worth the effort to unroll unusedness transitively) + import c._ // warn + println(123) + } + + { + import p1._ // warn + println(123) + } + + { + class Tree + import p1._ // no warn + import c._ // warn + val x: Tree = null + println(x) + } + + { + import p1.c._ // warn + println(123) + } +} + +trait Nested { + { + import p1._ // warn + trait Warn { // warn about unused local trait for good measure + import p2._ + println(new A) + println("abc".bippy) + } + println("") + } + + { + import p1._ // no warn + trait NoWarn { + import p2.B // no warn + println("abc".bippy) + println(new A) + } + println(new NoWarn { }) + } + + { + import p1.A // warn + trait Warn { + import p2.A + println(new A) + } + println(new Warn { }) + } +} diff --git a/tests/untried/neg/warn-unused-privates.check b/tests/untried/neg/warn-unused-privates.check new file mode 100644 index 000000000000..d012869c934a --- /dev/null +++ b/tests/untried/neg/warn-unused-privates.check @@ -0,0 +1,66 @@ +warn-unused-privates.scala:2: warning: private constructor in class Bippy is never used + private def this(c: Int) = this(c, c) // warn + ^ +warn-unused-privates.scala:4: warning: private method in class Bippy is never used + private def boop(x: Int) = x+a+b // warn + ^ +warn-unused-privates.scala:6: warning: private val in class Bippy is never used + final private val MILLIS2: Int = 1000 // warn + ^ +warn-unused-privates.scala:13: warning: private val in object Bippy is never used + private val HEY_INSTANCE: Int = 1000 // warn + ^ +warn-unused-privates.scala:35: warning: private val in class Boppy is never used + private val hummer = "def" // warn + ^ +warn-unused-privates.scala:42: warning: private var in trait Accessors is never used + private var v1: Int = 0 // warn + ^ +warn-unused-privates.scala:42: warning: private setter in trait Accessors is never used + private var v1: Int = 0 // warn + ^ +warn-unused-privates.scala:43: warning: private setter in trait Accessors is never used + private var v2: Int = 0 // warn, never set + ^ +warn-unused-privates.scala:44: warning: private var in trait Accessors is never used + private var v3: Int = 0 // warn, never got + ^ +warn-unused-privates.scala:56: warning: private default argument in trait DefaultArgs is never used + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + ^ +warn-unused-privates.scala:56: warning: private default argument in trait DefaultArgs is never used + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + ^ +warn-unused-privates.scala:67: warning: local var in method f0 is never used + var x = 1 // warn + ^ +warn-unused-privates.scala:74: warning: local val in method f1 is never used + val b = new Outer // warn + ^ +warn-unused-privates.scala:84: warning: private object in object Types is never used + private object Dongo { def f = this } // warn + ^ +warn-unused-privates.scala:94: warning: local object in method l1 is never used + object HiObject { def f = this } // warn + ^ +warn-unused-privates.scala:78: warning: local var x in method f2 is never set - it could be a val + var x = 100 // warn about it being a var + ^ +warn-unused-privates.scala:85: warning: private class Bar1 in object Types is never used + private class Bar1 // warn + ^ +warn-unused-privates.scala:87: warning: private type Alias1 in object Types is never used + private type Alias1 = String // warn + ^ +warn-unused-privates.scala:95: warning: local class Hi is never used + class Hi { // warn + ^ +warn-unused-privates.scala:99: warning: local class DingDongDoobie is never used + class DingDongDoobie // warn + ^ +warn-unused-privates.scala:102: warning: local type OtherThing is never used + type OtherThing = String // warn + ^ +error: No warnings can be incurred under -Xfatal-warnings. +21 warnings found +one error found diff --git a/tests/untried/neg/warn-unused-privates.flags b/tests/untried/neg/warn-unused-privates.flags new file mode 100644 index 000000000000..25474aefb362 --- /dev/null +++ b/tests/untried/neg/warn-unused-privates.flags @@ -0,0 +1 @@ +-Ywarn-unused -Xfatal-warnings diff --git a/tests/untried/neg/warn-unused-privates.scala b/tests/untried/neg/warn-unused-privates.scala new file mode 100644 index 000000000000..cb6e946a3407 --- /dev/null +++ b/tests/untried/neg/warn-unused-privates.scala @@ -0,0 +1,105 @@ +class Bippy(a: Int, b: Int) { + private def this(c: Int) = this(c, c) // warn + private def bippy(x: Int): Int = bippy(x) // TODO: could warn + private def boop(x: Int) = x+a+b // warn + final private val MILLIS1 = 2000 // no warn, might have been inlined + final private val MILLIS2: Int = 1000 // warn + final private val HI_COMPANION: Int = 500 // no warn, accessed from companion + def hi() = Bippy.HI_INSTANCE +} +object Bippy { + def hi(x: Bippy) = x.HI_COMPANION + private val HI_INSTANCE: Int = 500 // no warn, accessed from instance + private val HEY_INSTANCE: Int = 1000 // warn +} + +class A(val msg: String) +class B1(msg: String) extends A(msg) +class B2(msg0: String) extends A(msg0) +class B3(msg0: String) extends A("msg") + +/*** Early defs warnings disabled primarily due to SI-6595. + * The test case is here to assure we aren't issuing false positives; + * the ones labeled "warn" don't warn. + ***/ +class Boppy extends { + private val hmm: String = "abc" // no warn, used in early defs + private val hom: String = "def" // no warn, used in body + private final val him = "ghi" // no warn, might have been (was) inlined + final val him2 = "ghi" // no warn, same + final val himinline = him + private val hum: String = "jkl" // warn + final val ding = hmm.length +} with Mutable { + val dinger = hom + private val hummer = "def" // warn + + private final val bum = "ghi" // no warn, might have been (was) inlined + final val bum2 = "ghi" // no warn, same +} + +trait Accessors { + private var v1: Int = 0 // warn + private var v2: Int = 0 // warn, never set + private var v3: Int = 0 // warn, never got + private var v4: Int = 0 // no warn + + def bippy(): Int = { + v3 = 5 + v4 = 6 + v2 + v4 + } +} + +trait DefaultArgs { + // warn about default getters for x2 and x3 + private def bippy(x1: Int, x2: Int = 10, x3: Int = 15): Int = x1 + x2 + x3 + + def boppy() = bippy(5, 100, 200) +} + +class Outer { + class Inner +} + +trait Locals { + def f0 = { + var x = 1 // warn + var y = 2 + y = 3 + y + y + } + def f1 = { + val a = new Outer // no warn + val b = new Outer // warn + new a.Inner + } + def f2 = { + var x = 100 // warn about it being a var + x + } +} + +object Types { + private object Dongo { def f = this } // warn + private class Bar1 // warn + private class Bar2 // no warn + private type Alias1 = String // warn + private type Alias2 = String // no warn + def bippo = (new Bar2).toString + + def f(x: Alias2) = x.length + + def l1() = { + object HiObject { def f = this } // warn + class Hi { // warn + def f1: Hi = new Hi + def f2(x: Hi) = x + } + class DingDongDoobie // warn + class Bippy // no warn + type Something = Bippy // no warn + type OtherThing = String // warn + (new Bippy): Something + } +} diff --git a/tests/untried/neg/wellkinded_app.check b/tests/untried/neg/wellkinded_app.check new file mode 100644 index 000000000000..d57a0e4b5648 --- /dev/null +++ b/tests/untried/neg/wellkinded_app.check @@ -0,0 +1,4 @@ +wellkinded_app.scala:3: error: x does not take type parameters + type t = x[x] + ^ +one error found diff --git a/tests/untried/neg/wellkinded_app.scala b/tests/untried/neg/wellkinded_app.scala new file mode 100644 index 000000000000..7fa3f95a9848 --- /dev/null +++ b/tests/untried/neg/wellkinded_app.scala @@ -0,0 +1,4 @@ +// test well-kindedness checks +class WellKinded[x] { + type t = x[x] +} diff --git a/tests/untried/neg/wellkinded_app2.check b/tests/untried/neg/wellkinded_app2.check new file mode 100644 index 000000000000..20a177ea590e --- /dev/null +++ b/tests/untried/neg/wellkinded_app2.check @@ -0,0 +1,4 @@ +wellkinded_app2.scala:3: error: s does not take type parameters + val foo: s[Int] + ^ +one error found diff --git a/tests/untried/neg/wellkinded_app2.scala b/tests/untried/neg/wellkinded_app2.scala new file mode 100644 index 000000000000..7bb4c87f6b17 --- /dev/null +++ b/tests/untried/neg/wellkinded_app2.scala @@ -0,0 +1,4 @@ +// test well-kindedness checks +class WellKinded[s <: Throwable] { + val foo: s[Int] +} diff --git a/tests/untried/neg/wellkinded_bounds.check b/tests/untried/neg/wellkinded_bounds.check new file mode 100644 index 000000000000..806eb09a76d7 --- /dev/null +++ b/tests/untried/neg/wellkinded_bounds.check @@ -0,0 +1,4 @@ +wellkinded_bounds.scala:2: error: type List takes type parameters +class WellKindedWrongSyntax[s <: List] { // must be s[x] <: List[x] + ^ +one error found diff --git a/tests/untried/neg/wellkinded_bounds.scala b/tests/untried/neg/wellkinded_bounds.scala new file mode 100644 index 000000000000..cfa5e74c115f --- /dev/null +++ b/tests/untried/neg/wellkinded_bounds.scala @@ -0,0 +1,3 @@ +// test well-kindedness checks -- syntax error +class WellKindedWrongSyntax[s <: List] { // must be s[x] <: List[x] +} diff --git a/tests/untried/neg/wellkinded_wrongarity.check b/tests/untried/neg/wellkinded_wrongarity.check new file mode 100644 index 000000000000..b9f033b4536b --- /dev/null +++ b/tests/untried/neg/wellkinded_wrongarity.check @@ -0,0 +1,4 @@ +wellkinded_wrongarity.scala:5: error: Tuple2 takes two type parameters, expected: one +object mp extends Monad[Tuple2] + ^ +one error found diff --git a/tests/untried/neg/wellkinded_wrongarity.scala b/tests/untried/neg/wellkinded_wrongarity.scala new file mode 100644 index 000000000000..39c7601d53a3 --- /dev/null +++ b/tests/untried/neg/wellkinded_wrongarity.scala @@ -0,0 +1,5 @@ +// test well-kindedness checks -- arity error + +class Monad[m[x]] + +object mp extends Monad[Tuple2] diff --git a/tests/untried/neg/wellkinded_wrongarity2.check b/tests/untried/neg/wellkinded_wrongarity2.check new file mode 100644 index 000000000000..922f73381e29 --- /dev/null +++ b/tests/untried/neg/wellkinded_wrongarity2.check @@ -0,0 +1,13 @@ +wellkinded_wrongarity2.scala:5: error: String takes no type parameters, expected: one +trait ms1 extends Monad[String] // wrong + ^ +wellkinded_wrongarity2.scala:6: error: t takes no type parameters, expected: one +trait ms2[t] extends Monad[t] // wrong + ^ +wellkinded_wrongarity2.scala:7: error: m[t] takes no type parameters, expected: one +trait ms3[m[_], t] extends Monad[m[t]] // wrong -- added to check regression on bug + ^ +wellkinded_wrongarity2.scala:12: error: type m takes type parameters +trait Bar2[m[_]] extends Foo[m] // check that m is properly recognized as kind *->*, while * is expected + ^ +four errors found diff --git a/tests/untried/neg/wellkinded_wrongarity2.scala b/tests/untried/neg/wellkinded_wrongarity2.scala new file mode 100644 index 000000000000..aac617bd8770 --- /dev/null +++ b/tests/untried/neg/wellkinded_wrongarity2.scala @@ -0,0 +1,12 @@ +// test well-kindedness checks + +// expecting types of kind *->* +class Monad[m[x]] +trait ms1 extends Monad[String] // wrong +trait ms2[t] extends Monad[t] // wrong +trait ms3[m[_], t] extends Monad[m[t]] // wrong -- added to check regression on bug + +// expecting types of kind * +trait Foo[x] +trait Bar1[m[_]] extends Foo[m[Int]] // check that m[Int] is properly recognized as kind-* +trait Bar2[m[_]] extends Foo[m] // check that m is properly recognized as kind *->*, while * is expected diff --git a/tests/untried/neg/wrong-args-for-none.check b/tests/untried/neg/wrong-args-for-none.check new file mode 100644 index 000000000000..d3b2d572ab71 --- /dev/null +++ b/tests/untried/neg/wrong-args-for-none.check @@ -0,0 +1,4 @@ +wrong-args-for-none.scala:5: error: wrong number of arguments for pattern Test.Foo(x: Int,y: Int) + def f(x: Any) = x match { case Bar(Foo(5)) => } + ^ +one error found diff --git a/tests/untried/neg/wrong-args-for-none.scala b/tests/untried/neg/wrong-args-for-none.scala new file mode 100644 index 000000000000..1caa4782a3cb --- /dev/null +++ b/tests/untried/neg/wrong-args-for-none.scala @@ -0,0 +1,6 @@ +object Test { + case class Foo(x: Int, y: Int) + case class Bar(x: AnyRef) + + def f(x: Any) = x match { case Bar(Foo(5)) => } +} diff --git a/tests/untried/neg/xmlcorner.check b/tests/untried/neg/xmlcorner.check new file mode 100644 index 000000000000..8791829e50c2 --- /dev/null +++ b/tests/untried/neg/xmlcorner.check @@ -0,0 +1,7 @@ +xmlcorner.scala:2: error: illegal start of simple expression + val wrong = <:bla/> + ^ +xmlcorner.scala:5: error: in XML literal: name cannot end in ':' + val wrong = + ^ +two errors found diff --git a/tests/untried/neg/xmlcorner.scala b/tests/untried/neg/xmlcorner.scala new file mode 100644 index 000000000000..042ec05e68df --- /dev/null +++ b/tests/untried/neg/xmlcorner.scala @@ -0,0 +1,22 @@ +class foo { + val wrong = <:bla/> +} +class bar { + val wrong = +} + +// this "pos" test is only included as a parser test +object pos +{ + def wrap(f : Int => Unit) = f(5) + + wrap({ v => + if(v == 5) { + val n = { + val m = ({}) +
{ v }
+ } + () + } + }) +} diff --git a/tests/untried/neg/xmltruncated1.check b/tests/untried/neg/xmltruncated1.check new file mode 100644 index 000000000000..36daa342e56d --- /dev/null +++ b/tests/untried/neg/xmltruncated1.check @@ -0,0 +1,4 @@ +xmltruncated1.scala:2: error: input ended while parsing XML + val stuff = + ^ +one error found diff --git a/tests/untried/neg/xmltruncated1.scala b/tests/untried/neg/xmltruncated1.scala new file mode 100644 index 000000000000..f64573cc7fbd --- /dev/null +++ b/tests/untried/neg/xmltruncated1.scala @@ -0,0 +1,2 @@ +object Main { + val stuff = diff --git a/tests/untried/neg/xmltruncated2.check b/tests/untried/neg/xmltruncated2.check new file mode 100644 index 000000000000..f1de059f84e9 --- /dev/null +++ b/tests/untried/neg/xmltruncated2.check @@ -0,0 +1,4 @@ +xmltruncated2.scala:2: error: input ended while parsing XML + val stuff = + ^ +one error found diff --git a/tests/untried/neg/xmltruncated5.scala b/tests/untried/neg/xmltruncated5.scala new file mode 100644 index 000000000000..3ff8c9fc0edd --- /dev/null +++ b/tests/untried/neg/xmltruncated5.scala @@ -0,0 +1,3 @@ +object Main { + match { + case diff --git a/tests/untried/neg/xmltruncated6.check b/tests/untried/neg/xmltruncated6.check new file mode 100644 index 000000000000..f638f2f09056 --- /dev/null +++ b/tests/untried/neg/xmltruncated6.check @@ -0,0 +1,4 @@ +xmltruncated6.scala:2: error: in XML literal: expected end of Scala block + val stuff = { "no closing brace" + ^ +one error found diff --git a/tests/untried/neg/xmltruncated6.scala b/tests/untried/neg/xmltruncated6.scala new file mode 100644 index 000000000000..c53faedb225c --- /dev/null +++ b/tests/untried/neg/xmltruncated6.scala @@ -0,0 +1,2 @@ +object Main { + val stuff = { "no closing brace" diff --git a/tests/untried/neg/xmltruncated7.check b/tests/untried/neg/xmltruncated7.check new file mode 100644 index 000000000000..67e7bd4b189e --- /dev/null +++ b/tests/untried/neg/xmltruncated7.check @@ -0,0 +1,7 @@ +xmltruncated7.scala:2: error: in XML literal: in XML content, please use '}}' to express '}' +

foo}:

+ ^ +xmltruncated7.scala:2: error: I encountered a '}' where I didn't expect one, maybe this tag isn't closed

+

foo}:

+ ^ +two errors found diff --git a/tests/untried/neg/xmltruncated7.scala b/tests/untried/neg/xmltruncated7.scala new file mode 100644 index 000000000000..7e296a910db9 --- /dev/null +++ b/tests/untried/neg/xmltruncated7.scala @@ -0,0 +1,3 @@ +object Test { +

foo}:

+} \ No newline at end of file diff --git a/tests/untried/pos/A.scala b/tests/untried/pos/A.scala new file mode 100644 index 000000000000..fc50379d88f6 --- /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 000000000000..a5668bd7c0f0 --- /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 000000000000..b351b7bb9c56 --- /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 000000000000..30ebf5e1e784 --- /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 000000000000..8e27bd362d17 --- /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 000000000000..e42896661ec2 --- /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 000000000000..68706e3dd3b0 --- /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 000000000000..1e0f0288b1f7 --- /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 000000000000..f0b66a6e68fe --- /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 000000000000..50f1df27a23c --- /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 000000000000..7fceeea3c3ff --- /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 000000000000..6bc85927660b --- /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 000000000000..f292461804db --- /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 000000000000..c926ad6493d9 --- /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 000000000000..c87620e0208a --- /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 000000000000..7cb6356ec836 --- /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 000000000000..831475d00506 --- /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 000000000000..dc33e8c377a2 --- /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 000000000000..2edf010efdd5 --- /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 000000000000..6a8e97ed1a74 --- /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 000000000000..2ac06e59bd7e --- /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 000000000000..b746a358614e --- /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 000000000000..fa9691e0b51d --- /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 000000000000..079ca6224cea --- /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 000000000000..36a09ffe0cc3 --- /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 000000000000..84a01bcce59a --- /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 000000000000..cd66464f2f63 --- /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 000000000000..986287dfa088 --- /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(, TypeTree()) + // with the original of the TypeTree being Annotated(<@unchecked>, Ident()) + // then the macro tries to replace all Ident() 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 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 000000000000..1c6b862efe17 --- /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 000000000000..9235a1ee65bd --- /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 000000000000..3bce7f8ac4e2 --- /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 000000000000..88b9a3f301d8 --- /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 000000000000..795c486e370c --- /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 000000000000..f96be0b427fb --- /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 000000000000..cd66464f2f63 --- /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 000000000000..98062a9c764b --- /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 000000000000..022639bfe9b8 --- /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 000000000000..cd66464f2f63 --- /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 000000000000..98062a9c764b --- /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 000000000000..45a0609de0b9 --- /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 000000000000..60e00bff7d7c --- /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 000000000000..ab04c45131ca --- /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 000000000000..26bc84a1b91d --- /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 000000000000..fb0fdf0d01f9 --- /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 000000000000..958e5dd473d2 --- /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 000000000000..7f2c9ef2a6ec --- /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 000000000000..19475ad4c726 --- /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 000000000000..acdb4e290486 --- /dev/null +++ b/tests/untried/pos/chang/Outer.java @@ -0,0 +1,11 @@ +package com.netgents.hello; + +public class Outer
{ + + 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 000000000000..f74c6355b54f --- /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 000000000000..b2f0cdc32135 --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..768d2e27f4ef --- /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 000000000000..13661990caa9 --- /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 000000000000..20ac12d59ace --- /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 000000000000..0a016dec0766 --- /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 000000000000..b0f60de736c1 --- /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 000000000000..23b23d016e1b --- /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 000000000000..ad928f52a0f2 --- /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 000000000000..c3e6f8c19624 --- /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 000000000000..bb2526e4bc61 --- /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 000000000000..6886d39ca266 --- /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 000000000000..60890f9102b9 --- /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 000000000000..8d431efbac82 --- /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 000000000000..4e11d07eb4e0 --- /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 000000000000..8389d1332a15 --- /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 000000000000..084a4aaf5e00 --- /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 000000000000..86d456ad3016 --- /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 000000000000..6f0e53a36931 --- /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 000000000000..ca20f55172e9 --- /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 000000000000..d547ecd938dd --- /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 000000000000..ca20f55172e9 --- /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 000000000000..0cc218eebe50 --- /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 000000000000..c1840f3b99b7 --- /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 000000000000..395e88815ae7 --- /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 000000000000..9c7d6400fc4d --- /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 000000000000..83486579650a --- /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 000000000000..e9da24ef3759 --- /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 000000000000..95d498629b1a --- /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 000000000000..f5cd6947d128 --- /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 000000000000..48b438ddf86a --- /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 000000000000..8edfe4ac343c --- /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 000000000000..dff1917a476b --- /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 000000000000..2b4f443e6c9a --- /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 000000000000..ce5ea476d8c4 --- /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 000000000000..0c587cf16429 --- /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 000000000000..7e51861d60d4 --- /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 000000000000..598d3454c179 --- /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 000000000000..04b8f94e6485 --- /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 000000000000..c034e3ef5b7b --- /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 000000000000..f4da54949968 --- /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 000000000000..8c0e244e4e8e --- /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 000000000000..d65478bcb73e --- /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 000000000000..b0e30ade5860 --- /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 000000000000..b94066936a57 --- /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 000000000000..2dd2970ee753 --- /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 000000000000..243d5832ce94 --- /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 000000000000..4f4e47c43b5e --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..7fdecffa7e59 --- /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 000000000000..5fb709c52ce2 --- /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 000000000000..368899820f99 --- /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 000000000000..7fd784828642 --- /dev/null +++ b/tests/untried/pos/existential-java-case-class/J.java @@ -0,0 +1 @@ +public class J {} diff --git a/tests/untried/pos/existentials-harmful.scala b/tests/untried/pos/existentials-harmful.scala new file mode 100644 index 000000000000..8722852e8a4f --- /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 000000000000..9ca86d13d80d --- /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 000000000000..54515c1d21d5 --- /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 000000000000..200279be6ffe --- /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 000000000000..112fc720a057 --- /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 000000000000..8a7f86e21447 --- /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 000000000000..0207523dde8b --- /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 000000000000..662be9017d69 --- /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 000000000000..b67bafb32638 --- /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 000000000000..b59cd33c769b --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..98c50b8e8250 --- /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 000000000000..7482788a41e6 --- /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 000000000000..81af140163df --- /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 000000000000..0504fb4354da --- /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 000000000000..40519bae0663 --- /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 000000000000..30e347640421 --- /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 000000000000..7144068f3cfa --- /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 000000000000..f7d21f638343 --- /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 000000000000..e745d8bbe3e8 --- /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 000000000000..a9a4ab3e3311 --- /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 000000000000..36cd46332c28 --- /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 000000000000..a6803230eda3 --- /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 000000000000..0836f7d6fcb2 --- /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 000000000000..b469623f3293 --- /dev/null +++ b/tests/untried/pos/ilya/J.java @@ -0,0 +1,14 @@ +package test; + +class Foo { +} + +class Boo{} + +class Bar, 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 000000000000..952c004ccc25 --- /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 000000000000..923b50f04d0c --- /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 000000000000..4771493fdd7c --- /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 000000000000..ebbb013d7e70 --- /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 000000000000..5460c600151d --- /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 000000000000..94c80567477b --- /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 000000000000..aa6665f1943a --- /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 000000000000..9182893539be --- /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 000000000000..1afde26613f6 --- /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 000000000000..d5bf0ecfd6b2 --- /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 000000000000..b0e775086dfc --- /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 000000000000..f6a55e5e07e7 --- /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 000000000000..6aeed4049145 --- /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 000000000000..2ce88be544b9 --- /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 000000000000..de8f7aa1846e --- /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 000000000000..e1b37447c953 --- /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 000000000000..60f4ff07e60d --- /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 000000000000..fdea0e06f04c --- /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 000000000000..882f40f050b9 --- /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 000000000000..479fe0fc7163 --- /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 000000000000..639109eb1dd4 --- /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 000000000000..ea03113c66e6 --- /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 000000000000..bc83e04312d2 --- /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 000000000000..0a792b644a09 --- /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 000000000000..b4cacbf28620 --- /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 000000000000..9a97ded98812 --- /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 000000000000..2d6bf44c7002 --- /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 000000000000..b6bc3363a1ad --- /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 000000000000..9e6ae4a3be8a --- /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 000000000000..c4aad6cbfc84 --- /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 000000000000..7c7ff03b55d7 --- /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 000000000000..92441b0c6b7a --- /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. + static Ordering 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 f1 = new scala.runtime.AbstractFunction1() { + public B apply(A a) { + return null; + } + }; + + public static Function1, B> f2 = new scala.runtime.AbstractFunction1, B>() { + public B apply(Tuple2 tup) { + return tup._2(); + } + }; + + public static String vector(Vector x) { + Vector y = x.take(2); + return y.head(); + } + public static String list(List x) { + List y = x.drop(2); + return y.head(); + } + public static Tuple2 map(Map x) { + Traversable> y = x.drop(2); + return y.head(); + } + public static Object sum(Traversable 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) and sum(scala.collection.Traversable) have the same erasure + // [partest] public static B sum(Traversable x) { + // [partest] ^ + // + // + // can't make this work with an actual CanBuildFrom: see #4389. + // public static B sum(Traversable x) { + // // have to cast it unfortunately: map in TraversableLike returns + // // "That" and such types seem to be signature poison. + // return ((Traversable)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 000000000000..6d6da0c8b6d6 --- /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 000000000000..a80bd425c69c --- /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 000000000000..ee6ab9b49f1f --- /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 000000000000..c9094992e8fc --- /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 000000000000..bc997d6f81a5 --- /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 000000000000..01b224c3bda0 --- /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 000000000000..1f580b5b4275 --- /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 000000000000..8c29513bb579 --- /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 000000000000..249f5a0569e6 --- /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 000000000000..79c622bca06c --- /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 000000000000..49d036a8879c --- /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 000000000000..f6e6ddec77b5 --- /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 000000000000..47145bf037db --- /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 000000000000..ed7c50ead978 --- /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 000000000000..3e1600842c20 --- /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 000000000000..5d48251240c3 --- /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 000000000000..6e3313c463bc --- /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 000000000000..d09a3abf8e4d --- /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 000000000000..d7651f86b04f --- /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 000000000000..e69de29bb2d1 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 000000000000..40d965b0e764 --- /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 000000000000..e69de29bb2d1 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 000000000000..185177607882 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..8eb5a0238fb4 --- /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 000000000000..e69de29bb2d1 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 000000000000..bb83e3cc3823 --- /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 000000000000..de94d69d5d87 --- /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 000000000000..3a957bf0d69b --- /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 000000000000..b24311bd3324 --- /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 000000000000..a923a529fe0f --- /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 000000000000..6e86afeca6c6 --- /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 000000000000..18599ae71418 --- /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 000000000000..0dcb7f833d2f --- /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 000000000000..58916beb8a0f --- /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 000000000000..f930a682ef85 --- /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 000000000000..914c1b27ab31 --- /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 000000000000..348a66a10d14 --- /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 000000000000..ce9de29a2ea2 --- /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 000000000000..34832c00cad4 --- /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 000000000000..b32e8bed75a1 --- /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 000000000000..6651e643620e --- /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 000000000000..846d6a41bc90 --- /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 000000000000..8168a42d3c85 --- /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 000000000000..3da14af4fe9a --- /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 000000000000..51538417ed5d --- /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 000000000000..65faf53579c2 --- /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 000000000000..f721a57e8f8d --- /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 000000000000..a90c2575f254 --- /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 000000000000..b038fce39d06 --- /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 000000000000..421ea6facf95 --- /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 000000000000..144ddac9d3d8 --- /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 000000000000..6bd3dc479ebf --- /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 000000000000..64afdee602d2 --- /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 000000000000..f282cb914b4a --- /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 000000000000..1c68e29f01f8 --- /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 000000000000..614fcdf48087 --- /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 000000000000..d2e1e127a1e7 --- /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 000000000000..354be65da777 --- /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 000000000000..4105a25f1011 --- /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 000000000000..c34dee8faa94 --- /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 000000000000..22e9a95c4ff7 --- /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 000000000000..858f9b21fcf6 --- /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 000000000000..6312564f4d11 --- /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 000000000000..82be359d9f29 --- /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 000000000000..906f1eb3f2a2 --- /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 000000000000..de57e61ceb6d --- /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 000000000000..d948280d0d4b --- /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 000000000000..d0f28b36b863 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..91a1fb7e4856 --- /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 000000000000..91a1fb7e4856 --- /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 000000000000..ccab13371618 --- /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 000000000000..9f32a2202313 --- /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 ""; + + 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 000000000000..704d5b9c0008 --- /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 000000000000..46356ff58812 --- /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 000000000000..6417b49c2bb1 --- /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 000000000000..53e1c5f1fc9d --- /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 000000000000..547d692d87bb --- /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 000000000000..f660ea054360 --- /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 000000000000..de1972ca597e --- /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 000000000000..821fc43c6b01 --- /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 000000000000..001bd8989fb8 --- /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 000000000000..4b4b22ea79c6 --- /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 000000000000..55a283ddddee --- /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 000000000000..9442583997fb --- /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 000000000000..9ce3691f5e72 --- /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 000000000000..7d94e7a8bdfd --- /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 000000000000..464cc20ea684 --- /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 000000000000..5ed5eeddc993 --- /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 000000000000..eb163a956efa --- /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 000000000000..be8615d323a5 --- /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 000000000000..cc34263073ec --- /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 000000000000..5c20cac2a1fb --- /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 000000000000..ad928f52a0f2 --- /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 000000000000..b7efcf3e8dda --- /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 000000000000..588192079803 --- /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 000000000000..502dc2c1727d --- /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 000000000000..cd45a279c2a5 --- /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 000000000000..644633546df4 --- /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 000000000000..11108b890d42 --- /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 000000000000..8575ddaaf78d --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..0fd04855e06f --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..98c842aaf8ff --- /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 000000000000..fcf951d90723 --- /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 000000000000..623b096acb17 --- /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 000000000000..bd43bcac81c4 --- /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 000000000000..d2886fdce9e4 --- /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 000000000000..faedcc9bca0c --- /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 000000000000..e69de29bb2d1 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 000000000000..0add9704c77e --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/reflection-compat-c.scala b/tests/untried/pos/reflection-compat-c.scala new file mode 100644 index 000000000000..f5e3b01290f4 --- /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 000000000000..e69de29bb2d1 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 000000000000..028d8b1293fe --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/reflection-compat-ru.scala b/tests/untried/pos/reflection-compat-ru.scala new file mode 100644 index 000000000000..f3f493fba469 --- /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 000000000000..f17d0239d85b --- /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 000000000000..c0736c0ad985 --- /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 000000000000..48fd867160ba --- /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 000000000000..f43fa292c541 --- /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 000000000000..48fd867160ba --- /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 000000000000..79b85f3b0cad --- /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 000000000000..48fd867160ba --- /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 000000000000..c64e9c2b0812 --- /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 000000000000..48fd867160ba --- /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 000000000000..088106e9c164 --- /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 000000000000..08038db93b97 --- /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 000000000000..9fe1b5f3e5b7 --- /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 000000000000..39f3ef5f0ecd --- /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 000000000000..55fd32d3bd89 --- /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 000000000000..cfabf7a5b451 --- /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 000000000000..bdedb5c1f632 --- /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 000000000000..7c40ef37e69c --- /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 000000000000..a4253b80c7b0 --- /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 000000000000..517d8ae8aafe --- /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 000000000000..239b1b58168d --- /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 000000000000..792c40565bbc --- /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 000000000000..9bfffc2ceb3e --- /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 000000000000..3d1e3756a77c --- /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 000000000000..4236f27bed12 --- /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 000000000000..a9f16bf90b40 --- /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 000000000000..ed3d5d2c38e7 --- /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 000000000000..5a115501d8b8 --- /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 + + +/**

+ * Function with 1 parameters. + *

+ *

+ In the following example the definition of + * succ is a shorthand for the anonymous class definition + * anonfun1: + *

+ *
+ *  object Main extends App {
+ *
+ *    val succ = (x: Int) => x + 1
+ *
+ *    val anonfun1 = new Function1[Int, Int] {
+ *      def apply(x: Int): Int = x + 1
+ *    }
+ *
+ *    println(succ(0))
+ *    println(anonfun1(0))
+ *  }
+ */ +trait Function1[@specialized -T1, @specialized +R] extends AnyRef { self => + def apply(v1:T1): R + override def toString() = "" + + /** (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 000000000000..b23abf48e8cf --- /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 000000000000..8c039764f5aa --- /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 000000000000..ede579170956 --- /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 000000000000..c6acc862a0ef --- /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 000000000000..e908b65a415f --- /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 000000000000..6cd7685370c7 --- /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 000000000000..de438d6e9408 --- /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 000000000000..bde259e4facc --- /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 000000000000..870c0ed9b94d --- /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 000000000000..2163e654ed0e --- /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 000000000000..26a8c4ffbd12 --- /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 000000000000..aabe0d51e1e0 --- /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 000000000000..a742d81aaf16 --- /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 000000000000..9b6359a98256 --- /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 000000000000..46e164e9cbb4 --- /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 000000000000..2df500e20b7f --- /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 000000000000..d961110cda30 --- /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 000000000000..8434a1393679 --- /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 000000000000..959ce1591cbb --- /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 000000000000..33a252120cc1 --- /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 000000000000..90778e42a8e8 --- /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 000000000000..09684e024208 --- /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 000000000000..df2f460fd40b --- /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 000000000000..cd79170ebfb2 --- /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 000000000000..d7ecfaaabd77 --- /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 000000000000..71e56a485add --- /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 000000000000..19b660688f34 --- /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 000000000000..df31089fe2ee --- /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 000000000000..e10dabd542ad --- /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 000000000000..67179e023021 --- /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 000000000000..ff054aa7de4a --- /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 000000000000..4d87998ec650 --- /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 000000000000..703ec011ad92 --- /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 000000000000..52b2bf34b483 --- /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 000000000000..c8c8000d8dcd --- /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 000000000000..392949c6699d --- /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 000000000000..f548e156fe98 --- /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 000000000000..bbe197cda2cc --- /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 000000000000..7778ba277b0f --- /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 000000000000..aae4c96329a2 --- /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 000000000000..267a36fe5cad --- /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 000000000000..9fe8cfd94b6f --- /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 000000000000..2be8625baeb6 --- /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 000000000000..9435f504d6af --- /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 000000000000..9acbba0ec46e --- /dev/null +++ b/tests/untried/pos/super/Super_1.java @@ -0,0 +1,6 @@ +// A.java +interface Inter { } + +class Super implements Inter { + 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 000000000000..486d6b700c17 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..9de9ca028e46 --- /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 000000000000..1d4b742ff9c0 --- /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 000000000000..4c58ed3f4f6d --- /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 000000000000..d2bcda08d486 --- /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 000000000000..4f1e5b1732a9 --- /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 000000000000..937b6d70c049 --- /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 000000000000..2f23be14d98a --- /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 000000000000..d4050c818441 --- /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 000000000000..727a7d4e992d --- /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 000000000000..3c9a84f8ad33 --- /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 000000000000..652c606b0e38 --- /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 000000000000..dd866422637f --- /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 000000000000..44763ef144f3 --- /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 000000000000..670160f36e48 --- /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 000000000000..0796294403a3 --- /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 000000000000..dd3f94f30cec --- /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 000000000000..1eeca8dcad44 --- /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 000000000000..2153264e7a29 --- /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 000000000000..beb2c7c0abbd --- /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 000000000000..e4c242c0ee6c --- /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 000000000000..5419cf515436 --- /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 000000000000..20fd60497437 --- /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 000000000000..2b365ca3333b --- /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 000000000000..e018afb6ee02 --- /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 000000000000..d491b7cfb93d --- /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 000000000000..d648d773b08c --- /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 000000000000..71386cf5c7e9 --- /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 000000000000..79f0c907a323 --- /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 000000000000..9fb9430676cb --- /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 000000000000..76aef8524017 --- /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 000000000000..23d36523e93f --- /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 000000000000..806b20d4095c --- /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 000000000000..0850d7a57cf4 --- /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 000000000000..ac02b8c15a6e --- /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 000000000000..778ba65f58e4 --- /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 000000000000..bea3e3f8d0f7 --- /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 000000000000..24b4776010ab --- /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 000000000000..607a115db28e --- /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 000000000000..4838b1fcf867 --- /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 000000000000..fa5b7711ffe1 --- /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 000000000000..dfacc5eed7c6 --- /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 000000000000..b2b0b85e43f6 --- /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 000000000000..540e225a1465 --- /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 000000000000..15f2dba08e21 --- /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 000000000000..885159af664f --- /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 000000000000..1f260a5b02ea --- /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 000000000000..d12e64963de8 --- /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 000000000000..56145425998f --- /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 000000000000..e51ec7df5f1e --- /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 000000000000..07b4e727948d --- /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 000000000000..589eeec9f322 --- /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 000000000000..a765f7e3240f --- /dev/null +++ b/tests/untried/pos/t0695/JavaClass.java @@ -0,0 +1,5 @@ +public class JavaClass
{ + 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 000000000000..7318867bf7c7 --- /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 000000000000..d550d63f9807 --- /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 000000000000..7a0a2bf9bba3 --- /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 000000000000..8b137891791f --- /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 000000000000..1efdb2505eac --- /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 000000000000..4cd09f4a16a6 --- /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 000000000000..fc7109dcd457 --- /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 000000000000..79df8e804229 --- /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 000000000000..28ad30fc2dde --- /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 000000000000..8cd84759cf79 --- /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 000000000000..613af76b9435 --- /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 000000000000..7a06bfa0e22d --- /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 000000000000..2163b2b74183 --- /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 000000000000..6fb7f7ba494a --- /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 000000000000..02ba9a8a3e3e --- /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 000000000000..d268c714290a --- /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 000000000000..00589052cb8d --- /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 000000000000..9d966334a620 --- /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 000000000000..e0a9379c7ed9 --- /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 000000000000..cd16db5b60cd --- /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 000000000000..61d99f946cbf --- /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 000000000000..d34b0cff1687 --- /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 000000000000..1d4dfb637e99 --- /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 000000000000..68f1ff27310c --- /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 000000000000..1622043a85d8 --- /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 000000000000..59149a021b01 --- /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 000000000000..5f72957da1f7 --- /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 000000000000..c59e657cb29a --- /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 000000000000..a9bce90b00e7 --- /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 000000000000..2bc1d53e092c --- /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 000000000000..af7a591e589c --- /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 000000000000..530102b91c7a --- /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 000000000000..9beee8d901b0 --- /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 000000000000..0bf40bb4cc6e --- /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 000000000000..0198867704bd --- /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 000000000000..0dff0b94fdc3 --- /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 000000000000..8b36877c4948 --- /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 000000000000..3812fa3eb35c --- /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 000000000000..5bf532f8dd6f --- /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 000000000000..1b2a90457921 --- /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 000000000000..562b528ea337 --- /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 000000000000..92d603e69070 --- /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 000000000000..7e5adc4f401d --- /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 000000000000..d4b3967ddd51 --- /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 000000000000..0e6a63c16827 --- /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 000000000000..68fa04a178df --- /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 000000000000..41dd064037b5 --- /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 000000000000..6e562e573dcf --- /dev/null +++ b/tests/untried/pos/t1152/J.java @@ -0,0 +1 @@ +class J { java.util.List k = null; } diff --git a/tests/untried/pos/t1152/S.scala b/tests/untried/pos/t1152/S.scala new file mode 100644 index 000000000000..7f751c50909a --- /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 000000000000..7e09418b288f --- /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 000000000000..1e31b71bf04a --- /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 000000000000..ab58c1d6b434 --- /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 000000000000..75638e792f67 --- /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 000000000000..0d82c75fcb03 --- /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 000000000000..a7fc3e0ceadd --- /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 000000000000..fa863d158d2d --- /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 000000000000..5f2607623fec --- /dev/null +++ b/tests/untried/pos/t1186/t1186.java @@ -0,0 +1,8 @@ +import scala.collection.immutable.Map; + +class Test { + + void foo() { + Map map = null; + } +} diff --git a/tests/untried/pos/t119.scala b/tests/untried/pos/t119.scala new file mode 100644 index 000000000000..44a1566756f1 --- /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 000000000000..2ec7a711bbe4 --- /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 000000000000..f17cd249a727 --- /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 000000000000..b4e0a4255c7a --- /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 000000000000..7c9c15440f56 --- /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 000000000000..cf5ab9fba0ea --- /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 000000000000..7fae118e04a3 --- /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 000000000000..68eac4bf6d35 --- /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 000000000000..9ac783d39a87 --- /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 000000000000..78ddc41ee585 --- /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 000000000000..b3492f96e44a --- /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 000000000000..630e24ce4a77 --- /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 000000000000..0af21cbb61c3 --- /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 000000000000..35aefd2505f2 --- /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 000000000000..530dd4b85336 --- /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 000000000000..6b24205e5e44 --- /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 000000000000..f14aa2561bb5 --- /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 000000000000..2d9e3bbd588c --- /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 000000000000..29237780ac9c --- /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 000000000000..1b6bca73274e --- /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 000000000000..7bb83a849146 --- /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(); + } +} + diff --git a/tests/untried/pos/t1236.scala b/tests/untried/pos/t1236.scala new file mode 100644 index 000000000000..75a1befd263c --- /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 000000000000..31ba2966aadc --- /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 000000000000..9aed6786f637 --- /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 000000000000..17e1c60bf5e7 --- /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() { + public Integer apply() { return 0; } + }); + } + + public void test(scala.Option 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 000000000000..02f9e7e6b193 --- /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 000000000000..1718a990906d --- /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 { + 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 000000000000..92d8c1cdfa95 --- /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 000000000000..916b783bbb3e --- /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 000000000000..18b1e53f463e --- /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 000000000000..39406b2e3941 --- /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 000000000000..83a996d530a9 --- /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 000000000000..34e2bc8dd5b3 --- /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 000000000000..05f8d20ed602 --- /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 000000000000..b0b300c6f6f9 --- /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 000000000000..0762891898c7 --- /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 000000000000..aefd9c35b3bf --- /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 000000000000..5178ba987798 --- /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 000000000000..b22a94fa10d5 --- /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 000000000000..d427e957e5af --- /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 000000000000..dd288ceea289 --- /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 000000000000..658f5c730d75 --- /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 000000000000..221c3439dd8a --- /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 000000000000..bca57e478568 --- /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 000000000000..0efcc74b6545 --- /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 000000000000..492419416c45 --- /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 000000000000..36e5022e94d8 --- /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 000000000000..4ae51d8c5736 --- /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 000000000000..1d9f94d2e944 --- /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 000000000000..86667b49f709 --- /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 000000000000..2af299af86bf --- /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 000000000000..df333151d566 --- /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 000000000000..a7200a6d1ebc --- /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 000000000000..4d67f8afffae --- /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 000000000000..4f55d7ce1912 --- /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 000000000000..c671ad64729d --- /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 000000000000..91ac2ba8423a --- /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 000000000000..be994c3af3bd --- /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 000000000000..5db548ac7587 --- /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 000000000000..976e465ff7c4 --- /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 hashMap = new HashMap(); + } +} diff --git a/tests/untried/pos/t1642b.scala b/tests/untried/pos/t1642b.scala new file mode 100644 index 000000000000..72e53b0c9a6c --- /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 000000000000..10470d66f81b --- /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 000000000000..5ee6bb1759c2 --- /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 000000000000..8630890eed91 --- /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 000000000000..881bf89a00d7 --- /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 000000000000..c18f05cd73b3 --- /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 000000000000..5ec0f2297c20 --- /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 000000000000..d059bf22f8f6 --- /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 000000000000..f236d3fdc40d --- /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 000000000000..4ac52412aa16 --- /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 000000000000..8444eabb24d8 --- /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 000000000000..84c437133818 --- /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 000000000000..4c0eb28ba001 --- /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 000000000000..354d5eecd05d --- /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 000000000000..c768062e43f5 --- /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 000000000000..a415e4f57216 --- /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 000000000000..1d067c3b047b --- /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 000000000000..33b4de926413 --- /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 000000000000..0dcfbd2ed720 --- /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 000000000000..203a87b1c23b --- /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 000000000000..6aa8b4fa9e46 --- /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 000000000000..6467a74c2974 --- /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 000000000000..0b1fafb27c8d --- /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 000000000000..a2431343d1b7 --- /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 000000000000..9de149fbc50b --- /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 ) +| |-- super EXPRmode-POLYmode-QUALmode (silent: in O) +| | |-- this EXPRmode (silent: in O) +| | | \-> O.type +| | \-> O.type +| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ in O) +| | |-- (null: Any) BYVALmode-EXPRmode (site: value in O) +| | | |-- Any TYPEmode (site: value in O) +| | | | \-> Any +| | | |-- null : pt=Any EXPRmode (site: value in O) +| | | | \-> Null(null) +| | | \-> Any +| | |-- (_: LongTraversableLike[(_ @ )]) : pt=Any PATTERNmode (site: value in O) enrichment only +| | | |-- LongTraversableLike[(_ @ )] TYPEPATmode-TYPEmode (site: value in O) enrichment only +| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | | |-- Repr NOmode (site: type Repr in ) +| | | | | | | \-> Repr +| | | | | | \-> LongTraversableLike[Repr] +| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) +| | | | | \-> <: LongTraversableLike[Repr] +| | | | |-- (_ @ ) TYPEPATmode-TYPEmode (site: value 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 000000000000..1a37d48d0c24 --- /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 000000000000..1624e3025e06 --- /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 000000000000..d1a824416911 --- /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 000000000000..42f4e784a345 --- /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 000000000000..d7ed27f73055 --- /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 000000000000..7e435d70b583 --- /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 000000000000..a009a59e2197 --- /dev/null +++ b/tests/untried/pos/t1836/J.java @@ -0,0 +1 @@ +public abstract class J { 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 000000000000..88ce1063e9ca --- /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 000000000000..fd98b6c4a50b --- /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 000000000000..ff513d2c158f --- /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 000000000000..8504bf342cef --- /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 000000000000..c06e73e7e61e --- /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 000000000000..6b3150d96916 --- /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 000000000000..e1ab50679fcb --- /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 000000000000..59d604733740 --- /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 000000000000..4915b54a6403 --- /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 000000000000..6c045bbce53e --- /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 000000000000..711ce17deb0b --- /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 000000000000..3f4d41e7fbbf --- /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 000000000000..ccab13371618 --- /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 000000000000..ff27044b6910 --- /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 000000000000..a469ca6ea87a --- /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 000000000000..2730128196c1 --- /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 000000000000..b0c6b8da432a --- /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 000000000000..198b4be42a2f --- /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 000000000000..21c6fc96a621 --- /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 000000000000..8c8ca44da3b3 --- /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 000000000000..2c701150e4bd --- /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 000000000000..94c80567477b --- /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 000000000000..fb8103e4adcf --- /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 000000000000..30cb99d45c9f --- /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 000000000000..395134f71cef --- /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 000000000000..a7ee3789b994 --- /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 000000000000..6b6c4f077a69 --- /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 000000000000..f0b907aa5d1b --- /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 000000000000..d51c9706dad0 --- /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 000000000000..b9cb4d9c6d07 --- /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 000000000000..88cc9e7081ab --- /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 000000000000..8dd61c4d3093 --- /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 000000000000..1d0b33c3e51b --- /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 000000000000..c74d0a4bbf9a --- /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 000000000000..21afb239a094 --- /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 000000000000..eb4d19bcb91a --- /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 000000000000..6c754c76a656 --- /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 000000000000..89e22b6e2ae4 --- /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 000000000000..1243568b638f --- /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 000000000000..506cc496f50e --- /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 000000000000..8a33531541a8 --- /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 000000000000..e87be509d15e --- /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 000000000000..dd6d686baf46 --- /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 000000000000..218e9f5e5320 --- /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 000000000000..4e4cc5ab2c80 --- /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 000000000000..06360d50010c --- /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 000000000000..72ddfa74fec9 --- /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 000000000000..536d4ec3d0fd --- /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 000000000000..3338ab91192c --- /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 000000000000..68912b496194 --- /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 000000000000..a7f80ac98ecd --- /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 000000000000..e3d11c70e982 --- /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 000000000000..bda59ce0dba5 --- /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 000000000000..a99998a0a959 --- /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 000000000000..224b2ce83bfa --- /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 000000000000..6b7c45ff6d58 --- /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 000000000000..0412f7d82853 --- /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 000000000000..252c01fbc081 --- /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 000000000000..098e852dd7bf --- /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 000000000000..2544a1cb368c --- /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 000000000000..da60c1ef3a0a --- /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 000000000000..0df346166213 --- /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 000000000000..d212fb9036f9 --- /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 000000000000..477d5467aab3 --- /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 000000000000..4cda3bde1c48 --- /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 000000000000..340690c40227 --- /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 000000000000..151dd71ca197 --- /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 000000000000..02fd89b646b3 --- /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 000000000000..697e9e1f2d5e --- /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 000000000000..25eb2232c947 --- /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 000000000000..fac1e95d0f6a --- /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 000000000000..570ac4178d29 --- /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 000000000000..00f2e6f6773c --- /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 000000000000..ff36868a0eb4 --- /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 000000000000..1caf8ecae435 --- /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 000000000000..13a52c952bbd --- /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 000000000000..fdcafeb2c6cc --- /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 000000000000..15165c247c1e --- /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 000000000000..69fe4c127eb0 --- /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 000000000000..d0ff99a93747 --- /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 000000000000..67f8226852f5 --- /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 000000000000..d51b5511ebac --- /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 000000000000..6ad994223c49 --- /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 000000000000..64f4dc172f9f --- /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 000000000000..89421becbdd7 --- /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 000000000000..47ae551bfd3e --- /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 000000000000..8a82b4a72f87 --- /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 000000000000..3a64dbc28222 --- /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 000000000000..283d93bf2b97 --- /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 000000000000..ec6187b36bd1 --- /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 000000000000..76f0e303698e --- /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 000000000000..7cd55313561a --- /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 000000000000..d42dcc72b5d6 --- /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 000000000000..7b667d0106e2 --- /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 000000000000..e46453534c0f --- /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 000000000000..7f1f36f00bad --- /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 000000000000..72e931178c06 --- /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 000000000000..7e5876eae99b --- /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 000000000000..4ba34b554a91 --- /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 000000000000..5f0ddd122f87 --- /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 000000000000..5d4d0380c418 --- /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 000000000000..bce02e48b3d6 --- /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 000000000000..19485bf4ce0f --- /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 000000000000..8d07a8826551 --- /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 000000000000..e738143aeb62 --- /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 000000000000..d9d04f7ab0b9 --- /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 000000000000..a9fd9d7d0ee1 --- /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 000000000000..184fc6e864c2 --- /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 000000000000..fe0755953548 --- /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 000000000000..b0c108907071 --- /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 000000000000..ab12aaf1fe4d --- /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 000000000000..a17edf8cb34e --- /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 000000000000..e307133e0910 --- /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 000000000000..935cb1f44439 --- /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 000000000000..cf579d8de425 --- /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 000000000000..d1b831ea87cd --- /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 000000000000..7710cce26cdc --- /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 000000000000..1f68b0b07a90 --- /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 000000000000..c85eca164aa3 --- /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 000000000000..40277e2db233 --- /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 000000000000..8e5e8831c144 --- /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 000000000000..96c0244dfadb --- /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 000000000000..f9f2c87a98d0 --- /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 000000000000..6366548c6208 --- /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("", "")`. + // 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 000000000000..57dd5202485f --- /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 000000000000..934ca46297e1 --- /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 000000000000..025b79e79409 --- /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 000000000000..ff1f34b10e0a --- /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 000000000000..9fb1c6e1758f --- /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 000000000000..eef6c23b5ee8 --- /dev/null +++ b/tests/untried/pos/t2940/Cycle.java @@ -0,0 +1,3 @@ +public interface 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 000000000000..92f08f5800f7 --- /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 000000000000..0379e9ba1603 --- /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 000000000000..22c7beff4dcc --- /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 000000000000..2ff5daa25398 --- /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 000000000000..33803874b6bc --- /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 000000000000..0c267a307e93 --- /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 000000000000..f5dde856d9e3 --- /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 000000000000..f1a4a4a12d30 --- /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 000000000000..8b5eb9692419 --- /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 000000000000..016563e27fb8 --- /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 000000000000..b71ffe0418fa --- /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 000000000000..76da44157d12 --- /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 000000000000..dc056ecba2ca --- /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 000000000000..7e144329416c --- /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 000000000000..c8a6ea9e3e05 --- /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 000000000000..b710a2934374 --- /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 000000000000..b7bd63190114 --- /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 000000000000..a9591d0aaf9f --- /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 000000000000..12b23c1c9802 --- /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 000000000000..db6e85902014 --- /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 000000000000..fe2269308adb --- /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 000000000000..c02146fba151 --- /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 000000000000..33d42c2f3c2e --- /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 000000000000..cb7317af013d --- /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 000000000000..3d1dcbd6f098 --- /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 000000000000..cc007dc0148f --- /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 000000000000..8d9b2578d075 --- /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 000000000000..4df1bfe83789 --- /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 000000000000..89bbf8b5fca4 --- /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 000000000000..9b850966db71 --- /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 000000000000..dbe0e0528cbf --- /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 000000000000..eed25eb84ce6 --- /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 000000000000..4cc7cb2ab57c --- /dev/null +++ b/tests/untried/pos/t3249/Test.java @@ -0,0 +1,5 @@ +public class Test { + public static void meh() { + new A().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 000000000000..fad6f8da6bf7 --- /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 implements scala.ScalaObject { + public X$1(A null); + } +*/ diff --git a/tests/untried/pos/t3252.flags b/tests/untried/pos/t3252.flags new file mode 100644 index 000000000000..eb4d19bcb91a --- /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 000000000000..3ecc1e7cef17 --- /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 000000000000..cf54d6a848fe --- /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 000000000000..bd8b080c9a5c --- /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 000000000000..458070c5e7e7 --- /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 000000000000..aef965d2e795 --- /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 000000000000..9d1bc9355c4f --- /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 000000000000..38e4743ef483 --- /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 000000000000..16093676232e --- /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 000000000000..595beadc2089 --- /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 000000000000..14a073a95030 --- /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 000000000000..d4d43198476f --- /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 000000000000..36d4cd933843 --- /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 000000000000..897cd9de44ab --- /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 000000000000..91768e201df1 --- /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 000000000000..c9bedcf69472 --- /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 000000000000..4d4a81d69d54 --- /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 000000000000..c5df18cc9fcc --- /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 000000000000..b1a6c6b19ce6 --- /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 000000000000..6d46be4e4415 --- /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 000000000000..f11701a86ecb --- /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 000000000000..880c2838c088 --- /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 000000000000..ea03113c66e6 --- /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 000000000000..0fc56ed67bd8 --- /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 000000000000..ea89af16818b --- /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 000000000000..e7c57c90c563 --- /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 000000000000..eb4d19bcb91a --- /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 000000000000..f86d776bd8f5 --- /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 000000000000..449a763af759 --- /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 000000000000..0e7ca6b70fb0 --- /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 000000000000..efe25a62fc0d --- /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 000000000000..6a94baa6c8dc --- /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 000000000000..830365170b99 --- /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 000000000000..0bf388b72dcb --- /dev/null +++ b/tests/untried/pos/t3486/JTest.java @@ -0,0 +1,3 @@ +public class JTest extends T2 { + 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 000000000000..d4534e29f42e --- /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 000000000000..e61f7346f2af --- /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 000000000000..dd54b0f82faa --- /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 000000000000..08de722af064 --- /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 000000000000..8d5dff43020e --- /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 000000000000..ccf2af9dee92 --- /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 000000000000..118a8d849fff --- /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 000000000000..e8c093890bcd --- /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 000000000000..e9619b76e942 --- /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 000000000000..ff49b3e9298b --- /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 000000000000..44d3aafb6633 --- /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 000000000000..3cde9710dc85 --- /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 000000000000..4f83ba9f4312 --- /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 000000000000..f1f124b808ba --- /dev/null +++ b/tests/untried/pos/t3567/Outer.java @@ -0,0 +1,7 @@ +class Outer { + class Inner { + } + static Outer.Inner f() { + return null; + } +} diff --git a/tests/untried/pos/t3568.scala b/tests/untried/pos/t3568.scala new file mode 100755 index 000000000000..50f0cdb2ebf3 --- /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 000000000000..0e20905afae3 --- /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 000000000000..80a280f67ad6 --- /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 000000000000..d9841182083c --- /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 000000000000..d13d69775969 --- /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 000000000000..f7778148e0b5 --- /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 000000000000..11233c3ba458 --- /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 000000000000..f3716d4f9717 --- /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 000000000000..1d19ecb523af --- /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 000000000000..a9d063998ca1 --- /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 000000000000..cfcea3fe1a01 --- /dev/null +++ b/tests/untried/pos/t3622/AsyncTask.java @@ -0,0 +1,5 @@ +package test; + +public abstract class AsyncTask { + 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 000000000000..9ef4947052b2 --- /dev/null +++ b/tests/untried/pos/t3622/MyAsyncTask.java @@ -0,0 +1,9 @@ +package test; + +public abstract class MyAsyncTask extends AsyncTask { + 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 000000000000..d18953bbaca4 --- /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 000000000000..e723741307ed --- /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 000000000000..cd224a32f7a9 --- /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 000000000000..07c715ee90d4 --- /dev/null +++ b/tests/untried/pos/t3642/Tuppel_1.java @@ -0,0 +1,7 @@ +public class Tuppel_1 { + private Tuppel_1(){} + + public static Tuppel_1 get() { + return new Tuppel_1() {}; + } +} \ 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 000000000000..954795fe2ade --- /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 000000000000..ec4fbe5b4f08 --- /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 000000000000..afb3a539d19a --- /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 000000000000..b2752ce21ff7 --- /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 000000000000..60c0ceaec898 --- /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 000000000000..bf7983081112 --- /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 000000000000..9ce5b9ab7242 --- /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 000000000000..7a3cbec0f4ff --- /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 000000000000..fb9c0b40274a --- /dev/null +++ b/tests/untried/pos/t374.scala @@ -0,0 +1,21 @@ +object tokens extends Enumeration { + type Token = Value; + val BAD = Value(""); + 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 000000000000..2869925b01ff --- /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 000000000000..165eeebfdb91 --- /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 000000000000..364d46317889 --- /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 000000000000..096502174b32 --- /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 000000000000..8162fce72f58 --- /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 000000000000..2df658df1e33 --- /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 000000000000..840f171164f9 --- /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 000000000000..bcaf63cc8d39 --- /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 000000000000..132c95c5e6b1 --- /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 000000000000..9922073016bf --- /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 000000000000..5ebe02520322 --- /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 000000000000..8ca4a0586120 --- /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 000000000000..a7a50de2c418 --- /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 000000000000..5e97f8452bea --- /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 000000000000..1407324996b9 --- /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 000000000000..581c11c81b23 --- /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 000000000000..f778eb71a81a --- /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 000000000000..1b62c0c6d66a --- /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 000000000000..535bd4de8715 --- /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 000000000000..0c5f5dfe6f21 --- /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 000000000000..ab47bbd877ba --- /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 000000000000..b11b67c565e1 --- /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 000000000000..5e0d581d4eab --- /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 000000000000..b902d4528da9 --- /dev/null +++ b/tests/untried/pos/t3936/BlockingQueue.java @@ -0,0 +1,3 @@ +package pack; +import java.util.Queue; +public interface BlockingQueue extends Queue { } diff --git a/tests/untried/pos/t3936/Queue.java b/tests/untried/pos/t3936/Queue.java new file mode 100644 index 000000000000..25c9087601b8 --- /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 000000000000..c867a05ec98c --- /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 000000000000..08fae330bba8 --- /dev/null +++ b/tests/untried/pos/t3938/Parent.java @@ -0,0 +1,9 @@ +public class Parent{ + 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 000000000000..685d1a03a841 --- /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 000000000000..650ac9b7a922 --- /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 000000000000..1d38c5e76b12 --- /dev/null +++ b/tests/untried/pos/t3943/Outer_1.java @@ -0,0 +1,14 @@ +class Outer { + abstract class Inner { + abstract public void foo(E e); + } +} + +class Child extends Outer { + // the implicit prefix for Inner is Outer instead of Outer + 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 000000000000..70265229df28 --- /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 000000000000..8d8c71a92451 --- /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 000000000000..556c8486888d --- /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 000000000000..2519543008e4 --- /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 000000000000..4449dbbdf333 --- /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 000000000000..5c658e9fbc75 --- /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 000000000000..87be2987ab78 --- /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 000000000000..f1a977f26bbc --- /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 000000000000..635b00b1cb80 --- /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 000000000000..54c1b86ce373 --- /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 000000000000..775b839d9531 --- /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 000000000000..0f3f7d642971 --- /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 000000000000..2b265c571704 --- /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 000000000000..a5a3df4825a0 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..1231c133935e --- /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 000000000000..06486df0fdc8 --- /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 000000000000..8f5e8bef5e0b --- /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 000000000000..561e1704e948 --- /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 000000000000..f7033f686a0a --- /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 000000000000..a9777f02ed20 --- /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 000000000000..d6851b8cca26 --- /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 000000000000..ab0f36fdc4ab --- /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 000000000000..25eb2232c947 --- /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 000000000000..355b6136d199 --- /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 000000000000..33a713191a48 --- /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 000000000000..b4f1e705b1a1 --- /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 000000000000..11914c50c86d --- /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 000000000000..40e7d4924e36 --- /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 000000000000..65dcb04356ac --- /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 000000000000..b2a0c0120a05 --- /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 000000000000..003763f6c701 --- /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 000000000000..398fbdecc5a6 --- /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 000000000000..98f2649767a4 --- /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 000000000000..44bc814626fa --- /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 000000000000..e6c66faff09c --- /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 000000000000..fd150a150a6c --- /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 000000000000..9989ff4869c7 --- /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 000000000000..99a30785b4d1 --- /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 000000000000..ed2c6277098d --- /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 000000000000..1938aceadc7d --- /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 000000000000..1499f32b7a36 --- /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 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 000000000000..6b8e9070c56f --- /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 000000000000..68ec7b712ecf --- /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 000000000000..087fd70ababf --- /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 000000000000..e10d001585c5 --- /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 000000000000..b0131d5fa5f5 --- /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 000000000000..64cdcd9356ef --- /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 000000000000..a24b57772d5b --- /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 000000000000..e1423813f1b2 --- /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 000000000000..f3191c72fa2a --- /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 000000000000..f43f0865f002 --- /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 000000000000..edc00a5fd139 --- /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 000000000000..585a5e0a2c85 --- /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 000000000000..cdaefe9ecd19 --- /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 000000000000..746ecb271e4b --- /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 000000000000..106312311ae1 --- /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 000000000000..7192d97f4676 --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..ef38a19083a1 --- /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 000000000000..f7d45eaa539f --- /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 000000000000..53e4abc39773 --- /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 000000000000..4721a7d06773 --- /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 000000000000..b2b67fa8f6cc --- /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 000000000000..b771c6967116 --- /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 000000000000..4eefe57b2bef --- /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 000000000000..1182725e8633 --- /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 000000000000..b298ee579d0b --- /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() = ""; + } + + 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 000000000000..250f68216ad8 --- /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 000000000000..3fc13e4dd036 --- /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 000000000000..0c3f6b2bf232 --- /dev/null +++ b/tests/untried/pos/t4603/J.java @@ -0,0 +1,7 @@ +// J.java +public class J { + public static void f(java.lang.Class 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> cls) { } +} diff --git a/tests/untried/pos/t4603/S.scala b/tests/untried/pos/t4603/S.scala new file mode 100644 index 000000000000..c1364202bd30 --- /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 000000000000..9afa5b80434c --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..0d6caa8d7a6a --- /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 000000000000..0612a8fcfb9a --- /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 000000000000..2ed98a6eeaef --- /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 000000000000..ec29e8d2cbf3 --- /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 000000000000..ed35a8ad8742 --- /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 000000000000..d457543c1f4c --- /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 000000000000..284afd6c10a9 --- /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 000000000000..dc89d13168c8 --- /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 000000000000..ca20f55172e9 --- /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 000000000000..1fb6d7897362 --- /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 000000000000..6c764d0470cc --- /dev/null +++ b/tests/untried/pos/t4744/Foo.java @@ -0,0 +1 @@ +public class Foo> {} diff --git a/tests/untried/pos/t4757/A_2.scala b/tests/untried/pos/t4757/A_2.scala new file mode 100644 index 000000000000..63106a6179ef --- /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 000000000000..b50d1cd83473 --- /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 000000000000..8f01a4b66974 --- /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 000000000000..627dfd7a23bc --- /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 000000000000..d4407a86b496 --- /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 000000000000..f0579142b8d9 --- /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 000000000000..2a807ab05eec --- /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 000000000000..48002106e65c --- /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 000000000000..eb4d19bcb91a --- /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 000000000000..bf44f71d7a88 --- /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 000000000000..17ff684833d2 --- /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 000000000000..f227ef36e63c --- /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 000000000000..284a39b7abff --- /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 000000000000..f84aa4ed079e --- /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 000000000000..c66fd523f592 --- /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 000000000000..779916d58f80 --- /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 000000000000..cfb3792ae49e --- /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 000000000000..6e413128512a --- /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 000000000000..7f037ee25dbb --- /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 000000000000..f2f284f919c8 --- /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 000000000000..cf9a6a6ae97c --- /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 000000000000..97ed9369ea8c --- /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 000000000000..772b8f4486ab --- /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 000000000000..9eac556a23b0 --- /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 000000000000..ee21112a3ef2 --- /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 000000000000..28e674bf0eb4 --- /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 000000000000..5db71c6562af --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..b68fc0367108 --- /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 000000000000..7bc3ebd348fb --- /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 000000000000..c02e69db8e68 --- /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 000000000000..e51215db848c --- /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 000000000000..5934a6ba79d7 --- /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 000000000000..2079460b8395 --- /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 000000000000..23fede7d04fc --- /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 000000000000..3aa9fce5f403 --- /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 000000000000..78a1b27d5a14 --- /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 000000000000..44ad6276f2d9 --- /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 000000000000..63eeda38bae1 --- /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 000000000000..17d0a68adf82 --- /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 000000000000..b41697e572dd --- /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 000000000000..4a67244e50e9 --- /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 000000000000..5ec632d73051 --- /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 000000000000..c2f3b923f159 --- /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 000000000000..676d3c705003 --- /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 000000000000..d5b6036df878 --- /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 000000000000..188e4f2e56b5 --- /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 000000000000..129e97a5224a --- /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 000000000000..5561b7610c3d --- /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 000000000000..90886b7537ee --- /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 000000000000..eaf244e9d0b3 --- /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 000000000000..b317e6c6a318 --- /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 000000000000..02eb3f9d4c86 --- /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 000000000000..eaf244e9d0b3 --- /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 000000000000..ab4facebcd90 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..ac909e1d9966 --- /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 000000000000..ed0f814ec5db --- /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 000000000000..f403f77f7da4 --- /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 000000000000..e85037a90272 --- /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 000000000000..e6eb25b6c330 --- /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 000000000000..bfd1e153c397 --- /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 000000000000..065d175f2f80 --- /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 000000000000..45b54a67b5ff --- /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 000000000000..40c508f7d8c1 --- /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 000000000000..6c887d68217a --- /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 000000000000..c0237ca3bd61 --- /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 000000000000..d18a5c8860fa --- /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 000000000000..605e868793b5 --- /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 000000000000..052e84438cfb --- /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 000000000000..9604c8afc65a --- /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 000000000000..9bc9995d9c30 --- /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 000000000000..813acd4b832f --- /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 000000000000..dbeb165cd8c1 --- /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 000000000000..af31f3dfd116 --- /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 000000000000..c22b2b1c768c --- /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 + 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 000000000000..4e297d5935d7 --- /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 000000000000..d12bcf789b87 --- /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 000000000000..0e7cce3c1776 --- /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 000000000000..c40cef4f961b --- /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 000000000000..c2e42c0ac311 --- /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 000000000000..d40c01328f14 --- /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 000000000000..35cb2c8bae8d --- /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 000000000000..03eecf6e1925 --- /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 000000000000..3a38b9c5ea49 --- /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 000000000000..935f28609c9f --- /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 000000000000..f59d2bd6adb9 --- /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 000000000000..2b497580454e --- /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 000000000000..90e5e4130be7 --- /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 000000000000..464cc20ea684 --- /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 000000000000..0f1ef880a881 --- /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 000000000000..59ec1fd851a5 --- /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 000000000000..59ec1fd851a5 --- /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 000000000000..8269bf18f277 --- /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 000000000000..8c589eba6068 --- /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 000000000000..9423efd8a39b --- /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 000000000000..179dcb10c639 --- /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 000000000000..179dcb10c639 --- /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 000000000000..f7c58ebe8391 --- /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 000000000000..f7c58ebe8391 --- /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 000000000000..f50d568bfa58 --- /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 000000000000..2545271e32d8 --- /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 000000000000..c501dfbe60c6 --- /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 000000000000..f577500acd04 --- /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 000000000000..1a07734a8e38 --- /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 000000000000..74c4c6b4b94e --- /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 000000000000..50388fd9ec26 --- /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 000000000000..1f8d05bfedcd --- /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 000000000000..6a2a0a362109 --- /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 000000000000..353eec93d6ae --- /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 000000000000..7fbfb5dba7ee --- /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 000000000000..cd66464f2f63 --- /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 000000000000..6e5069aff82d --- /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 000000000000..72ecd95762a8 --- /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 000000000000..16796826b471 --- /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 000000000000..cd66464f2f63 --- /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 000000000000..82109075f37e --- /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 000000000000..72ecd95762a8 --- /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 000000000000..f9a9c4aa552e --- /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 000000000000..9b2dfafcf653 --- /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 000000000000..fa75cc3bddde --- /dev/null +++ b/tests/untried/pos/t5703/Base.java @@ -0,0 +1,3 @@ +public abstract class Base { + 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 000000000000..f0120ef0b9a9 --- /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 000000000000..cd66464f2f63 --- /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 000000000000..6f0207366b14 --- /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 000000000000..e171ce9c2a7e --- /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. + * + 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 000000000000..1ef14ac790cb --- /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 000000000000..2c6c0f3056a9 --- /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 000000000000..944aa04d8c0a --- /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 000000000000..694d001e3c18 --- /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 000000000000..ec2b08e0160f --- /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 000000000000..1cd73e0cb3b9 --- /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 000000000000..11da37f17bfd --- /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 000000000000..dc3de03e42eb --- /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 000000000000..411f5b05df8e --- /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 000000000000..a0256f633bfa --- /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 000000000000..924bf35fa982 --- /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 000000000000..d7ec23a56524 --- /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 000000000000..ede45399a07c --- /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 000000000000..24cea3616346 --- /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); + // 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); + // 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 (): MyApp.type = { + // > MyApp.super.(); + // 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 000000000000..61fd734f9c57 --- /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 000000000000..6f95dd8cea7c --- /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 000000000000..72ca89f7a4e0 --- /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 000000000000..e93641e9319e --- /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 000000000000..6101f546b34c --- /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 000000000000..84b450ab31f7 --- /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 000000000000..823c722c145d --- /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 000000000000..05cabed6a0a1 --- /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 000000000000..2ebb6667dc0f --- /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 000000000000..2a31e68ee53d --- /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 000000000000..e3006ddc3f7a --- /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 000000000000..939013cd0155 --- /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 000000000000..43a2ea2f066c --- /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 000000000000..066187322de8 --- /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 000000000000..26dd1f73da9a --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..2e9751afe08e --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..852b4e3e7708 --- /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 000000000000..cb02f67fb250 --- /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 000000000000..e007a1fbb59b --- /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 000000000000..6a941ef51aeb --- /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 000000000000..c7d406c649e8 --- /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 000000000000..202765b32efa --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..d824523d5b05 --- /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 000000000000..44124c90c912 --- /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 000000000000..7ba035ec3bca --- /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 000000000000..10ead0b1ca09 --- /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 000000000000..10ead0b1ca09 --- /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 000000000000..8465e8f8c6ce --- /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 000000000000..f7e4704b3e62 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..29ad9547a232 --- /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 000000000000..29ad9547a232 --- /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 000000000000..6ced0e709065 --- /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 000000000000..8465e8f8c6ce --- /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 000000000000..a4aa2eb587e1 --- /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 000000000000..339dcbf0f0c9 --- /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 000000000000..4fbd257d9577 --- /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 000000000000..3e078d2aaea9 --- /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 000000000000..b1b5471b2f81 --- /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 000000000000..eb9bd6dfa7fa --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..0093f84fc0bd --- /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 000000000000..968e2deaee53 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..50edf2c4ba02 --- /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 000000000000..26e258a27ff8 --- /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 000000000000..18dd4056455d --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..87f7cbf3b2f2 --- /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 000000000000..6ceb928162c6 --- /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 000000000000..6edb76069ebe --- /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 000000000000..f44048c0ab53 --- /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 000000000000..8f1bbb4ebff5 --- /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 000000000000..60142af6be97 --- /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 000000000000..3558d7ff0b5e --- /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 000000000000..fb90d5ae31b5 --- /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 000000000000..7a5b2daedb90 --- /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 000000000000..cd66464f2f63 --- /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 000000000000..e7d0c38c6eae --- /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 000000000000..42c3a15a8547 --- /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 000000000000..e25ebbffc5a9 --- /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 000000000000..1aa1fed391e8 --- /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 000000000000..9378a74a0540 --- /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 000000000000..954eaba3523b --- /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 000000000000..72e663ec3b26 --- /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 000000000000..de4e8992eded --- /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 000000000000..6aca84f72c42 --- /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 000000000000..b36707c7cfcf --- /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 000000000000..86f522728ecf --- /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 000000000000..e140833106d1 --- /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 000000000000..4161a24b5698 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..b5bde826b1c1 --- /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 000000000000..8fefc952e032 --- /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 000000000000..0ebca3e7afeb --- /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 000000000000..294387cc67d9 --- /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 000000000000..bb91c732a606 --- /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 000000000000..c6bfaf1f64a4 --- /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 000000000000..fca751edabd7 --- /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 000000000000..dfc6b36b33e7 --- /dev/null +++ b/tests/untried/pos/t6169/Exist.java @@ -0,0 +1,4 @@ +public class Exist { + // java helpfully re-interprets Exist as Exist + 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 000000000000..70fabd74cf90 --- /dev/null +++ b/tests/untried/pos/t6169/ExistF.java @@ -0,0 +1,4 @@ +public class ExistF> { + // java helpfully re-interprets ExistF as ExistF> + 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 000000000000..e66d1698c42e --- /dev/null +++ b/tests/untried/pos/t6169/ExistIndir.java @@ -0,0 +1,4 @@ +public class ExistIndir { + // java helpfully re-interprets ExistIndir as ExistIndir + 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 000000000000..15e4c5640fa5 --- /dev/null +++ b/tests/untried/pos/t6169/OP.java @@ -0,0 +1 @@ +public abstract class OP { } diff --git a/tests/untried/pos/t6169/Skin.java b/tests/untried/pos/t6169/Skin.java new file mode 100644 index 000000000000..780de1ee095f --- /dev/null +++ b/tests/untried/pos/t6169/Skin.java @@ -0,0 +1 @@ +public interface Skin { } diff --git a/tests/untried/pos/t6169/Skinnable.java b/tests/untried/pos/t6169/Skinnable.java new file mode 100644 index 000000000000..f91eaa30d83e --- /dev/null +++ b/tests/untried/pos/t6169/Skinnable.java @@ -0,0 +1,3 @@ +public interface Skinnable { + OP> skinProperty(); +} diff --git a/tests/untried/pos/t6169/skinnable.scala b/tests/untried/pos/t6169/skinnable.scala new file mode 100644 index 000000000000..08204f29d8ee --- /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 000000000000..84b2d2dadeec --- /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 000000000000..386399963e30 --- /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 000000000000..9d6667b6fdde --- /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 000000000000..dbc1144b42d9 --- /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 000000000000..62f2b5d5c533 --- /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 000000000000..52078bd5f46f --- /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 000000000000..dac571346dbe --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..855c621b8e39 --- /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 000000000000..2f66892b690e --- /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 000000000000..bb2f1dde78ff --- /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 000000000000..d3d30d9e16ef --- /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 000000000000..1e5b4e0e1a16 --- /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 000000000000..b4ddfe785bca --- /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 000000000000..651ea08bf2d9 --- /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 000000000000..ea7a99e12acf --- /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 000000000000..4267f4e40b0f --- /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 000000000000..2349d8294d80 --- /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 000000000000..8edfe4ac343c --- /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 000000000000..194294e981d3 --- /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 000000000000..73e2e58f736c --- /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 000000000000..cf769fc72d84 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..6b5ec7dcebfb --- /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 000000000000..a1c93fca8ffd --- /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 000000000000..f32c1cad0f4a --- /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 000000000000..fa81bbfa77a0 --- /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 000000000000..d27ad2f5026e --- /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 000000000000..50e34092d10f --- /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 000000000000..c0e740dd68c0 --- /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 000000000000..25539c885efb --- /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 000000000000..7c2beb60d04f --- /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 000000000000..1214be7418df --- /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 000000000000..4031ae26725e --- /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 000000000000..45608bc3d436 --- /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 000000000000..6ef69d48525b --- /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 000000000000..e4a4ff6011ae --- /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 000000000000..24ea38e519a4 --- /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 000000000000..cc7dc3d3e7e2 --- /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 000000000000..54e260ac744d --- /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 000000000000..46d707073921 --- /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 000000000000..db376572ee28 --- /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 000000000000..c146446af935 --- /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 000000000000..7c58605d39c6 --- /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 000000000000..2980d83eb676 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..d0ca3ba435a8 --- /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 000000000000..c9b68d70dc6a --- /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 000000000000..53bd798219d9 --- /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 000000000000..ada4bea44ddb --- /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 000000000000..98e686a1aefc --- /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 000000000000..e1a6f49b8614 --- /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 000000000000..600234a297ea --- /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 000000000000..6bb0042c6614 --- /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 000000000000..f128714dabee --- /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 000000000000..d3e58b2a166d --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..437c0bcf05e6 --- /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 000000000000..1e8137894cd6 --- /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 000000000000..dc0137420e51 --- /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 000000000000..461b8397b2d8 --- /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 000000000000..3a447241fe12 --- /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 000000000000..43bc565cb545 --- /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 000000000000..9593ebfee9d1 --- /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 000000000000..55a3b74e4cad --- /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 000000000000..7eb85f619d88 --- /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 000000000000..a62286683898 --- /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 000000000000..d1b831ea87cd --- /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 000000000000..f3bebea5be94 --- /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 000000000000..f70d1a8732c9 --- /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 000000000000..576746c91595 --- /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 000000000000..2ab8e6d39a58 --- /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 000000000000..905d29d44a35 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..0f0bd4e4a09e --- /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 000000000000..4a358046c607 --- /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 000000000000..ef1afa1eb346 --- /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 000000000000..9244b3d353ca --- /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 000000000000..56f4358d5971 --- /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 000000000000..fb5cac3a1a88 --- /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 000000000000..009566493fce --- /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 000000000000..fe048006aa8d --- /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 000000000000..bed2d0d77770 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..ab527a804aee --- /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 000000000000..a93c54f007e2 --- /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 000000000000..36e70e5d2c3e --- /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 000000000000..c6f418519911 --- /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 000000000000..9130e22a6ffe --- /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 000000000000..ebabc658ce15 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..592f62efb43c --- /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 000000000000..77963d263487 --- /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 000000000000..12a1d7eaf2e8 --- /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 000000000000..4d6e04914f18 --- /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 000000000000..d3c3616eb248 --- /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 000000000000..a43d7c50197a --- /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 000000000000..6caea418d59b --- /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 000000000000..9b3a69edd9aa --- /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 000000000000..50bc247accb1 --- /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 000000000000..2fea5e299307 --- /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 000000000000..00b37079767e --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..d70719642347 --- /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 000000000000..a4c161553eea --- /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 000000000000..18d7aeee7161 --- /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 000000000000..ed508804e3ca --- /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 000000000000..4df1dc787a02 --- /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 000000000000..7c73f700befa --- /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 000000000000..0609e2d25011 --- /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 000000000000..b24d70c9291b --- /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 000000000000..a4d256673b69 --- /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 000000000000..f45bd0a878cc --- /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 000000000000..aedd8c03afdc --- /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 000000000000..72e81a2ea865 --- /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 000000000000..4dd60409690d --- /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 000000000000..edac56d28d8c --- /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 000000000000..15582f6df370 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..7647c1634bf8 --- /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 000000000000..449e5c83f183 --- /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 000000000000..ef04d01becd0 --- /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 000000000000..67ef7fcc6969 --- /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 <: #3.this.T#7068]( f#11333: A#11329)A#11329 +// 2) [A#11329 <: #3.this.T#7068]( f#11333: A#11329)A#11329 +// 3) ( f#12556: A#11336)A#11336 +// 4) [A#11336 <: #3.this.T#7068]( 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 <: #3.this.T#7068]( 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 000000000000..06f0c95dc47b --- /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 000000000000..5d936f652901 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..3478301b3089 --- /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 000000000000..e42c63aa67a3 --- /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 000000000000..49c3c12aed02 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..94f08d545e3c --- /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 000000000000..ce977152b95a --- /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 000000000000..6377e26becc5 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..bbda09a2da8a --- /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 000000000000..aa7c71094839 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..0cfb6fb25be6 --- /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 000000000000..df7114a0f056 --- /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 000000000000..89a8063b3c17 --- /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 000000000000..ae15c08c3569 --- /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 000000000000..927c7fcfd12f --- /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 000000000000..16e9d00f1733 --- /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 ` => 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 000000000000..044d0110a214 --- /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 000000000000..a8af2e727ef4 --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..34e79c741b5b --- /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 .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 000000000000..ccac2b14005f --- /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 000000000000..0c078d3657b3 --- /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 000000000000..d1b831ea87cd --- /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 000000000000..5033600fdf9f --- /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 000000000000..006bf89e9f02 --- /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 000000000000..143ea3cd13c5 --- /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 000000000000..2692fa085fc4 --- /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 000000000000..384716532316 --- /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 000000000000..fbb428adba6a --- /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 000000000000..06b50f67665c --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..2b43bcaabfe3 --- /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 000000000000..5728956ccaf4 --- /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 000000000000..b38687c8b3cc --- /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 000000000000..aeee800d57b7 --- /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 000000000000..8e42ad1812f6 --- /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 000000000000..9c7d6400fc4d --- /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 000000000000..cca52950d10f --- /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 000000000000..e8fb65d50c20 --- /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 000000000000..22e7e343448e --- /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 000000000000..74ebf5af9658 --- /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 000000000000..866e3dc6fc25 --- /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 000000000000..810ce9a05cda --- /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 000000000000..a34743b8be5c --- /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 000000000000..497c2bf44369 --- /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 000000000000..fbc965c4cac7 --- /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 000000000000..253293e5f17e --- /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 000000000000..6dd7f4c4ac8e --- /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 000000000000..bc8c7fad6151 --- /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 000000000000..3bd477dcda1f --- /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 000000000000..1b8531bc8510 --- /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 000000000000..df4f40130450 --- /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 000000000000..747f5278e50c --- /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 000000000000..1ade76cc703b --- /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 000000000000..40bc0615a655 --- /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 000000000000..586465ee6e54 --- /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 000000000000..c4f15daf5c61 --- /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 000000000000..a3c790c65482 --- /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 000000000000..602f3cd4dc48 --- /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 000000000000..f52652b1ba78 --- /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 000000000000..160bf3717203 --- /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 000000000000..4fa0ca0b2254 --- /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 000000000000..696d53585bc5 --- /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 -- + * --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 []", "scala.tools.cmd.Demo") + + help("""Usage: demo []""") + 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 000000000000..76860272eafd --- /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 000000000000..fcf951d90723 --- /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 000000000000..d70dc05ea49e --- /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 000000000000..222a13d03902 --- /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 000000000000..c3da64f1e02b --- /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 000000000000..5a846b97e981 --- /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 000000000000..022e7ab7a01f --- /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 000000000000..4d88c334844a --- /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 000000000000..9852d5ec79d8 --- /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() 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 000000000000..40117051ed8c --- /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 000000000000..80e2f1c66742 --- /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..type}} + ){(v: si.instance.Out)si.instance.Out}( + 23{} + ){}; + */ + + } +} diff --git a/tests/untried/pos/t7776.check b/tests/untried/pos/t7776.check new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t7776.scala b/tests/untried/pos/t7776.scala new file mode 100644 index 000000000000..627d20dd63fe --- /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 000000000000..037bdad673a6 --- /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: ( 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 000000000000..09da4a5c5be6 --- /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: ( 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 000000000000..1de693d137fe --- /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 000000000000..c97cb34cee74 --- /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 000000000000..7ed6745d9f42 --- /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 000000000000..12a434c5b013 --- /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 000000000000..77b99e7d5d0d --- /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 000000000000..fc9a0aa09dda --- /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 000000000000..b6cce6ee79cf --- /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 000000000000..c214f2dcab38 --- /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 000000000000..b09254e99a58 --- /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 000000000000..b0e9221e220c --- /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 000000000000..7ccd56103ae5 --- /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 000000000000..b2d8911a179d --- /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 000000000000..19638dd17083 --- /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 000000000000..7a17f10b0e51 --- /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 000000000000..47c525c1795d --- /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 000000000000..64f261ec1608 --- /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 000000000000..d9e29935b311 --- /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 000000000000..2fe2c5866dbf --- /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 000000000000..066625179e71 --- /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 000000000000..bae9f3333fa4 --- /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 000000000000..81f717b9c4ca --- /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 000000000000..5896fdb51796 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8001.flags b/tests/untried/pos/t8001.flags new file mode 100644 index 000000000000..e8fb65d50c20 --- /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 000000000000..077082a9c243 --- /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 000000000000..55024506edc4 --- /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 000000000000..a2088bce7a0f --- /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 000000000000..451590d77e71 --- /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 000000000000..954eaba3523b --- /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 000000000000..90e571b42c8c --- /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 000000000000..612e1d727df8 --- /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 000000000000..2dea7036d657 --- /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 000000000000..86824084ed0b --- /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 000000000000..94c9b2f8d269 --- /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 000000000000..066abecffa35 --- /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 000000000000..21154e386abf --- /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 000000000000..304d70b6b872 --- /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 000000000000..45b99fd7e044 --- /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 000000000000..f05b4c15b547 --- /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 000000000000..37bf6b5ef87f --- /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 000000000000..66a55e8b5380 --- /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 000000000000..90e014d74b49 --- /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 000000000000..49d036a8879c --- /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 000000000000..ca0411dae811 --- /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 000000000000..f0a6761488a7 --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..42c9b21ce73a --- /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 000000000000..9f1e6955b4c5 --- /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 000000000000..281f0a10cdc3 --- /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 000000000000..055b7a606534 --- /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 000000000000..60996bfeca3e --- /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 000000000000..0eeb92ea2476 --- /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 000000000000..7ec002c9b72d --- /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 000000000000..709b59c194e6 --- /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 000000000000..e06f38d5db11 --- /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 000000000000..b6f76691b021 --- /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 000000000000..b4d6fd944161 --- /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 000000000000..32bce003fb94 --- /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 000000000000..32bce003fb94 --- /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 000000000000..b9809309551b --- /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: , [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 000000000000..e4eb8d3fd1e1 --- /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 000000000000..dd031f66c8ef --- /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 000000000000..1991da72f425 --- /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 000000000000..53036f6c8a76 --- /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 000000000000..fe265f8d0a3c --- /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 000000000000..7e2cfb386c3e --- /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 000000000000..82f41b61530b --- /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 000000000000..d15a05a359c9 --- /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 000000000000..cb1136ff117b --- /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 000000000000..237257b69dbf --- /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 000000000000..90b8a26ce7c0 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8187.scala b/tests/untried/pos/t8187.scala new file mode 100644 index 000000000000..84b8cd0f4c7b --- /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 000000000000..680b40f3790f --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8209a/Macros_1.scala b/tests/untried/pos/t8209a/Macros_1.scala new file mode 100644 index 000000000000..5d7852cb7add --- /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 000000000000..bedef776ff87 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8209b/Macros_1.scala b/tests/untried/pos/t8209b/Macros_1.scala new file mode 100644 index 000000000000..fa521d38db00 --- /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 000000000000..bedef776ff87 --- /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 000000000000..e1653b623826 --- /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 000000000000..d55d3139e197 --- /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 000000000000..52d6b0098eeb --- /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 000000000000..2fae925df3e4 --- /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 000000000000..005089079e8b --- /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 000000000000..52bb310e8bff --- /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 000000000000..36c212341864 --- /dev/null +++ b/tests/untried/pos/t8244d/InodeBase_1.java @@ -0,0 +1,6 @@ +import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; + +abstract class INodeBase_1 { + @SuppressWarnings("rawtypes") + public static final AtomicReferenceFieldUpdater 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 000000000000..cb39c9692ca0 --- /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 000000000000..1a24da7502af --- /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 000000000000..a571dbea9040 --- /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 000000000000..2eeba0a66ca7 --- /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 000000000000..ab3a3c960526 --- /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 000000000000..0acad4406956 --- /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 000000000000..2d10864c57e7 --- /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 000000000000..5641547c188e --- /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 000000000000..49d036a8879c --- /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 000000000000..e04b054eb9bb --- /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 000000000000..c926ad6493d9 --- /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 000000000000..2f7742ed6735 --- /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 000000000000..c926ad6493d9 --- /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 000000000000..d7a2bf565fb4 --- /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 000000000000..2cb1562326e4 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8352/Macros_1.scala b/tests/untried/pos/t8352/Macros_1.scala new file mode 100644 index 000000000000..c1c63e57bea3 --- /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 000000000000..1f84c3ca1e91 --- /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 000000000000..48b438ddf86a --- /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 000000000000..639faf4120a7 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8364.scala b/tests/untried/pos/t8364.scala new file mode 100644 index 000000000000..7a7ea1ff123d --- /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 000000000000..9ac2ce7c24e0 --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8369a.scala b/tests/untried/pos/t8369a.scala new file mode 100644 index 000000000000..13046007fbad --- /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 000000000000..e69de29bb2d1 diff --git a/tests/untried/pos/t8369b.scala b/tests/untried/pos/t8369b.scala new file mode 100644 index 000000000000..3194463fb794 --- /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 000000000000..165fdaf5f6df --- /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 000000000000..ba078a35324b --- /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 000000000000..72f6ca0ec964 --- /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 000000000000..70f18673c72a --- /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 000000000000..b8c50afd3557 --- /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 000000000000..41da7095bdea --- /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 000000000000..cfa4f49dc1cd --- /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 000000000000..c903f19867fe --- /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 000000000000..d9d37d127bfa --- /dev/null +++ b/tests/untried/pos/t942/Amount_1.java @@ -0,0 +1,5 @@ +import java.util.concurrent.Callable; + +public abstract class Amount_1 extends Object + implements Callable> { +} diff --git a/tests/untried/pos/t942/Test_2.scala b/tests/untried/pos/t942/Test_2.scala new file mode 100644 index 000000000000..3cc84dae3c62 --- /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 000000000000..c4bd6e9ba415 --- /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 000000000000..8c605dc7b6c7 --- /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 000000000000..63263cb15290 --- /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 000000000000..3734405f8bda --- /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 000000000000..89b66cfba65d --- /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 000000000000..3905b3b96d8b --- /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 000000000000..0f1929502c85 --- /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 000000000000..f719972a17fe --- /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 000000000000..19243505b433 --- /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 000000000000..70cfac06291b --- /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 000000000000..80459a6adc45 --- /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 000000000000..24e8f663bc3c --- /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 000000000000..e2f0bcffb388 --- /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 000000000000..294b53b915da --- /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 000000000000..4f6334685b2a --- /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 000000000000..f8a03f664f89 --- /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 000000000000..1ba04e29df87 --- /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 000000000000..57ec8da76c16 --- /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 000000000000..731fe048ad55 --- /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 000000000000..8d2f6e7c381c --- /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 000000000000..88cc4d061077 --- /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 000000000000..d2387b36bd24 --- /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 000000000000..4cb1da4f74cd --- /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 000000000000..a56d0a25475c --- /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 000000000000..b63abce2026e --- /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 000000000000..f6d1b666d002 --- /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 000000000000..314f10932821 --- /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 000000000000..a36d2436ecdf --- /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 000000000000..4fe65a8f1973 --- /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 000000000000..ada0ba4e5f49 --- /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 000000000000..671096293432 --- /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 000000000000..4dbafc9ac394 --- /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 000000000000..5459b3b97532 --- /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 000000000000..5631b3330672 --- /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 000000000000..d4184e4f0b45 --- /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 000000000000..265c821ad6ee --- /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 000000000000..7319cc1ecb4b --- /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 000000000000..94ef8e49fc41 --- /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 000000000000..3c9a04f8bd6f --- /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 000000000000..21af170cf1d4 --- /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 000000000000..c220e85350cf --- /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) + // :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 000000000000..5e564171099a --- /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 000000000000..eb4d19bcb91a --- /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 000000000000..c2b33869c3af --- /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: 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 000000000000..c5908cdcd996 --- /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 000000000000..3c6f9437a5fa --- /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 000000000000..c6c2febf7a25 --- /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 000000000000..cdba1a64d070 --- /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 000000000000..93d1dce4dc31 --- /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 000000000000..2cb899591afc --- /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 000000000000..ebb643d321c4 --- /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 000000000000..524328016059 --- /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 000000000000..684ea1018658 --- /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 000000000000..148fcc1bb693 --- /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 000000000000..1db8c5160fb3 --- /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 000000000000..987efdd95691 --- /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 000000000000..3a96e189afc6 --- /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 000000000000..6d13cc8b52f6 --- /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 000000000000..368b9b937588 --- /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 000000000000..779916d58f80 --- /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 000000000000..deceb91c3662 --- /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 000000000000..9818ed64a436 --- /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 000000000000..c8f78cd2bf32 --- /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 000000000000..a7e64e4f0c3f --- /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 000000000000..79de5d93054a --- /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 000000000000..79de5d93054a --- /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 000000000000..c3ea7b571d5f --- /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 000000000000..35e395095cf1 --- /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 000000000000..7dc56b0225d4 --- /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 000000000000..38945ad2f9b4 --- /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 000000000000..6dd0389c8e3e --- /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 000000000000..3f5a3100e469 --- /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 000000000000..e27c52f9c772 --- /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 000000000000..73b54b18b0f7 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..8ec931fe78fa --- /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 000000000000..3f5a3100e469 --- /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 000000000000..ffe74eda71e9 --- /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 000000000000..a2f47c88c8d8 --- /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 000000000000..85d8eb2ba295 --- /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 000000000000..641f2b4f9a32 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..6cad017b0b30 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..f6ebb3ee2f84 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..6a6d428b1a09 --- /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 000000000000..728006276350 --- /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 000000000000..727922b31c0c --- /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 000000000000..3f5a3100e469 --- /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 000000000000..02dbad68d9d0 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..0e2a7817b8b4 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..46bcf7aa1c99 --- /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 000000000000..3f5a3100e469 --- /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 000000000000..63bb98dd541f --- /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 000000000000..2a2a23d883c4 --- /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 000000000000..562f7e146101 --- /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 000000000000..7c10d60e1aaa --- /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 000000000000..7949c2afa212 --- /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 000000000000..27936d8b14c7 --- /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 000000000000..7394d428c1f7 --- /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 000000000000..531968159074 --- /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 000000000000..574b9bbd03d3 --- /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) + } +}