Skip to content

Whether support *: as a valid return type of unapply in extractors #11008

Closed
@liufengyun

Description

@liufengyun

The following code is currently not supported by the compiler:

object U:
  def unapply(s:String): String *: EmptyTuple = Tuple1(s)

"hello" match
case U(x) => 

If we change String *: EmptyTuple to Tuple1[String], it will compile without problem.

The problem is that according to the current specification, String *: EmptyTuple does not qualify as a product pattern, as it does not contain selectors _1, ..., _N.

The question is:

  • Whether we should support String *: EmptyTuple?
  • How to change the specification?

One particular concern is that making *: a special case seems to cancel the past efforts to make pattern match more generic.

Related PR: #10987

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions