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 {
22232223 * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
22242224 */
22252225 val prefixExpr : Location => Tree = location =>
2226- if isIdent && nme.raw.isUnary(in.name)
2226+ if in.isNonBackquotedIdent && nme.raw.isUnary(in.name)
22272227 && in.canStartExprTokens.contains(in.lookahead.token)
22282228 then
22292229 val start = in.offset
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ object Scanners {
7070 def isNewLine = token == NEWLINE || token == NEWLINES
7171 def isStatSep = isNewLine || token == SEMI
7272 def isIdent = token == IDENTIFIER || token == BACKQUOTED_IDENT
73+ def isNonBackquotedIdent = token == IDENTIFIER
7374 def isIdent (name : Name ) = token == IDENTIFIER && this .name == name
7475
7576 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