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

Casts on numeric value types behave differently when they are boxed #8094

Closed
scabug opened this issue Dec 19, 2013 · 2 comments
Closed

Casts on numeric value types behave differently when they are boxed #8094

scabug opened this issue Dec 19, 2013 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Dec 19, 2013

Casting a numeric value type to another will result in a conversion:

5L.asInstanceOf[Int]        // --> 5: Int
(5L: Any).asInstanceOf[Int] // throws ClassCastException

Boxing should be transparent, so they should result in the same behavior.

It is discussable which behavior is desirable:

  • From a typing point of view, a Long is not an Int and the cast should therefore fail. Also, a cast could/should be considered as a pure type operation and not a conversion/coercion.
  • The scala spec supports the behavior of the unboxed version in §12.1
@scabug
Copy link
Author

scabug commented Dec 19, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8094?orig=1
Reporter: @gzm0
Affected Versions: 2.10.2, 2.11.0-M7
See #4437
Duplicates #1448

@scabug
Copy link
Author

scabug commented Dec 19, 2013

@paulp said:
Duplicate of #1448.

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