File tree 5 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc/parsing
5 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -2293,10 +2293,10 @@ object Parsers {
2293
2293
isOperator = ! (location.inArgs && followingIsVararg()))
2294
2294
2295
2295
/** PrefixExpr ::= [PrefixOperator'] SimpleExpr
2296
- * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
2296
+ * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ (if not backquoted)
2297
2297
*/
2298
2298
val prefixExpr : Location => Tree = location =>
2299
- if isIdent && nme.raw.isUnary(in.name)
2299
+ if in.token == IDENTIFIER && nme.raw.isUnary(in.name)
2300
2300
&& in.canStartExprTokens.contains(in.lookahead.token)
2301
2301
then
2302
2302
val start = in.offset
Original file line number Diff line number Diff line change @@ -254,7 +254,7 @@ InfixExpr ::= PrefixExpr
254
254
| InfixExpr MatchClause
255
255
MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases)
256
256
PrefixExpr ::= [PrefixOperator] SimpleExpr PrefixOp(expr, op)
257
- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
257
+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
258
258
SimpleExpr ::= SimpleRef
259
259
| Literal
260
260
| ‘_’
Original file line number Diff line number Diff line change @@ -252,7 +252,7 @@ InfixExpr ::= PrefixExpr
252
252
| InfixExpr MatchClause
253
253
MatchClause ::= ‘match’ <<< CaseClauses >>>
254
254
PrefixExpr ::= [PrefixOperator] SimpleExpr
255
- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
255
+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
256
256
SimpleExpr ::= SimpleRef
257
257
| Literal
258
258
| ‘_’
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 parenthesized argument
5
+ + (6 ): Int // Parser prioritizes + as unary when possible
6
+ }
You can’t perform that action at this time.
0 commit comments