aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/customArgs/overrideClass.scala3
-rw-r--r--tests/neg/i1750.scala12
-rw-r--r--tests/neg/i1750a.scala13
-rw-r--r--tests/neg/i1806.scala2
-rw-r--r--tests/neg/overrides.scala5
-rw-r--r--tests/neg/structural.scala11
-rw-r--r--tests/neg/t7278.scala2
-rw-r--r--tests/neg/zoo.scala14
-rw-r--r--tests/pos/i1866.scala5
-rw-r--r--tests/pos/zoo2.scala45
-rw-r--r--tests/run/functionXXL.scala (renamed from tests/pos/functionXXL.scala)4
-rw-r--r--tests/run/i1915.scala9
-rw-r--r--tests/run/structural.scala25
-rw-r--r--tests/run/structuralNoSuchMethod.check1
-rw-r--r--tests/run/structuralNoSuchMethod.scala23
15 files changed, 156 insertions, 18 deletions
diff --git a/tests/neg/customArgs/overrideClass.scala b/tests/neg/customArgs/overrideClass.scala
index 803d97dd9..431b846d9 100644
--- a/tests/neg/customArgs/overrideClass.scala
+++ b/tests/neg/customArgs/overrideClass.scala
@@ -8,8 +8,7 @@
}
trait FooB extends FooA {
type A <: Ax;
- trait Ax extends super.Ax { def xxx : Int; } // error: cyclic inheritance: trait Ax extends itself
- // (Note that inheriting a class of the same name is no longer allowed)
+ trait Ax extends super.Ax { def xxx : Int; } // error: cyclic inheritance: trait Ax extends itself) // error: class definitions cannot be overridden
abstract class InnerB extends InnerA {
// type B <: A;
val a : A = doB;
diff --git a/tests/neg/i1750.scala b/tests/neg/i1750.scala
new file mode 100644
index 000000000..a2ebe8f2b
--- /dev/null
+++ b/tests/neg/i1750.scala
@@ -0,0 +1,12 @@
+trait Lang1 {
+ trait Exp
+ trait Visitor { def f(left: Exp): Unit }
+ class Eval1 extends Visitor { self =>
+ def f(left: Exp) = ()
+ }
+}
+trait Lang2 extends Lang1 {
+ class Visitor extends Eval1 { Visitor => // error: classes cannot be overridden
+ }
+}
+
diff --git a/tests/neg/i1750a.scala b/tests/neg/i1750a.scala
new file mode 100644
index 000000000..cbb5bec95
--- /dev/null
+++ b/tests/neg/i1750a.scala
@@ -0,0 +1,13 @@
+trait Lang1 {
+ trait Exp
+ trait Visitor { def f(left: Exp): Unit }
+ class Eval1 extends Visitor { self =>
+ def f(left: Exp) = ()
+ }
+}
+trait Lang3 { self: Lang1 =>
+ class Visitor extends Eval1 { Visitor => // error: classes cannot be overridden
+ }
+}
+trait Lang4 extends Lang1 with Lang3
+
diff --git a/tests/neg/i1806.scala b/tests/neg/i1806.scala
index 7e5e132f2..199ab4791 100644
--- a/tests/neg/i1806.scala
+++ b/tests/neg/i1806.scala
@@ -2,6 +2,6 @@ trait A {
class Inner
}
trait B extends A {
- class Inner extends super.Inner // error
+ class Inner extends super.Inner // error // error
}
diff --git a/tests/neg/overrides.scala b/tests/neg/overrides.scala
index 81a93a7a2..149220bd5 100644
--- a/tests/neg/overrides.scala
+++ b/tests/neg/overrides.scala
@@ -34,11 +34,6 @@ package p2 { // all being in the same package compiles fine
}
}
- abstract class T3 extends T2 {
- class A { // error: classes cannot be overridden
- bug()
- }
- }
}
class A[T] {
diff --git a/tests/neg/structural.scala b/tests/neg/structural.scala
new file mode 100644
index 000000000..aab52b2cb
--- /dev/null
+++ b/tests/neg/structural.scala
@@ -0,0 +1,11 @@
+object Test3 {
+ import scala.reflect.Selectable.reflectiveSelectable
+ def g(x: { type T ; def t: T ; def f(a: T): Boolean }) = x.f(x.t) // error: no ClassTag for x.T
+ g(new { type T = Int; def t = 4; def f(a:T) = true })
+ g(new { type T = Any; def t = 4; def f(a:T) = true })
+ val y: { type T = Int; def t = 4; def f(a:T) = true }
+ = new { type T = Int; def t = 4; def f(a:T) = true }
+
+ def h(x: { def f[T](a: T): Int }) = x.f[Int](4) // error: polymorphic refinement method ... no longer allowed
+
+}
diff --git a/tests/neg/t7278.scala b/tests/neg/t7278.scala
index 643a3c858..7b13535f0 100644
--- a/tests/neg/t7278.scala
+++ b/tests/neg/t7278.scala
@@ -1,5 +1,5 @@
class A { class E }
-class B extends A { class E }
+class B extends A { class EB }
trait C { type E = Int }
trait D { type E = String }
trait EC { type E }
diff --git a/tests/neg/zoo.scala b/tests/neg/zoo.scala
index 19efcc1d7..1674548e8 100644
--- a/tests/neg/zoo.scala
+++ b/tests/neg/zoo.scala
@@ -7,19 +7,19 @@ type Grass = {
}
type Animal = {
type Food
- def eats(food: Food): Unit // error
- def gets: Food // error
+ def eats(food: Food): Unit
+ def gets: Food
}
type Cow = {
type IsMeat = Any
type Food <: Grass
- def eats(food: Grass): Unit // error
- def gets: Grass // error
+ def eats(food: Grass): Unit
+ def gets: Grass
}
type Lion = {
type Food = Meat
- def eats(food: Meat): Unit // error
- def gets: Meat // error
+ def eats(food: Meat): Unit
+ def gets: Meat
}
def newMeat: Meat = new {
type IsMeat = Any
@@ -40,5 +40,5 @@ def newLion: Lion = new {
}
val milka = newCow
val leo = newLion
-leo.eats(milka) // structural select not supported
+leo.eats(milka) // error: no projector found
}
diff --git a/tests/pos/i1866.scala b/tests/pos/i1866.scala
new file mode 100644
index 000000000..918d2e182
--- /dev/null
+++ b/tests/pos/i1866.scala
@@ -0,0 +1,5 @@
+import scala.reflect.Selectable.reflectiveSelectable
+object Test {
+ def f(g: { val update: Unit }) = g.update
+ def main(update: Array[String]) = {}
+}
diff --git a/tests/pos/zoo2.scala b/tests/pos/zoo2.scala
new file mode 100644
index 000000000..06210fe67
--- /dev/null
+++ b/tests/pos/zoo2.scala
@@ -0,0 +1,45 @@
+import scala.reflect.Selectable.reflectiveSelectable
+object Test {
+type Meat = {
+ type IsMeat = Any
+}
+type Grass = {
+ type IsGrass = Any
+}
+type Animal = {
+ type Food
+ def eats(food: Food): Unit
+ def gets: Food
+}
+type Cow = {
+ type IsMeat = Any
+ type Food <: Grass
+ def eats(food: Grass): Unit
+ def gets: Grass
+}
+type Lion = {
+ type Food = Meat
+ def eats(food: Meat): Unit
+ def gets: Meat
+}
+def newMeat: Meat = new {
+ type IsMeat = Any
+}
+def newGrass: Grass = new {
+ type IsGrass = Any
+}
+def newCow: Cow = new {
+ type IsMeat = Any
+ type Food = Grass
+ def eats(food: Grass) = ()
+ def gets = newGrass
+}
+def newLion: Lion = new {
+ type Food = Meat
+ def eats(food: Meat) = ()
+ def gets = newMeat
+}
+val milka = newCow
+val leo = newLion
+leo.eats(milka)
+}
diff --git a/tests/pos/functionXXL.scala b/tests/run/functionXXL.scala
index 1063e4170..de8c8e3fa 100644
--- a/tests/pos/functionXXL.scala
+++ b/tests/run/functionXXL.scala
@@ -59,12 +59,12 @@ object Test {
- println(f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ assert(42 == f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26))
- println(g(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ assert(42 == g(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26))
}
diff --git a/tests/run/i1915.scala b/tests/run/i1915.scala
new file mode 100644
index 000000000..ee192f6fe
--- /dev/null
+++ b/tests/run/i1915.scala
@@ -0,0 +1,9 @@
+object Test {
+ def main(args: Array[String]) = {
+ assert(new IntFunction26().apply(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26) == 42)
+ }
+}
+
+class IntFunction26 extends Function26[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] {
+ def apply(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, x24: Int, x25: Int, x26: Int) = 42
+}
diff --git a/tests/run/structural.scala b/tests/run/structural.scala
new file mode 100644
index 000000000..0f18f4579
--- /dev/null
+++ b/tests/run/structural.scala
@@ -0,0 +1,25 @@
+case class Record(elems: (String, Any)*) extends Selectable {
+ def selectDynamic(name: String): Any = elems.find(_._1 == name).get._2
+}
+
+object Test {
+ import scala.reflect.Selectable.reflectiveSelectable
+
+ def f(closeable: { def close(): Unit }) =
+ closeable.close()
+
+ type RN = Record { val name: String; val age: Int }
+
+ def g(r: RN) = r.name
+
+ val rr: RN = Record("name" -> "Bob", "age" -> 42).asInstanceOf[RN]
+
+ def main(args: Array[String]): Unit = {
+ f(new java.io.PrintStream("foo"))
+ assert(g(rr) == "Bob")
+
+ val s: { def concat(s: String): String } = "abc"
+ assert(s.concat("def") == "abcdef")
+ }
+}
+
diff --git a/tests/run/structuralNoSuchMethod.check b/tests/run/structuralNoSuchMethod.check
new file mode 100644
index 000000000..20576fc9c
--- /dev/null
+++ b/tests/run/structuralNoSuchMethod.check
@@ -0,0 +1 @@
+no such method
diff --git a/tests/run/structuralNoSuchMethod.scala b/tests/run/structuralNoSuchMethod.scala
new file mode 100644
index 000000000..476d7ed82
--- /dev/null
+++ b/tests/run/structuralNoSuchMethod.scala
@@ -0,0 +1,23 @@
+import scala.reflect.Selectable.reflectiveSelectable
+
+/** Demonstrates limitation of structural method dispatch (in Scala 2.x and dotty).
+ * The method must be defined at exactly the argument types given in the structural type;
+ * Generic instantiation is not possible.
+ */
+object Test {
+ type T = { def f(x: String, y: String): String }
+
+ class C[X] {
+ def f(x: X, y: String): String = "f1"
+ }
+
+ val x: T = new C[String]
+
+ def main(args: Array[String]) =
+ try println(x.f("", "")) // throws NoSuchMethodException
+ catch {
+ case ex: NoSuchMethodException =>
+ println("no such method")
+ }
+
+}