diff options
author | Thiago Pereira <thiagoandrade6@gmail.com> | 2016-10-25 00:08:37 -0200 |
---|---|---|
committer | Thiago Pereira <thiago.pereira@vivareal.com> | 2016-10-31 10:43:20 -0200 |
commit | 1c0e48fe8cd0b44bfcfbd3705c4f7fcbe448a5be (patch) | |
tree | 98d56876973bd95fb9ec6928d630e54d89d17b28 | |
parent | 9f3005c1b742b6d05e94a93ad9ac31b02f951008 (diff) | |
download | dotty-1c0e48fe8cd0b44bfcfbd3705c4f7fcbe448a5be.tar.gz dotty-1c0e48fe8cd0b44bfcfbd3705c4f7fcbe448a5be.tar.bz2 dotty-1c0e48fe8cd0b44bfcfbd3705c4f7fcbe448a5be.zip |
Add error message IdentifierExpected
This commit adds the semantic object fir the ```identifier expected``` error.
It is part of the https://github.com/lampepfl/dotty/issues/1589
-rw-r--r-- | src/dotty/tools/dotc/parsing/JavaParsers.scala | 3 | ||||
-rw-r--r-- | src/dotty/tools/dotc/parsing/Parsers.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 24 |
3 files changed, 27 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/parsing/JavaParsers.scala b/src/dotty/tools/dotc/parsing/JavaParsers.scala index 0be4226ed..b6a423dc7 100644 --- a/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -21,6 +21,7 @@ import Symbols._ import ast.Trees._ import Decorators._ import StdNames._ +import dotty.tools.dotc.reporting.diagnostic.messages.IdentifierExpected import dotty.tools.dotc.util.SourceFile import util.Positions._ import annotation.switch @@ -230,7 +231,7 @@ object JavaParsers { case AppliedTypeTree(_, _) | Select(_, _) => tree case _ => - syntaxError("identifier expected", tree.pos) + syntaxError(IdentifierExpected(tree.show), tree.pos) errorTypeTree } } diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 754db3d3b..4926ebb9f 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -316,7 +316,7 @@ object Parsers { case id @ Select(qual, name) => cpy.Select(id)(qual, name.toTypeName) case _ => - syntaxError("identifier expected", tree.pos) + syntaxError(IdentifierExpected(tree.show), tree.pos) tree } diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 67d53fd22..bec49e728 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -691,4 +691,28 @@ object messages { |${s"trait A[${mods.flags} type $identifier]"} |""".stripMargin } + + case class IdentifierExpected(identifier: String)(implicit ctx: Context) extends Message(25) { + val kind = "Syntax" + + val msg = "identifier expected" + + val wrongIdentifier = s"def foo: $identifier = {...}" + + val validIdentifier = s"def foo = {...}" + + val explanation = { + hl"""|A valid identifier expected, but `$identifier` found. + |Let the compiler infer the type for you. + |For example, instead of: + | + |$wrongIdentifier + | + |Write your code like: + | + |$validIdentifier + | + |""".stripMargin + } + } } |