Skip to content

Commit fcefd2b

Browse files
committed
Finish up pattern-matching.md
1 parent 77d4320 commit fcefd2b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

docs/_docs/reference/changed-features/pattern-matching.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ and `S` conforms to one of the following matches:
6363
The former form of `unapply` has higher precedence, and _single match_ has higher
6464
precedence over _name-based match_.
6565

66+
**Note:** the `S` in `R` can be `U`.
67+
6668
A usage of a fixed-arity extractor is irrefutable if one of the following condition holds:
6769

6870
- `U = true`
6971
- the extractor is used as a product match
7072
- `U <: R` and `U <: { def isEmpty: false }`
71-
- `U = Some[T]` (since `Some` has `def isEmpty: Boolean` for compatibility reasons)
73+
- `U = Some[T]`
7274

73-
**Note:** the `S` in `R` can be `U`.
75+
**Note:** The last rule is necessary because, for compatibility reasons, `isEmpty` on `Some` has return type `Boolean` rather than `false`, even though it always returns `false`.
7476

7577
### Boolean Match
7678

@@ -201,7 +203,9 @@ A usage of a variadic extractor is irrefutable if one of the following condition
201203

202204
- the extractor is used directly as a sequence match or product-sequence match
203205
- `U <: R` and `U <: { def isEmpty: false }`
204-
- `U = Some[T]` (since `Some` has `def isEmpty: Boolean` for compatibility reasons)
206+
- `U = Some[T]`
207+
208+
**Note:** The last rule is necessary because, for compatibility reasons, `isEmpty` on `Some` has return type `Boolean` rather than `false`, even though it always returns `false`.
205209

206210
**Note:** Be careful, by the first condition and the note above, it is possible to define an irrefutable extractor with a `def isEmpty: true`.
207211
This is strongly discouraged and, if found in the wild, is almost certainly a bug.

0 commit comments

Comments
 (0)