File tree 5 files changed +17
-2
lines changed
compiler/src/dotty/tools/dotc
5 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -342,8 +342,8 @@ object Names {
342
342
343
343
override def encode : SimpleName = {
344
344
val dontEncode =
345
- length >= 3 &&
346
- head == '<' && last == '>' && isIdentifierStart(apply( 1 ) )
345
+ length >= 6 &&
346
+ head == '<' && ( this == StdNames .nme. CONSTRUCTOR || this == StdNames .nme. STATIC_CONSTRUCTOR )
347
347
if (dontEncode) this else NameTransformer .encode(this )
348
348
}
349
349
Original file line number Diff line number Diff line change @@ -978,6 +978,10 @@ object Parsers {
978
978
def ident (): TermName =
979
979
if (isIdent) {
980
980
val name = in.name
981
+ if name == nme.CONSTRUCTOR || name == nme.STATIC_CONSTRUCTOR then
982
+ report.error(
983
+ i """ Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden """ ,
984
+ in.sourcePos())
981
985
in.nextToken()
982
986
name
983
987
}
@@ -996,6 +1000,7 @@ object Parsers {
996
1000
997
1001
private def makeIdent (tok : Token , offset : Offset , name : Name ) = {
998
1002
val tree = Ident (name)
1003
+
999
1004
if (tok == BACKQUOTED_IDENT ) tree.pushAttachment(Backquoted , ())
1000
1005
1001
1006
// Make sure that even trees with parsing errors have a offset that is within the offset
Original file line number Diff line number Diff line change
1
+ class Test (i : Int ):
2
+ val `<init>` = " init" // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
3
+ val `<clinit>` = " clinit" // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
4
+ class `<init>` : // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
5
+ def `<init>` (in : String ) = ??? // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
6
+ class `<clinit>` : // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
7
+ def `<clinit>` (in : String ) = ??? // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
Original file line number Diff line number Diff line change
1
+ object Test :
2
+ val `<x>` = " hello!"
3
+ def main (args : Array [String ]): Unit = println(`<x>`)
You can’t perform that action at this time.
0 commit comments