Fix a bug where kotlin common classes were seen as missing dependencies

When kotlin referred to them through java signatures
Java resolver ignores expect classes

 #KT-24185 Fixed
This commit is contained in:
Pavel V. Talanov
2018-08-17 18:10:08 +02:00
parent 7087a1b3f5
commit 3a8499b10e
19 changed files with 197 additions and 2 deletions
@@ -29,7 +29,8 @@ abstract class AbstractJavaResolverCache(private val resolveSession: ResolveSess
protected val trace: BindingTrace get() = resolveSession.trace
override fun getClassResolvedFromSource(fqName: FqName): ClassDescriptor? {
return trace.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe()) ?: findInPackageFragments(fqName)
return trace.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe())?.takeUnless { it.isExpect }
?: findInPackageFragments(fqName)
}
private fun findInPackageFragments(fullFqName: FqName): ClassDescriptor? {
@@ -123,7 +123,7 @@ internal class ProjectResolutionFacade(
packagePartProviderFactory = { IDEPackagePartProvider(it.moduleContentScope) },
moduleByJavaClass = { javaClass: JavaClass ->
val psiClass = (javaClass as JavaClassImpl).psi
psiClass.getNullableModuleInfo()
psiClass.getPlatformModuleInfo(JvmPlatform)?.platformModule ?: psiClass.getNullableModuleInfo()
}
)
@@ -0,0 +1,3 @@
package common
class A<T1, T2>(val t1: T1, val t2: T2)
@@ -0,0 +1,13 @@
package j1;
import common.A;
public class Use {
public static A<String, String> returnA() {
return new A<String, String>("", "");
}
public static void acceptA(A<String, String> a) {
}
}
@@ -0,0 +1,5 @@
package j1
fun j() {
Use.acceptA(Use.returnA())
}
@@ -0,0 +1,13 @@
package j2;
import common.A;
public class Use {
public static A<String, String> returnA() {
return new A<String, String>("", "");
}
public static void acceptA(A<String, String> a) {
}
}
@@ -0,0 +1,5 @@
package j2
fun j() {
Use.acceptA(Use.returnA())
}
@@ -0,0 +1,18 @@
package j1;
import common.A;
public class Use {
public static void use() {
A a = new A();
a.id1();
}
public static void acceptA(A a) {
}
public static A returnA() {
return new A();
}
}
@@ -0,0 +1,11 @@
package common
actual class A {
fun id1() {}
}
fun use() {
j2.Use.acceptA(j2.Use.returnA())
j2.Use.returnA().id2()
}
@@ -0,0 +1,18 @@
package j2;
import common.A;
public class Use {
public static void use() {
A a = new A();
a.id2();
}
public static void acceptA(A a) {
}
public static A returnA() {
return new A();
}
}
@@ -0,0 +1,11 @@
package common
actual class A {
fun id2() {}
}
fun use() {
j2.Use.acceptA(j2.Use.returnA())
j2.Use.returnA().id2()
}
@@ -0,0 +1,17 @@
package j;
import common.A;
public class Use {
public static void use(A a) {
a.id2();
}
public static void acceptA(A a) {
}
public static A returnA() {
return new A();
}
}
@@ -0,0 +1,11 @@
package b
import common.A
fun use(a: A) {
a.id2()
j.Use.acceptA(j.Use.returnA())
val a2: A = j.Use.returnA()
a2.id2()
j.Use.returnA().id2()
}
@@ -0,0 +1,17 @@
package j;
import common.A;
public class Use {
public static void use(A a) {
a.id1();
}
public static void acceptA(A a) {
}
public static A returnA() {
return new A();
}
}
@@ -0,0 +1,11 @@
package c
import common.A
fun use(a: A) {
// errors happen when common module part appears before platform part in dependencies list
// this is incorrect behaviour but doesn't seem to lead to user facing bugs atm
a.<error>id1</error>()
val a2: A = j.Use.returnA()
a2.<error>id1</error>()
}
@@ -0,0 +1,17 @@
package j;
import common.A;
public class Use {
public static void use(A a) {
a.id1();
}
public static void acceptA(A a) {
}
public static A returnA() {
return new A();
}
}
@@ -0,0 +1,11 @@
package c
import common.A
fun use(a: A) {
a.id1()
j.Use.acceptA(j.Use.returnA())
j.Use.returnA().id1()
val a2: A = j.Use.returnA()
a2.id1()
}
@@ -99,6 +99,16 @@ public class MultiPlatformHighlightingTestGenerated extends AbstractMultiPlatfor
runTest("idea/testData/multiModuleHighlighting/multiplatform/javaUsesPlatformFacade/");
}
@TestMetadata("jvmKotlinReferencesCommonKotlinThroughJava")
public void testJvmKotlinReferencesCommonKotlinThroughJava() throws Exception {
runTest("idea/testData/multiModuleHighlighting/multiplatform/jvmKotlinReferencesCommonKotlinThroughJava/");
}
@TestMetadata("jvmKotlinReferencesCommonKotlinThroughJavaDifferentJvmImpls")
public void testJvmKotlinReferencesCommonKotlinThroughJavaDifferentJvmImpls() throws Exception {
runTest("idea/testData/multiModuleHighlighting/multiplatform/jvmKotlinReferencesCommonKotlinThroughJavaDifferentJvmImpls/");
}
@TestMetadata("multifileFacade")
public void testMultifileFacade() throws Exception {
runTest("idea/testData/multiModuleHighlighting/multiplatform/multifileFacade/");