fixup! [FIR] Fix missing INVISIBLE_REFERENCE on imports

^KT-59927 Fixed
diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceUtils.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceUtils.kt
index e560337..b4bf9d1 100644
--- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceUtils.kt
+++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/FirSourceUtils.kt
@@ -73,32 +73,7 @@
 
 /**
  * Looks for the source element of the last segment
- * of `fqName` within the given import.
- * If the given fqName doesn't match the beginning
- * of the imported fqName or the imported fqName
- * has no segments this function returns `null`.
- *
- * For example, calling this function for `import a.b.c`
- * and fqName `a.b` returns the source element for `b`.
+ * of `importedFqName`.
  */
-fun FirImport.getSourceForFqNamePrefix(fqName: FqName): KtSourceElement? {
-    // For the example from the doc. comment
-    // we'd get [a, a.b, a.b.c]
-    val cumulativeSegmentSources = generateSequence(source) { it.getChild(IMPORT_PARENT_TOKEN_TYPES) }.drop(1).toList().asReversed()
-    // [a, b, c]
-    val segmentSources = cumulativeSegmentSources.map { it.getChild(KtNodeTypes.REFERENCE_EXPRESSION, reverse = true) ?: it }
-    // [a, b]
-    val fqNameSegments = fqName.pathSegments()
-
-    if (segmentSources.size < fqNameSegments.size || segmentSources.isEmpty()) {
-        return null
-    }
-
-    for (currentSegmentIndex in fqNameSegments.indices) {
-        if (segmentSources[currentSegmentIndex].text != fqNameSegments[currentSegmentIndex].identifier) {
-            return null
-        }
-    }
-
-    return segmentSources[fqNameSegments.lastIndex]
-}
+fun FirImport.getLastImportedFqNameSegmentSource(): KtSourceElement? =
+    source?.getChild(KtNodeTypes.REFERENCE_EXPRESSION, reverse = true)
diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt
index 40f8cf3..176aca6 100644
--- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt
+++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirImportsChecker.kt
@@ -16,7 +16,7 @@
 import org.jetbrains.kotlin.fir.analysis.checkers.unsubstitutedScope
 import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
 import org.jetbrains.kotlin.fir.analysis.diagnostics.toInvisibleReferenceDiagnostic
-import org.jetbrains.kotlin.fir.analysis.getSourceForFqNamePrefix
+import org.jetbrains.kotlin.fir.analysis.getLastImportedFqNameSegmentSource
 import org.jetbrains.kotlin.fir.analysis.getSourceForImportSegment
 import org.jetbrains.kotlin.fir.declarations.*
 import org.jetbrains.kotlin.fir.declarations.utils.isEnumClass
@@ -84,7 +84,7 @@
             reporter.reportOn(import.source, FirErrors.CANNOT_ALL_UNDER_IMPORT_FROM_SINGLETON, classSymbol.classId.shortClassName, context)
         }
         if (!classLike.fir.isVisible(context)) {
-            val source = import.getSourceForFqNamePrefix(fqName) ?: error("`${import.source}` does not contain `$fqName`")
+            val source = import.getLastImportedFqNameSegmentSource() ?: error("`${import.source}` does not contain `$fqName`")
             reporter.report(classLike.toInvisibleReferenceDiagnostic(source), context)
         }
     }