From fbea0ff750306f3427bebcbd524f6fe7be3134f9 Mon Sep 17 00:00:00 2001 From: Tom Grigg Date: Tue, 24 Aug 2021 15:46:06 -0700 Subject: [PATCH] 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(),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 --- compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala | 4 +++- tests/pos/i13310.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i13310.java diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index c9514eeb7cd4..e5b0b24bdd2f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -1013,7 +1013,9 @@ object JavaParsers { } val unit = atSpan(start) { PackageDef(pkg, buf.toList) } accept(EOF) - unit + unit match + case PackageDef(Ident(nme.EMPTY_PACKAGE), Nil) => EmptyTree + case _ => unit } } diff --git a/tests/pos/i13310.java b/tests/pos/i13310.java new file mode 100644 index 000000000000..7553cbc3130c --- /dev/null +++ b/tests/pos/i13310.java @@ -0,0 +1,2 @@ +// The entire contents of this file is intentionally commented out +// public class i13310 {}