Skip to content

Instantly share code, notes, and snippets.

@ohsitab
Created July 11, 2010 17:39
Show Gist options
  • Save ohsitab/471701 to your computer and use it in GitHub Desktop.
Save ohsitab/471701 to your computer and use it in GitHub Desktop.
// コンパニオンオブジェクトにあるimplicit parameterの探索には優先順位はない?
abstract class M[T] { def s: String }
object M { implicit object MA extends M[A] { def s = "M" } }
class A
object A { implicit object MA extends M[A] { def s = "A" } }
def f[T: M](t: T) = implicitly[M[T]].s
f(new A) // error: ambiguous implicit values
// 当然、スコープに直接定義されてる場合はそちらが優先される
implicit object MA extends M[A] { def s = "scope" }
f(new A)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment