File tree Expand file tree Collapse file tree 4 files changed +12
-1
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 4 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -2223,7 +2223,7 @@ object Parsers {
2223
2223
* PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
2224
2224
*/
2225
2225
val prefixExpr : Location => Tree = location =>
2226
- if isIdent && nme.raw.isUnary(in.name)
2226
+ if in.isNonBackquotedIdent && nme.raw.isUnary(in.name)
2227
2227
&& in.canStartExprTokens.contains(in.lookahead.token)
2228
2228
then
2229
2229
val start = in.offset
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ object Scanners {
70
70
def isNewLine = token == NEWLINE || token == NEWLINES
71
71
def isStatSep = isNewLine || token == SEMI
72
72
def isIdent = token == IDENTIFIER || token == BACKQUOTED_IDENT
73
+ def isNonBackquotedIdent = token == IDENTIFIER
73
74
def isIdent (name : Name ) = token == IDENTIFIER && this .name == name
74
75
75
76
def isNestedStart = token == LBRACE || token == INDENT
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def + [T ](x : T ): String = " x"
3
+ + [Int ](6 ): String // error: expression expected but '[' found
4
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ def + [T ](x : T ): String = " x"
3
+ `+`[Int ](6 ): String // Parser can treat + as identifier when backquoted and followed by a type argument
4
+ `+`(6 ): String // Parser can treat + as identifier when backquoted and followed by a type argument
5
+ + (6 ): Int // Parser prioritizes + as unary when possible
6
+ }
You can’t perform that action at this time.
0 commit comments