Skip to content

Commit 2bdb3a2

Browse files
committed
Add error message IdentifierExpected
This commit adds the semantic object fir the ```identifier expected``` error. It is part of the #1589
1 parent 557d448 commit 2bdb3a2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Symbols._
2121
import ast.Trees._
2222
import Decorators._
2323
import StdNames._
24+
import dotty.tools.dotc.reporting.diagnostic.messages.IdentifierExpected
2425
import dotty.tools.dotc.util.SourceFile
2526
import util.Positions._
2627
import annotation.switch
@@ -230,7 +231,7 @@ object JavaParsers {
230231
case AppliedTypeTree(_, _) | Select(_, _) =>
231232
tree
232233
case _ =>
233-
syntaxError("identifier expected", tree.pos)
234+
syntaxError(IdentifierExpected(tree.show), tree.pos)
234235
errorTypeTree
235236
}
236237
}

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ object Parsers {
316316
case id @ Select(qual, name) =>
317317
cpy.Select(id)(qual, name.toTypeName)
318318
case _ =>
319-
syntaxError("identifier expected", tree.pos)
319+
syntaxError(IdentifierExpected(tree.show), tree.pos)
320320
tree
321321
}
322322

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,28 @@ object messages {
678678
|$fixedVarInAlternative""".stripMargin
679679
}
680680
}
681+
682+
case class IdentifierExpected(identifier: String)(implicit ctx: Context) extends Message(24) {
683+
val kind = "Syntax"
684+
685+
val msg = "identifier expected"
686+
687+
val wrongIdentifier = s"def foo: $identifier = {...}"
688+
689+
val validIdentifier = s"def foo = {...}"
690+
691+
val explanation = {
692+
hl"""|A valid identifier is expected, but $identifier was found.
693+
|Let the compiler infer the type for you.
694+
|For example, instead of:
695+
|
696+
|$wrongIdentifier
697+
|
698+
|Write your sentence to:
699+
|
700+
|$validIdentifier
701+
|
702+
|""".stripMargin
703+
}
704+
}
681705
}

0 commit comments

Comments
 (0)