Skip to content

Add error messages - Parsers.scala:626 and Parsers.scala:1492 #1615

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 21, 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
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ object Parsers {
if (inPattern) Block(Nil, inBraces(pattern()))
else expr()
else {
syntaxErrorOrIncomplete("error in interpolated string: identifier or block expected")
ctx.error(InterpolatedStringError())
EmptyTree
}
})
Expand Down Expand Up @@ -1489,7 +1489,7 @@ object Parsers {

private def addModifier(mods: Modifiers): Modifiers = {
val flag = flagOfToken(in.token)
if (mods is flag) syntaxError("repeated modifier")
if (mods is flag) syntaxError(RepeatedModifier(flag.toString))
val res = addFlag(mods, flag)
in.nextToken()
res
Expand Down
47 changes: 47 additions & 0 deletions src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,51 @@ object messages {
| ((${nestedRepresentation}))""".stripMargin
}
}

case class RepeatedModifier(modifier: String)(implicit ctx:Context) extends Message(14) {
val kind = "Syntax"

val msg = hl"""repeated modifier $modifier"""

val code1 = hl"""private private val Origin = Point(0, 0)"""

val code2 = hl"""private final val Origin = Point(0, 0)"""

val explanation =
hl"""This happens when you accidentally specify the same modifier twice.
|
|Example:
|
|$code1
|
|instead of
|
|$code2
|
|""".stripMargin
Copy link
Contributor

Choose a reason for hiding this comment

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

@liufengyun has been working on modifiers with positions, and I'm thinking maybe we could enhance this further to say make the following recommendation:

This happens when you accidentally specify the same modifier twice:

private private lazy val x = ...

instead of:

private lazy val x = ...

Where this would be the user's code without the duplicate modifier. What do you think @liufengyun - can this be done with the new modifier objects?

}

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

val msg = "error in interpolated string: identifier or block expected"

val code1 = "s\"$new Point(0, 0)\""

val code2 = "s\"${new Point(0, 0)}\""

val explanation =
hl"""
|This usually happens when you forget to place your expressions inside curly braces.
|
|$code1
|
|should be written as
|
|$code2
|
|""".stripMargin

}

}