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
def f(x: Byte, b: Boolean) = x
def f(x: Byte, b: Int) = x
f(4, true)
errors out with:
Main.scala:5: error: overloaded method value f with alternatives:
(x: Byte,b: Int)Byte
(x: Byte,b: Boolean)Byte
cannot be applied to (Int, Boolean)
f(4, true)
^
The text was updated successfully, but these errors were encountered:
@paulp said:
This is not really a bug, although I can see why it would feel like one. 4 is an Int, not a Byte. A literal Int within the Byte range will be converted to a Byte if the expected type is Byte, but once you overload the method you lose that condition. It may be obvious in this case to the casual human observer that the first argument has to be a Byte, but in the general case analyzing overloads for expected types would be expensive, complicated, and typically fail to deliver the goods anyway.
If you're not aware, this works: f(4: Byte, true).
def f(x: Byte, b: Boolean) = x
def f(x: Byte, b: Int) = x
f(4, true)
errors out with:
Main.scala:5: error: overloaded method value f with alternatives:
(x: Byte,b: Int)Byte
(x: Byte,b: Boolean)Byte
cannot be applied to (Int, Boolean)
f(4, true)
^
The text was updated successfully, but these errors were encountered: