Mpp resolve: fix actual/expect declaration lookup
Previously we would look fo expect declaration in common dependencies
as opposed to looking inside the module exclusively
This commit is contained in:
+8
-3
@@ -125,11 +125,12 @@ object ExpectedActualResolver {
|
||||
is FunctionDescriptor -> scopes.flatMap { it.getContributedFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) }
|
||||
is PropertyDescriptor -> scopes.flatMap { it.getContributedVariables(name, NoLookupLocation.FOR_ALREADY_TRACKED) }
|
||||
else -> throw AssertionError("Unsupported declaration: $this")
|
||||
}
|
||||
}.onlyFromThis(module)
|
||||
}
|
||||
|
||||
private fun ClassifierDescriptorWithTypeParameters.findClassifiersFromModule(
|
||||
module: ModuleDescriptor
|
||||
module: ModuleDescriptor,
|
||||
includeDependencies: Boolean = false
|
||||
): Collection<ClassifierDescriptorWithTypeParameters> {
|
||||
val classId = classId ?: return emptyList()
|
||||
|
||||
@@ -139,6 +140,7 @@ object ExpectedActualResolver {
|
||||
|
||||
val segments = classId.relativeClassName.pathSegments()
|
||||
var classifiers = module.getPackage(classId.packageFqName).memberScope.getAllClassifiers(segments.first())
|
||||
if (!includeDependencies) classifiers = classifiers.onlyFromThis(module)
|
||||
|
||||
for (name in segments.subList(1, segments.size)) {
|
||||
classifiers = classifiers.mapNotNull { classifier ->
|
||||
@@ -151,6 +153,9 @@ object ExpectedActualResolver {
|
||||
return classifiers
|
||||
}
|
||||
|
||||
private fun <T : DeclarationDescriptor> Iterable<T>.onlyFromThis(module: ModuleDescriptor): List<T> =
|
||||
filter { it.module == module }
|
||||
|
||||
sealed class Compatibility {
|
||||
// For IncompatibilityKind.STRONG `actual` declaration is considered as overload and error reports on expected declaration
|
||||
enum class IncompatibilityKind {
|
||||
@@ -322,7 +327,7 @@ object ExpectedActualResolver {
|
||||
return expected is ClassifierDescriptorWithTypeParameters &&
|
||||
expected.isExpect &&
|
||||
actual is ClassifierDescriptorWithTypeParameters &&
|
||||
expected.findClassifiersFromModule(platformModule).any { classifier ->
|
||||
expected.findClassifiersFromModule(platformModule, includeDependencies = true).any { classifier ->
|
||||
// Note that it's fine to only check that this "actual typealias" expands to the expected class, without checking
|
||||
// whether the type arguments in the expansion are in the correct order or have the correct variance, because we only
|
||||
// allow simple cases like "actual typealias Foo<A, B> = FooImpl<A, B>", see DeclarationsChecker#checkActualTypeAlias
|
||||
|
||||
+1
@@ -1 +1,2 @@
|
||||
expect class My
|
||||
expect fun bar()
|
||||
+2
-1
@@ -1 +1,2 @@
|
||||
class <error descr="[ACTUAL_MISSING] Declaration must be marked with 'actual'">My</error>
|
||||
class My
|
||||
fun bar() {}
|
||||
+2
-1
@@ -1 +1,2 @@
|
||||
expect class My
|
||||
expect class My
|
||||
expect fun bar()
|
||||
Vendored
+3
@@ -1,3 +1,6 @@
|
||||
class My
|
||||
fun bar() {
|
||||
|
||||
}
|
||||
|
||||
actual fun foo(my: Any) {}
|
||||
Vendored
+3
-1
@@ -1 +1,3 @@
|
||||
expect class My
|
||||
expect class My
|
||||
|
||||
expect fun bar()
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
class <error descr="[ACTUAL_MISSING] Declaration must be marked with 'actual'">My</error>
|
||||
class My
|
||||
fun bar() {}
|
||||
|
||||
actual fun foo(my: My) {}
|
||||
Reference in New Issue
Block a user