diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 3ffef90057ef..f880e1fb6535 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1247,13 +1247,17 @@ object Parsers { // note: next is defined here because current == NEWLINE if (in.token == NEWLINE && p(in.next.token)) newLineOpt() - def colonAtEOLOpt(): Unit = { + def colonAtEOLOpt(): Boolean = { possibleColonOffset = in.lastOffset - if in.token == COLONEOL then in.nextToken() + if in.token == COLONEOL then { + in.nextToken() + true + } else false } - def argumentStart(): Unit = - colonAtEOLOpt() + // returns true if COLONEOL encountered + def argumentStart(): Boolean = + val result = colonAtEOLOpt() if migrateTo3 && in.token == NEWLINE && in.next.token == LBRACE then in.nextToken() if in.indentWidth(in.offset) == in.currentRegion.indentWidth then @@ -1263,6 +1267,7 @@ object Parsers { |an argument to the previous expression.${rewriteNotice()}""", in.sourcePos()) patch(source, Span(in.offset), " ") + result def possibleTemplateStart(isNew: Boolean = false): Unit = in.observeColonEOL() @@ -2304,7 +2309,7 @@ object Parsers { } def simpleExprRest(t: Tree, location: Location, canApply: Boolean = true): Tree = { - if (canApply) argumentStart() + val seenCOLONEOL = if (canApply) argumentStart() else false in.token match { case DOT => in.nextToken() @@ -2338,6 +2343,9 @@ object Parsers { if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled => val app = applyToClosure(t, in.offset, convertToParams(termIdent())) simpleExprRest(app, location, canApply = true) + case EOF if in.fewerBracesEnabled && seenCOLONEOL => + incompleteInputError("indented definitions expected, eof found") + t case _ => t } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 3c70f838caa3..a4b75b234a63 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -280,3 +280,13 @@ class ReplVerboseTests extends ReplTest(ReplTest.defaultOptions :+ "-verbose"): assert(storedOutput().trim().endsWith("val a: Int = 42")) } end ReplVerboseTests + +class FewerBracesTests extends ReplTest(ReplTest.defaultOptions :+ "-language:experimental.fewerBraces" :+ "-Ydebug-error"): + @Test def i13097_1 = contextually { + assert(ParseResult.isIncomplete("val x = List(42).foreach:")) + } + + @Test def i13097_2 = contextually { + assert(ParseResult.isIncomplete("class C:")) + } +end FewerBracesTests