Skip to content

compiler infers non-wildcard existential type for case-module-unapply #6541

@scabug

Description

@scabug
trait A
trait B[T]
case class C(a: A, b: B[_])

generates the following unapply method

case <synthetic> def unapply(x$0: C): Option[(A, B[_$1])] forSome { type _$1 } =
  if (x$0.==(null))
    scala.this.None
  else
    Some.apply[(A, B[_$1])](Tuple2.apply[A, B[_$1]](x$0.a, x$0.b));

The problematic return type

Option[(A, B[_$1])] forSome { type _$1 }

is not generated together with the unapply method, but inferred by the compiler (when the generated method is type-checked). Martin suggests to provide the return type explicitly.

Also, in the body of the unapply, what is the type name _$1 is bound to?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions