diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index c4da4975268b..69627752fe97 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2184,14 +2184,15 @@ object Parsers { /** PrefixExpr ::= [`-' | `+' | `~' | `!'] SimpleExpr */ val prefixExpr: Location => Tree = location => - if (isIdent && nme.raw.isUnary(in.name)) { + if isIdent && nme.raw.isUnary(in.name) + && in.canStartExprTokens.contains(in.lookahead.token) + then val start = in.offset val op = termIdent() if (op.name == nme.raw.MINUS && isNumericLit) simpleExprRest(literal(start), location, canApply = true) else atSpan(start) { PrefixOp(op, simpleExpr(location)) } - } else simpleExpr(location) /** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody] diff --git a/tests/pos/i12396.scala b/tests/pos/i12396.scala new file mode 100644 index 000000000000..772cfaf49533 --- /dev/null +++ b/tests/pos/i12396.scala @@ -0,0 +1,7 @@ +object + { + val x = 1 +} + +object Check { + val y = +.x +} \ No newline at end of file