Skip to content

refactor: use existing IllegalVariableInPatternAlternative message #14805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down