diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 3b743906fd51..e479e18a829e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -709,6 +709,7 @@ object Checking { def checkValue(tree: Tree)(using Context): Unit = val sym = tree.tpe.termSymbol + sym.ensureCompleted() if sym.is(Flags.Package) || sym.isAllOf(Flags.JavaModule) && !ctx.isJava then report.error(JavaSymbolIsNotAValue(sym), tree.srcPos) diff --git a/compiler/test/dotty/tools/repl/JavaDefinedTests.scala b/compiler/test/dotty/tools/repl/JavaDefinedTests.scala new file mode 100644 index 000000000000..d3c86364fc60 --- /dev/null +++ b/compiler/test/dotty/tools/repl/JavaDefinedTests.scala @@ -0,0 +1,16 @@ +package dotty.tools.repl + +import org.junit.Assert._ +import org.junit.Test + +class JavaDefinedTests extends ReplTest { + @Test def typeOfJavaDefinedString = fromInitialState { implicit s => + run("String") + assertTrue(storedOutput().contains("Java defined class String is not a value")) + } + + @Test def typeOfJavaDefinedClass = fromInitialState { implicit s => + run("Class") + assertTrue(storedOutput().contains("Java defined class Class is not a value")) + } +}