Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13097: Fix FewerBraces eta expansion error #14092

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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