From 35c81ea86a58d15882ca9911337cfc6d70277bd5 Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Tue, 17 May 2022 23:50:16 +0800 Subject: [PATCH 1/2] Eliminate the '[E030] Match case Unreachable Warning' from a code example - Use the new vararg splices syntax -- the original code example use both the old and new vararg splices syntax - Add return values rather than keep returning `()` implicitly for both cases -- no real world code would be written in this way. --- docs/_docs/reference/changed-features/pattern-matching.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/_docs/reference/changed-features/pattern-matching.md b/docs/_docs/reference/changed-features/pattern-matching.md index b4660f893141..a2b3fdf88bfd 100644 --- a/docs/_docs/reference/changed-features/pattern-matching.md +++ b/docs/_docs/reference/changed-features/pattern-matching.md @@ -221,14 +221,14 @@ 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 From c1f1833ed2e9e514ccdd0536625e6cf8d39060c9 Mon Sep 17 00:00:00 2001 From: "Lan, Jian" Date: Wed, 18 May 2022 00:02:35 +0800 Subject: [PATCH 2/2] Fix the inconsistent Markdown emphasis style issue in pattern-matching.md --- docs/_docs/reference/changed-features/pattern-matching.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/_docs/reference/changed-features/pattern-matching.md b/docs/_docs/reference/changed-features/pattern-matching.md index a2b3fdf88bfd..45931bd0ccdb 100644 --- a/docs/_docs/reference/changed-features/pattern-matching.md +++ b/docs/_docs/reference/changed-features/pattern-matching.md @@ -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). @@ -180,7 +180,6 @@ object ProdEmpty: case _ => () ``` - ## Sequence Match - `U <: X`, `T2` and `T3` conform to `T1` @@ -231,8 +230,8 @@ def foo(f: Foo) = f match 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