Skip to content

Skip empty statements around end markers #11602

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 1 commit into from
Mar 5, 2021
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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,15 @@ object Parsers {
if in.isNewLine then in.nextToken() else accept(SEMI)

def acceptStatSepUnlessAtEnd[T <: Tree](stats: ListBuffer[T], altEnd: Token = EOF): Unit =
def skipEmptyStats(): Unit =
while (in.token == SEMI || in.token == NEWLINE || in.token == NEWLINES) do in.nextToken()

in.observeOutdented()
in.token match
case SEMI | NEWLINE | NEWLINES =>
in.nextToken()
skipEmptyStats()
checkEndMarker(stats)
skipEmptyStats()
case `altEnd` =>
case _ =>
if !isStatSeqEnd then
Expand Down
33 changes: 33 additions & 0 deletions tests/neg/i11581.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Abc:
def a = {
println(10)
10
}

; ;

end a
end a // error
; ;
end Abc
end Abc // error

class D:
end D
end D // error

class Xyz {
def a =
println(10)
10

}


;
end Xyz
;
;

end Xyz // error

27 changes: 27 additions & 0 deletions tests/pos/i11581.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Abc:
def a = {
println(10)
10
}

; ;

end a


; ;

end Abc

class Xyz {
def a =
println(10)
10

}


; ;
;

end Xyz