Skip to content

Commit 284d270

Browse files
committed
Improve missing parameter type error message
1 parent f7eed40 commit 284d270

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,16 @@ object messages {
195195
else
196196
""
197197

198+
val inferred =
199+
if (pt == WildcardType) ""
200+
else i"\nWhat I could infer was: $pt"
201+
198202
i"""Missing parameter type
199203
|
200-
|The argument types of an anonymous function must be fully known. (SLS 8.5)
201-
|Expected type: $pt
202-
|Missing type for parameter ${param.name}$ofFun"""
204+
|I could not infer the type of the parameter ${param.name}$ofFun.$inferred"""
203205
}
204206

205-
val explanation: String =
206-
hl"""|Anonymous functions must define a type. For example, if you define a function like this one:
207-
|
208-
|${"val f = { case x: Int => x + 1 }"}
209-
|
210-
|Make sure you give it a type of what you expect to match and help the type inference system:
211-
|
212-
|${"val f: Any => Int = { case x: Int => x + 1 }"} """
207+
val explanation: String = ""
213208
}
214209

215210
case class WildcardOnTypeArgumentNotAllowedOnNew()(implicit ctx: Context)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ class Typer extends Namer
940940
}
941941
case _ =>
942942
}
943-
errorType(AnonymousFunctionMissingParamType(param, params, tree, pt), param.sourcePos)
943+
errorType(AnonymousFunctionMissingParamType(param, params, tree, formal), param.sourcePos)
944944
}
945945

946946
def protoFormal(i: Int): Type =

0 commit comments

Comments
 (0)