Skip to content

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

Merged
merged 1 commit into from
Nov 1, 2018

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Oct 31, 2018

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)

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.
Copy link
Member

@dottybot dottybot left a 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:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

Copy link
Contributor

@odersky odersky left a 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!

@odersky odersky merged commit cd3cfce into scala:master Nov 1, 2018
@allanrenucci allanrenucci deleted the new-spec-for-weak-conformance branch November 1, 2018 16:48
---

To simplify the underlying type theory, Dotty drops the notion of weak
conformance altogether. Instead, it provides more flexibility when
Copy link
Member

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)

Copy link
Member

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:
Copy link
Member

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

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

Successfully merging this pull request may close these issues.

5 participants