Skip to content

Commit 8cc355c

Browse files
som-snyttWojciechMazur
authored andcommitted
Deprecate infix named args
1 parent dbd4988 commit 8cc355c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,14 @@ object Parsers {
11201120
if (prec < opPrec || leftAssoc && prec == opPrec) {
11211121
opStack = opStack.tail
11221122
recur {
1123-
atSpan(opInfo.operator.span union opInfo.operand.span union top.span) {
1123+
atSpan(opInfo.operator.span union opInfo.operand.span union top.span):
1124+
def deprecateInfixNamedArg(t: Tree): Unit = t match
1125+
case Tuple(ts) => ts.foreach(deprecateInfixNamedArg)
1126+
case Parens(t) => deprecateInfixNamedArg(t)
1127+
case t: Assign => report.deprecationWarning(em"named argument is deprecated for infix syntax", t.srcPos)
1128+
case _ =>
1129+
deprecateInfixNamedArg(top)
11241130
InfixOp(opInfo.operand, opInfo.operator, top)
1125-
}
11261131
}
11271132
}
11281133
else top

tests/warn/infix-named-args.scala

Lines changed: 7 additions & 0 deletions
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)