Skip to content

TypeAssigner#avoid assumes that type variables are always instantiated to their lower bounds #782

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
smarter opened this issue Sep 6, 2015 · 0 comments
Assignees

Comments

@smarter
Copy link
Member

smarter commented Sep 6, 2015

This is another case where avoid is wrong (see #750, #741, #711, and I can probably come up with more contrived examples too):

class M

class A extends M
class B extends M

class Foo[T](x: T) {
  def foo[S >: T](other: S): Foo[S] = ???
}

object C {
  def xy() = {
    val x: Foo[A] = new Foo(new A)
    x.foo(new B)
  }
}

This compiles but fails with -Ycheck:all because the block inside the method xy() is assigned the type Foo[A | B] but the expression x.foo(new B) is assigned the type Foo[M]:

final module class C$() extends Object() { this: C.type => 
  def xy(): Foo[A | B] = {
    val x: Foo[A] = new Foo[A](new A())
    x.foo[M](new B())
  }
}

The issue is that in TypeAssigner#avoid, when we see the type parameter S >: x.T | B we replace it by A | B (see TypeAssigner.scala#L90-L93), but in TypeVar#interpolate we instantiate S to M because its upper bound is not a union-type (see Types.scala#L2457-L2461).

@odersky : in #750 you said "Maybe we should instantiate those type variables that have escaping refs as bounds", this would also solve this issue. Note that this issue is currently blocking me from experimenting with improving type inference by removing/reducing the use of interpolateUndetVars.

@smarter smarter self-assigned this Nov 18, 2015
allanrenucci added a commit that referenced this issue Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant