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 {
|
public void testPackageProperty() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/javaVisibility/package/packageProperty.kt");
|
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
|
@Nested
|
||||||
|
|||||||
@@ -148,9 +148,12 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
|||||||
): FirClassLikeDeclaration? {
|
): FirClassLikeDeclaration? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is FirCallableDeclaration -> {
|
is FirCallableDeclaration -> {
|
||||||
if (dispatchReceiverValue != null && dispatchReceiverType != null) {
|
if (dispatchReceiverValue != null) {
|
||||||
dispatchReceiverValue.type.findClassRepresentation(dispatchReceiverType!!, session)?.toSymbol(session)?.fir?.let {
|
val baseReceiverType = dispatchReceiverClassTypeOrNull()
|
||||||
return it
|
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? =
|
fun FirCallableSymbol<*>.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? =
|
||||||
fir.dispatchReceiverClassOrNull()
|
fir.dispatchReceiverClassOrNull()
|
||||||
|
|
||||||
fun FirCallableDeclaration.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? {
|
fun FirCallableDeclaration.dispatchReceiverClassTypeOrNull(): ConeClassLikeType? =
|
||||||
if (dispatchReceiverType is ConeIntersectionType && isIntersectionOverride) return symbol.baseForIntersectionOverride!!.fir.dispatchReceiverClassOrNull()
|
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 FirCallableSymbol<*>.containingClassLookupTag(): ConeClassLikeLookupTag? = fir.containingClassLookupTag()
|
||||||
fun FirCallableDeclaration.containingClassLookupTag(): ConeClassLikeLookupTag? {
|
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 {
|
public void testPackageProperty() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/javaVisibility/package/packageProperty.kt");
|
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
|
@Nested
|
||||||
|
|||||||
Reference in New Issue
Block a user