Skip to content

Update error message at Parsers.scala:1901 #1616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ object Parsers {
else EmptyTree
}
else {
if (!isExprIntro) syntaxError("missing return type", in.lastOffset)
if (!isExprIntro) syntaxError(MissingReturnType(), in.lastOffset)
accept(EQUALS)
expr()
}
Expand Down
16 changes: 14 additions & 2 deletions src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ object messages {

val explanation = ""
}

case class EarlyDefinitionsNotSupported()(implicit ctx:Context) extends Message(9) {
val kind = "Syntax"

val msg = "early definitions are not supported; use trait parameters instead"

val code1 =
Expand Down Expand Up @@ -500,4 +500,16 @@ object messages {
|which cannot start with ${Red(illegalToken)}.""".stripMargin
}
}

case class MissingReturnType()(implicit ctx:Context) extends Message(18) {
val kind = "Syntax"
val msg = "missing return type"
val explanation =
hl"""An abstract declaration must have a return type. For example:
|
|trait Shape {
| def area: Double // abstract declaration returning a ${"Double"}
|}""".stripMargin
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So first off, you're correctly stating that if a trait method does not have a return type it needs to be clarified. But why is this? It's an abstract definition; we need to know what it's type is when we implement it somewhere else.

I also have a different nitpick, so the error messages obey a flag called -pagewidth X, where X is the max number of columns that should be printed in the terminal. As such, I would suggest that you split line 408 to be no more than 80 characters (i.e. newline after area).

Good job otherwise, and thanks for cleaning up the trailing whitespace ❤️

Copy link
Contributor Author

@ljdelight ljdelight Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments. How does this read?

An abstract declaration must have a return type. For example:
        |
        |trait Shape {
        |  def area: Double // abstract declaration returning a ${"Double"}
        |}

Copy link
Contributor

@felixmulder felixmulder Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks fine. Make the change and this is approved for merge :)


}