Skip to content

Commit 9c0bca3

Browse files
oderskyWojciechMazur
authored andcommitted
Turn on -explain in test
[Cherry-picked 8df6b48]
1 parent 6440434 commit 9c0bca3

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

tests/neg/i18684.check

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,51 @@
22
3 | val s(): String = "hello, world" // error
33
| ^
44
| no pattern match extractor named s was found
5-
|
6-
| longer explanation available when compiling with `-explain`
5+
|---------------------------------------------------------------------------------------------------------------------
6+
| Explanation (enabled by `-explain`)
7+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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.
11+
| Here, no extractor named s was found, so the pattern could not be typed.
12+
---------------------------------------------------------------------------------------------------------------------
713
-- [E189] Not Found Error: tests/neg/i18684.scala:5:6 ------------------------------------------------------------------
814
5 | val i() = 22 // error
915
| ^
1016
| no pattern match extractor named i was found
11-
|
12-
| longer explanation available when compiling with `-explain`
17+
|---------------------------------------------------------------------------------------------------------------------
18+
| Explanation (enabled by `-explain`)
19+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20+
| 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.
23+
| Here, no extractor named i was found, so the pattern could not be typed.
24+
---------------------------------------------------------------------------------------------------------------------
1325
-- [E189] Not Found Error: tests/neg/i18684.scala:10:8 -----------------------------------------------------------------
1426
10 | val foo() = "33" // error
1527
| ^^^
1628
| no pattern match extractor named foo was found
17-
|
18-
| longer explanation available when compiling with `-explain`
29+
|--------------------------------------------------------------------------------------------------------------------
30+
| Explanation (enabled by `-explain`)
31+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32+
| 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.
35+
| Here, no extractor named foo was found, so the pattern could not be typed.
36+
--------------------------------------------------------------------------------------------------------------------
1937
-- [E127] Pattern Match Error: tests/neg/i18684.scala:12:6 -------------------------------------------------------------
2038
12 | val inner(x) = 3 // error
2139
| ^^^^^
2240
| Test.inner cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method
41+
|--------------------------------------------------------------------------------------------------------------------
42+
| Explanation (enabled by `-explain`)
43+
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44+
| An unapply method should be defined in an object as follow:
45+
| - If it is just a test, return a Boolean. For example case even()
46+
| - If it returns a single sub-value of type T, return an Option[T]
47+
| - If it returns several sub-values T1,...,Tn, group them in an optional tuple Option[(T1,...,Tn)]
2348
|
24-
| longer explanation available when compiling with `-explain`
49+
| Sometimes, the number of sub-values isn't fixed and we would like to return a sequence.
50+
| For this reason, you can also define patterns through unapplySeq which returns Option[Seq[T]].
51+
| This mechanism is used for instance in pattern case List(x1, ..., xn)
52+
--------------------------------------------------------------------------------------------------------------------

tests/neg/i18684.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using option -explain
1+
//> using options -explain
22
object Test:
33
val s(): String = "hello, world" // error
44

0 commit comments

Comments
 (0)