Skip to content

Commit 405d680

Browse files
committed
Show expanded function for more missing parameter types errors
Fixes #11561 It's the best I could do. The second error leads to code that's too far removed from what's intended for it to be recoverable in a robust way.
1 parent 98e3839 commit 405d680

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Contexts._
77
import Decorators._, Symbols._, Names._, NameOps._, Types._, Flags._, Phases._
88
import Denotations.SingleDenotation
99
import SymDenotations.SymDenotation
10+
import NameKinds.WildcardParamName
1011
import util.SourcePosition
1112
import parsing.Scanners.Token
1213
import parsing.Tokens
@@ -149,10 +150,10 @@ import transform.SymUtils._
149150
extends TypeMsg(AnonymousFunctionMissingParamTypeID) {
150151
def msg = {
151152
val ofFun =
152-
if (MethodType.syntheticParamNames(args.length + 1) contains param.name)
153-
i" of expanded function:\n$tree"
154-
else
155-
""
153+
if param.name.is(WildcardParamName)
154+
|| (MethodType.syntheticParamNames(args.length + 1) contains param.name)
155+
then i" of expanded function:\n$tree"
156+
else ""
156157

157158
val inferred =
158159
if (pt == WildcardType) ""

tests/neg/i11561.check

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- [E081] Type Error: tests/neg/i11561.scala:2:32 ----------------------------------------------------------------------
2+
2 | val updateText1 = copy(text = _) // error
3+
| ^
4+
| Missing parameter type
5+
|
6+
| I could not infer the type of the parameter _$1 of expanded function:
7+
| _$1 => State.this.text = _$1.
8+
-- [E052] Type Error: tests/neg/i11561.scala:3:30 ----------------------------------------------------------------------
9+
3 | val updateText2 = copy(text = (_: String)) // error
10+
| ^^^^^^^^^^^^^^^^^^
11+
| Reassignment to val text
12+
13+
longer explanation available when compiling with `-explain`

tests/neg/i11561.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
case class State(text: String):
2+
val updateText1 = copy(text = _) // error
3+
val updateText2 = copy(text = (_: String)) // error

0 commit comments

Comments
 (0)