Skip to content

Commit b7731b3

Browse files
committed
Fix i18042
1 parent ed319e8 commit b7731b3

File tree

5 files changed

+37
-25
lines changed

5 files changed

+37
-25
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,27 @@ extends SyntaxMsg(CaseClassMissingParamListID) {
160160

161161
class AnonymousFunctionMissingParamType(param: untpd.ValDef,
162162
tree: untpd.Function,
163-
pt: Type)
163+
inferredType: Type,
164+
expectedType: Type,
165+
)
164166
(using Context)
165167
extends TypeMsg(AnonymousFunctionMissingParamTypeID) {
166168
def msg(using Context) = {
167169
val ofFun =
168170
if param.name.is(WildcardParamName)
169171
|| (MethodType.syntheticParamNames(tree.args.length + 1) contains param.name)
170-
then i" of expanded function:\n$tree"
172+
then i"\n\nIn expanded function:\n$tree"
171173
else ""
172174

173175
val inferred =
174-
if (pt == WildcardType) ""
175-
else i"\nWhat I could infer was: $pt"
176+
if (inferredType == WildcardType) ""
177+
else i"\n\nPartially inferred type for the parameter: $inferredType"
176178

177-
i"""Missing parameter type
178-
|
179-
|I could not infer the type of the parameter ${param.name}$ofFun.$inferred"""
179+
val expected =
180+
if (expectedType == WildcardType) ""
181+
else i"\n\nExpected type for the whole anonymous function: $expectedType"
182+
183+
i"Could not infer type for parameter ${param.name} of anonymous function$ofFun$inferred$expected"
180184
}
181185

182186
def explain(using Context) = ""
@@ -2985,4 +2989,4 @@ class ImplausiblePatternWarning(pat: tpd.Tree, selType: Type)(using Context)
29852989
i"""|Implausible pattern:
29862990
|$pat could match selector of type $selType
29872991
|only if there is an `equals` method identifying elements of the two types."""
2988-
def explain(using Context) = ""
2992+
def explain(using Context) = ""

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16201620
else
16211621
inferredFromTarget(param, formal, calleeType, isErased, paramIndex).orElse(
16221622
if knownFormal then formal0
1623-
else errorType(AnonymousFunctionMissingParamType(param, tree, formal), param.srcPos)
1623+
else errorType(AnonymousFunctionMissingParamType(param, tree, inferredType = formal, expectedType = pt), param.srcPos)
16241624
)
16251625
val paramTpt = untpd.TypedSplice(
16261626
(if knownFormal then InferredTypeTree() else untpd.TypeTree())
@@ -3957,7 +3957,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
39573957
sym.isConstructor
39583958
|| sym.matchNullaryLoosely
39593959
|| Feature.warnOnMigration(msg, tree.srcPos, version = `3.0`)
3960-
&& {
3960+
&& {
39613961
msg.actions
39623962
.headOption
39633963
.foreach(Rewrites.applyAction)

tests/neg/i11350.check

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
-- [E081] Type Error: tests/neg/i11350.scala:1:39 ----------------------------------------------------------------------
22
1 |class A1[T](action: A1[T] ?=> String = "") // error
33
| ^
4-
| Missing parameter type
4+
| Could not infer type for parameter evidence$1 of anonymous function
55
|
6-
| I could not infer the type of the parameter evidence$1.
7-
| What I could infer was: A1[<?>]
6+
| Partially inferred type for the parameter: A1[<?>]
7+
|
8+
| Expected type for the whole anonymous function: (A1[<?>]) ?=> String
89
-- [E081] Type Error: tests/neg/i11350.scala:2:39 ----------------------------------------------------------------------
910
2 |class A2[T](action: A1[T] ?=> String = summon[A1[T]]) // error
1011
| ^
11-
| Missing parameter type
12+
| Could not infer type for parameter evidence$2 of anonymous function
13+
|
14+
| Partially inferred type for the parameter: A1[<?>]
1215
|
13-
| I could not infer the type of the parameter evidence$2.
14-
| What I could infer was: A1[<?>]
16+
| Expected type for the whole anonymous function: (A1[<?>]) ?=> String

tests/neg/i11561.check

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
-- [E081] Type Error: tests/neg/i11561.scala:2:32 ----------------------------------------------------------------------
22
2 | val updateText1 = copy(text = _) // error
33
| ^
4-
| Missing parameter type
4+
| Could not infer type for parameter _$1 of anonymous function
55
|
6-
| I could not infer the type of the parameter _$1 of expanded function:
7-
| _$1 => State.this.text = _$1.
6+
| In expanded function:
7+
| _$1 => State.this.text = _$1
8+
|
9+
| Expected type for the whole anonymous function: String
810
-- [E052] Type Error: tests/neg/i11561.scala:3:30 ----------------------------------------------------------------------
911
3 | val updateText2 = copy(text = (_: String)) // error
1012
| ^^^^^^^^^^^^^^^^^^

tests/neg/i17183.check

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
-- [E081] Type Error: tests/neg/i17183.scala:11:24 ---------------------------------------------------------------------
22
11 |def test = Context(f = (_, _) => ???) // error // error
33
| ^
4-
| Missing parameter type
4+
| Could not infer type for parameter _$1 of anonymous function
55
|
6-
| I could not infer the type of the parameter _$1 of expanded function:
7-
| (_$1, _$2) => ???.
6+
| In expanded function:
7+
| (_$1, _$2) => ???
8+
|
9+
| Expected type for the whole anonymous function: MyFunc
810
-- [E081] Type Error: tests/neg/i17183.scala:11:27 ---------------------------------------------------------------------
911
11 |def test = Context(f = (_, _) => ???) // error // error
1012
| ^
11-
| Missing parameter type
13+
| Could not infer type for parameter _$2 of anonymous function
14+
|
15+
| In expanded function:
16+
| (_$1, _$2) => ???
1217
|
13-
| I could not infer the type of the parameter _$2 of expanded function:
14-
| (_$1, _$2) => ???.
18+
| Expected type for the whole anonymous function: MyFunc

0 commit comments

Comments
 (0)