Skip to content

Instantly share code, notes, and snippets.

@andresilva
Created July 25, 2013 23:17
Show Gist options
  • Save andresilva/6084682 to your computer and use it in GitHub Desktop.
Save andresilva/6084682 to your computer and use it in GitHub Desktop.
Low priority implicits issue
def test(m: Magnet): Int = m.i
class Magnet(val i: Int)
object Magnet extends LowerPriorityMagnet {
implicit def fromUnitWithInt(u: Unit)(implicit i: Int) = new Magnet(i)
}
abstract class LowerPriorityMagnet {
implicit def fromUnitWithString(u: Unit)(implicit s: String) = new Magnet(s.toInt)
}
implicit val ev = 3
test() == 3 // true
implicit val ev = "3"
test() == 3
// <console>:32: error: not enough arguments for method test: (m: Magnet)Int.
// Unspecified value parameter m.
// test()
// ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment