Skip to content

Unused type parameter of kind * -> * doesn't allow proving subtyping of other type parameters #15677

Closed
@KacperFKorban

Description

@KacperFKorban

Compiler version

Compiles correctly for 3.0.0, 3.0.1
Gives an error for 3.0.2
Compiles correctly for 3.1.0, 3.1.1
Gives an error for 3.1.2, 3.1.3, 3.2.0-RC1, 3.2.1-RC1-bin-20220712-7e20b81-NIGHTLY

Minimized code

class Interval[E, D[_]]
class BoundedAbove[E, D[_]] extends Interval[E, D] {
  def upper: Upper[E] = ???
}
class Upper[E]

def reference: Interval[Int, Option] = ???

def bound: Upper[Int] =
  reference match {
    case int: BoundedAbove[_, _] => int.upper
    case _ => null
  }

Output

[error] ./main.scala:13:37: Found:    Upper[_]
[error] Required: Upper[Int]
[error]     case int: BoundedAbove[_, _] => int.upper
[error]                                     ^^^^^^^^^

Expectation

Compile correctly.
It should be possible to prove that int.upper.type <:< Upper[Int]

More information

Interestingly, the following piece of code compiles correctly. (If we change the kind of D to * or remove it altogether)

class Interval[E, D]
class BoundedAbove[E, D] extends Interval[E, D] {
  def upper: Upper[E] = ???
}
class Upper[E]

def reference: Interval[Int, String] = ???

def bound: Upper[Int] =
  reference match {
    case int: BoundedAbove[_, _] => int.upper
    case _ => null
  }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions