[FIR] Allow treating candidates from the same non-source module as equivalent
This situation occurs in Native metadata compilation and lead to false-positive OVERLOAD_RESOLUTION_AMBIGUITY reports. #KT-61461 Fixed
This commit is contained in:
committed by
Space Team
parent
fd5ac8575c
commit
a42cb2f37f
+5
-2
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.calls.jvm
|
package org.jetbrains.kotlin.fir.resolve.calls.jvm
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||||
@@ -70,11 +71,13 @@ class ConeEquivalentCallConflictResolver(
|
|||||||
secondCandidate: Candidate
|
secondCandidate: Candidate
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (first.symbol.callableId != second.symbol.callableId) return false
|
if (first.symbol.callableId != second.symbol.callableId) return false
|
||||||
// Emulate behavior from K1 where declarations from the same module are never equivalent.
|
// Emulate behavior from K1 where declarations from the same source module are never equivalent.
|
||||||
// We expect REDECLARATION or CONFLICTING_OVERLOADS to be reported in those cases.
|
// We expect REDECLARATION or CONFLICTING_OVERLOADS to be reported in those cases.
|
||||||
// See a.containingDeclaration == b.containingDeclaration check in
|
// See a.containingDeclaration == b.containingDeclaration check in
|
||||||
// org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent.
|
// org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent.
|
||||||
if (first.moduleData == second.moduleData) return false
|
// We can't rely on the fact that library declarations will have different moduleData, e.g. in Native metadata compilation,
|
||||||
|
// multiple stdlib declarations with the same moduleData can be present, see KT-61461.
|
||||||
|
if (first.moduleData == second.moduleData && first.moduleData.session.kind == FirSession.Kind.Source) return false
|
||||||
if (first.isExpect != second.isExpect) return false
|
if (first.isExpect != second.isExpect) return false
|
||||||
if (first is FirVariable != second is FirVariable) {
|
if (first is FirVariable != second is FirVariable) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
+12
@@ -89,6 +89,18 @@ class CustomK2Tests : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled("disable until kotlin/native dependency is updated to include KT-61461")
|
||||||
|
@GradleTest
|
||||||
|
@DisplayName("Native metadata of intermediate with multiple targets. KT-61461")
|
||||||
|
fun nativeMetadataOfIntermediateWithMultipleTargets(gradleVersion: GradleVersion) {
|
||||||
|
with(project("k2-native-intermediate-multiple-targets", gradleVersion, buildOptions = defaultBuildOptions.copy(languageVersion = "2.0"))) {
|
||||||
|
val taskToExecute = ":compileNativeMainKotlinMetadata"
|
||||||
|
build(taskToExecute) {
|
||||||
|
assertTasksExecuted(taskToExecute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Disabled("disable until kotlin/native dependency is updated to include KT-58145")
|
@Disabled("disable until kotlin/native dependency is updated to include KT-58145")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
@DisplayName("Compiling shared native source with FirFakeOverrideGenerator referencing a common entity. KT-58145")
|
@DisplayName("Compiling shared native source with FirFakeOverrideGenerator referencing a common entity. KT-58145")
|
||||||
|
|||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
group = "test"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
applyDefaultHierarchyTemplate()
|
||||||
|
linuxX64()
|
||||||
|
macosX64()
|
||||||
|
macosArm64()
|
||||||
|
mingwX64()
|
||||||
|
androidNativeX64()
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
require(true)
|
||||||
|
for (i in 0 until 42) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val mutexPool by lazy { 42 }
|
||||||
Reference in New Issue
Block a user