File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import Symbols._
2121import ast .Trees ._
2222import Decorators ._
2323import StdNames ._
24+ import dotty .tools .dotc .reporting .diagnostic .messages .IdentifierExpected
2425import dotty .tools .dotc .util .SourceFile
2526import util .Positions ._
2627import 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 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -678,4 +678,27 @@ 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+ val msg = " identifier expected"
685+
686+ val wrongIdentifier = s " def foo: $identifier = {...} "
687+
688+ val validIdentifier = s " def foo = {...} "
689+
690+ val explanation = {
691+ hl """ |A valid identifier is expected, but $identifier was found.
692+ |Let the compiler infer the type for you.
693+ |For example, instead of:
694+ |
695+ | $wrongIdentifier
696+ |
697+ |Write your sentence to:
698+ |
699+ | $validIdentifier
700+ |
701+ | """ .stripMargin
702+ }
703+ }
681704}
You can’t perform that action at this time.
0 commit comments