Skip to content

Rewrite a.type & B to Nothing #1055

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

Closed
wants to merge 1 commit into from
Closed

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 4, 2016

provided !(a.type <: B). Fixes #864, which turned out
to be a long sequence of comparisons between intersections
of singleton types.

Review by @smarter.

provided !(a.type <: B). Fixes scala#864, which turned out
to be a long sequence of comparisons between intersections
of singleton types.

Review by @smarter.
@@ -1047,7 +1047,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
else hkCombine(tp1, tp2, tparams1, tparams2, op)
}

/** Try to distribute `&` inside type, detect and handle conflicts */
/** Try to distribute `&` inside type, detect and handle conflicts
* pre: !(tp1 <: tp2) && !(tp2 <:< tp2) -- these cases were handled before
Copy link
Member

Choose a reason for hiding this comment

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

!(tp2 <:< tp2) did you mean !(tp2 <:< tp1) ?

Copy link
Member

Choose a reason for hiding this comment

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

(Also we usually write @pre)

@DarkDimius
Copy link
Contributor

Should we also add such rule:
If tp1 is class and tp2 is class and !((tp1 <:< tp2) || (tp2 <:< tp1)) then tp1& tp2 == Nothing

@odersky
Copy link
Contributor Author

odersky commented Feb 4, 2016

@DarkDimius That would only work for unparameterized classes, and right now their glb would be Null. But yes, we could try that.

@smarter
Copy link
Member

smarter commented Feb 4, 2016

This seems to be equivalent to what you tried before in #843 and it fails in the same way, afterwards you changed your patch to only apply to ConstantType and added a comment that says:

// Make use of the fact that the intersection of two constant types
// types which are not subtypes of each other is known to be empty.
// Note: The same does not apply to singleton types in general.
// E.g. we could have a pattern match against `x.type & y.type`
// which might succeed if `x` and `y` happen to be the same ref
// at run time. It would not work to replace that with `Nothing`.
// However, maybe we can still apply the replacement to
// types which are not explicitly written.

@odersky
Copy link
Contributor Author

odersky commented Feb 5, 2016

@smarter Thanks for reminding me. Yes this is the same as #843 and it does not work.
I have a new PR that fixes the problem in a different way: #1058.

@odersky odersky closed this Feb 5, 2016
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