FIR2IR: Unwrap intersection overrides for intersection types
This commit is contained in:
@@ -232,7 +232,19 @@ internal tailrec fun FirCallableSymbol<*>.unwrapCallRepresentative(root: FirCall
|
|||||||
val originalForTypeAlias = fir.originalConstructorIfTypeAlias
|
val originalForTypeAlias = fir.originalConstructorIfTypeAlias
|
||||||
if (originalForTypeAlias != null) return originalForTypeAlias.symbol.unwrapCallRepresentative(this)
|
if (originalForTypeAlias != null) return originalForTypeAlias.symbol.unwrapCallRepresentative(this)
|
||||||
}
|
}
|
||||||
if (fir.isIntersectionOverride) return this
|
|
||||||
|
if (fir.isIntersectionOverride) {
|
||||||
|
// We've got IR declarations (fake overrides) for intersection overrides in classes, but not for intersection types
|
||||||
|
// interface A { fun foo() }
|
||||||
|
// interface B { fun foo() }
|
||||||
|
// interface C : A, B // for C.foo we've got an IR fake override
|
||||||
|
// for {A & B} we don't have such an IR declaration, so we're unwrapping it
|
||||||
|
if (fir is FirCallableMemberDeclaration && fir.dispatchReceiverType is ConeIntersectionType) {
|
||||||
|
return fir.baseForIntersectionOverride!!.symbol.unwrapCallRepresentative(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
val overriddenSymbol = fir.originalForSubstitutionOverride?.takeIf {
|
val overriddenSymbol = fir.originalForSubstitutionOverride?.takeIf {
|
||||||
it.containingClass() == root.containingClass()
|
it.containingClass() == root.containingClass()
|
||||||
|
|||||||
+5
@@ -150,6 +150,11 @@ public class FirCompileKotlinAgainstKotlinTestGenerated extends AbstractFirCompi
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fakeOverridesForIntersectionTypes.kt")
|
||||||
|
public void testFakeOverridesForIntersectionTypes() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("importCompanion.kt")
|
@TestMetadata("importCompanion.kt")
|
||||||
public void testImportCompanion() throws Exception {
|
public void testImportCompanion() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// FILE: A.kt
|
||||||
|
package a
|
||||||
|
|
||||||
|
interface T {
|
||||||
|
var x: String
|
||||||
|
}
|
||||||
|
|
||||||
|
interface A : T {
|
||||||
|
override var x: String
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B : T {
|
||||||
|
override var x: String
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : A, B {
|
||||||
|
override var x: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : A, B {
|
||||||
|
override var x: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: B.kt
|
||||||
|
import a.*
|
||||||
|
|
||||||
|
fun foo(condition: Boolean): String {
|
||||||
|
val aAndB = if (condition) C() else D()
|
||||||
|
aAndB.x = "OK"
|
||||||
|
|
||||||
|
return aAndB.x
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (foo(true) != "OK") return "fail 1"
|
||||||
|
if (foo(false) != "OK") return "fail 2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
Generated
+5
@@ -149,6 +149,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fakeOverridesForIntersectionTypes.kt")
|
||||||
|
public void testFakeOverridesForIntersectionTypes() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("importCompanion.kt")
|
@TestMetadata("importCompanion.kt")
|
||||||
public void testImportCompanion() throws Exception {
|
public void testImportCompanion() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
||||||
|
|||||||
Generated
+5
@@ -150,6 +150,11 @@ public class IrCompileKotlinAgainstKotlinTestGenerated extends AbstractIrCompile
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fakeOverridesForIntersectionTypes.kt")
|
||||||
|
public void testFakeOverridesForIntersectionTypes() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("importCompanion.kt")
|
@TestMetadata("importCompanion.kt")
|
||||||
public void testImportCompanion() throws Exception {
|
public void testImportCompanion() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
||||||
|
|||||||
+5
@@ -150,6 +150,11 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fakeOverridesForIntersectionTypes.kt")
|
||||||
|
public void testFakeOverridesForIntersectionTypes() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("importCompanion.kt")
|
@TestMetadata("importCompanion.kt")
|
||||||
public void testImportCompanion() throws Exception {
|
public void testImportCompanion() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
||||||
|
|||||||
+5
@@ -150,6 +150,11 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
|
|||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("fakeOverridesForIntersectionTypes.kt")
|
||||||
|
public void testFakeOverridesForIntersectionTypes() throws Exception {
|
||||||
|
runTest("compiler/testData/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("importCompanion.kt")
|
@TestMetadata("importCompanion.kt")
|
||||||
public void testImportCompanion() throws Exception {
|
public void testImportCompanion() throws Exception {
|
||||||
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
runTest("compiler/testData/compileKotlinAgainstKotlin/importCompanion.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user