[K2, MPP] Fix reporting of MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED
This commit is contained in:
committed by
Space Team
parent
60edf1def3
commit
cd07eba25c
+6
@@ -85,6 +85,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/kt54827.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("manyInterfacesMemberNotImplemented.kt")
|
||||
public void testManyInterfacesMemberNotImplemented() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/manyInterfacesMemberNotImplemented.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("modifierApplicability.kt")
|
||||
public void testModifierApplicability() throws Exception {
|
||||
|
||||
+6
@@ -85,6 +85,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/kt54827.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("manyInterfacesMemberNotImplemented.kt")
|
||||
public void testManyInterfacesMemberNotImplemented() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/manyInterfacesMemberNotImplemented.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("modifierApplicability.kt")
|
||||
public void testModifierApplicability() throws Exception {
|
||||
|
||||
-4
@@ -153,10 +153,6 @@ fun KtDiagnosticReporterWithImplicitIrBasedContext.reportMissingActual(irDeclara
|
||||
at(irDeclaration).report(CommonBackendErrors.NO_ACTUAL_FOR_EXPECT, irDeclaration.module)
|
||||
}
|
||||
|
||||
fun KtDiagnosticReporterWithImplicitIrBasedContext.reportManyInterfacesMembersNotImplemented(declaration: IrClass, actualMember: IrDeclarationWithName) {
|
||||
at(declaration).report(CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED, actualMember.name.asString())
|
||||
}
|
||||
|
||||
internal fun IrElement.containsOptionalExpectation(): Boolean {
|
||||
return this is IrClass &&
|
||||
this.kind == ClassKind.ANNOTATION_CLASS &&
|
||||
|
||||
+20
-16
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.common.actualizer
|
||||
|
||||
import org.jetbrains.kotlin.KtDiagnosticReporterWithImplicitIrBasedContext
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendErrors
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildProperty
|
||||
@@ -39,7 +40,7 @@ class MissingFakeOverridesAdder(
|
||||
|
||||
private fun processSupertypes(declaration: IrClass) {
|
||||
val members by lazy(LazyThreadSafetyMode.NONE) {
|
||||
val notBuiltinMembers = declaration.declarations.filter { !it.isBuiltinMember() }
|
||||
val notBuiltinMembers = declaration.declarations.filterNot { it.isBuiltinMember() }
|
||||
val result = mutableMapOf<String, MutableList<IrDeclaration>>()
|
||||
for (member in notBuiltinMembers) {
|
||||
result.getOrPut(generateIrElementFullNameFromExpect(member, typeAliasMap)) { mutableListOf() }.add(member)
|
||||
@@ -71,22 +72,25 @@ class MissingFakeOverridesAdder(
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFakeOverride(actualMember: IrDeclaration, members: Map<String, List<IrDeclaration>>, declaration: IrClass) {
|
||||
when (actualMember) {
|
||||
is IrFunctionImpl,
|
||||
is IrPropertyImpl -> {
|
||||
if (members.getMatch(actualMember, expectActualMap, typeAliasMap) != null) {
|
||||
diagnosticsReporter.reportManyInterfacesMembersNotImplemented(declaration, actualMember as IrDeclarationWithName)
|
||||
return
|
||||
}
|
||||
private fun addFakeOverride(
|
||||
actualMember: IrDeclaration,
|
||||
members: MutableMap<String, MutableList<IrDeclaration>>,
|
||||
declaration: IrClass
|
||||
) {
|
||||
val newMember = when (actualMember) {
|
||||
is IrFunctionImpl -> createFakeOverrideFunction(actualMember, declaration)
|
||||
is IrPropertyImpl -> createFakeOverrideProperty(actualMember, declaration)
|
||||
else -> return
|
||||
}
|
||||
|
||||
val newMember = if (actualMember is IrFunctionImpl) {
|
||||
createFakeOverrideFunction(actualMember, declaration)
|
||||
} else {
|
||||
createFakeOverrideProperty(actualMember as IrPropertyImpl, declaration)
|
||||
}
|
||||
declaration.declarations.add(newMember)
|
||||
}
|
||||
if (members.getMatch(newMember, expectActualMap, typeAliasMap) == null) {
|
||||
declaration.declarations.add(newMember)
|
||||
members.getOrPut(generateIrElementFullNameFromExpect(newMember, typeAliasMap)) { mutableListOf() }.add(newMember)
|
||||
} else {
|
||||
diagnosticsReporter.at(declaration).report(
|
||||
CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED,
|
||||
(actualMember as IrDeclarationWithName).name.asString()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: common.kt
|
||||
|
||||
expect interface S1
|
||||
expect interface S2
|
||||
|
||||
<!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED{JVM}!>open class A : S1, S2<!>
|
||||
|
||||
class B : A()
|
||||
|
||||
// MODULE: jvm()()(common)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: main.kt
|
||||
|
||||
actual interface S1 {
|
||||
fun f() {}
|
||||
}
|
||||
|
||||
actual interface S2 {
|
||||
fun f() {}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: common.kt
|
||||
|
||||
expect interface S1
|
||||
expect interface S2
|
||||
|
||||
open <!MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED{JVM}!>class A<!> : S1, S2
|
||||
|
||||
class B : A()
|
||||
|
||||
// MODULE: jvm()()(common)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: main.kt
|
||||
|
||||
actual interface S1 {
|
||||
fun f() {}
|
||||
}
|
||||
|
||||
actual interface S2 {
|
||||
fun f() {}
|
||||
}
|
||||
Generated
+6
@@ -21732,6 +21732,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/kt54827.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("manyInterfacesMemberNotImplemented.kt")
|
||||
public void testManyInterfacesMemberNotImplemented() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/multiplatform/manyInterfacesMemberNotImplemented.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("modifierApplicability.kt")
|
||||
public void testModifierApplicability() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user