Created
January 3, 2010 21:32
-
-
Save retronym/268141 to your computer and use it in GitHub Desktop.
Implicit Search Odditiies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for 2.7.x compatibility | |
def locally[T](x: T): T = x | |
def implicitly[T](implicit e: T) = e | |
object A { | |
implicit val one = 1 | |
} | |
object Test { | |
locally { | |
import A._ | |
locally { | |
// assert(implicitly[Int] == 1) // error: could not find implicit value for parameter e: Int. | |
// !!! Why one A.one? | |
implicit val one = 2 | |
assert(implicitly[Int] == 2) | |
assert(one == 2) | |
} | |
} | |
locally { | |
import A._ | |
assert(implicitly[Int] == 1) | |
implicit val one = 2 | |
assert(implicitly[Int] == 1) // !!! why not 2?. why different from the example above? | |
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] == 1) // !!! why not 2? | |
assert(one == 2) | |
} | |
locally { | |
import A.one | |
assert(implicitly[Int] == 1) | |
implicit val two = 2 | |
assert(implicitly[Int] == 2) // !!! Not ambiguous in 2.8.0. Ambigous in 2.7.6 | |
} | |
locally { | |
import A._ | |
assert(implicitly[Int] == 1) | |
implicit val two = 2 | |
import A.{one => _} | |
assert(implicitly[Int] == 2) // !!! Not ambiguous in 2.8.0. Ambiguous in 2.7.6 | |
} | |
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 | |
} | |
} | |
Test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment