diff options
author | Shane Delmore <shane@delmore.io> | 2016-10-24 18:20:29 -0700 |
---|---|---|
committer | Shane Delmore <shane@delmore.io> | 2016-10-25 14:37:00 -0700 |
commit | a2245dde469e29b0a93479a73961511e269b7440 (patch) | |
tree | 8a17ff1e9bb34d43bf6e2a04fcb54279c3c2c3df /src/dotty | |
parent | 63f1a3c5d0149d173eb8f65405b5983591752229 (diff) | |
download | dotty-a2245dde469e29b0a93479a73961511e269b7440.tar.gz dotty-a2245dde469e29b0a93479a73961511e269b7440.tar.bz2 dotty-a2245dde469e29b0a93479a73961511e269b7440.zip |
Update IllegalVariableInPatternAlternative error message
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 8b8e0b318..639dac930 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -1051,7 +1051,7 @@ object desugar { elems foreach collect case Alternative(trees) => for (tree <- trees; (vble, _) <- getVariables(tree)) - ctx.error("illegal variable in pattern alternative", vble.pos) + ctx.error(IllegalVariableInPatternAlternative(), vble.pos) case Annotated(arg, _) => collect(arg) case InterpolatedString(_, segments) => diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 57d96224a..7e897f081 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -640,4 +640,30 @@ object messages { | If you specify one type parameter then you need to specify every type parameter.""".stripMargin } } + + case class IllegalVariableInPatternAlternative()(implicit ctx: Context) + extends Message(19) { + val kind = "Syntax" + + val msg = hl"""|Variables are not allowed in alternative patterns""" + + val explanation = { + hl"""|Variables are not allowed within alternate pattern matches. + |You can workaround this issue by adding additional cases for each alternative. + |For example, the illegal function: + | def g(pair: (Int,Int)): Int = pair match { + | case (1, n) | (n, 1) => n + | case _ => 0 + | } + | + | could be implemented by moving each alternative into a separate case: + | def g(pair: (Int,Int)): Int = pair match { + | case (1, n) => n + | case (n, 1) => n + | case _ => 0 + | } + | + |""".stripMargin + } + } } |