diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/neg/i1568.scala | 3 | ||||
-rw-r--r-- | tests/neg/structural.scala | 11 | ||||
-rw-r--r-- | tests/neg/valueclasses-impl-restrictions.scala | 19 | ||||
-rw-r--r-- | tests/neg/zoo.scala | 14 | ||||
-rw-r--r-- | tests/pos/backquoted_type_operator.scala | 4 | ||||
-rw-r--r-- | tests/pos/f-bounded-case-class.scala | 1 | ||||
-rw-r--r-- | tests/pos/i1723.scala | 8 | ||||
-rw-r--r-- | tests/pos/i1866.scala | 5 | ||||
-rw-r--r-- | tests/pos/zoo2.scala | 45 | ||||
-rw-r--r-- | tests/repl/errmsgs.check | 7 | ||||
-rw-r--r-- | tests/run/functionXXL.scala (renamed from tests/pos/functionXXL.scala) | 4 | ||||
-rw-r--r-- | tests/run/i1569.check | 2 | ||||
-rw-r--r-- | tests/run/i1569.scala | 5 | ||||
-rw-r--r-- | tests/run/i1915.scala | 9 | ||||
-rw-r--r-- | tests/run/structural.scala | 25 | ||||
-rw-r--r-- | tests/run/structuralNoSuchMethod.check | 1 | ||||
-rw-r--r-- | tests/run/structuralNoSuchMethod.scala | 23 | ||||
-rw-r--r-- | tests/run/t10170.check | 1 | ||||
-rw-r--r-- | tests/run/t10170.scala | 7 | ||||
-rw-r--r-- | tests/untried/neg/valueclasses-impl-restrictions.scala | 29 |
20 files changed, 185 insertions, 38 deletions
diff --git a/tests/neg/i1568.scala b/tests/neg/i1568.scala new file mode 100644 index 000000000..a260c530b --- /dev/null +++ b/tests/neg/i1568.scala @@ -0,0 +1,3 @@ +object Test { + inline def foo(n: Int) = foo(n) // error: cyclic reference +} 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/valueclasses-impl-restrictions.scala b/tests/neg/valueclasses-impl-restrictions.scala new file mode 100644 index 000000000..9f33b7e7c --- /dev/null +++ b/tests/neg/valueclasses-impl-restrictions.scala @@ -0,0 +1,19 @@ +class X1(val s: String) extends AnyVal { + trait I2 { // error: value class may not define an inner class or trait + val q: String + def z = s + q + } +} + +class X2(val s: String) extends AnyVal { + private[this] class I2(val q: String) // error: value class may not define an inner class or trait + + def y(i: Int) = { + val i2 = new I2(i.toString) + i2.q + s + } +} + +class X3(val s: String) extends AnyVal { + object I3 // error: value class may not define non-parameter field +} 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/backquoted_type_operator.scala b/tests/pos/backquoted_type_operator.scala new file mode 100644 index 000000000..5ee875702 --- /dev/null +++ b/tests/pos/backquoted_type_operator.scala @@ -0,0 +1,4 @@ +object Test { + type `&`[L,R] = L + val x: Int `&` String = 10 +} diff --git a/tests/pos/f-bounded-case-class.scala b/tests/pos/f-bounded-case-class.scala new file mode 100644 index 000000000..82b8758b2 --- /dev/null +++ b/tests/pos/f-bounded-case-class.scala @@ -0,0 +1 @@ +case class Test[X <: List[Y], Y <: List[X]](x: X, y: Y) diff --git a/tests/pos/i1723.scala b/tests/pos/i1723.scala new file mode 100644 index 000000000..75f7cd95c --- /dev/null +++ b/tests/pos/i1723.scala @@ -0,0 +1,8 @@ +class A { + private val x: List[Int] = List(1) + def foo = x.head // foo inferred type is this.x.scala$collection$immutable$List$$A +} + +class B extends A { + foo +} 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/repl/errmsgs.check b/tests/repl/errmsgs.check index f0ccdf53f..0dc8e8ae5 100644 --- a/tests/repl/errmsgs.check +++ b/tests/repl/errmsgs.check @@ -78,4 +78,11 @@ scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr 4 |class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr | ^^^^^^^^ | value `barr` is not a member of Foo(foo) - did you mean `foo.bar`? +scala> val x: List[Int] = "foo" :: List(1) +-- [E007] Type Mismatch Error: <console> --------------------------------------- +4 |val x: List[Int] = "foo" :: List(1) + | ^^^^^ + | found: String($1$) + | required: Int + | scala> :quit 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/i1569.check b/tests/run/i1569.check new file mode 100644 index 000000000..0d55bed3a --- /dev/null +++ b/tests/run/i1569.check @@ -0,0 +1,2 @@ +foo +foo diff --git a/tests/run/i1569.scala b/tests/run/i1569.scala new file mode 100644 index 000000000..2c5dd4e5a --- /dev/null +++ b/tests/run/i1569.scala @@ -0,0 +1,5 @@ +object Test { + inline def foo(inline n: => Int) = n + n + + def main(args: Array[String]): Unit = foo({ println("foo"); 42 }) +} 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") + } + +} diff --git a/tests/run/t10170.check b/tests/run/t10170.check new file mode 100644 index 000000000..29d6383b5 --- /dev/null +++ b/tests/run/t10170.check @@ -0,0 +1 @@ +100 diff --git a/tests/run/t10170.scala b/tests/run/t10170.scala new file mode 100644 index 000000000..683bad371 --- /dev/null +++ b/tests/run/t10170.scala @@ -0,0 +1,7 @@ +object Test { + def main(args: Array[String]) = println(f) + + def f = { + val a = 100; ({ val a = 0; (c: Int) => c })(a) + } +} diff --git a/tests/untried/neg/valueclasses-impl-restrictions.scala b/tests/untried/neg/valueclasses-impl-restrictions.scala deleted file mode 100644 index f0577a94a..000000000 --- a/tests/untried/neg/valueclasses-impl-restrictions.scala +++ /dev/null @@ -1,29 +0,0 @@ -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 - } -} |