Skip to content

Commit fbea0ff

Browse files
committed
Parse empty Java compilation units as EmptyTree
Before this commit, an empty Java compilation unit (one without a package declaration or any top level declarations) was parsed as `PackageDef(Ident(<empty>),List())` which resulted in position not set errors. With this commit, an empty Java compilation unit is parsed as `EmptyTree`. This is consistent with the parsing of empty Scala compilation units. Fixes #13310
1 parent 8bb0ca7 commit fbea0ff

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,9 @@ object JavaParsers {
10131013
}
10141014
val unit = atSpan(start) { PackageDef(pkg, buf.toList) }
10151015
accept(EOF)
1016-
unit
1016+
unit match
1017+
case PackageDef(Ident(nme.EMPTY_PACKAGE), Nil) => EmptyTree
1018+
case _ => unit
10171019
}
10181020
}
10191021

tests/pos/i13310.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// The entire contents of this file is intentionally commented out
2+
// public class i13310 {}

0 commit comments

Comments
 (0)