Skip to content

Commit 81291f1

Browse files
committed
Make message more obvious in the myopic case
1 parent 82aab28 commit 81291f1

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
217217
case NonNamedArgumentInJavaAnnotationID // errorNumber: 201
218218
case QuotedTypeMissingID // errorNumber: 202
219219
case AmbiguousNamedTupleAssignmentID // errorNumber: 203
220+
case DeprecatedNamedInfixArgID // errorNumber: 204 - used ONLY in LTS
220221

221222
def errorNumber = ordinal - 1
222223

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

+7-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ object ErrorReporting {
110110
case tp => i" and expected result type $tp"
111111
}
112112
i"(${tp.typedArgs().tpes}%, %)$result"
113-
s"arguments ${argStr(tp)}"
113+
def hasNames = tp.args.exists:
114+
case tree: untpd.Tuple => tree.trees.exists:
115+
case NamedArg(_, _) => true
116+
case _ => false
117+
case _ => false
118+
val addendum = if hasNames then " (a named tuple)" else ""
119+
s"arguments ${argStr(tp)}$addendum"
114120
case _ =>
115121
i"expected type $tp"
116122
}

docs/_docs/reference/other-new-features/named-tuples.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ val persons: List[Person] = ...
1717
val minors = persons.filter: p =>
1818
p.age < 18
1919
```
20-
Named bindings in tuples are similar to function parameters and arguments. We use `name: Type` for element types and `name = value` for element values. It is illegal to mix named and unnamed elements in a tuple, or to use the same same
21-
name for two different elements.
20+
Named bindings in tuples are similar to function parameters and arguments.
21+
We use `name: Type` for element types and `name = value` for element values.
22+
It is illegal to mix named and unnamed elements in a tuple, or to use the same name for two different elements.
2223

2324
Fields of named tuples can be selected by their name, as in the line `p.age < 18` above.
2425

tests/neg/infix-named-args.check

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- [E134] Type Error: tests/neg/infix-named-args.scala:2:13 ------------------------------------------------------------
2+
2 | def f = 42 + (x = 1) // error // a named tuple!
3+
| ^^^^
4+
| None of the overloaded alternatives of method + in class Int with types
5+
| (x: Double): Double
6+
| (x: Float): Float
7+
| (x: Long): Long
8+
| (x: Int): Int
9+
| (x: Char): Int
10+
| (x: Short): Int
11+
| (x: Byte): Int
12+
| (x: String): String
13+
| match arguments ((x : Int)) (a named tuple)

tests/neg/infix-named-args.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C {
2+
def f = 42 + (x = 1) // error // a named tuple!
3+
def multi(x: Int, y: Int): Int = x + y
4+
def **(x: Int, y: Int): Int = x + y
5+
def g = new C() `multi` (x = 42, y = 27) // werror // werror // not actually a tuple! appearances to the contrary
6+
def h = new C() ** (x = 42, y = 27) // werror // werror
7+
}

tests/warn/infix-named-args.scala

-7
This file was deleted.

0 commit comments

Comments
 (0)