aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/i50-volatile.scala2
-rw-r--r--tests/neg/i827.scala7
-rw-r--r--tests/neg/singletons.scala2
-rw-r--r--tests/neg/typers.scala2
-rw-r--r--tests/neg/validate-parsing.scala13
-rw-r--r--tests/neg/validate-refchecks.scala13
-rw-r--r--tests/neg/validate.scala48
-rw-r--r--tests/pending/pos/contraImplicits.scala18
-rw-r--r--tests/pending/pos/depsel.scala14
-rw-r--r--tests/pending/run/ordered.scala22
-rw-r--r--tests/pos/finalvals.scala8
-rw-r--r--tests/pos/freezeBounds.scala6
-rw-r--r--tests/pos/i566.scala2
-rw-r--r--tests/pos/i831.scala4
-rw-r--r--tests/pos/inf.scala28
-rw-r--r--tests/pos/sets.scala11
-rw-r--r--tests/pos/tycons.scala2
-rw-r--r--tests/run/LazyValsLongs.scala65
-rw-r--r--tests/run/classTags.scala5
-rw-r--r--tests/run/i806.scala10
-rw-r--r--tests/run/puzzle.check2
-rw-r--r--tests/run/puzzle.scala11
22 files changed, 287 insertions, 8 deletions
diff --git a/tests/neg/i50-volatile.scala b/tests/neg/i50-volatile.scala
index ae31a764c..9098b47d6 100644
--- a/tests/neg/i50-volatile.scala
+++ b/tests/neg/i50-volatile.scala
@@ -1,4 +1,4 @@
-object Test {
+class Test {
class Base {
class Inner
}
diff --git a/tests/neg/i827.scala b/tests/neg/i827.scala
new file mode 100644
index 000000000..cc795b590
--- /dev/null
+++ b/tests/neg/i827.scala
@@ -0,0 +1,7 @@
+trait A { trait Inner }
+trait B { self: A =>
+ trait Inner extends self.Inner
+}
+
+
+class C extends C
diff --git a/tests/neg/singletons.scala b/tests/neg/singletons.scala
index 5dff13096..2155bfe31 100644
--- a/tests/neg/singletons.scala
+++ b/tests/neg/singletons.scala
@@ -5,7 +5,7 @@ object Test {
val n: null = null // error: Null is not a legal singleton type
- val sym: 'sym = 'sym // error: Symbol is a legal singleton type
+ val sym: 'sym = 'sym // error: Symbol is not a legal singleton type
val foo: s"abc" = "abc" // error: not a legal singleton type
}
diff --git a/tests/neg/typers.scala b/tests/neg/typers.scala
index 8bd39a557..537c4cdb0 100644
--- a/tests/neg/typers.scala
+++ b/tests/neg/typers.scala
@@ -30,7 +30,7 @@ object typers {
}
type L[X] = scala.collection.immutable.List[X]
- type M[X, Y] <: scala.collection.immutable.Map[X, Y]
+ type M[X, Y] <: scala.collection.immutable.Map[X, Y] // error: only classes can have declared but undefined members
object hk {
def f(x: L) // error: missing type parameter
diff --git a/tests/neg/validate-parsing.scala b/tests/neg/validate-parsing.scala
new file mode 100644
index 000000000..d0eee526a
--- /dev/null
+++ b/tests/neg/validate-parsing.scala
@@ -0,0 +1,13 @@
+object A {
+ sealed def y: Int = 1 // error: modifier(s) `sealed' not allowed for method
+ sealed var x = 1 // error: modifier(s) `sealed' not allowed for variable
+ lazy trait T // error: modifier(s) `lazy' not allowed for trait
+}
+
+class C () {
+ implicit this() = this() // error: ';' expected but 'implicit' found.
+ override this() = this() // error: ';' expected but 'override' found.
+}
+class D override() // error: ';' expected but 'override' found.
+
+case class ByName(x: => Int) // error: `val' parameters may not be call-by-name
diff --git a/tests/neg/validate-refchecks.scala b/tests/neg/validate-refchecks.scala
new file mode 100644
index 000000000..10e61407d
--- /dev/null
+++ b/tests/neg/validate-refchecks.scala
@@ -0,0 +1,13 @@
+
+trait A {
+ class C {}
+}
+
+trait B extends A {
+ class C {} // error: cannot override
+}
+
+trait C extends A {
+ type C = Int // error: cannot override
+}
+
diff --git a/tests/neg/validate.scala b/tests/neg/validate.scala
new file mode 100644
index 000000000..38da83fd7
--- /dev/null
+++ b/tests/neg/validate.scala
@@ -0,0 +1,48 @@
+trait X {
+ type Y
+ abstract val v: Y // error: abstract term
+ abstract def y: Y // error: abstract term
+}
+
+implicit object Z { // error: implict at toplevel
+ implicit case class C() // error: implicit classes may not be case classes
+ implicit type T = Int // error: implicit modifier cannot be used for types or traits
+ implicit trait U // error: implicit modifier cannot be used for types or traits
+ val x: X = new X {
+ type Y = Int
+ val v: Int = 1
+ }
+ var y: Int // error: only classes can have declared but undefined members
+ val z: Int = {
+ val u: Int // error: only classes can have declared but undefined members
+ 1
+ }
+}
+
+trait T {
+ type X
+ def foo: Unit = {
+ var x: Int // error: only classes can have declared but undefined members
+ ()
+ }
+ private def bar: Int // error: abstract member may not have private modifier
+ final def baz: Int // error: abstract member may not have final modifier
+}
+
+final sealed class A { // error: illegal combination of modifiers: final and sealed
+ private protected def f: Int = 1 // error: illegal combination of modifiers: private and protected
+}
+
+
+class E extends T {
+ abstract override def foo: Unit // error: abstract override only allowed for members of traits
+}
+
+trait U extends T {
+ abstract override type X // error: `abstract override' incompatible with type definition
+ @native def f(): Unit = 1 // error: `@native' members may not have implementation
+}
+
+trait TT extends AnyVal // error: trait TT annot extend AnyVal
+
+final trait UU // error: trait UU may not be `final'
diff --git a/tests/pending/pos/contraImplicits.scala b/tests/pending/pos/contraImplicits.scala
new file mode 100644
index 000000000..c4d659615
--- /dev/null
+++ b/tests/pending/pos/contraImplicits.scala
@@ -0,0 +1,18 @@
+import scala.reflect._
+// this needs to be fleshed out further
+class Contra[-T]
+
+object Test {
+ def getParam[T](c: Contra[T])(implicit ct: ClassTag[T]): Unit = {
+ println(ct)
+ ct
+ }
+ def f[T](x: Contra[T]): Contra[T] = x
+
+ def main(args: Array[String]): Unit = {
+ val x = f(new Contra[Int])
+ val y: Contra[Int] = x
+ getParam(new Contra[Int])
+ }
+}
+
diff --git a/tests/pending/pos/depsel.scala b/tests/pending/pos/depsel.scala
new file mode 100644
index 000000000..2cec4349e
--- /dev/null
+++ b/tests/pending/pos/depsel.scala
@@ -0,0 +1,14 @@
+// demonstrates selection on non-path types. Needs to be fleshed out to
+// become a real test.
+object Test {
+
+ class C {
+ type T
+ val f: T => T = ???
+ }
+
+ var x = new C
+ val y = x.f
+
+
+}
diff --git a/tests/pending/run/ordered.scala b/tests/pending/run/ordered.scala
new file mode 100644
index 000000000..ffcdc624b
--- /dev/null
+++ b/tests/pending/run/ordered.scala
@@ -0,0 +1,22 @@
+// infers wrong instance --> an implementatioin is missing
+trait Ord[-T] {
+ def less(x: T, y: T): Boolean
+}
+
+object Test {
+
+ implicit val anyIsOrd: Ord[Any] = new Ord[Any] {
+ def less(x: Any, y: Any): Boolean = ???
+ }
+
+ implicit val intIsOrd: Ord[Int] = new Ord[Int] {
+ def less(x: Int, y: Int): Boolean = x < y
+ }
+
+ def less[T: Ord](x: T, y: T): Boolean =
+ implicitly[Ord[T]].less(x, y)
+
+ def main(args: Array[String]) =
+ assert(less(1, 2))
+
+}
diff --git a/tests/pos/finalvals.scala b/tests/pos/finalvals.scala
new file mode 100644
index 000000000..03a992053
--- /dev/null
+++ b/tests/pos/finalvals.scala
@@ -0,0 +1,8 @@
+object Test {
+ final val x = 2
+ final val y = { println("x"); 2 }
+ val x1 = x
+ val y1 = y
+ object O { val x = 42 }
+ println(O.x)
+}
diff --git a/tests/pos/freezeBounds.scala b/tests/pos/freezeBounds.scala
new file mode 100644
index 000000000..6cc644d99
--- /dev/null
+++ b/tests/pos/freezeBounds.scala
@@ -0,0 +1,6 @@
+object Test {
+
+ def f[X]: (Set[X], Set[X]) = ???
+
+ val a = if (true) f else (Set[Int](), Set[String]())
+}
diff --git a/tests/pos/i566.scala b/tests/pos/i566.scala
index 34d25f8f2..a0e6f2fe7 100644
--- a/tests/pos/i566.scala
+++ b/tests/pos/i566.scala
@@ -1,4 +1,4 @@
-object Test {
+class Test {
type T = String
type U
reflect.classTag[T]
diff --git a/tests/pos/i831.scala b/tests/pos/i831.scala
new file mode 100644
index 000000000..629853b9c
--- /dev/null
+++ b/tests/pos/i831.scala
@@ -0,0 +1,4 @@
+object Test { self =>
+ def a = 5
+ self.a
+}
diff --git a/tests/pos/inf.scala b/tests/pos/inf.scala
new file mode 100644
index 000000000..71bb38f57
--- /dev/null
+++ b/tests/pos/inf.scala
@@ -0,0 +1,28 @@
+object Test {
+
+ def f[T](x: T, y: T): T = x
+ def g[T](x: T)(y: T): T = x
+
+ val x: Int = 1
+ val y: Long = x
+
+ val xs: Seq[Int] = Seq(1)
+ val ys: Traversable[Int] = xs
+
+ val r1 = f(x, y)
+ val s1: AnyVal = r1
+ val r2 = f(y, x)
+ val s2: AnyVal = r2
+ val r3 = f(xs, ys)
+ val s3: Traversable[Int] = r3
+ val r4 = f(ys, xs)
+ val s4: Traversable[Int] = r4
+ val r5 = g(x)(y)
+ val s5: AnyVal = r5
+ val r6 = g(y)(x)
+ val s6: AnyVal = r6
+ val r7 = g(xs)(ys)
+ val s7: Traversable[Int]= r7
+ val r8 = g(ys)(xs)
+ val s8: Traversable[Int] = r8
+}
diff --git a/tests/pos/sets.scala b/tests/pos/sets.scala
new file mode 100644
index 000000000..577d709f5
--- /dev/null
+++ b/tests/pos/sets.scala
@@ -0,0 +1,11 @@
+object Test {
+
+ val subPatBinders = List[Symbol]()
+
+ def extraStoredBinders: Set[Symbol] = ???
+
+ val storedBinders: Set[Symbol] =
+ (if (true) subPatBinders.toSet else Set.empty) ++ extraStoredBinders// -- ignoredSubPatBinders
+
+
+}
diff --git a/tests/pos/tycons.scala b/tests/pos/tycons.scala
index ef16a7792..1ed4d2855 100644
--- a/tests/pos/tycons.scala
+++ b/tests/pos/tycons.scala
@@ -16,7 +16,7 @@ abstract class Functor[F <: TypeConstructor] {
def map[A, B](f: F { type TypeArg <: A }): F { type TypeArg <: B }
}
-implicit object ListFunctor extends Functor[List] {
+object ListFunctor extends Functor[List] {
override def map[A, B](f: List { type TypeArg <: A }): List { type TypeArg <: B } = ???
}
diff --git a/tests/run/LazyValsLongs.scala b/tests/run/LazyValsLongs.scala
new file mode 100644
index 000000000..920a4b887
--- /dev/null
+++ b/tests/run/LazyValsLongs.scala
@@ -0,0 +1,65 @@
+class I {
+ object A1
+ object A2
+ object A3
+ object A4
+ object A5
+ object A6
+ object A7
+ object A8
+ object A9
+ object A10
+ object A11
+ object A12
+ object A13
+ object A14
+ object A15
+ object A16
+ object A17
+ object A18
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val c = new I
+ import c._
+ val l1 = List(A1,
+ A2,
+ A3,
+ A4,
+ A5,
+ A6,
+ A7,
+ A8,
+ A9,
+ A10,
+ A11,
+ A12,
+ A13,
+ A14,
+ A15,
+ A16,
+ A17,
+ A18)
+ val l2 = List(A1,
+ A2,
+ A3,
+ A4,
+ A5,
+ A6,
+ A7,
+ A8,
+ A9,
+ A10,
+ A11,
+ A12,
+ A13,
+ A14,
+ A15,
+ A16,
+ A17,
+ A18)
+ assert(l1.mkString == l2.mkString)
+ assert(!l1.contains(null))
+ }
+}
diff --git a/tests/run/classTags.scala b/tests/run/classTags.scala
index 9af6747f3..d0bd1c0ee 100644
--- a/tests/run/classTags.scala
+++ b/tests/run/classTags.scala
@@ -1,6 +1,5 @@
-object Test {
+object Test {
type T = String
- type U
/* val a /* : Class[T] */ = classOf[T] // [Ljava/lang/String;
println(a)
@@ -14,7 +13,7 @@ object Test {
val f /* : ClassTag[Array[T with U]] */ = reflect.classTag[Array[T with U]] // ClassTag(arrayClass(classOf[java.lang.String]))
println(f)
val g /* : Class[Meter] */ = classOf[Meter] // [LMeter;
- println(g)
+ println(g)
val h /* : ClassTag[Meter] */ = reflect.classTag[Meter] // ClassTag(classOf[Meter])
println(h)
*/
diff --git a/tests/run/i806.scala b/tests/run/i806.scala
new file mode 100644
index 000000000..889085022
--- /dev/null
+++ b/tests/run/i806.scala
@@ -0,0 +1,10 @@
+trait T{
+ def foo(a: List[String]): String = "1"
+ def foo(a: List[Int]): Int = 1
+ foo(List("1"))
+ foo(List(1))
+}
+// to be compiled by dotty
+object Test extends T{
+ def main(args: Array[String]): Unit = ()
+}
diff --git a/tests/run/puzzle.check b/tests/run/puzzle.check
new file mode 100644
index 000000000..fc788f211
--- /dev/null
+++ b/tests/run/puzzle.check
@@ -0,0 +1,2 @@
+53.0
+53.0
diff --git a/tests/run/puzzle.scala b/tests/run/puzzle.scala
new file mode 100644
index 000000000..2f3052cb5
--- /dev/null
+++ b/tests/run/puzzle.scala
@@ -0,0 +1,11 @@
+object Test {
+
+ def main(args: Array[String]): Unit = {
+ println(if (false) 5.0 else '5')
+ val x = if (false) 5.0 else '5'
+ println(x)
+ val z = 1L
+ val y: Float = z
+ }
+
+}