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 @@ -2220,10 +2220,10 @@ object Parsers {
2220
2220
isOperator = ! (location.inArgs && followingIsVararg()))
2221
2221
2222
2222
/** PrefixExpr ::= [PrefixOperator'] SimpleExpr
2223
- * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
2223
+ * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ (if not backquoted)
2224
2224
*/
2225
2225
val prefixExpr : Location => Tree = location =>
2226
- if isIdent && nme.raw.isUnary(in.name)
2226
+ if in.token == IDENTIFIER && 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 @@ -238,7 +238,7 @@ InfixExpr ::= PrefixExpr
238
238
| InfixExpr MatchClause
239
239
MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases)
240
240
PrefixExpr ::= [PrefixOperator] SimpleExpr PrefixOp(expr, op)
241
- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
241
+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
242
242
SimpleExpr ::= SimpleRef
243
243
| Literal
244
244
| ‘_’
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ InfixExpr ::= PrefixExpr
236
236
| InfixExpr MatchClause
237
237
MatchClause ::= ‘match’ <<< CaseClauses >>>
238
238
PrefixExpr ::= [PrefixOperator] SimpleExpr
239
- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
239
+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
240
240
SimpleExpr ::= SimpleRef
241
241
| Literal
242
242
| ‘_’
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