diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 073055ba5b58..1f82b9ddc084 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -806,10 +806,11 @@ object Checking { def checkAndAdaptExperimentalImports(trees: List[Tree])(using Context): Unit = def nonExperimentalTopLevelDefs(pack: Symbol): Iterator[Symbol] = def isNonExperimentalTopLevelDefinition(sym: Symbol) = - !sym.isExperimental + sym.isDefinedInCurrentRun && sym.source == ctx.compilationUnit.source && !sym.isConstructor // not constructor of package object && !sym.is(Package) && !sym.name.isPackageObjectName + && !sym.isExperimental pack.info.decls.toList.iterator.flatMap: sym => if sym.isClass && (sym.is(Package) || sym.isPackageObject) then diff --git a/sbt-test/java-compat/moduleInfo/A.scala b/sbt-test/java-compat/moduleInfo/A.scala new file mode 100644 index 000000000000..4b46ae7047d6 --- /dev/null +++ b/sbt-test/java-compat/moduleInfo/A.scala @@ -0,0 +1,2 @@ +// Previously, we crashed trying to parse module-info.class in the empty package. +class A diff --git a/sbt-test/java-compat/moduleInfo/build.sbt b/sbt-test/java-compat/moduleInfo/build.sbt new file mode 100644 index 000000000000..a0308b6cb83a --- /dev/null +++ b/sbt-test/java-compat/moduleInfo/build.sbt @@ -0,0 +1,5 @@ +scalaVersion := sys.props("plugin.scalaVersion") + +scalacOptions ++= Seq( + "-experimental" +) diff --git a/sbt-test/java-compat/moduleInfo/test b/sbt-test/java-compat/moduleInfo/test new file mode 100644 index 000000000000..5df2af1f3956 --- /dev/null +++ b/sbt-test/java-compat/moduleInfo/test @@ -0,0 +1 @@ +> compile