JVM: restore incorrect DFS logic in JavaModuleGraph for compatibility
The problem is tracked in KT-66622. It should be fixed later, with a proper deprecation, because otherwise it can potentially break a lot of code.
This commit is contained in:
committed by
Space Team
parent
94e5cafb61
commit
621fe41b17
@@ -78,6 +78,9 @@ class JavaModuleGraph(finder: JavaModuleFinder) {
|
|||||||
for ((dependencyModuleName, isTransitive) in module.moduleInfo.requires) {
|
for ((dependencyModuleName, isTransitive) in module.moduleInfo.requires) {
|
||||||
if (dependencyModuleName == dependencyName) return true
|
if (dependencyModuleName == dependencyName) return true
|
||||||
if (isTransitive && dfs(dependencyModuleName)) return true
|
if (isTransitive && dfs(dependencyModuleName)) return true
|
||||||
|
|
||||||
|
// This is incorrect, but is left for compatibility, see KT-66622.
|
||||||
|
if (isTransitive && dfs(dependencyName)) return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
public class Foo {}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
module main {
|
||||||
|
requires transitive kotlin.stdlib;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
val a = foo.Foo()
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
public class Foo {}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
module main {
|
||||||
|
requires kotlin.stdlib;
|
||||||
|
|
||||||
|
requires transitive unrelated;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
val a = foo.Foo()
|
||||||
compiler/testData/javaModules/namedDoesNotReadAutomaticWithUnrelatedNamed/unrelated/module-info.java
Vendored
+3
@@ -0,0 +1,3 @@
|
|||||||
|
module unrelated {
|
||||||
|
exports unrelated;
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package unrelated;
|
||||||
|
|
||||||
|
public class Unrelated {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
public class Foo {}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
module main {
|
||||||
|
requires kotlin.stdlib;
|
||||||
|
requires unrelated;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
val a = foo.Foo()
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package unrelated;
|
||||||
|
|
||||||
|
public class Unrelated {}
|
||||||
@@ -387,4 +387,27 @@ abstract class AbstractJavaModulesIntegrationTest(
|
|||||||
val lib = module("lib", destination = File(tmpdir, name))
|
val lib = module("lib", destination = File(tmpdir, name))
|
||||||
module("main", additionalKotlinArguments = listOf("-classpath", lib.path))
|
module("main", additionalKotlinArguments = listOf("-classpath", lib.path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testNamedDoesNotReadAutomaticWithUnrelatedNamed() {
|
||||||
|
// This test should result in an error because 'main' does not depend on 'lib' or any other automatic module.
|
||||||
|
// But currently it's OK for compatibility, see KT-66622.
|
||||||
|
val lib = module("lib")
|
||||||
|
val unrelated = module("unrelated")
|
||||||
|
module("main", listOf(lib, unrelated))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNamedDoesNotReadAutomaticWithTransitiveStdlib() {
|
||||||
|
// This test should result in an error because 'main' does not depend on 'lib' or any other automatic module.
|
||||||
|
// But currently it's OK for compatibility, see KT-66622.
|
||||||
|
val lib = module("lib")
|
||||||
|
module("main", listOf(lib))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testNamedReadsAutomaticWithUnrelatedAutomatic() {
|
||||||
|
// Similarly to how it works in javac, if we depend on one automatic module, we depend on all of them. So even though 'main' does
|
||||||
|
// not have explicit "requires lib", in fact it depends on 'lib' because it has "requires unrelated". So "OK" is expected.
|
||||||
|
val lib = module("lib")
|
||||||
|
val unrelated = module("unrelated")
|
||||||
|
module("main", listOf(lib, unrelated))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user