[K/N][K2]: K2 behavioral difference with inconsistent inheritance of ObjCName
The problem arises when retrieveDirectOverriddenOf returns a substitution override member. For such members, it is impossible to get the first base member. For a correct result, it is required to find originalForSubstitutionOverride for all substitutionOverrides. #KT-64276 Fixed
This commit is contained in:
committed by
Space Team
parent
5525a6829a
commit
434470a4f5
+24
@@ -74,6 +74,30 @@ public class LLFirNativeTestGenerated extends AbstractLLFirNativeTest {
|
|||||||
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName2.kt")
|
||||||
|
public void testObjCName2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName3.kt")
|
||||||
|
public void testObjCName3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName4.kt")
|
||||||
|
public void testObjCName4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName5.kt")
|
||||||
|
public void testObjCName5() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objCRefinement.kt")
|
@TestMetadata("objCRefinement.kt")
|
||||||
public void testObjCRefinement() throws Exception {
|
public void testObjCRefinement() throws Exception {
|
||||||
|
|||||||
+24
@@ -74,6 +74,30 @@ public class LLFirReversedNativeTestGenerated extends AbstractLLFirReversedNativ
|
|||||||
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName2.kt")
|
||||||
|
public void testObjCName2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName3.kt")
|
||||||
|
public void testObjCName3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName4.kt")
|
||||||
|
public void testObjCName4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName5.kt")
|
||||||
|
public void testObjCName5() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objCRefinement.kt")
|
@TestMetadata("objCRefinement.kt")
|
||||||
public void testObjCRefinement() throws Exception {
|
public void testObjCRefinement() throws Exception {
|
||||||
|
|||||||
+3
-5
@@ -8,12 +8,10 @@ package org.jetbrains.kotlin.fir.analysis.native.checkers
|
|||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope
|
import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.native.FirNativeErrors
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.native.FirNativeErrors
|
||||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||||
@@ -74,7 +72,7 @@ object FirNativeObjCNameUtilities {
|
|||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
reporter: DiagnosticReporter
|
reporter: DiagnosticReporter
|
||||||
) {
|
) {
|
||||||
val overriddenSymbols = firTypeScope.retrieveDirectOverriddenOf(memberSymbol)
|
val overriddenSymbols = firTypeScope.retrieveDirectOverriddenOf(memberSymbol).map { it.originalForSubstitutionOverride ?: it }
|
||||||
if (overriddenSymbols.isEmpty()) return
|
if (overriddenSymbols.isEmpty()) return
|
||||||
val objCNames = overriddenSymbols.map { it.getFirstBaseSymbol(context).getObjCNames(context.session) }
|
val objCNames = overriddenSymbols.map { it.getFirstBaseSymbol(context).getObjCNames(context.session) }
|
||||||
if (!objCNames.allNamesEquals()) {
|
if (!objCNames.allNamesEquals()) {
|
||||||
@@ -95,7 +93,7 @@ object FirNativeObjCNameUtilities {
|
|||||||
val session = context.session
|
val session = context.session
|
||||||
val ownScope = containingClassLookupTag()?.toSymbol(session)?.fullyExpandedClass(session)?.unsubstitutedScope(context)
|
val ownScope = containingClassLookupTag()?.toSymbol(session)?.fullyExpandedClass(session)?.unsubstitutedScope(context)
|
||||||
?: return this
|
?: return this
|
||||||
val overriddenMemberSymbols = ownScope.retrieveDirectOverriddenOf(this)
|
val overriddenMemberSymbols = ownScope.retrieveDirectOverriddenOf(this).map { it.originalForSubstitutionOverride ?: it }
|
||||||
return if (overriddenMemberSymbols.isEmpty()) this else overriddenMemberSymbols.first().getFirstBaseSymbol(context)
|
return if (overriddenMemberSymbols.isEmpty()) this else overriddenMemberSymbols.first().getFirstBaseSymbol(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// FILE: kotlin.kt
|
||||||
|
@file:OptIn(ExperimentalObjCName::class)
|
||||||
|
|
||||||
|
package kotlin.native
|
||||||
|
import kotlin.experimental.ExperimentalObjCName
|
||||||
|
|
||||||
|
fun interface BaseInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MiddleInterface<S> : BaseInterface {
|
||||||
|
override fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DerivedInterface<S> : MiddleInterface<S> {
|
||||||
|
override fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class BaseClass {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DerivedClass : BaseClass(), DerivedInterface<Any> {}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// FILE: kotlin.kt
|
||||||
|
@file:OptIn(ExperimentalObjCName::class)
|
||||||
|
|
||||||
|
package kotlin.native
|
||||||
|
import kotlin.experimental.ExperimentalObjCName
|
||||||
|
|
||||||
|
fun interface BaseInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DerivedInterface<S> : BaseInterface {
|
||||||
|
override fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class BaseClass {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close(){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DerivedClass : BaseClass(), DerivedInterface<Any> {}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// FILE: kotlin.kt
|
||||||
|
@file:OptIn(ExperimentalObjCName::class)
|
||||||
|
|
||||||
|
package kotlin.native
|
||||||
|
|
||||||
|
import kotlin.experimental.ExperimentalObjCName
|
||||||
|
|
||||||
|
fun interface BaseInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DerivedInterface : BaseInterface {
|
||||||
|
override fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface IntersectionInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class IntersectionAbstract<T> {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class IntersectionBaseClass<T> : IntersectionAbstract<T>(), IntersectionInterface
|
||||||
|
|
||||||
|
class DerivedClass : IntersectionBaseClass<Any>(), DerivedInterface {}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// FILE: kotlin.kt
|
||||||
|
@file:OptIn(ExperimentalObjCName::class)
|
||||||
|
|
||||||
|
package kotlin.native
|
||||||
|
|
||||||
|
import kotlin.experimental.ExperimentalObjCName
|
||||||
|
|
||||||
|
fun interface BaseInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DerivedInterface : BaseInterface {
|
||||||
|
override fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun interface IntersectionInterface {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class IntersectionAbstract {
|
||||||
|
@ObjCName("close")
|
||||||
|
fun close() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class IntersectionBaseClass : IntersectionAbstract(), IntersectionInterface
|
||||||
|
|
||||||
|
class DerivedClass : IntersectionBaseClass(), DerivedInterface {}
|
||||||
+24
@@ -72,6 +72,30 @@ public class DiagnosticsNativeTestGenerated extends AbstractDiagnosticsNativeTes
|
|||||||
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName2.kt")
|
||||||
|
public void testObjCName2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName3.kt")
|
||||||
|
public void testObjCName3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName4.kt")
|
||||||
|
public void testObjCName4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName5.kt")
|
||||||
|
public void testObjCName5() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objCRefinement.kt")
|
@TestMetadata("objCRefinement.kt")
|
||||||
public void testObjCRefinement() throws Exception {
|
public void testObjCRefinement() throws Exception {
|
||||||
|
|||||||
+24
@@ -76,6 +76,30 @@ public class FirLightTreeOldFrontendNativeDiagnosticsTestGenerated extends Abstr
|
|||||||
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName2.kt")
|
||||||
|
public void testObjCName2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName3.kt")
|
||||||
|
public void testObjCName3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName4.kt")
|
||||||
|
public void testObjCName4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName5.kt")
|
||||||
|
public void testObjCName5() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objCRefinement.kt")
|
@TestMetadata("objCRefinement.kt")
|
||||||
public void testObjCRefinement() throws Exception {
|
public void testObjCRefinement() throws Exception {
|
||||||
|
|||||||
+24
@@ -76,6 +76,30 @@ public class FirPsiOldFrontendNativeDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
runTest("compiler/testData/diagnostics/nativeTests/objCName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName2.kt")
|
||||||
|
public void testObjCName2() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName3.kt")
|
||||||
|
public void testObjCName3() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName4.kt")
|
||||||
|
public void testObjCName4() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("objCName5.kt")
|
||||||
|
public void testObjCName5() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/nativeTests/objCName5.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objCRefinement.kt")
|
@TestMetadata("objCRefinement.kt")
|
||||||
public void testObjCRefinement() throws Exception {
|
public void testObjCRefinement() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user