-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New specification for dropped weak conformance. #5358
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
New specification for dropped weak conformance. #5358
Conversation
Including more details on it. Now, only Int literals can be adapted to a single other numeric type (excluding `Char`), if no loss of precision occurs.
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
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.
That's a nicely lucid description!
--- | ||
|
||
To simplify the underlying type theory, Dotty drops the notion of weak | ||
conformance altogether. Instead, it provides more flexibility when |
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.
I just realized that in the spec, the definition of numeric widening depends on the definition of weak conformance, from https://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html:
If e has a primitive number type which weakly conforms to the expected type, it is widened to the expected type using one of the numeric conversion methods toShort, toChar, toInt, toLong, toFloat, toDouble defined here.
So we'll need to rewrite that definition (relatedly, I'm also trying to restrict what numeric widening can do in scala/scala#7405)
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.
Actually it seems that we simply don't have any notion of numeric widening in Dotty, we just rely on the implicit conversions defined in Int.scala/Float.scala/etc
|
||
To simplify the underlying type theory, Dotty drops the notion of weak | ||
conformance altogether. Instead, it provides more flexibility when | ||
assigning a type to a constant expression. The new rule is: |
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.
I think it would be good if this rule declared its name, which I think is "harmonize" (and also known as "new weak conformance").
Including more details on it.
Now, only Int literals can be adapted to a single other numeric type (excluding
Char
), if no loss of precision occurs.(better late than never)