Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downcasting int literals to bytes and shorts does not work on overloaded methods #6708

Closed
scabug opened this issue Nov 24, 2012 · 2 comments
Closed

Comments

@scabug
Copy link

scabug commented Nov 24, 2012

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)
^

@scabug
Copy link
Author

scabug commented Nov 24, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6708?orig=1
Reporter: Mark Hammons (markehammons)
Affected Versions: 2.9.2

@scabug
Copy link
Author

scabug commented Nov 24, 2012

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants