Skip to content

Instantly share code, notes, and snippets.

@retronym
Created January 3, 2010 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronym/268141 to your computer and use it in GitHub Desktop.
Save retronym/268141 to your computer and use it in GitHub Desktop.
Implicit Search Odditiies
// 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