Skip to content

Fix #6146: Fix bounds check involving wildcards and f-bounds #6147

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 5 commits into from
Mar 25, 2019

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 22, 2019

Don't map arguments to their upper bounds before doing the bound check.
There was a comment justifiying that by talking about non
fully-determined arguments, but this check is done in PostTyper when all
types should already be fully-determined. Given that this comment was
written in 2014 I'm assuming it's no longer relevant.

Don't map arguments to their upper bounds before doing the bound check.
There was a comment justifiying that by talking about non
fully-determined arguments, but this check is done in PostTyper when all
types should already be fully-determined. Given that this comment was
written in 2014 I'm assuming it's no longer relevant.
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 was quick! I think it needs to be tweaked though. "Undetermined argument" in the comment means wildcard, which can well happen in PostTyper.

What we need here looks like another (simple) instance of capture conversion. I.e. replace any TypeBounds argument L..U by a skolem $n.CAP, where $n is of type TypeBox[L, U].

@odersky odersky assigned smarter and unassigned odersky Mar 22, 2019
@smarter
Copy link
Member Author

smarter commented Mar 22, 2019

Hmm, I'm having trouble coming up with an example where this would make a difference and our tests are green, can you take over this PR or come up with an example ?

@smarter
Copy link
Member Author

smarter commented Mar 22, 2019

What we need here looks like another (simple) instance of capture conversion. I.e. replace any TypeBounds argument L..U by a skolem $n.CAP, where $n is of type TypeBox[L, U].

Isn't the existing wildcard capture logic in subtyping going to do that for us ?

@odersky odersky assigned odersky and unassigned smarter Mar 22, 2019
Use substApprox for F-bounds instantiation if there are wildcards.

This is the simplest checking algorithm I could find that is not obviously wrong and
that accepts i6146.scala. I can't prove it's correct, though.
@odersky odersky assigned smarter and unassigned odersky Mar 23, 2019
@odersky
Copy link
Contributor

odersky commented Mar 23, 2019

In fact, thinking more about it the last commit 48f7ed6 still feels wrong. substApprox is no magic bullet. It does not claim to be a meaning preserving substitution in the presence of wildcards. All it guarantees is that the result is not ill-formed.

The only way to deal with wildcards consistently is by skolemizing them in one way or another.

odersky added 3 commits March 23, 2019 18:25
Revised scheme for checking applied types containing wildcards in F-bounds.
With skolemization we fail compiling the standard lib with:
```
[E057] Type Mismatch Error: /Users/odersky/workspace/dotty/tests/scala2-library/src/library/scala/collection/generic/ParMapFactory.scala:28:76
28 |abstract class ParMapFactory[CC[X, Y] <: ParMap[X, Y] with ParMapLike[X, Y, CC[X, Y], _]]
   |                                                                            ^
   |Type argument CC[X, Y] does not conform to upper bound scala.collection.parallel.ParMapLike[X, Y, LazyRef(CC[X, Y]),
   |  collection.parallel.ParMapLike[X, Y, CC[X, Y], _]#Sequential
   |] & scala.collection.parallel.ParMap[X, Y]
--
```
I have no idea whether this bound is correct or not, and am not inclined to find out. But we clearly have to support it
anyway under Scala-2 mode.
@odersky
Copy link
Contributor

odersky commented Mar 23, 2019

I think this should be a migration warning.

It's hard to identify the point where we should issue such a warning. Also there's no good guideline we could give.

@odersky odersky merged commit 8ecc927 into scala:master Mar 25, 2019
@allanrenucci allanrenucci deleted the fix-fbounds-wildcards branch March 25, 2019 17:27
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.

2 participants