Do not add all modules from module path when compiling unnamed module
Note that javac reports a nice error in this case ("package foo is
declared in module lib, which is not in the module graph"), but we only
report "unresolved reference" because the corresponding modules are not
added to classpath roots. We should improve this in the future
#KT-18598 In Progress
This commit is contained in:
@@ -144,7 +144,7 @@ internal class ClasspathRootsResolver(
|
||||
val rootModules = when {
|
||||
sourceModules.isNotEmpty() -> listOf(sourceModules.single().name) + additionalModules
|
||||
addAllModulePathToRoots -> modules.map(JavaModule::name)
|
||||
else -> computeDefaultRootModules() + modules.map(JavaModule::name)
|
||||
else -> computeDefaultRootModules() + additionalModules
|
||||
}
|
||||
|
||||
// TODO: if at least one automatic module is added, add all automatic modules as per java.lang.module javadoc
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package foo;
|
||||
|
||||
public class Foo {}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
module moduleA {
|
||||
exports foo;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
compiler/testData/javaModules/unnamedDoesNotReadNotAdded/moduleB/usage.kt:1:8: error: unresolved reference: foo
|
||||
import foo.Foo
|
||||
^
|
||||
compiler/testData/javaModules/unnamedDoesNotReadNotAdded/moduleB/usage.kt:4:5: error: unresolved reference: Foo
|
||||
Foo()
|
||||
^
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,5 @@
|
||||
import foo.Foo
|
||||
|
||||
fun usage() {
|
||||
Foo()
|
||||
}
|
||||
@@ -101,4 +101,10 @@ class Java9ModulesIntegrationTest : AbstractKotlinCompilerIntegrationTest() {
|
||||
fun testJdkModulesFromUnnamed() {
|
||||
module("main")
|
||||
}
|
||||
|
||||
fun testUnnamedDoesNotReadNotAdded() {
|
||||
// Test that although we have moduleA in the module path, it's not in the module graph
|
||||
// because we did not provide -Xadd-modules=moduleA
|
||||
module("moduleB", listOf(module("moduleA")), addModules = emptyList())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user