Create special descriptor for an object corresponding to type alias.

This commit is contained in:
Dmitry Petrov
2016-09-16 12:00:08 +03:00
parent 4f49444f3b
commit 34240e2ff9
8 changed files with 78 additions and 5 deletions
@@ -246,7 +246,7 @@ class CandidateResolver(
nestedClass = candidateDescriptor.containingDeclaration
}
else if (candidateDescriptor is FakeCallableDescriptorForObject) {
nestedClass = candidateDescriptor.getReferencedDescriptor()
nestedClass = candidateDescriptor.getReferencedObject()
}
if (nestedClass != null) {
tracing.nestedClassAccessViaInstanceReference(trace, nestedClass, candidateCall.explicitReceiverKind)
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForTypeAliasObject
import org.jetbrains.kotlin.resolve.coroutine.CoroutineReceiverValue
import org.jetbrains.kotlin.resolve.coroutine.createCoroutineSuspensionFunctionView
import org.jetbrains.kotlin.resolve.descriptorUtil.HIDES_MEMBERS_NAME_LIST
@@ -273,7 +274,12 @@ private fun ResolutionScope.getContributedObjectVariables(name: Name, location:
fun getFakeDescriptorForObject(classifier: ClassifierDescriptor?): FakeCallableDescriptorForObject? =
when (classifier) {
is TypeAliasDescriptor ->
getFakeDescriptorForObject(classifier.classDescriptor)
classifier.classDescriptor?.let { classDescriptor ->
if (classDescriptor.hasClassValueDescriptor)
FakeCallableDescriptorForTypeAliasObject(classifier)
else
null
}
is ClassDescriptor ->
if (classifier.hasClassValueDescriptor)
FakeCallableDescriptorForObject(classifier)
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassValueDescriptor
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
class FakeCallableDescriptorForObject(
open class FakeCallableDescriptorForObject(
val classDescriptor: ClassDescriptor
) : DeclarationDescriptorWithVisibility by classDescriptor.getClassObjectReferenceTarget(), VariableDescriptor {
@@ -34,7 +34,9 @@ class FakeCallableDescriptorForObject(
}
fun getReferencedDescriptor(): ClassDescriptor = classDescriptor.getClassObjectReferenceTarget()
open fun getReferencedDescriptor(): ClassifierDescriptorWithTypeParameters = classDescriptor.getClassObjectReferenceTarget()
fun getReferencedObject(): ClassDescriptor = classDescriptor.getClassObjectReferenceTarget()
override fun getExtensionReceiverParameter(): ReceiverParameterDescriptor? = null
@@ -0,0 +1,32 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve.calls.util
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
class FakeCallableDescriptorForTypeAliasObject(val typeAliasDescriptor: TypeAliasDescriptor) :
FakeCallableDescriptorForObject(typeAliasDescriptor.classDescriptor!!) {
override fun getReferencedDescriptor() =
typeAliasDescriptor
override fun equals(other: Any?): Boolean =
other is FakeCallableDescriptorForTypeAliasObject &&
typeAliasDescriptor == other.typeAliasDescriptor
override fun hashCode(): Int =
typeAliasDescriptor.hashCode()
}
@@ -0,0 +1,8 @@
class C {
private companion object
}
typealias CAlias = C
val <!EXPOSED_PROPERTY_TYPE!>test1<!> = <!INVISIBLE_MEMBER!>CAlias<!>
val <!EXPOSED_PROPERTY_TYPE!>test1a<!> = <!INVISIBLE_MEMBER!>C<!>
@@ -0,0 +1,19 @@
package
public val test1: C.Companion
public val test1a: C.Companion
public final class C {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
private companion object Companion {
private constructor Companion()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public typealias CAlias = C
@@ -20397,6 +20397,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("typeAliasInvisibleObject.kt")
public void testTypeAliasInvisibleObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.kt");
doTest(fileName);
}
@TestMetadata("typeAliasNotNull.kt")
public void testTypeAliasNotNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasNotNull.kt");
@@ -433,7 +433,7 @@ public final class StaticContext {
}
FakeCallableDescriptorForObject fakeCallableDescriptor = (FakeCallableDescriptorForObject) descriptor;
return getNameForDescriptor(fakeCallableDescriptor.getReferencedDescriptor());
return getNameForDescriptor(fakeCallableDescriptor.getReferencedObject());
}
};