FIR: unwrap intersection overrides when looking for owner class
But not substitution overrides! This is important if the method called is an intersection override where one of the intersected types is a subtype of a generic type.
This commit is contained in:
+6
@@ -28763,6 +28763,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testPackageProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaVisibility/package/packageProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("publicInterfaceImplementedByPackagePrivateClass.kt")
|
||||
public void testPublicInterfaceImplementedByPackagePrivateClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaVisibility/package/publicInterfaceImplementedByPackagePrivateClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
@@ -148,9 +148,12 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
): FirClassLikeDeclaration? {
|
||||
return when (this) {
|
||||
is FirCallableDeclaration -> {
|
||||
if (dispatchReceiverValue != null && dispatchReceiverType != null) {
|
||||
dispatchReceiverValue.type.findClassRepresentation(dispatchReceiverType!!, session)?.toSymbol(session)?.fir?.let {
|
||||
return it
|
||||
if (dispatchReceiverValue != null) {
|
||||
val baseReceiverType = dispatchReceiverClassTypeOrNull()
|
||||
if (baseReceiverType != null) {
|
||||
dispatchReceiverValue.type.findClassRepresentation(baseReceiverType, session)?.toSymbol(session)?.fir?.let {
|
||||
return it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,14 @@ fun FirCallableSymbol<*>.dispatchReceiverTypeOrNull(): ConeKotlinType? =
|
||||
fun FirCallableSymbol<*>.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? =
|
||||
fir.dispatchReceiverClassOrNull()
|
||||
|
||||
fun FirCallableDeclaration.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? {
|
||||
if (dispatchReceiverType is ConeIntersectionType && isIntersectionOverride) return symbol.baseForIntersectionOverride!!.fir.dispatchReceiverClassOrNull()
|
||||
fun FirCallableDeclaration.dispatchReceiverClassTypeOrNull(): ConeClassLikeType? =
|
||||
if (dispatchReceiverType is ConeIntersectionType && isIntersectionOverride)
|
||||
baseForIntersectionOverride!!.dispatchReceiverClassTypeOrNull()
|
||||
else
|
||||
dispatchReceiverType as? ConeClassLikeType
|
||||
|
||||
return (dispatchReceiverType as? ConeClassLikeType)?.lookupTag
|
||||
}
|
||||
fun FirCallableDeclaration.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? =
|
||||
dispatchReceiverClassTypeOrNull()?.lookupTag
|
||||
|
||||
fun FirCallableSymbol<*>.containingClassLookupTag(): ConeClassLikeLookupTag? = fir.containingClassLookupTag()
|
||||
fun FirCallableDeclaration.containingClassLookupTag(): ConeClassLikeLookupTag? {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// MODULE: lib
|
||||
// FILE: I.java
|
||||
package test;
|
||||
|
||||
public interface I {
|
||||
String foo();
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
package test;
|
||||
|
||||
class JBase<T> {
|
||||
public String foo() { return "OK"; }
|
||||
}
|
||||
|
||||
public class J extends JBase<String> {}
|
||||
|
||||
// FILE: JImpl.java
|
||||
package test;
|
||||
|
||||
public class JImpl {
|
||||
public static class C1 extends J implements I {}
|
||||
public static class C2 extends J implements I {}
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: main.kt
|
||||
import test.JImpl
|
||||
|
||||
fun <T> select(a: T, b: T): T = a
|
||||
|
||||
fun box() = select(JImpl.C1(), JImpl.C2()).foo()
|
||||
+6
@@ -28763,6 +28763,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testPackageProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaVisibility/package/packageProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("publicInterfaceImplementedByPackagePrivateClass.kt")
|
||||
public void testPublicInterfaceImplementedByPackagePrivateClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaVisibility/package/publicInterfaceImplementedByPackagePrivateClass.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user