@@ -973,66 +973,63 @@ extends SyntaxMsg(IllegalStartOfSimplePatternID) {
973
973
def msg (using Context ) = " pattern expected"
974
974
def explain (using Context ) = {
975
975
val sipCode =
976
- """ def f(x: Int, y: Int) = x match {
977
- | case `y` => ...
978
- |}
979
- """
976
+ """ def f(x: Int, y: Int) = x match
977
+ | case `y` => ...""" .stripMargin
980
978
val constructorPatternsCode =
981
979
""" case class Person(name: String, age: Int)
982
980
|
983
- |def test(p: Person) = p match {
984
- | case Person(name, age) => ...
985
- |}
986
- """
987
- val tupplePatternsCode =
988
- """ def swap(tuple: (String, Int)): (Int, String) = tuple match {
989
- | case (text, number) => (number, text)
990
- |}
991
- """
981
+ | def test(p: Person) = p match
982
+ | case Person(name, age) => ...""" .stripMargin
983
+ val tuplePatternsCode =
984
+ """ def swap(tuple: (String, Int)): (Int, String) = tuple match
985
+ | case (text, number) => (number, text)""" .stripMargin
992
986
val patternSequencesCode =
993
- """ def getSecondValue(list: List[Int]): Int = list match {
994
- | case List(_, second, x:_*) => second
995
- | case _ => 0
996
- |}"""
987
+ """ def getSecondValue(list: List[Int]): Int = list match
988
+ | case List(_, second, x*) => second
989
+ | case _ => 0""" .stripMargin
997
990
i """ |Simple patterns can be divided into several groups:
998
- |- Variable Patterns: ${hl(" case x => ..." )}.
991
+ |- Variable Patterns: ${hl(" case x => ..." )} or ${hl( " case _ => ... " )}
999
992
| It matches any value, and binds the variable name to that value.
1000
993
| A special case is the wild-card pattern _ which is treated as if it was a fresh
1001
994
| variable on each occurrence.
1002
995
|
1003
- |- Typed Patterns: ${hl(" case x: Int => ..." )} or ${hl(" case _: Int => ..." )}.
996
+ |- Typed Patterns: ${hl(" case x: Int => ..." )} or ${hl(" case _: Int => ..." )}
1004
997
| This pattern matches any value matched by the specified type; it binds the variable
1005
998
| name to that value.
1006
999
|
1007
- |- Literal Patterns: ${hl(" case 123 => ..." )} or ${hl(" case 'A' => ..." )}.
1000
+ |- Given Patterns: ${hl(" case given ExecutionContext => ..." )}
1001
+ | This pattern matches any value matched by the specified type; it binds a ${hl(" given" )}
1002
+ | instance with the same type to that value.
1003
+ |
1004
+ |- Literal Patterns: ${hl(" case 123 => ..." )} or ${hl(" case 'A' => ..." )}
1008
1005
| This type of pattern matches any value that is equal to the specified literal.
1009
1006
|
1010
1007
|- Stable Identifier Patterns:
1011
1008
|
1012
- | $sipCode
1009
+ | ${hl( sipCode)}
1013
1010
|
1014
1011
| the match succeeds only if the x argument and the y argument of f are equal.
1015
1012
|
1016
1013
|- Constructor Patterns:
1017
1014
|
1018
- | $constructorPatternsCode
1015
+ | ${hl( constructorPatternsCode)}
1019
1016
|
1020
1017
| The pattern binds all object's fields to the variable names (name and age, in this
1021
1018
| case).
1022
1019
|
1023
1020
|- Tuple Patterns:
1024
1021
|
1025
- | $tupplePatternsCode
1022
+ | ${hl(tuplePatternsCode)}
1026
1023
|
1027
1024
| Calling:
1028
1025
|
1029
- | ${hl(""" swap(("Luftballons", 99)""" )}
1026
+ | ${hl(""" swap(("Luftballons", 99)) """ )}
1030
1027
|
1031
1028
| would give ${hl(""" (99, "Luftballons")""" )} as a result.
1032
1029
|
1033
1030
|- Pattern Sequences:
1034
1031
|
1035
- | $patternSequencesCode
1032
+ | ${hl( patternSequencesCode)}
1036
1033
|
1037
1034
| Calling:
1038
1035
|
0 commit comments