Skip to content

Commit

Permalink
Deprecate infix named args
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Sep 7, 2024
1 parent 614170f commit 4d25ea3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1104,9 +1104,14 @@ object Parsers {
if (prec < opPrec || leftAssoc && prec == opPrec) {
opStack = opStack.tail
recur {
atSpan(opInfo.operator.span union opInfo.operand.span union top.span) {
atSpan(opInfo.operator.span union opInfo.operand.span union top.span):
def deprecateInfixNamedArg(t: Tree): Unit = t match
case Tuple(ts) => ts.foreach(deprecateInfixNamedArg)
case Parens(t) => deprecateInfixNamedArg(t)
case t: Assign => report.deprecationWarning(em"named argument is deprecated for infix syntax", t.srcPos)
case _ =>
deprecateInfixNamedArg(top)
InfixOp(opInfo.operand, opInfo.operator, top)
}
}
}
else top
Expand Down
7 changes: 7 additions & 0 deletions tests/warn/infix-named-args.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -deprecation

class C {
def f = 42 + (x = 1) // warn
def multi(x: Int, y: Int): Int = x + y
def g = new C() `multi` (x = 42, y = 27) // warn // warn
}

0 comments on commit 4d25ea3

Please sign in to comment.