File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -1051,7 +1051,7 @@ object desugar {
1051
1051
elems foreach collect
1052
1052
case Alternative (trees) =>
1053
1053
for (tree <- trees; (vble, _) <- getVariables(tree))
1054
- ctx.error(" illegal variable in pattern alternative " , vble.pos)
1054
+ ctx.error(IllegalVariableInPatternAlternative () , vble.pos)
1055
1055
case Annotated (arg, _) =>
1056
1056
collect(arg)
1057
1057
case InterpolatedString (_, segments) =>
Original file line number Diff line number Diff line change @@ -640,4 +640,30 @@ object messages {
640
640
| If you specify one type parameter then you need to specify every type parameter. """ .stripMargin
641
641
}
642
642
}
643
+
644
+ case class IllegalVariableInPatternAlternative ()(implicit ctx : Context )
645
+ extends Message (19 ) {
646
+ val kind = " Syntax"
647
+
648
+ val msg = hl """ |Variables are not allowed in alternative patterns """
649
+
650
+ val explanation = {
651
+ hl """ |Variables are not allowed within alternate pattern matches.
652
+ |You can workaround this issue by adding additional cases for each alternative.
653
+ |For example, the illegal function:
654
+ | def g(pair: (Int,Int)): Int = pair match {
655
+ | case (1, n) | (n, 1) => n
656
+ | case _ => 0
657
+ | }
658
+ |
659
+ | could be implemented by moving each alternative into a separate case:
660
+ | def g(pair: (Int,Int)): Int = pair match {
661
+ | case (1, n) => n
662
+ | case (n, 1) => n
663
+ | case _ => 0
664
+ | }
665
+ |
666
+ | """ .stripMargin
667
+ }
668
+ }
643
669
}
You can’t perform that action at this time.
0 commit comments