diff options
author | Sebastian Harko <sebastian.harko@lightbend.com> | 2016-10-21 10:59:33 -0700 |
---|---|---|
committer | Sebastian Harko <sebastian.harko@lightbend.com> | 2016-10-21 10:59:33 -0700 |
commit | ac24603b7c04739d2ea2e2441e3b1f76dc2c9281 (patch) | |
tree | 317d0f2abc4f8b75532a721de9e8b8ba4b38a2a3 | |
parent | 0d1721c8aebaf6877e9d1ea3d65d40446a869170 (diff) | |
download | dotty-ac24603b7c04739d2ea2e2441e3b1f76dc2c9281.tar.gz dotty-ac24603b7c04739d2ea2e2441e3b1f76dc2c9281.tar.bz2 dotty-ac24603b7c04739d2ea2e2441e3b1f76dc2c9281.zip |
add messages for interpolated string error and repeated modifier error
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 47 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 46e7512f3..292e410f5 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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 } }) @@ -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 diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 633501295..c05110b66 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -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 + } + + 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 + + } + } |