aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/typers.scala
blob: b2d1d50e1ab49425eb6f3578db7a42cc74c9a33c (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import annotation.{tailrec, switch}

object typers {

  class List[+T] {
    def :: (x: T) = new :: (x, this)
    
    def len: Int = this match {
      case x :: xs1 => 1 + xs1.len
      case Nil => 0
    }
  }
  
  object Nil extends List[Nothing]
  
  case class :: [+T] (hd: T, tl: List[T]) extends List[T]
  
  def len[U](xs: List[U]): Int = xs match {
    case x :: xs1 => 1 + len(xs1)
    case Nil => 0
  }
  
  object returns {
    
    def foo(x: Int): Int = {
      return 3
    }
  }
  
  object tries {

    val x = try {
      "abc"
    } catch {
      case ex: java.io.IOException =>
        123
    } finally {
      println("done")
    }

    val y = try 2 catch Predef.identity

    val z = try 3 finally "abc"

  }

  class C {
    
    @tailrec def factorial(acc: Int, n: Int): Int = (n: @switch) match {
      case 0 => acc
      case _ => factorial(acc * n, n - 1)
    }
      
    println(factorial(1, 10))
    
    
  }
  
  class Refinements {
    val y: C { type T; val key: T; def process(x: T): Int }
  }

}