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 @@ -2220,10 +2220,10 @@ object Parsers {
22202220 isOperator = ! (location.inArgs && followingIsVararg()))
22212221
22222222 /** PrefixExpr ::= [PrefixOperator'] SimpleExpr
2223- * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
2223+ * PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ (if not backquoted)
22242224 */
22252225 val prefixExpr : Location => Tree = location =>
2226- if isIdent && nme.raw.isUnary(in.name)
2226+ if in.token == IDENTIFIER && 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 @@ -238,7 +238,7 @@ InfixExpr ::= PrefixExpr
238238 | InfixExpr MatchClause
239239MatchClause ::= ‘match’ <<< CaseClauses >>> Match(expr, cases)
240240PrefixExpr ::= [PrefixOperator] SimpleExpr PrefixOp(expr, op)
241- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
241+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
242242SimpleExpr ::= SimpleRef
243243 | Literal
244244 | ‘_’
Original file line number Diff line number Diff line change @@ -236,7 +236,7 @@ InfixExpr ::= PrefixExpr
236236 | InfixExpr MatchClause
237237MatchClause ::= ‘match’ <<< CaseClauses >>>
238238PrefixExpr ::= [PrefixOperator] SimpleExpr
239- PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’
239+ PrefixOperator ::= ‘-’ | ‘+’ | ‘~’ | ‘!’ -- unless backquoted
240240SimpleExpr ::= SimpleRef
241241 | Literal
242242 | ‘_’
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