Skip to content

Commit 67ba634

Browse files
committed
Fix named arg deprecation
1 parent 81291f1 commit 67ba634

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ object Parsers {
11081108
def deprecateInfixNamedArg(t: Tree): Unit = t match
11091109
case Tuple(ts) => ts.foreach(deprecateInfixNamedArg)
11101110
case Parens(t) => deprecateInfixNamedArg(t)
1111-
case t: Assign => report.deprecationWarning(em"named argument is deprecated for infix syntax", t.srcPos)
1111+
case t: NamedArg => report.deprecationWarning(InfixNamedArgDeprecation(), t.srcPos)
11121112
case _ =>
11131113
deprecateInfixNamedArg(top)
11141114
InfixOp(opInfo.operand, opInfo.operator, top)

compiler/src/dotty/tools/dotc/reporting/messages.scala

+7
Original file line numberDiff line numberDiff line change
@@ -3352,3 +3352,10 @@ final class AmbiguousNamedTupleAssignment(key: Name, value: untpd.Tree)(using Co
33523352
|To assign a value, use curly braces: `{${key} = ${value}}`."""
33533353

33543354
override protected def explain(using Context): String = ""
3355+
3356+
class InfixNamedArgDeprecation()(using Context) extends SyntaxMsg(DeprecatedNamedInfixArgID):
3357+
def msg(using Context) = "Named argument syntax is deprecated for infix application"
3358+
def explain(using Context) =
3359+
i"""The argument will be parsed as a named tuple in future.
3360+
|
3361+
|To avoid this warning, either remove the argument names or use dotted selection."""

tests/neg/infix-named-args.check

+8
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
| (x: Byte): Int
1212
| (x: String): String
1313
| match arguments ((x : Int)) (a named tuple)
14+
-- [E007] Type Mismatch Error: tests/neg/infix-named-args.scala:13:18 --------------------------------------------------
15+
13 | def g = this ** 2 // error
16+
| ^
17+
| Found: (2 : Int)
18+
| Required: X
19+
|
20+
| longer explanation available when compiling with `-explain`
21+
there were 6 deprecation warnings; re-run with -deprecation for details

tests/neg/infix-named-args.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
class C {
1+
class C:
22
def f = 42 + (x = 1) // error // a named tuple!
33
def multi(x: Int, y: Int): Int = x + y
44
def **(x: Int, y: Int): Int = x + y
55
def g = new C() `multi` (x = 42, y = 27) // werror // werror // not actually a tuple! appearances to the contrary
66
def h = new C() ** (x = 42, y = 27) // werror // werror
7-
}
7+
8+
type X = (x: Int)
9+
10+
class D(d: Int):
11+
def **(x: X): Int = d * x.x
12+
def f = this ** (x = 2)
13+
def g = this ** 2 // error

tests/warn/infix-named-args.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using options -deprecation
2+
type X = (x: Int)
3+
4+
class E(e: Int):
5+
def **(x: Int): Int = e * x
6+
def **(x: X): Int = e * x.x
7+
def f = this ** (x = 2) // warn

0 commit comments

Comments
 (0)