@@ -973,66 +973,63 @@ extends SyntaxMsg(IllegalStartOfSimplePatternID) {
973973 def msg (using Context ) = " pattern expected"
974974 def explain (using Context ) = {
975975 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
980978 val constructorPatternsCode =
981979 """ case class Person(name: String, age: Int)
982980 |
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
992986 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
997990 i """ |Simple patterns can be divided into several groups:
998- |- Variable Patterns: ${hl(" case x => ..." )}.
991+ |- Variable Patterns: ${hl(" case x => ..." )} or ${hl( " case _ => ... " )}
999992 | It matches any value, and binds the variable name to that value.
1000993 | A special case is the wild-card pattern _ which is treated as if it was a fresh
1001994 | variable on each occurrence.
1002995 |
1003- |- Typed Patterns: ${hl(" case x: Int => ..." )} or ${hl(" case _: Int => ..." )}.
996+ |- Typed Patterns: ${hl(" case x: Int => ..." )} or ${hl(" case _: Int => ..." )}
1004997 | This pattern matches any value matched by the specified type; it binds the variable
1005998 | name to that value.
1006999 |
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' => ..." )}
10081005 | This type of pattern matches any value that is equal to the specified literal.
10091006 |
10101007 |- Stable Identifier Patterns:
10111008 |
1012- | $sipCode
1009+ | ${hl( sipCode)}
10131010 |
10141011 | the match succeeds only if the x argument and the y argument of f are equal.
10151012 |
10161013 |- Constructor Patterns:
10171014 |
1018- | $constructorPatternsCode
1015+ | ${hl( constructorPatternsCode)}
10191016 |
10201017 | The pattern binds all object's fields to the variable names (name and age, in this
10211018 | case).
10221019 |
10231020 |- Tuple Patterns:
10241021 |
1025- | $tupplePatternsCode
1022+ | ${hl(tuplePatternsCode)}
10261023 |
10271024 | Calling:
10281025 |
1029- | ${hl(""" swap(("Luftballons", 99)""" )}
1026+ | ${hl(""" swap(("Luftballons", 99)) """ )}
10301027 |
10311028 | would give ${hl(""" (99, "Luftballons")""" )} as a result.
10321029 |
10331030 |- Pattern Sequences:
10341031 |
1035- | $patternSequencesCode
1032+ | ${hl( patternSequencesCode)}
10361033 |
10371034 | Calling:
10381035 |
0 commit comments