Skip to content

Unable to define an extractor that refines a type with a reference to a self-type member #10674

@julienrf

Description

@julienrf

Consider the following program:

trait Foo { self =>

  val bar: Bar

  // Note that the type refinement (in the result) uses `self.bar.type`
  def unapply(other: Foo): Option[Foo { val bar: self.bar.type }] = ???

}

trait Bar

class Usage(foo1: Foo, foo2: Foo) {

  foo1 match {
    case foo2(_) => ()
  }

}

It produces the following error:

[error] an unapply result must have a member `def isEmpty: Boolean
[error]     case foo2(_) => ()
[error]          ^
[error] one error found

If I use other.bar.type instead of self.bar.type, the code compiles, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions