Skip to content

Commit c8595ca

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/neg/i871.scala to verify the change.
1 parent cdb83f9 commit c8595ca

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-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: 14 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 =
@@ -500,4 +500,16 @@ object messages {
500500
|which cannot start with ${Red(illegalToken)}.""".stripMargin
501501
}
502502
}
503+
504+
case class MissingReturnType()(implicit ctx:Context) extends Message(18) {
505+
val kind = "Syntax"
506+
val msg = "missing return type"
507+
val explanation =
508+
hl"""An abstract declaration must have a return type. For example:
509+
|
510+
|trait Shape {
511+
| def area: Double // abstract declaration returning a ${"Double"}
512+
|}""".stripMargin
513+
}
514+
503515
}

0 commit comments

Comments
 (0)