File: t2866.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 (44 lines) | stat: -rw-r--r-- 1,102 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
39
40
41
42
43
44
// for 2.7.x compatibility

object A {
  implicit val one = 1
}

object Test extends App {

  locally {
    import A._
    locally {
      // assert(implicitly[Int] == 1) // error: could not find implicit value for parameter e: Int.
                                     // !!! Why one A.one?
      // (I assume you mean: why _not_ A.one? A.one is shadowed by local one.
      // but the local one cannot be used yet because it does not have an explicit type.
      implicit val one = 2
      assert(implicitly[Int] == 2)
      assert(one == 2)
    }
  }

  locally {
    import A._
    implicit val one: Int = 2
    assert(implicitly[Int] == 2)
    assert(one == 2)
  }

  locally {
    import A.one // warning: imported `one' is permanently hidden by definition of value one.
                 // !!! Really?
    //assert(implicitly[Int] == 1)
    implicit val one = 2
    assert(implicitly[Int] == 2) // !!! why not 2?
    assert(one == 2)
  }

  locally {
    import A.{one => _, _}
    implicit val two = 2
    assert(implicitly[Int] == 2) // not ambiguous in 2.8.0 nor im ambiguous in 2.7.6
  }

}