Skip to content

Require indent after colon at EOL #16466

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

Merged
merged 2 commits into from
Dec 5, 2022
Merged
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
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ object Parsers {
lookahead.isArrow
&& {
lookahead.nextToken()
lookahead.token == INDENT
lookahead.token == INDENT || lookahead.token == EOF
}
lookahead.nextToken()
if lookahead.isIdent || lookahead.token == USCORE then
Expand Down Expand Up @@ -1340,11 +1340,16 @@ object Parsers {
// note: next is defined here because current == NEWLINE
if (in.token == NEWLINE && p(in.next.token)) newLineOpt()

def colonAtEOLOpt(): Unit = {
def acceptIndent() =
if in.token != INDENT then
syntaxErrorOrIncomplete(em"indented definitions expected, ${in} found")

def colonAtEOLOpt(): Unit =
possibleColonOffset = in.lastOffset
in.observeColonEOL(inTemplate = false)
if in.token == COLONeol then in.nextToken()
}
if in.token == COLONeol then
in.nextToken()
acceptIndent()

def argumentStart(): Unit =
colonAtEOLOpt()
Expand All @@ -1364,8 +1369,7 @@ object Parsers {
if in.lookahead.token == END then in.token = NEWLINE
else
in.nextToken()
if in.token != INDENT && in.token != LBRACE then
syntaxErrorOrIncomplete(em"indented definitions expected, ${in} found")
if in.token != LBRACE then acceptIndent()
else
newLineOptWhenFollowedBy(LBRACE)

Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i16452.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i16452.scala:2:8 -----------------------------------------------------------------------------------
2 |// error
| ^
| indented definitions expected, eof found
2 changes: 2 additions & 0 deletions tests/neg/i16452.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
val x = Seq(1, 2, 3).map:
// error