[FIR] Skip creation of `JvmMappedScope` for mapped companions

Although they are mapped, they do not require a separate scope.
On the other hand, implementation of `JvmMappedScope` depends on the
fact that the status of internal objects they're mapped to is resolved
in some cases, which potentially might not be true for mapped
companions.
diff --git a/compiler/fir/fir-jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt b/compiler/fir/fir-jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
index 79e6596..6012c4e 100644
--- a/compiler/fir/fir-jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
+++ b/compiler/fir/fir-jvm/src/org/jetbrains/kotlin/fir/resolve/scopes/JvmMappedScopes.kt
@@ -5,6 +5,7 @@
 
 package org.jetbrains.kotlin.fir.resolve.scopes
 
+import org.jetbrains.kotlin.builtins.CompanionObjectMapping
 import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
 import org.jetbrains.kotlin.fir.FirSession
 import org.jetbrains.kotlin.fir.declarations.FirClass
@@ -29,6 +30,8 @@
 ): FirContainingNamesAwareScope {
     if (klass !is FirRegularClass) return declaredMemberScope
     val classId = klass.classId
+    // These are mapped but don't require a dedicated scope
+    if (classId in CompanionObjectMapping.companionClassIds) return declaredMemberScope
     val kotlinUnsafeFqName = classId.asSingleFqName().toUnsafe()
     val javaClassId = JavaToKotlinClassMap.mapKotlinToJava(kotlinUnsafeFqName)
         ?: return declaredMemberScope
diff --git a/core/compiler.common/src/org/jetbrains/kotlin/builtins/CompanionObjectMapping.kt b/core/compiler.common/src/org/jetbrains/kotlin/builtins/CompanionObjectMapping.kt
index b1f223a..928e4cf 100644
--- a/core/compiler.common/src/org/jetbrains/kotlin/builtins/CompanionObjectMapping.kt
+++ b/core/compiler.common/src/org/jetbrains/kotlin/builtins/CompanionObjectMapping.kt
@@ -6,14 +6,21 @@
 package org.jetbrains.kotlin.builtins
 
 import org.jetbrains.kotlin.name.ClassId
+import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.name.Name
 
 object CompanionObjectMapping {
-    val classIds: Set<ClassId> = (
-            PrimitiveType.NUMBER_TYPES.map(StandardNames::getPrimitiveFqName) +
-                    StandardNames.FqNames.string.toSafe() +
-                    StandardNames.FqNames._boolean.toSafe() +
-                    StandardNames.FqNames._enum.toSafe()
-            ).mapTo(linkedSetOf(), ClassId::topLevel)
+
+    private val fqNames: List<FqName>
+        get() = PrimitiveType.entries.map(StandardNames::getPrimitiveFqName) +
+                StandardNames.FqNames.string.toSafe() +
+                StandardNames.FqNames._enum.toSafe()
+
+    val classIds: Set<ClassId> = fqNames.mapTo(linkedSetOf(), ClassId::topLevel)
+
+    val companionClassIds: Set<ClassId> = classIds.mapTo(linkedSetOf()) {
+        it.createNestedClassId(Name.identifier("Companion"))
+    }
 
     fun allClassesWithIntrinsicCompanions(): Set<ClassId> = classIds
 }