Skip to content

Fix a code example in the doc pattern-matching.md #15208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions docs/_docs/reference/changed-features/pattern-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: "Option-less pattern matching"
movedTo: https://docs.scala-lang.org/scala3/reference/changed-features/pattern-matching.html
---

The implementation of pattern matching in Scala 3 was greatly simplified compared to Scala 2. From a user perspective, this means that Scala 3 generated patterns are a *lot* easier to debug, as variables all show up in debug modes and positions are correctly preserved.
The implementation of pattern matching in Scala 3 was greatly simplified compared to Scala 2. From a user perspective, this means that Scala 3 generated patterns are a _lot_ easier to debug, as variables all show up in debug modes and positions are correctly preserved.

Scala 3 supports a superset of Scala 2 [extractors](https://www.scala-lang.org/files/archive/spec/2.13/08-pattern-matching.html#extractor-patterns).

Expand Down Expand Up @@ -180,7 +180,6 @@ object ProdEmpty:
case _ => ()
```


## Sequence Match

- `U <: X`, `T2` and `T3` conform to `T1`
Expand Down Expand Up @@ -221,18 +220,18 @@ object CharList:
the type of the remaining patterns are determined as in Seq Pattern.

```Scala
class Foo(val name: String, val children: Int *)
class Foo(val name: String, val children: Int*)
object Foo:
def unapplySeq(f: Foo): Option[(String, Seq[Int])] =
Some((f.name, f.children))

def foo(f: Foo) = f match
case Foo(name, ns : _*) =>
case Foo(name, x, y, ns : _*) =>
case Foo(name, x, y, ns*) => ">= two children."
case Foo(name, ns*) => => "< two children."
```

There are plans for further simplification, in particular to factor out *product
match* and *name-based match* into a single type of extractor.
There are plans for further simplification, in particular to factor out _product match_
and _name-based match_ into a single type of extractor.

## Type testing

Expand Down