KT-14400: Properly handle TypeAliasConstructorDescriptor in KotlinTypeMapper.mapToCallableMethod(...)
Implement getDefaultType() in TypeAliasDescriptor subclasses.
This commit is contained in:
@@ -639,9 +639,13 @@ public class KotlinTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
if (descriptor instanceof TypeAliasConstructorDescriptor) {
|
||||
return mapToCallableMethod(((TypeAliasConstructorDescriptor) descriptor).getUnderlyingConstructorDescriptor(), superCall);
|
||||
}
|
||||
|
||||
if (descriptor instanceof ClassConstructorDescriptor) {
|
||||
JvmMethodSignature method = mapSignatureSkipGeneric(descriptor);
|
||||
Type owner = mapClass(((ConstructorDescriptor) descriptor).getContainingDeclaration());
|
||||
Type owner = mapClass(((ClassConstructorDescriptor) descriptor).getContainingDeclaration());
|
||||
String defaultImplDesc = mapDefaultMethod(descriptor, OwnerKind.IMPLEMENTATION).getDescriptor();
|
||||
return new CallableMethod(owner, owner, defaultImplDesc, method, INVOKESPECIAL, null, null, null);
|
||||
}
|
||||
|
||||
+3
@@ -41,9 +41,11 @@ class LazyTypeAliasDescriptor(
|
||||
|
||||
private lateinit var underlyingTypeImpl: NotNullLazyValue<SimpleType>
|
||||
private lateinit var expandedTypeImpl: NotNullLazyValue<SimpleType>
|
||||
private lateinit var defaultTypeImpl: NotNullLazyValue<SimpleType>
|
||||
|
||||
override val underlyingType: SimpleType get() = underlyingTypeImpl()
|
||||
override val expandedType: SimpleType get() = expandedTypeImpl()
|
||||
override fun getDefaultType(): SimpleType = defaultTypeImpl()
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
@@ -53,6 +55,7 @@ class LazyTypeAliasDescriptor(
|
||||
super.initialize(declaredTypeParameters)
|
||||
this.underlyingTypeImpl = lazyUnderlyingType
|
||||
this.expandedTypeImpl = lazyExpandedType
|
||||
this.defaultTypeImpl = storageManager.createLazyValue { computeDefaultType() }
|
||||
}
|
||||
|
||||
private val lazyTypeConstructorParameters =
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
open class Foo<T>(val x: T)
|
||||
|
||||
typealias FooStr = Foo<String>
|
||||
|
||||
val test = object : FooStr("OK") {}
|
||||
|
||||
fun box() = test.x
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class Foo<T>
|
||||
|
||||
typealias FooStr = Foo<String>
|
||||
|
||||
val test = object : FooStr() {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public val test: FooStr /* = Foo<kotlin.String> */
|
||||
|
||||
public open class Foo</*0*/ T> {
|
||||
public constructor Foo</*0*/ T>()
|
||||
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 FooStr = Foo<kotlin.String>
|
||||
+6
@@ -15982,6 +15982,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasInAnonymousObjectType.kt")
|
||||
public void testTypeAliasInAnonymousObjectType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasInAnonymousObjectType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasObject.kt")
|
||||
public void testTypeAliasObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
|
||||
|
||||
@@ -20862,6 +20862,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasInAnonymousObjectType.kt")
|
||||
public void testTypeAliasInAnonymousObjectType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasInAnonymousObjectType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasInvisibleObject.kt")
|
||||
public void testTypeAliasInvisibleObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/typeAliasInvisibleObject.kt");
|
||||
|
||||
@@ -15982,6 +15982,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasInAnonymousObjectType.kt")
|
||||
public void testTypeAliasInAnonymousObjectType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasInAnonymousObjectType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasObject.kt")
|
||||
public void testTypeAliasObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
|
||||
|
||||
+5
-3
@@ -21,9 +21,11 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
abstract class AbstractTypeAliasDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
@@ -57,9 +59,6 @@ abstract class AbstractTypeAliasDescriptor(
|
||||
|
||||
override fun getVisibility() = visibilityImpl
|
||||
|
||||
override fun getDefaultType(): SimpleType =
|
||||
TODO("typealias getDefaultType")
|
||||
|
||||
override fun getTypeConstructor(): TypeConstructor =
|
||||
typeConstructor
|
||||
|
||||
@@ -67,6 +66,9 @@ abstract class AbstractTypeAliasDescriptor(
|
||||
|
||||
protected abstract fun getTypeConstructorTypeParameters(): List<TypeParameterDescriptor>
|
||||
|
||||
protected fun computeDefaultType(): SimpleType =
|
||||
TypeUtils.makeUnsubstitutedType(this, classDescriptor?.unsubstitutedMemberScope ?: MemberScope.Empty)
|
||||
|
||||
private val typeConstructor = object : TypeConstructor {
|
||||
override fun getDeclarationDescriptor(): TypeAliasDescriptor =
|
||||
this@AbstractTypeAliasDescriptor
|
||||
|
||||
+2
@@ -133,6 +133,8 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
|
||||
get() = builtIns.nullableAnyType
|
||||
override val expandedType: SimpleType
|
||||
get() = builtIns.nullableAnyType
|
||||
override fun getDefaultType(): SimpleType =
|
||||
builtIns.nullableAnyType
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor) = this
|
||||
|
||||
|
||||
+5
@@ -155,6 +155,7 @@ class DeserializedTypeAliasDescriptor(
|
||||
override lateinit var underlyingType: SimpleType private set
|
||||
override lateinit var expandedType: SimpleType private set
|
||||
private lateinit var typeConstructorParameters: List<TypeParameterDescriptor>
|
||||
private lateinit var defaultTypeImpl: SimpleType private set
|
||||
|
||||
fun initialize(
|
||||
declaredTypeParameters: List<TypeParameterDescriptor>,
|
||||
@@ -165,8 +166,12 @@ class DeserializedTypeAliasDescriptor(
|
||||
this.underlyingType = underlyingType
|
||||
this.expandedType = expandedType
|
||||
typeConstructorParameters = computeConstructorTypeParameters()
|
||||
defaultTypeImpl = computeDefaultType()
|
||||
}
|
||||
|
||||
override fun getDefaultType(): SimpleType =
|
||||
defaultTypeImpl
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): TypeAliasDescriptor {
|
||||
if (substitutor.isEmpty) return this
|
||||
val substituted = DeserializedTypeAliasDescriptor(containingDeclaration, annotations, name, visibility, proto, nameResolver, typeTable, containerSource)
|
||||
|
||||
@@ -77,6 +77,12 @@ public class TypeAliasesTestsGenerated extends AbstractTypeAliasesTests {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasInAnonymousObjectType.kt")
|
||||
public void testTypeAliasInAnonymousObjectType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasInAnonymousObjectType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasObject.kt")
|
||||
public void testTypeAliasObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
|
||||
|
||||
Reference in New Issue
Block a user