[K2 MPP] Fix hasStableParameterNames check for fake overrides

This fixes a false positive error regarding different
parameter names in expect actual matching with fake overrides.

#KT-59737 Fixed
This commit is contained in:
Kirill Rakhman
2023-07-05 11:24:54 +02:00
committed by Space Team
parent 116de97f54
commit 04f16d75d2
6 changed files with 112 additions and 12 deletions
@@ -730,6 +730,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
runTest("compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.kt");
}
@Test
@TestMetadata("inheritedJavaMembers.kt")
public void testInheritedJavaMembers() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/java/inheritedJavaMembers.kt");
}
@Test
@TestMetadata("parameterNames.kt")
public void testParameterNames() throws Exception {
@@ -730,6 +730,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
runTest("compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.kt");
}
@Test
@TestMetadata("inheritedJavaMembers.kt")
public void testInheritedJavaMembers() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/java/inheritedJavaMembers.kt");
}
@Test
@TestMetadata("parameterNames.kt")
public void testParameterNames() throws Exception {
@@ -9,7 +9,10 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.collectEnumEntries
import org.jetbrains.kotlin.fir.declarations.isAnnotationConstructor
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
@@ -301,10 +304,5 @@ class FirExpectActualMatchingContext(
}
override val CallableSymbolMarker.hasStableParameterNames: Boolean
get() = when (asSymbol().origin) {
is FirDeclarationOrigin.Java,
FirDeclarationOrigin.Enhancement,
FirDeclarationOrigin.DynamicScope -> false
else -> true
}
get() = asSymbol().rawStatus.hasStableParameterNames
}
@@ -407,11 +407,19 @@ internal abstract class IrExpectActualMatchingContext(
}
override val CallableSymbolMarker.hasStableParameterNames: Boolean
get() = when (asIr().origin) {
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB,
-> false
else -> true
get() {
var ir = asIr()
if (ir.isFakeOverride && ir is IrOverridableDeclaration<*>) {
ir.resolveFakeOverrideOrNull()?.let { ir = it }
}
return when (ir.origin) {
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB,
-> false
else -> true
}
}
override fun onMatchedMembers(expectSymbol: DeclarationSymbolMarker, actualSymbol: DeclarationSymbolMarker) {
@@ -0,0 +1,76 @@
// FIR_IDENTICAL
// WITH_STDLIB
// MODULE: m1-common
// FILE: common.kt
interface MutableListEx<E> : MutableList<E> {
fun removeRange(fromIndex: Int, toIndex: Int)
fun addAll(elements: FastArrayList<E>): Boolean = addAll(elements as Collection<E>)
fun setAddAll(index: Int, elements: FastArrayList<E>, offset: Int = 0, size: Int = elements.size - offset) {}
fun setAll(index: Int, elements: FastArrayList<E>, offset: Int = 0, size: Int = elements.size - offset) {}
fun addAll(elements: FastArrayList<E>, offset: Int = 0, size: Int = elements.size - offset) {}
fun removeToSize(size: Int) {}
}
expect class FastArrayList<E> : MutableListEx<E>, RandomAccess {
constructor()
constructor(initialCapacity: Int)
constructor(elements: Collection<E>)
fun trimToSize()
fun ensureCapacity(minCapacity: Int)
override val size: Int
override fun isEmpty(): Boolean
override fun contains(element: @UnsafeVariance E): Boolean
override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
override operator fun get(index: Int): E
override fun indexOf(element: @UnsafeVariance E): Int
override fun lastIndexOf(element: @UnsafeVariance E): Int
override fun iterator(): MutableIterator<E>
override fun add(element: E): Boolean
override fun remove(element: E): Boolean
override fun addAll(elements: Collection<E>): Boolean
override fun addAll(index: Int, elements: Collection<E>): Boolean
override fun removeAll(elements: Collection<E>): Boolean
override fun retainAll(elements: Collection<E>): Boolean
override fun clear()
override operator fun set(index: Int, element: E): E
override fun add(index: Int, element: E)
override fun removeAt(index: Int): E
override fun listIterator(): MutableListIterator<E>
override fun listIterator(index: Int): MutableListIterator<E>
override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>
}
// MODULE: m2-jvm()()(m1-common)
// FILE: jvm.kt
public actual open class FastArrayList<E> internal constructor(
var array: Array<Any?>,
var _size: Int = array.size,
var arrayCapacity: Int = array.size,
) : AbstractMutableList<E>(), MutableListEx<E>, RandomAccess {
public actual constructor() : this(arrayOfNulls(16), 0) {}
public actual constructor(initialCapacity: Int) : this(arrayOfNulls(initialCapacity), 0) {}
public actual constructor(elements: Collection<E>) : this(elements.toTypedArray<Any?>()) {}
public actual fun trimToSize() {}
public actual fun ensureCapacity(minCapacity: Int) {}
actual override val size: Int get() = _size
@Suppress("UNCHECKED_CAST") actual override fun get(index: Int): E = array[0] as E
actual override fun set(index: Int, element: E): E = element
actual override fun add(element: E): Boolean = true
actual override fun add(index: Int, element: E) {}
actual override fun addAll(elements: Collection<E>): Boolean = true
actual override fun addAll(index: Int, elements: Collection<E>): Boolean = true
actual override fun remove(element: E): Boolean = true
@Suppress("UNCHECKED_CAST") actual override fun removeAt(index: Int): E = array[0] as E
override fun removeRange(fromIndex: Int, toIndex: Int) {}
override fun setAll(index: Int, elements: FastArrayList<E>, offset: Int, size: Int) {}
override fun addAll(elements: FastArrayList<E>, offset: Int, size: Int) {}
actual override fun clear() {}
actual override fun contains(element: E): Boolean = false
actual override fun indexOf(element: E): Int = -1
actual override fun lastIndexOf(element: E): Int = -1
}
@@ -23215,6 +23215,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/multiplatform/java/flexibleTypes.kt");
}
@Test
@TestMetadata("inheritedJavaMembers.kt")
public void testInheritedJavaMembers() throws Exception {
runTest("compiler/testData/diagnostics/tests/multiplatform/java/inheritedJavaMembers.kt");
}
@Test
@TestMetadata("parameterNames.kt")
public void testParameterNames() throws Exception {