K2 JVM: Take JVM declarations conflicting error back

Since SimpleDiagnosticsCollectorWithSuppress have been replaced by
PendingDiagnosticsCollectorWithSuppress after commit 9add6f3d55,
diagnostics need to be committed now.

#KT-54366 Fixed
This commit is contained in:
Xin Wang
2022-10-09 14:24:39 +08:00
committed by Space Team
parent 51619e0969
commit 69a4de0461
6 changed files with 52 additions and 1 deletions
@@ -38,6 +38,10 @@ open class KtDiagnosticReporterWithContext(
) : DiagnosticReporter() {
override fun report(diagnostic: KtDiagnostic?, context: DiagnosticContext) = diagnosticReporter.report(diagnostic, context)
override fun checkAndCommitReportsOn(element: AbstractKtSourceElement, context: DiagnosticContext?) {
diagnosticReporter.checkAndCommitReportsOn(element, context)
}
open fun at(sourceElement: AbstractKtSourceElement?, containingFilePath: String): DiagnosticContextImpl =
DiagnosticContextImpl(sourceElement, containingFilePath)
@@ -81,6 +85,13 @@ open class KtDiagnosticReporterWithContext(
sourceElement?.let { report(factory.on(it, a1, a2, positioningStrategy), this) }
}
fun <A : Any> reportAndCommit(factory: KtDiagnosticFactory1<A>, a: A) {
sourceElement?.let {
reportOn(it, factory, a, this)
checkAndCommitReportsOn(it, this)
}
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is DiagnosticContextImpl) return false
@@ -147,7 +147,7 @@ class JvmSignatureClashDetector(
irDeclarations.mapNotNullTo(LinkedHashSet()) { irDeclaration ->
classCodegen.context.ktDiagnosticReporter.atFirstValidFrom(irDeclaration, classCodegen.irClass, containingIrFile = irDeclaration.file)
}.forEach {
it.report(diagnosticFactory1, conflictingJvmDeclarationsData)
it.reportAndCommit(diagnosticFactory1, conflictingJvmDeclarationsData)
}
}
@@ -0,0 +1,4 @@
$TESTDATA_DIR$/conflictingJvmDeclarations.kt
-Xuse-k2
-d
$TEMP_DIR$
@@ -0,0 +1,9 @@
class Foo {
val x: Int
get() = 42
fun getX() = 42
@JvmName("getX")
fun getY() = 42
}
@@ -0,0 +1,22 @@
warning: ATTENTION!
This build uses experimental K2 compiler:
-Xuse-k2
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:2:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
fun `<get-x>`(): Int defined in Foo
fun getX(): Int defined in Foo
fun getY(): Int defined in Foo
val x: Int
^
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:5:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
fun `<get-x>`(): Int defined in Foo
fun getX(): Int defined in Foo
fun getY(): Int defined in Foo
fun getX() = 42
^
compiler/testData/cli/jvm/conflictingJvmDeclarations.kt:7:5: error: platform declaration clash: The following declarations have the same JVM signature (getX()I):
fun `<get-x>`(): Int defined in Foo
fun getX(): Int defined in Foo
fun getY(): Int defined in Foo
@JvmName("getX")
^
COMPILATION_ERROR
@@ -237,6 +237,11 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/compatqualWrong.args");
}
@TestMetadata("conflictingJvmDeclarations.args")
public void testConflictingJvmDeclarations() throws Exception {
runTest("compiler/testData/cli/jvm/conflictingJvmDeclarations.args");
}
@TestMetadata("conflictingOverloads.args")
public void testConflictingOverloads() throws Exception {
runTest("compiler/testData/cli/jvm/conflictingOverloads.args");