File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import Symbols._
21
21
import ast .Trees ._
22
22
import Decorators ._
23
23
import StdNames ._
24
+ import dotty .tools .dotc .reporting .diagnostic .messages .IdentifierExpected
24
25
import dotty .tools .dotc .util .SourceFile
25
26
import util .Positions ._
26
27
import annotation .switch
@@ -230,7 +231,7 @@ object JavaParsers {
230
231
case AppliedTypeTree (_, _) | Select (_, _) =>
231
232
tree
232
233
case _ =>
233
- syntaxError(" identifier expected " , tree.pos)
234
+ syntaxError(IdentifierExpected (tree.show) , tree.pos)
234
235
errorTypeTree
235
236
}
236
237
}
Original file line number Diff line number Diff line change @@ -316,7 +316,7 @@ object Parsers {
316
316
case id @ Select (qual, name) =>
317
317
cpy.Select (id)(qual, name.toTypeName)
318
318
case _ =>
319
- syntaxError(" identifier expected " , tree.pos)
319
+ syntaxError(IdentifierExpected (tree.show) , tree.pos)
320
320
tree
321
321
}
322
322
Original file line number Diff line number Diff line change @@ -678,4 +678,28 @@ object messages {
678
678
| $fixedVarInAlternative""" .stripMargin
679
679
}
680
680
}
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
+ }
681
705
}
You can’t perform that action at this time.
0 commit comments