[FIR] Fix exception in scopes caused by property and extension property with the same name in KJK hierarchy
#KT-65373 Fixed
This commit is contained in:
committed by
Space Team
parent
9688865953
commit
d937fb4350
+6
@@ -22074,6 +22074,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kjkPropertyAndExtensionProperty.kt")
|
||||
public void testKjkPropertyAndExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/kjkPropertyAndExtensionProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1402.kt")
|
||||
public void testKt1402() throws Exception {
|
||||
|
||||
+6
@@ -22074,6 +22074,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kjkPropertyAndExtensionProperty.kt")
|
||||
public void testKjkPropertyAndExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/kjkPropertyAndExtensionProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1402.kt")
|
||||
public void testKt1402() throws Exception {
|
||||
|
||||
+6
@@ -22068,6 +22068,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kjkPropertyAndExtensionProperty.kt")
|
||||
public void testKjkPropertyAndExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/kjkPropertyAndExtensionProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1402.kt")
|
||||
public void testKt1402() throws Exception {
|
||||
|
||||
+6
@@ -22074,6 +22074,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kjkPropertyAndExtensionProperty.kt")
|
||||
public void testKjkPropertyAndExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/kjkPropertyAndExtensionProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1402.kt")
|
||||
public void testKt1402() throws Exception {
|
||||
|
||||
+11
-11
@@ -46,7 +46,6 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
|
||||
/**
|
||||
@@ -141,8 +140,8 @@ class JavaClassUseSiteMemberScope(
|
||||
}
|
||||
|
||||
/*
|
||||
* From supertype we can get at most two results:
|
||||
* 1. Set of properties with same name
|
||||
* From supertype we can get:
|
||||
* 1. Set of properties with same name (including regular and extension properties)
|
||||
* 2. Field from some java superclass (only one, if class have more than one superclass then we can choose
|
||||
* just one field because this is incorrect code anyway)
|
||||
*/
|
||||
@@ -153,23 +152,24 @@ class JavaClassUseSiteMemberScope(
|
||||
}
|
||||
|
||||
assert(fieldsFromSupertype.size in 0..1)
|
||||
assert(propertiesFromSupertypes.size in 0..1)
|
||||
|
||||
fieldsFromSupertype.firstOrNull()?.chosenSymbol?.let { fieldSymbol ->
|
||||
require(fieldSymbol is FirFieldSymbol)
|
||||
if (fieldSymbol.name !in fieldNames) {
|
||||
result.addIfNotNull(fieldSymbol)
|
||||
result.add(fieldSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val overriddenProperty = propertiesFromSupertypes.firstOrNull() as ResultOfIntersection<FirPropertySymbol>? ?: return result
|
||||
val overrideInClass = syntheticPropertyCache.getValue(name, this to overriddenProperty)
|
||||
for (overriddenProperty in propertiesFromSupertypes as List<ResultOfIntersection<FirPropertySymbol>>) {
|
||||
val overrideInClass = syntheticPropertyCache.getValue(name, this to overriddenProperty)
|
||||
|
||||
val chosenSymbol = overrideInClass ?: overriddenProperty.chosenSymbol
|
||||
directOverriddenProperties[chosenSymbol] = listOf(overriddenProperty)
|
||||
overriddenProperty.overriddenMembers.forEach { overrideByBase[it.member] = overrideInClass }
|
||||
result += chosenSymbol
|
||||
}
|
||||
|
||||
val chosenSymbol = overrideInClass ?: overriddenProperty.chosenSymbol
|
||||
directOverriddenProperties[chosenSymbol] = listOf(overriddenProperty)
|
||||
overriddenProperty.overriddenMembers.forEach { overrideByBase[it.member] = overrideInClass }
|
||||
result += chosenSymbol
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
// ISSUE: KT-65373, KT-65464
|
||||
|
||||
// FILE: J.java
|
||||
public class J extends D {}
|
||||
|
||||
// FILE: JOverridesRegular.java
|
||||
public class JOverridesRegular extends D {
|
||||
@Override
|
||||
public int getA() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: JOverridesExtension.java
|
||||
public class JOverridesExtension extends D {
|
||||
@Override
|
||||
public int getA(String $this) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: JOVerridesBoth.java
|
||||
public class JOVerridesBoth extends D {
|
||||
@Override
|
||||
public int getA() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getA(String $this) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
open class D {
|
||||
open val a: Int
|
||||
get() = 2
|
||||
|
||||
open val String.a: Int
|
||||
get() = 1
|
||||
}
|
||||
|
||||
class F : J() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
|
||||
class F2 : JOverridesRegular() {
|
||||
fun test() {
|
||||
a
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>
|
||||
}
|
||||
}
|
||||
|
||||
class F3 : JOverridesExtension() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
|
||||
class F4 : JOVerridesBoth() {
|
||||
fun test() {
|
||||
a
|
||||
"".<!UNRESOLVED_REFERENCE!>a<!>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// ISSUE: KT-65373, KT-65464
|
||||
|
||||
// FILE: J.java
|
||||
public class J extends D {}
|
||||
|
||||
// FILE: JOverridesRegular.java
|
||||
public class JOverridesRegular extends D {
|
||||
@Override
|
||||
public int getA() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: JOverridesExtension.java
|
||||
public class JOverridesExtension extends D {
|
||||
@Override
|
||||
public int getA(String $this) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: JOVerridesBoth.java
|
||||
public class JOVerridesBoth extends D {
|
||||
@Override
|
||||
public int getA() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getA(String $this) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 1.kt
|
||||
open class D {
|
||||
open val a: Int
|
||||
get() = 2
|
||||
|
||||
open val String.a: Int
|
||||
get() = 1
|
||||
}
|
||||
|
||||
class F : J() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
|
||||
class F2 : JOverridesRegular() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
|
||||
class <!CONFLICTING_INHERITED_JVM_DECLARATIONS!>F3<!> : JOverridesExtension() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
|
||||
class <!CONFLICTING_INHERITED_JVM_DECLARATIONS!>F4<!> : JOVerridesBoth() {
|
||||
fun test() {
|
||||
a
|
||||
"".a
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -22074,6 +22074,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/KJKInheritanceGeneric.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kjkPropertyAndExtensionProperty.kt")
|
||||
public void testKjkPropertyAndExtensionProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/j+k/kjkPropertyAndExtensionProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1402.kt")
|
||||
public void testKt1402() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user