Skip to content

Fix isNullable when <:< term refs. #1711

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 17, 2016

Conversation

nicolasstucki
Copy link
Contributor

Note that without the fix console tests will fail and without
the warning there is no way to test the fix.

@nicolasstucki
Copy link
Contributor Author

/rebuild

ctx.warning(ex"comparing values of types ${lhs.widenDealias} and ${rhs.widenDealias} using `!=' will always yield true",
tree.pos)
}
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why put that test here? And why is it done only on != but not on ==?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where in the pipeline would be the best place to put this test?

Copy link
Contributor

@odersky odersky Nov 16, 2016

Choose a reason for hiding this comment

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

I actually thing the test is wrong. Consider:

trait A
trait B
class C extends A with B
val c = new C
val x: A = c
val y: B = c
x != y

Multiversal equality is meant to deal with these kinds of things. I am not sure we need a separate mechanism.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the tests is incomplete, in scalac there is a different waring for those cases:

scala> x != y
<console>:18: warning: A and B are unrelated: they will most likely always compare unequal
       x != y

Now I'm convinced that these should not be a separate mechanism from multiversal equality.

There is also the question of the NullType <:< X tests failing for Xs that are term refs to some subtype of AnyRef. In all the currently tests those term refs are widen first and therefore we never have false negatives. Is this the correct way to handle those cases or the change to isNullabe should be done?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the isNullable change is good. TermRefs should be nullable if their underlying typrs are nullable. So I propose to just keep this change and drop the rest.

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 agree.

Note that without the fix console tests will fail and without
the warning there is no way to test the fix.
@nicolasstucki nicolasstucki changed the title Add warning on != with same type fix isNullable. Fix isNullable when <:< term refs. Nov 17, 2016
@odersky
Copy link
Contributor

odersky commented Nov 17, 2016

LGTM 👍

@odersky odersky merged commit 6f04ca7 into scala:master Nov 17, 2016
OlivierBlanvillain pushed a commit to OlivierBlanvillain/dotty that referenced this pull request Dec 8, 2016
OlivierBlanvillain pushed a commit to OlivierBlanvillain/dotty that referenced this pull request Dec 12, 2016
@allanrenucci allanrenucci deleted the fix-isNullable branch December 14, 2017 19:20
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