Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SI-5136 correct return type for unapplySeq

  • Loading branch information...
commit 71e45e0707887f83f287c8870324072e70da1248 1 parent aa6e4b3
@adriaanm adriaanm authored
Showing with 7 additions and 15 deletions.
  1. +7 −15 10-pattern-matching.md
View
22 10-pattern-matching.md
@@ -207,10 +207,9 @@ the following applies:
$p_i$ matches the corresponding value $v_i$.
An `unapplySeq` method in an object $x$ matches the pattern
-$x(p_1 , \ldots , p_n)$ if it takes exactly one argument and its
-result type is of the form `Option[$S$]`, where $S$ is a subtype of
-`Seq[$T$]` for some element type $T$.
-This case is further discussed [here](#pattern-seqs).
+$x(q_1 , \ldots , q_m, p_1 , \ldots , p_n)$ if it takes exactly one argument
+and its result type is of the form `Option[($T_1 , \ldots , T_m$, Seq[S])]` (if `m = 0`, the type `Option[Seq[S]]` is also accepted).
+This case is further discussed [below](#pattern-seqs).
###### Example
The `Predef` object contains a definition of an
@@ -240,17 +239,10 @@ val y = x match {
SimplePattern ::= StableId `(' [Patterns `,'] [varid `@'] `_' `*' `)'
```
-A pattern sequence $p_1 , \ldots , p_n$ appears in two
-contexts. First, in a constructor pattern
-$c(q_1 , \ldots , q_m, p_1 , \ldots , p_n$), where $c$ is a case
-class which has $m+1$ primary constructor parameters,
-ending in a [repeated parameter](#repeated-parameters) of type
-$S*$. Second, in an extractor pattern
-$x(p_1 , \ldots , p_n)$ if the extractor object $x$ has an
-`unapplySeq` method with a result type conforming to
-`Seq[$S$]`, but does not have an `unapply` method that
-matches $p_1 , \ldots , p_n$.
-The expected type for the pattern sequence is in each case the type $S$.
+A pattern sequence $p_1 , \ldots , p_n$ appears in two contexts.
+First, in a constructor pattern $c(q_1 , \ldots , q_m, p_1 , \ldots , p_n)$, where $c$ is a case class which has $m+1$ primary constructor parameters, ending in a [repeated parameter](#repeated-parameters) of type $S*$.
+Second, in an extractor pattern $x(q_1 , \ldots , q_m, p_1 , \ldots , p_n)$ if the extractor object $x$ does not have an `unapply` method,
+but it does define an `unapplySeq` method with a result type conforming to `Option[(T_1, ... , T_m, Seq[S])]` (if `m = 0`, the type `Option[Seq[S]]` is also accepted). The expected type for the patterns $p_i$ is $S$.
The last pattern in a pattern sequence may be a _sequence wildcard_ `_*`.
Each element pattern $p_i$ is type-checked with
Please sign in to comment.
Something went wrong with that request. Please try again.