You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By passing 'getOrElse' to 'f' the type 'B' must be a super type of 'String' and a subtype of 'TraversableOnce[Char]'. No such type exist but the closest is 'Comparable[String]'. This leaks into the error message which then becomes misleading.
A better error message would inform the programmer that "no type B could be found that is a super type of String and a subtype of TraversableOnce[Char]" or something along these lines.
By the way, forcing the type B to String
f(optionalString.getOrElse[String]("<none>"))
makes the code compile. Now, getOrElse's result is a String and an implicit conversion to StringOps can kick in to make String compatible with TraversableOnce[Char].
The text was updated successfully, but these errors were encountered:
(Leaving the ticket open primarily because I agree the error message seems improvable, not so much because I hold out hope of improving type inference in this case.)
If we have this function
and an optional string
and try to pass the result of 'Option.getOrElse' to the function
f(optionalString.getOrElse("<none>"))
we get this error message:
This is a bit misleading.
The definition of Option.getOrElse is:
By passing 'getOrElse' to 'f' the type 'B' must be a super type of 'String' and a subtype of 'TraversableOnce[Char]'. No such type exist but the closest is 'Comparable[String]'. This leaks into the error message which then becomes misleading.
A better error message would inform the programmer that "no type B could be found that is a super type of String and a subtype of TraversableOnce[Char]" or something along these lines.
By the way, forcing the type B to String
makes the code compile. Now, getOrElse's result is a String and an implicit conversion to StringOps can kick in to make String compatible with TraversableOnce[Char].
The text was updated successfully, but these errors were encountered: