Skip to content

Valid pattern match on this.type rejected as neither super nor subtype #5787

Closed
@abgruszecki

Description

@abgruszecki
enum Expr[A] {
  case BoolLit(b: Boolean) extends Expr[Boolean]
  def eval: A = {
    def go[AA](self: this.type & Expr[AA]): A = self match {
      case BoolLit(b) => b
    }
    go(this)
  }
}

Error message:

  |Pattern type Expr.BoolLit[A] is neither a subtype nor a supertype of selector type Expr'[A'](Expr'.this) & Expr'[AA]
  |
  |where:    A     is a type variable
  |          A'    is a type in class Expr
  |          Expr  is a object
  |          Expr' is a class

Motivation for why someone would want to do this: it could allow "indirectly" constraining type parameters of enclosing class.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions