Define a method which accepts types: List[_ <: AnyVal]
def foo(x : List[_ <: AnyVal]) = x
Try to use an AnyRef:
foo(List(new Test))
error: type mismatch;
found : Test
required: AnyVal
Note that implicit conversions are not applicable because they are ambiguous:
both method ArrowAssoc in object Predef of type [A](self: A)ArrowAssoc[A]
and method Ensuring in object Predef of type [A](self: A)Ensuring[A]
are possible conversion functions from Test to AnyVal
Question 1: In the warning message, why does the compiler ignore the other two "generic to AnyVal" implicit conversions defined in Predef.scala?
final implicit class StringFormat[A] extends AnyVal
final implicit class any2stringadd[A] extends AnyVal
Removing the previous ambiguity and forcing compiler to use the ArrowAssoc implicit conversion:
foo(List(new Test -> 1))
error: the result type of an implicit conversion must be more specific than AnyVal
Question 2: What is this error message implying? Its confusing. The method def -> [B](y: B): Tuple2[A, B] = Tuple2(self, y)
in the ArrowAssoc class returns a Tuple2 which is of AnyRef type. So, a more useful error message could have been found Tuple2 required AnyVal
?