diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 235d3ff0c6b0..9cd30b94d692 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1869,7 +1869,7 @@ object desugar { elems foreach collect case Alternative(trees) => for (tree <- trees; (vble, _) <- getVariables(tree, shouldAddGiven)) - report.error(IllegalVariableInPatternAlternative(), vble.srcPos) + report.error(IllegalVariableInPatternAlternative(vble.symbol.name), vble.srcPos) case Annotated(arg, _) => collect(arg) case InterpolatedString(_, segments) => diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 8e494ab3b40d..f8fec07e9f9f 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -738,9 +738,9 @@ import transform.SymUtils._ } } - class IllegalVariableInPatternAlternative()(using Context) + class IllegalVariableInPatternAlternative(name: Name)(using Context) extends SyntaxMsg(IllegalVariableInPatternAlternativeID) { - def msg = "Variables are not allowed in alternative patterns" + def msg = em"Illegal variable $name in pattern alternative" def explain = { val varInAlternative = """|def g(pair: (Int,Int)): Int = pair match { diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 0f847a9b6232..2ae55032d7ae 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2115,7 +2115,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer val sym = newPatternBoundSymbol(name, symTp, tree.span) if (pt == defn.ImplicitScrutineeTypeRef || tree.mods.is(Given)) sym.setFlag(Given) if (ctx.mode.is(Mode.InPatternAlternative)) - report.error(i"Illegal variable ${sym.name} in pattern alternative", tree.srcPos) + report.error(IllegalVariableInPatternAlternative(sym.name), tree.srcPos) assignType(cpy.Bind(tree)(name, body1), sym) } }