aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/reporting/diagnostic
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-02-15 11:10:16 +0100
committerGitHub <noreply@github.com>2017-02-15 11:10:16 +0100
commit39af2f595979c6bbeb3cfa52d401cf59be68126b (patch)
tree71c00946da2050fdafa2349e6bc3891237b0b0de /compiler/src/dotty/tools/dotc/reporting/diagnostic
parent606e36be88c47cd3f2e8856d6bd6b95aed7aa191 (diff)
parent81cda70db72046901e8ca5f8c958224cafdf1bf4 (diff)
downloaddotty-39af2f595979c6bbeb3cfa52d401cf59be68126b.tar.gz
dotty-39af2f595979c6bbeb3cfa52d401cf59be68126b.tar.bz2
dotty-39af2f595979c6bbeb3cfa52d401cf59be68126b.zip
Merge pull request #1983 from ennru/ennru_ExpectedTokenError
Change '... expected but found ...' to Message
Diffstat (limited to 'compiler/src/dotty/tools/dotc/reporting/diagnostic')
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala37
2 files changed, 37 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
index 2497fb216..ab1222dab 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/Message.scala
@@ -119,6 +119,8 @@ class ExtendMessage(_msg: () => Message)(f: String => String) { self =>
class NoExplanation(val msg: String) extends Message(NoExplanation.ID) {
val explanation = ""
val kind = ""
+
+ override def toString(): String = s"NoExplanation($msg)"
}
/** The extractor for `NoExplanation` can be used to check whether any error
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 4d61f21cf..94611e10d 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -4,10 +4,17 @@ package reporting
package diagnostic
import dotc.core._
-import Contexts.Context, Decorators._, Symbols._, Names._, NameOps._, Types._
+import Contexts.Context
+import Decorators._
+import Symbols._
+import Names._
+import NameOps._
+import Types._
import util.SourcePosition
import config.Settings.Setting
-import interfaces.Diagnostic.{ERROR, WARNING, INFO}
+import interfaces.Diagnostic.{ERROR, INFO, WARNING}
+import dotc.parsing.Scanners.Token
+import dotc.parsing.Tokens
import printing.Highlighting._
import printing.Formatting
@@ -1053,4 +1060,30 @@ object messages {
|""".stripMargin
}
+ case class ExpectedTokenButFound(expected: Token, found: Token, foundName: TermName)(implicit ctx: Context)
+ extends Message(40) {
+ val kind = "Syntax"
+
+ private val expectedText =
+ if (Tokens.isIdentifier(expected)) "an identifier"
+ else Tokens.showToken(expected)
+
+ private val foundText =
+ if (foundName != null) hl"`${foundName.show}`"
+ else Tokens.showToken(found)
+
+ val msg = hl"""${expectedText} expected, but ${foundText} found"""
+
+ private val ifKeyword =
+ if (Tokens.isIdentifier(expected) && Tokens.isKeyword(found))
+ s"""
+ |If you necessarily want to use $foundText as identifier, you may put it in backticks.""".stripMargin
+ else
+ ""
+
+ val explanation =
+ s"""|The text ${foundText} may not occur at that position, the compiler expected ${expectedText}.$ifKeyword
+ |""".stripMargin
+ }
+
}