Skip to content

Commit 82aab28

Browse files
committed
Deprecate infix named args
1 parent 276d0a3 commit 82aab28

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+7-2
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,14 @@ object Parsers {
11041104
if (prec < opPrec || leftAssoc && prec == opPrec) {
11051105
opStack = opStack.tail
11061106
recur {
1107-
atSpan(opInfo.operator.span union opInfo.operand.span union top.span) {
1107+
atSpan(opInfo.operator.span union opInfo.operand.span union top.span):
1108+
def deprecateInfixNamedArg(t: Tree): Unit = t match
1109+
case Tuple(ts) => ts.foreach(deprecateInfixNamedArg)
1110+
case Parens(t) => deprecateInfixNamedArg(t)
1111+
case t: Assign => report.deprecationWarning(em"named argument is deprecated for infix syntax", t.srcPos)
1112+
case _ =>
1113+
deprecateInfixNamedArg(top)
11081114
InfixOp(opInfo.operand, opInfo.operator, top)
1109-
}
11101115
}
11111116
}
11121117
else top

tests/warn/infix-named-args.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using options -deprecation
2+
3+
class C {
4+
def f = 42 + (x = 1) // warn
5+
def multi(x: Int, y: Int): Int = x + y
6+
def g = new C() `multi` (x = 42, y = 27) // warn // warn
7+
}

0 commit comments

Comments
 (0)