Discriminate header class in resolution from sources in AbstractLazyMemberScope

Similarly to getFirstClassifierDiscriminateHeaders, we select the first
non-header class if possible, otherwise we select just the first class.
This makes sure that a reference will never be resolved to a header
class if the corresponding impl class is present.

Note that overall the issue may not be fixed yet, because there are
other scopes where header classes are not yet discriminated
(LazyImportScope, DeserializedMemberScope). However, at this point I
cannot reproduce this problem with these other scopes

 #KT-15521 Fixed
This commit is contained in:
Alexander Udalov
2017-03-20 14:41:23 +03:00
parent 93e3bdc1ab
commit 81774926fa
5 changed files with 30 additions and 3 deletions
@@ -66,9 +66,15 @@ protected constructor(
override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
recordLookup(name, location)
// NB we should resolve type alias descriptors even if a class descriptor with corresponding name is present
val firstClassDescriptor = classDescriptors(name).firstOrNull()
val firstTypeAliasDescriptor = typeAliasDescriptors(name).firstOrNull()
return firstClassDescriptor ?: firstTypeAliasDescriptor
val classes = classDescriptors(name)
val typeAliases = typeAliasDescriptors(name)
var resultingClass: ClassDescriptor? = null
for (klass in classes) {
// See getFirstClassifierDiscriminateHeaders()
if (!klass.isHeader) return klass
if (resultingClass == null) resultingClass = klass
}
return resultingClass ?: typeAliases.firstOrNull()
}
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
@@ -0,0 +1 @@
header class Foo
@@ -0,0 +1,7 @@
impl class Foo(x: Int) {
impl constructor() : this(0)
val x: Int = x
}
val y = Foo(42).x
@@ -0,0 +1,7 @@
-- Common --
Exit code: OK
Output:
-- JVM --
Exit code: OK
Output:
@@ -42,6 +42,12 @@ public class MultiPlatformIntegrationTestGenerated extends AbstractMultiPlatform
doTest(fileName);
}
@TestMetadata("createImplClassInPlatformModule")
public void testCreateImplClassInPlatformModule() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/createImplClassInPlatformModule/");
doTest(fileName);
}
@TestMetadata("genericDeclarations")
public void testGenericDeclarations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/genericDeclarations/");