Skip to content

Commit af4b7f4

Browse files
committed
Update error message at Parsers.scala:1901.
This one is about a 'missing return type' when we can't infer a type. I used tests/ng/i871.scala to verify the change Dropped a closing brace on a rebase
1 parent 0e3b4aa commit af4b7f4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ object Parsers {
18981898
else EmptyTree
18991899
}
19001900
else {
1901-
if (!isExprIntro) syntaxError("missing return type", in.lastOffset)
1901+
if (!isExprIntro) syntaxError(MissingReturnType(), in.lastOffset)
19021902
accept(EQUALS)
19031903
expr()
19041904
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ object messages {
275275

276276
val explanation = ""
277277
}
278-
278+
279279
case class EarlyDefinitionsNotSupported()(implicit ctx:Context) extends Message(9) {
280280
val kind = "Syntax"
281-
281+
282282
val msg = "early definitions are not supported; use trait parameters instead"
283283

284284
val code1 =
@@ -482,4 +482,15 @@ object messages {
482482
|but an uninitialized var definition
483483
""".stripMargin
484484
}
485+
486+
case class MissingReturnType()(implicit ctx:Context) extends Message(17) {
487+
val kind = "Syntax"
488+
val msg = "missing return type"
489+
val explanation =
490+
hl"""The return type is missing and needs to be clarified. For example, `area` returns a ${"Double"}:
491+
|
492+
|trait Shape {
493+
| def area: Double
494+
|}""".stripMargin
495+
}
485496
}

0 commit comments

Comments
 (0)