Skip to content

Instantly share code, notes, and snippets.

@maxaf
Created December 9, 2010 17:47
Show Gist options
  • Save maxaf/735043 to your computer and use it in GitHub Desktop.
Save maxaf/735043 to your computer and use it in GitHub Desktop.
trait X
case class A(i: Int) extends X
case class B(i: Int) extends X
implicit def int2a(i: Int): A = A(i)
implicit def int2b(i: Int): B = B(i)
implicit def int2x(i: Int)(implicit multiplier: Int): X =
if (System.currentTimeMillis % 100 == 0) A(i * multiplier) else B(i * multiplier)
val a: A = 1
val b: B = 2
val x: X = 3
ambig.scala:13: error: type mismatch;
found : Int(3)
required: this.X
Note that implicit conversions are not applicable because they are ambiguous:
both method int2x of type (i: Int)(implicit multiplier: Int)this.X
and method int2b of type (i: Int)this.B
are possible conversion functions from Int(3) to this.X
val x: X = 3
^
one error found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment