diff options
Diffstat (limited to 'src')
-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 + } + } } |