Skip to content

Upper bound info of wildcard type argument lost #14271

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
KacperFKorban opened this issue Jan 14, 2022 · 1 comment · Fixed by #17509
Closed

Upper bound info of wildcard type argument lost #14271

KacperFKorban opened this issue Jan 14, 2022 · 1 comment · Fixed by #17509

Comments

@KacperFKorban
Copy link
Member

Compiler version

3.0.0, 3.1.0, 3.1.2-RC1-bin-20220111-1292246-NIGHTLY

Minimized code

class Bound[T]
class MyClass[T <: Bound[T]]

class Container[V] {
  def doSth(): V = ???
}

def bug() = {
  val m = new Container[MyClass[_]]
  if (true) {
    m.doSth()
  }
}

Output

[error] ./main.scala:11:14: Type argument ?1.CAP does not conform to upper bound Bound[?1.CAP] in inferred type MyClass[?1.CAP]
[error]     m.doSth()
[error]

Expectation

Compile correctly.

After small changes to make the code compatible with Scala 2 (adding an outer object for def), it compiles correctly in 2.13.8.

class Bound[T]
class MyClass[T <: Bound[T]]

class Container[V] {
  def doSth(): V = ???
}

object Bug {
  def bug() = {
    val m = new Container[MyClass[_]]
    if (true) {
      m.doSth()
    }
  }
}

Workaround

The workaround for this is to add a pure expression after m.doSth(). The following code compiles:

class Bound[T]
class MyClass[T <: Bound[T]]

class Container[V] {
  def doSth(): V = ???
}

def bug() = {
  val m = new Container[MyClass[_]]
  if (true) {
    m.doSth()
    ()
  }
}
ckipp01 added a commit to ckipp01/dotty that referenced this issue May 15, 2023
nicolasstucki added a commit that referenced this issue May 16, 2023
@dwijnand
Copy link
Member

Curious what fixed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants