Skip to content

Typer#escapingRefs: don't let the types of lower bounds escape #749

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
Oct 14, 2016

Conversation

smarter
Copy link
Member

@smarter smarter commented Aug 5, 2015

In 0efa171 I changed the definition of NamedPartsAccumulator to exclude lower bounds as this is required for the implicit search, but NamedPartsAccumulator is also used by Typer#escapingRefs so in the following code:

class Foo[T]
val z = {
  class C

  ??? : Foo[_ >: C]
}

the type of z was inferred to be Foo[_ >: C] instead of Foo.

To avoid this, NamedPartsAccumulator will only exclude lower bounds if the parameter excludeLowerBounds is explicitely set to true.

No test because there is no way to detect that a type has escaped, this might be something that could be added to TreeChecker.


This PR also removes dead code from Typer#escapingRefs.


Review by @odersky .

@smarter smarter force-pushed the fix/escaping-refs-2 branch from 395383e to 8ed77f4 Compare August 5, 2015 20:31
@odersky
Copy link
Contributor

odersky commented Aug 5, 2015

In fact, given the observed failure of implicits, I would revert completely. Implicits should be searched in lower as well as upper bounds. So NamedParts can be reverted to use both bounds.

@smarter
Copy link
Member Author

smarter commented Aug 5, 2015

@odersky : That's one way to do it, but I think this is unnecessary, the failures we get for implicits are due to issues in the inference of type parameters: #739

For example, in #553 we have the type CC? >: ([+HK$0] => scala.collection.immutable.List[HK$0])[HK$0 =+ (T? >: Int)] <: ([HK$0] => <: scala.collection.TraversableOnce[HK$0]) and implicit search fail, but if #739 was fixed then CC would be instantiated to List like it is in Scala2 and the implicit search would succeed.

I have a prototype that fixes the inference of type parameters, but it uncovered some issues with Typer#ensureNoLocalRefs which I need to fix first, including the issue fixed by this pull request.

smarter added 2 commits March 24, 2016 16:22
In 0efa171 I changed the definition of
NamedPartsAccumulator to exclude lower bounds as this is required for the
implicit search, but NamedPartsAccumulator is also used by
Typer#escapingRefs so in the following code:
  class Foo[T]
  val z = {
    class C

    ??? : Foo[_ >: C]
  }
the type of z was inferred to be Foo[_ >: C] instead of Foo.

To avoid this, NamedPartsAccumulator will only exclude lower bounds if
the parameter excludeLowerBounds is explicitely set to true.

No test because there is no way to detect that a type has escaped, this
might be something that could be added to TreeChecker.
@smarter smarter force-pushed the fix/escaping-refs-2 branch from 3c92ecd to f13fe71 Compare March 24, 2016 15:22
@smarter
Copy link
Member Author

smarter commented Mar 24, 2016

@odersky : could you take another look at this? I just rebased it because it turns out I need this for the sbt phase.

@odersky
Copy link
Contributor

odersky commented Oct 14, 2016

LGTM

@odersky odersky merged commit 148551a into scala:master Oct 14, 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