File tree Expand file tree Collapse file tree 5 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc/parsing Expand file tree Collapse file tree 5 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -2293,10 +2293,10 @@ object Parsers {
22932293 isOperator = ! (location.inArgs && followingIsVararg()))
22942294
22952295 /** PrefixExpr ::= [PrefixOperator'] SimpleExpr
2296- * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
2296+ * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ (if not backquoted)
22972297 */
22982298 val prefixExpr : Location => Tree = location =>
2299- if isIdent && nme.raw.isUnary(in.name)
2299+ if in.token == IDENTIFIER && nme.raw.isUnary(in.name)
23002300 && in.canStartExprTokens.contains(in.lookahead.token)
23012301 then
23022302 val start = in.offset
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ InfixExpr ::= PrefixExpr
254254 | InfixExpr MatchClause
255255MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases)
256256PrefixExpr ::= [PrefixOperator] SimpleExpr PrefixOp(expr, op)
257- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
257+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
258258SimpleExpr ::= SimpleRef
259259 | Literal
260260 | ‘_’
Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ InfixExpr ::= PrefixExpr
252252 | InfixExpr MatchClause
253253MatchClause ::= ‘match’ <<< CaseClauses >>>
254254PrefixExpr ::= [PrefixOperator] SimpleExpr
255- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
255+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
256256SimpleExpr ::= SimpleRef
257257 | Literal
258258 | ‘_’
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