Skip to content

existential type bound check fails in value class #11562

Open
@kailuowang

Description

@kailuowang

Happens in 2.12 and 2.13 (didn't check in 2.11)

object Test {
  trait M[A] {
    def d[AA <: A](a: AA): Unit
  }
  
  class MWorks[A](val a: A) {
    def d(M: M[_ >: A]): Unit = M.d(a)
  }

  class MFails[A](val a: A) extends AnyVal {
    def d(M: M[_ >: A]): Unit = M.d(a)  //fails compilation in value class
  }
}

The same simple code in a value class causes compilation error:

type arguments [A] do not conform to method d's type parameter bounds [AA <: _$2]

Scastie https://scastie.scala-lang.org/Uyhm8ZzAQkqJTiNP02zXmw

To be clear, the bound AA <: A in trait M is clear redundant, but it's needed in the real use case where the parameter is of slightly more complex type.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions