Skip to content

Commit 89217ca

Browse files
Merge pull request #11602 from Kordyjan/excessive-ends
Skip empty statements around end markers
2 parents 0d51319 + 1785f36 commit 89217ca

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,15 @@ object Parsers {
364364
if in.isNewLine then in.nextToken() else accept(SEMI)
365365

366366
def acceptStatSepUnlessAtEnd[T <: Tree](stats: ListBuffer[T], altEnd: Token = EOF): Unit =
367+
def skipEmptyStats(): Unit =
368+
while (in.token == SEMI || in.token == NEWLINE || in.token == NEWLINES) do in.nextToken()
369+
367370
in.observeOutdented()
368371
in.token match
369372
case SEMI | NEWLINE | NEWLINES =>
370-
in.nextToken()
373+
skipEmptyStats()
371374
checkEndMarker(stats)
375+
skipEmptyStats()
372376
case `altEnd` =>
373377
case _ =>
374378
if !isStatSeqEnd then

tests/neg/i11581.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Abc:
2+
def a = {
3+
println(10)
4+
10
5+
}
6+
7+
; ;
8+
9+
end a
10+
end a // error
11+
; ;
12+
end Abc
13+
end Abc // error
14+
15+
class D:
16+
end D
17+
end D // error
18+
19+
class Xyz {
20+
def a =
21+
println(10)
22+
10
23+
24+
}
25+
26+
27+
;
28+
end Xyz
29+
;
30+
;
31+
32+
end Xyz // error
33+

tests/pos/i11581.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Abc:
2+
def a = {
3+
println(10)
4+
10
5+
}
6+
7+
; ;
8+
9+
end a
10+
11+
12+
; ;
13+
14+
end Abc
15+
16+
class Xyz {
17+
def a =
18+
println(10)
19+
10
20+
21+
}
22+
23+
24+
; ;
25+
;
26+
27+
end Xyz

0 commit comments

Comments
 (0)