Skip to content

Fix #5976: Don't assume T <:< (=>T). #5981

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 2 commits into from
Mar 1, 2019
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 24, 2019

It's incorrect to assume T <:< (=> T) since, taken as parameters,
the erasure of the two types is different: |T| vs Function1.

To compenate, we need to widenExpr in various places.

It's incorrect to assume `T <:< => T` since, taken as parameters,
the erasure of the two types is different: `|T|` vs `Function1`.

To compenate, we need to `widenExpr` in various places.
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
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! ☀️

Align lub/glb with the changes to subtyping.
@@ -603,7 +603,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
* argument trees.
*/
class ApplicableToTreesDirectly(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context) extends ApplicableToTrees(methRef, targs, args, resultType)(ctx) {
override def argOK(arg: TypedArg, formal: Type): Boolean = argType(arg, formal) <:< formal
override def argOK(arg: TypedArg, formal: Type): Boolean = argType(arg, formal) <:< formal.widenExpr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some guarantee that the result of argType cannot be an ExprType here ? Even if we do, it seems more regular to widen both sides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case we dropped in TypeComparer is where the RHS is an ExprType. => T was never a subtype of T.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but if both argType and formal are => T, then argOK used to return true but will return false now that we widen formal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I believe argTypes are never ExprTypes. They might be TermRefs with an underlying ExprType. But we skip the ExprType when we do a widen on these. lub also does widen, not widenExpr. So I think we are good.

@@ -98,7 +98,7 @@ object Implicits {
else if (mt.paramInfos.lengthCompare(1) == 0 && {
var formal = widenSingleton(mt.paramInfos.head)
if (approx) formal = wildApprox(formal)
ctx.test(implicit ctx => argType relaxed_<:< formal)
ctx.test(implicit ctx => argType relaxed_<:< formal.widenExpr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here.

@smarter
Copy link
Member

smarter commented Feb 25, 2019

I'm wondering if we should introduce a widen_<:< to make the pattern more formal.

@odersky
Copy link
Contributor Author

odersky commented Feb 25, 2019

I'm wondering if we should introduce a widen_<:< to make the pattern more formal.

I had a look at it. We have 8 occurrences of the pattern <:< t.widenExpr but 5 use <:< and 3 use frozen_<:<. So we'd have to create two new methods to capture all these cases. My tendency is to not do that, though.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still be in favor of having widened_<:< and widenedFrozen_<:<, but I guess we can always go that route later if we find more cases where widening is needed.

@odersky odersky merged commit 4dc4002 into scala:master Mar 1, 2019
@allanrenucci allanrenucci deleted the fix-#5976 branch March 1, 2019 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants