aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/inferred.scala
blob: 62d84c5594c7576c310afd3d727ac30fc2c1bd6b (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
class List[+T] {
  
  def isEmpty: Boolean
  def head: T
  def tail: List[T]
  
  def prepend [U >: T] (x: U): List[U] = new Cons(x, this)
  
  def map[U](f: T => U): List[U] = if (isEmpty) Nil else tail.map(f).prepend(f(head))
  
}

object Nil extends List[Nothing] {
  def isEmpty = true
  def head = throw new Error
  def tail = ???
}

class Cons[T](hd: T, tl: List[T]) extends List[T] {
  def isEmpty = false
  def head = hd
  def tail = tl
}


object Inferred {

  def foo[T](x: T): T = x

  val x = foo(1)

  val y = foo("abc")

  def bar[U](xs: List[U]): List[U] = xs

  val n = Nil

  val nn = bar(Nil)

  val ints: List[Int] = Nil prepend 1

  val a = if (1 == 0) Nil else ints
  
  val n2 = scala.collection.immutable.Nil
  
  val ss2: scala.collection.immutable.List[String] = "abc" :: n2
  
  val ss3 = "abc" :: n2
  
  def cl = ((x: Int) => x + 1)
  
  val ints2 = ints map (_ + 1)
}