-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Constant fold all the number conversion methods #17446
Conversation
line 1 (one) should be marked OK now. |
This is nice but I guess we won't get range checking like normal constant conversion.
|
495573e
to
a72373c
Compare
that's right, it won't generate an error. It may be better to at least emit a warning in order to catch some mistakes, WDYT? |
This might have an unintended side effect that we should protect against. Unless I'm mistaken, this allows to define constants (in the sense of Constant Expression in the spec) whose type is a Byte or Short: object Foo {
final val x = 5.toByte // previously typed as Int, now ConstantType(5: Byte)
inline val x = 5.toShort // same thing
} As much as I would like to have Byte and Short Constants, I don't think we should allow that to happen, because we cannot write such a constant type. It would be good to ensure that inferred types widen ConstantType's for Bytes and Shorts to non-constant |
I think that Nicolas expected that to be allowed when he wrote #13990, didn't he? I agree that it might be a bit weird because we cannot write such a constant type. On the other hand, it might also be confusing to allow |
Oh yes sorry. That should have been make it a non-constant |
Yeah, @nicolasstucki had this in mind. But I see how it's a problem to infer types that cannot be written explicitly. So, if we don't want that, I guess the solution is just to remove the cases for |
No, I think you have the right behavior. Byte the way, maybe this behavior should be described in the standard library documentation. Seems like it is similar to WebAssembly's wrap operation:
|
a72373c
to
9a14f01
Compare
Co-authored-by: Eugene Flesselle <[email protected]> Co-authored-by: Martin Kucera <[email protected]>
9a14f01
to
3a1c0f4
Compare
I've removed the const-folding for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I don't understand the point about omitting I expected I have that expectation even if literal folding doesn't warn me that my literal doesn't fit. (Which I also don't understand, as it's an obvious gotcha and an easy lint win.) The ticket says to allow inline val, which to me means as if the RHS were ascribed well, as you can see, I don't even know how to use Scala 3.
|
but the type of that value is |
Co-authored-by: Eugene Flesselle [email protected]
Co-authored-by: Martin Kucera [email protected]
Fixes #13990. Made during the Scala Spree :)