File: t2636.scala

package info (click to toggle)
scala 2.11.12-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 62,828 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,250; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (38 lines) | stat: -rw-r--r-- 990 bytes parent folder | download | duplicates (4)
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
27
28
29
30
31
32
33
34
35
36
37
38

import scala.language.{ reflectiveCalls }

object Test
{
  type Foo = { def update(x: Int, value: String): Unit }
  type Foo2 = { def update(x: Int, value: String): Int }
  type Foo3 = { def update(x: Int, value: String): Array[Int] }

  def alen() = {
    type L1 = { def length: Int }
    def len(p: L1) = p.length
    val x: L1 = Array(1,2,3)
    len(x)
  }

  type A1 = { def apply(x: Int): String }
  def arrApply(a: A1, x: Int) = a(x)

  def main(args: Array[String]): Unit = {
    val arr = new Array[String](3)
    val p1: Foo = arr
    def a1 = p1(0) = "b"

    val p2: Foo2 = new { def update(x: Int, value: String) = { p1(1) = "o" ; 1 } }
    def a2 = p2(0) = "c"

    val p3: Foo3 = new { def update(x: Int, value: String) = { p1(2) = "b" ; Array(1) } }
    def a3 = p3(10) = "hi mom"

    a1 ; a2 ; a3 ;

    assert(arr.mkString == "bob")
    assert(alen() == 3)
    assert(arrApply(arr, 1) == "o")
    assert(arrApply(new { def apply(x: Int) = "tom" }, -100) == "tom")
  }
}