diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index a7f4cbd0952b..6187f0a4f05c 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1054,14 +1054,17 @@ object Parsers { else { val opInfo = opStack.head val opPrec = precedence(opInfo.operator.name) - if (prec < opPrec || leftAssoc && prec == opPrec) { + if prec < opPrec || leftAssoc && prec == opPrec then opStack = opStack.tail - recur { - atSpan(opInfo.operator.span union opInfo.operand.span union top.span) { + recur: + 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(InfixNamedArgDeprecation(), t.srcPos) + case _ => + deprecateInfixNamedArg(top) InfixOp(opInfo.operand, opInfo.operator, top) - } - } - } else top } recur(top) diff --git a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala index bfeb426d6f9a..68260ecc9dad 100644 --- a/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala +++ b/compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala @@ -214,6 +214,10 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe case UnusedSymbolID // errorNumber: 198 case TailrecNestedCallID //errorNumber: 199 - unused in LTS case FinalLocalDefID // errorNumber: 200 + case NonNamedArgumentInJavaAnnotationID // errorNumber: 201 - unused in LTS + case QuotedTypeMissingID // errorNumber: 202 - unused in LTS + case AmbiguousNamedTupleAssignmentID // errorNumber: 203 - unused in LTS + case DeprecatedNamedInfixArgID // errorNumber: 204 - used ONLY in LTS def errorNumber = ordinal - 1 diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index 393816714931..5830dc5d1ce7 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -3150,3 +3150,12 @@ object UnusedSymbol { def privateMembers(using Context): UnusedSymbol = new UnusedSymbol(i"unused private member") def patVars(using Context): UnusedSymbol = new UnusedSymbol(i"unused pattern variable") } + +class InfixNamedArgDeprecation()(using Context) + extends Message(DeprecatedNamedInfixArgID): + def kind = MessageKind.PotentialIssue + def msg(using Context) = "Named argument syntax is deprecated for infix application" + def explain(using Context) = + i"""The argument will be parsed as a named tuple in future. + | + |To avoid this warning, either remove the argument names or use dotted selection.""" diff --git a/tests/warn/infix-named-args.scala b/tests/warn/infix-named-args.scala new file mode 100644 index 000000000000..e6953810e567 --- /dev/null +++ b/tests/warn/infix-named-args.scala @@ -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 +}