K2: report JVM backend errors in the same way in PSI as LT

Do not try to find PSI element, but always use the IR element offsets
instead. This greatly simplifies test data because we don't need to have
custom PSI- and LT- based diagnostic ranges in every test, and K1/K2
behavior also is mostly the same.

The exact offset ranges are not as important for backend diagnostics, so
it's better to have K2+PSI and K2+LT behaving the same.
This commit is contained in:
Alexander Udalov
2023-07-27 19:12:36 +02:00
committed by Space Team
parent 6069aaee9c
commit 965946d3ef
148 changed files with 267 additions and 860 deletions
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.backend.jvm.codegen
import org.jetbrains.kotlin.backend.common.lower.ANNOTATION_IMPLEMENTATION
import org.jetbrains.kotlin.backend.common.sourceElement
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory1
@@ -145,8 +146,10 @@ class JvmSignatureClashDetector(
irDeclarations: Collection<IrDeclaration>,
conflictingJvmDeclarationsData: ConflictingJvmDeclarationsData
) {
irDeclarations.mapNotNullTo(LinkedHashSet()) { irDeclaration ->
classCodegen.context.ktDiagnosticReporter.atFirstValidFrom(irDeclaration, classCodegen.irClass, containingIrFile = irDeclaration.file)
irDeclarations.mapTo(LinkedHashSet()) { irDeclaration ->
// Offset can be negative (SYNTHETIC_OFFSET) for delegated members; report an error on the class in that case.
val reportOn = irDeclaration.takeUnless { it.startOffset < 0 } ?: classCodegen.irClass
classCodegen.context.ktDiagnosticReporter.at(reportOn.sourceElement(), reportOn, irDeclaration.file)
}.forEach {
it.report(diagnosticFactory1, conflictingJvmDeclarationsData)
}