|
6 | 6 | | Explanation (enabled by `-explain`)
|
7 | 7 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
8 | 8 | | An application s(...) in a pattern can refer to an extractor
|
9 |
| - | which defines an unapply or unapplySeq method. Case classes and enum cases |
10 |
| - | implicitly define extractors with the name of the class or enum case. |
| 9 | + | which defines an unapply or unapplySeq method. Example: |
| 10 | + | |
| 11 | + | object split: |
| 12 | + | def unapply(x: String) = |
| 13 | + | val (leading, trailing) = x.splitAt(x.length / 2) |
| 14 | + | Some((leading, trailing)) |
| 15 | + | |
| 16 | + | val split(fst, snd) = "HiHo" |
| 17 | + | |
| 18 | + | The extractor pattern `split(fst, snd)` defines `fst` as the first half "Hi" and |
| 19 | + | `snd` as the second half "Ho" of the right hand side "HiHo". Case classes and |
| 20 | + | enum cases implicitly define extractors with the name of the class or enum case. |
11 | 21 | | Here, no extractor named s was found, so the pattern could not be typed.
|
12 | 22 | ---------------------------------------------------------------------------------------------------------------------
|
13 | 23 | -- [E189] Not Found Error: tests/neg/i18684.scala:5:6 ------------------------------------------------------------------
|
|
18 | 28 | | Explanation (enabled by `-explain`)
|
19 | 29 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
20 | 30 | | An application i(...) in a pattern can refer to an extractor
|
21 |
| - | which defines an unapply or unapplySeq method. Case classes and enum cases |
22 |
| - | implicitly define extractors with the name of the class or enum case. |
| 31 | + | which defines an unapply or unapplySeq method. Example: |
| 32 | + | |
| 33 | + | object split: |
| 34 | + | def unapply(x: String) = |
| 35 | + | val (leading, trailing) = x.splitAt(x.length / 2) |
| 36 | + | Some((leading, trailing)) |
| 37 | + | |
| 38 | + | val split(fst, snd) = "HiHo" |
| 39 | + | |
| 40 | + | The extractor pattern `split(fst, snd)` defines `fst` as the first half "Hi" and |
| 41 | + | `snd` as the second half "Ho" of the right hand side "HiHo". Case classes and |
| 42 | + | enum cases implicitly define extractors with the name of the class or enum case. |
23 | 43 | | Here, no extractor named i was found, so the pattern could not be typed.
|
24 | 44 | ---------------------------------------------------------------------------------------------------------------------
|
25 | 45 | -- [E189] Not Found Error: tests/neg/i18684.scala:10:8 -----------------------------------------------------------------
|
|
30 | 50 | | Explanation (enabled by `-explain`)
|
31 | 51 | |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
32 | 52 | | An application foo(...) in a pattern can refer to an extractor
|
33 |
| - | which defines an unapply or unapplySeq method. Case classes and enum cases |
34 |
| - | implicitly define extractors with the name of the class or enum case. |
| 53 | + | which defines an unapply or unapplySeq method. Example: |
| 54 | + | |
| 55 | + | object split: |
| 56 | + | def unapply(x: String) = |
| 57 | + | val (leading, trailing) = x.splitAt(x.length / 2) |
| 58 | + | Some((leading, trailing)) |
| 59 | + | |
| 60 | + | val split(fst, snd) = "HiHo" |
| 61 | + | |
| 62 | + | The extractor pattern `split(fst, snd)` defines `fst` as the first half "Hi" and |
| 63 | + | `snd` as the second half "Ho" of the right hand side "HiHo". Case classes and |
| 64 | + | enum cases implicitly define extractors with the name of the class or enum case. |
35 | 65 | | Here, no extractor named foo was found, so the pattern could not be typed.
|
36 | 66 | --------------------------------------------------------------------------------------------------------------------
|
37 | 67 | -- [E127] Pattern Match Error: tests/neg/i18684.scala:12:6 -------------------------------------------------------------
|
|
0 commit comments