-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extension methods do not have priority - is this intended? #20242
Unanswered
scf37
asked this question in
General Question
-
When defining extension methods via good old implicits, it is possible to specify priority:
case class AOpsLow(a: A) { def foo: String = "low" } case class AOpsHigh(a: A) { def foo: String = "high" } trait LowPriorityImplicits { implicit def lowPriorityOps(a: A): AOpsLow = AOpsLow(a) } class A object A extends LowPriorityImplicits { implicit def highPriorityOps(a: A): AOpsHigh = AOpsHigh(a) } println(A().foo) // prints "high"
While it does not work using new extension methods syntax:
class LowPriorityOps { extension(a: A) def foo: String = "low" } trait LowPriorityImplicits { given LowPriorityOps = LowPriorityOps() } class A object A extends LowPriorityImplicits { extension(a: A) def foo: String = "high" } println(A().foo) // Note that implicit extension methods cannot be applied because they are ambiguous;
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment