Skip to content

Commit 15fccde

Browse files
authored
Merge pull request #14805 from ckipp01/illegalStuff
refactor: use existing IllegalVariableInPatternAlternative message
2 parents 7208bd8 + cf135dc commit 15fccde

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ object desugar {
18691869
elems foreach collect
18701870
case Alternative(trees) =>
18711871
for (tree <- trees; (vble, _) <- getVariables(tree, shouldAddGiven))
1872-
report.error(IllegalVariableInPatternAlternative(), vble.srcPos)
1872+
report.error(IllegalVariableInPatternAlternative(vble.symbol.name), vble.srcPos)
18731873
case Annotated(arg, _) =>
18741874
collect(arg)
18751875
case InterpolatedString(_, segments) =>

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,9 @@ import transform.SymUtils._
738738
}
739739
}
740740

741-
class IllegalVariableInPatternAlternative()(using Context)
741+
class IllegalVariableInPatternAlternative(name: Name)(using Context)
742742
extends SyntaxMsg(IllegalVariableInPatternAlternativeID) {
743-
def msg = "Variables are not allowed in alternative patterns"
743+
def msg = em"Illegal variable $name in pattern alternative"
744744
def explain = {
745745
val varInAlternative =
746746
"""|def g(pair: (Int,Int)): Int = pair match {

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
21152115
val sym = newPatternBoundSymbol(name, symTp, tree.span)
21162116
if (pt == defn.ImplicitScrutineeTypeRef || tree.mods.is(Given)) sym.setFlag(Given)
21172117
if (ctx.mode.is(Mode.InPatternAlternative))
2118-
report.error(i"Illegal variable ${sym.name} in pattern alternative", tree.srcPos)
2118+
report.error(IllegalVariableInPatternAlternative(sym.name), tree.srcPos)
21192119
assignType(cpy.Bind(tree)(name, body1), sym)
21202120
}
21212121
}

0 commit comments

Comments
 (0)