Type alias constructors for inner classes in expressions ans supertype lists.
This commit is contained in:
@@ -4049,11 +4049,27 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
@NotNull
|
||||
public ClassConstructorDescriptor getConstructorDescriptor(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
FunctionDescriptor accessibleDescriptor = accessibleFunctionDescriptor(resolvedCall);
|
||||
assert accessibleDescriptor instanceof ConstructorDescriptor :
|
||||
assert accessibleDescriptor instanceof ClassConstructorDescriptor :
|
||||
"getConstructorDescriptor must be called only for constructors: " + accessibleDescriptor;
|
||||
return (ClassConstructorDescriptor) accessibleDescriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ReceiverValue getConstructorReceiver(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
CallableDescriptor constructor = resolvedCall.getResultingDescriptor();
|
||||
if (constructor.getExtensionReceiverParameter() != null) {
|
||||
assert constructor instanceof TypeAliasConstructorDescriptor :
|
||||
"Only type alias constructor can have an extension receiver: " + constructor;
|
||||
return resolvedCall.getExtensionReceiver();
|
||||
}
|
||||
else if (constructor.getDispatchReceiverParameter() != null) {
|
||||
return resolvedCall.getDispatchReceiver();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StackValue generateConstructorCall(@NotNull final ResolvedCall<?> resolvedCall, @NotNull final Type objectType) {
|
||||
return StackValue.functionCall(objectType, new Function1<InstructionAdapter, Unit>() {
|
||||
@@ -4068,7 +4084,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
ClassDescriptor containingDeclaration = constructor.getContainingDeclaration();
|
||||
if (dispatchReceiver != null) {
|
||||
Type receiverType = typeMapper.mapType(dispatchReceiver.getType());
|
||||
ReceiverValue receiver = resolvedCall.getDispatchReceiver();
|
||||
ReceiverValue receiver = getConstructorReceiver(resolvedCall);
|
||||
boolean callSuper = containingDeclaration.isInner() && receiver instanceof ImplicitClassReceiver;
|
||||
generateReceiverValue(receiver, callSuper).put(receiverType, v);
|
||||
}
|
||||
|
||||
@@ -248,7 +248,8 @@ private fun ClassConstructorDescriptor.getConstructorDescriptorForResolution(
|
||||
typeAliasDescriptor: TypeAliasDescriptor?
|
||||
): ConstructorDescriptor =
|
||||
if (typeAliasDescriptor != null)
|
||||
TypeAliasConstructorDescriptorImpl.create(typeAliasDescriptor, this, knownSubstitutor ?: TypeSubstitutor.EMPTY)
|
||||
TypeAliasConstructorDescriptorImpl.createIfAvailable(typeAliasDescriptor, this, knownSubstitutor ?: TypeSubstitutor.EMPTY,
|
||||
withDispatchReceiver = true)
|
||||
?: throw AssertionError("Failed to create type alias constructor with substitutor: $knownSubstitutor")
|
||||
else
|
||||
this
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.getImmediateSuperclassNotAny
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import java.util.*
|
||||
|
||||
internal abstract class AbstractScopeTowerLevel(
|
||||
@@ -265,14 +266,26 @@ private fun ResolutionScope.getContributedFunctionsAndConstructors(
|
||||
location: LookupLocation,
|
||||
syntheticConstructorsProvider: SyntheticConstructorsProvider
|
||||
): Collection<FunctionDescriptor> {
|
||||
val result = ArrayList<FunctionDescriptor>(getContributedFunctions(name, location))
|
||||
|
||||
val classifier = getContributedClassifier(name, location)
|
||||
return getContributedFunctions(name, location) +
|
||||
(getClassWithConstructors(classifier)?.constructors?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) +
|
||||
(classifier?.getTypeAliasConstructors()?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) +
|
||||
(classifier?.let { syntheticConstructorsProvider.getSyntheticConstructors(it, location) }
|
||||
?.filter { it.dispatchReceiverParameter == null } ?: emptyList())
|
||||
if (classifier != null) {
|
||||
classifier.getCallableConstructors().filterTo(result) { it.dispatchReceiverParameter == null }
|
||||
syntheticConstructorsProvider.getSyntheticConstructors(classifier, location).filterTo(result) { it.dispatchReceiverParameter == null }
|
||||
}
|
||||
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
private fun ClassifierDescriptor.getCallableConstructors(): Collection<FunctionDescriptor> =
|
||||
when (this) {
|
||||
is TypeAliasDescriptor ->
|
||||
getTypeAliasConstructors()
|
||||
is ClassDescriptor ->
|
||||
if (canHaveCallableConstructors) constructors else emptyList()
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
private fun ResolutionScope.getContributedObjectVariables(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
|
||||
val objectDescriptor = getFakeDescriptorForObject(getContributedClassifier(name, location))
|
||||
return listOfNotNull(objectDescriptor)
|
||||
@@ -304,19 +317,15 @@ private fun getClassWithConstructors(classifier: ClassifierDescriptor?): ClassDe
|
||||
private val ClassDescriptor.canHaveCallableConstructors: Boolean
|
||||
get() = !ErrorUtils.isError(this) && !kind.isSingleton
|
||||
|
||||
fun ClassifierDescriptor.getTypeAliasConstructors(): Collection<TypeAliasConstructorDescriptor> {
|
||||
if (this !is TypeAliasDescriptor) return emptyList()
|
||||
|
||||
fun TypeAliasDescriptor.getTypeAliasConstructors(): Collection<TypeAliasConstructorDescriptor> {
|
||||
val classDescriptor = this.classDescriptor ?: return emptyList()
|
||||
if (!classDescriptor.canHaveCallableConstructors) return emptyList()
|
||||
|
||||
val substitutor = this.getTypeSubstitutorForUnderlyingClass() ?: throw AssertionError("classDescriptor should be non-null for $this")
|
||||
val substitutor = this.getTypeSubstitutorForUnderlyingClass() ?:
|
||||
throw AssertionError("classDescriptor should be non-null for $this")
|
||||
|
||||
return classDescriptor.constructors.mapNotNull {
|
||||
if (it.dispatchReceiverParameter == null)
|
||||
TypeAliasConstructorDescriptorImpl.create(this, it, substitutor)
|
||||
else
|
||||
null
|
||||
TypeAliasConstructorDescriptorImpl.createIfAvailable(this, it, substitutor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Outer(val x: String) {
|
||||
inner class Inner(val y: String) {
|
||||
val z = x + y
|
||||
}
|
||||
}
|
||||
|
||||
typealias OI = Outer.Inner
|
||||
|
||||
fun box(): String =
|
||||
Outer("O").OI("K").z
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class Outer(val x: String) {
|
||||
abstract inner class InnerBase
|
||||
|
||||
inner class Inner(val y: String) : OIB() {
|
||||
val z = x + y
|
||||
}
|
||||
}
|
||||
|
||||
typealias OIB = Outer.InnerBase
|
||||
|
||||
fun box(): String =
|
||||
Outer("O").Inner("K").z
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
class Outer {
|
||||
inner class Inner
|
||||
}
|
||||
|
||||
typealias OI = Outer.Inner
|
||||
|
||||
fun test1(x: Outer) = x.OI()
|
||||
|
||||
|
||||
class Generic<T> {
|
||||
inner class Inner
|
||||
}
|
||||
|
||||
typealias GI<T> = Generic<T>.Inner
|
||||
typealias GIntI = Generic<Int>.Inner
|
||||
|
||||
fun test2(x: Generic<Int>) = x.GI()
|
||||
fun <T> test3(x: Generic<T>) = x.GI()
|
||||
fun <T> test4(x: Generic<List<T>>) = x.GI()
|
||||
fun <T> test5(x: Generic<T>) = <!TYPE_MISMATCH!>x<!>.GIntI()
|
||||
fun Generic<Int>.test6() = GIntI()
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package
|
||||
|
||||
public fun test1(/*0*/ x: Outer): Outer.Inner
|
||||
public fun test2(/*0*/ x: Generic<kotlin.Int>): Generic<kotlin.Int>.Inner
|
||||
public fun </*0*/ T> test3(/*0*/ x: Generic<T>): Generic<T>.Inner
|
||||
public fun </*0*/ T> test4(/*0*/ x: Generic<kotlin.collections.List<T>>): Generic<kotlin.collections.List<T>>.Inner
|
||||
public fun </*0*/ T> test5(/*0*/ x: Generic<T>): Generic<kotlin.Int>.Inner
|
||||
public fun Generic<kotlin.Int>.test6(): Generic<kotlin.Int>.Inner
|
||||
|
||||
public final class Generic</*0*/ T> {
|
||||
public constructor Generic</*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 final inner class Inner /*captured type parameters: /*0*/ T*/ {
|
||||
public constructor Inner()
|
||||
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 final class Outer {
|
||||
public constructor Outer()
|
||||
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 final inner class Inner {
|
||||
public constructor Inner()
|
||||
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 GI</*0*/ T> = Generic<T>.Inner
|
||||
public typealias GIntI = Generic<kotlin.Int>.Inner
|
||||
public typealias OI = Outer.Inner
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
package test
|
||||
|
||||
typealias OI = Outer.Inner
|
||||
|
||||
class Outer {
|
||||
open inner class Inner
|
||||
|
||||
inner class Test : OI()
|
||||
}
|
||||
|
||||
|
||||
typealias GI<T> = Generic<T>.Inner
|
||||
typealias GIInt = Generic<Int>.Inner
|
||||
typealias GIStar = Generic<*>.Inner
|
||||
typealias GG<T1, T2> = Generic<T1>.Generic<T2>
|
||||
typealias GIntG<T2> = Generic<Int>.Generic<T2>
|
||||
typealias GGInt<T1> = Generic<T1>.Generic<Int>
|
||||
|
||||
class Generic<T1> {
|
||||
open inner class Inner
|
||||
open inner class Generic<T2>
|
||||
|
||||
inner class Test1 : GI<T1>()
|
||||
inner class Test2 : <!UNRESOLVED_REFERENCE, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>GIInt<!>()
|
||||
inner class Test3 : GIStar()
|
||||
inner class Test3a : test.Generic<*>.Inner()
|
||||
|
||||
inner class Test4<T2> : GG<T1, T2>()
|
||||
inner class Test5 : GG<T1, Int>()
|
||||
inner class Test6 : <!UNRESOLVED_REFERENCE, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>GG<!><Int, T1>()
|
||||
inner class Test7 : <!UNRESOLVED_REFERENCE, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>GG<!><Int, Int>()
|
||||
inner class Test8 : <!UNRESOLVED_REFERENCE, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>GIntG<!><Int>()
|
||||
inner class Test9 : <!UNRESOLVED_REFERENCE, DEBUG_INFO_UNRESOLVED_WITH_TARGET!>GGInt<!><Int>()
|
||||
inner class Test10 : GGInt<T1>()
|
||||
|
||||
inner class Test11 : GG<T1, Int> {
|
||||
constructor() : super()
|
||||
}
|
||||
}
|
||||
Vendored
+137
@@ -0,0 +1,137 @@
|
||||
package
|
||||
|
||||
package test {
|
||||
|
||||
public final class Generic</*0*/ T1> {
|
||||
public constructor Generic</*0*/ T1>()
|
||||
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 open inner class Generic</*0*/ T2> /*captured type parameters: /*1*/ T1*/ {
|
||||
public constructor Generic</*0*/ T2>()
|
||||
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 open inner class Inner /*captured type parameters: /*0*/ T1*/ {
|
||||
public constructor Inner()
|
||||
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 final inner class Test1 /*captured type parameters: /*0*/ T1*/ : test.GI<T1> /* = test.Generic<T1>.Inner */ {
|
||||
public constructor Test1()
|
||||
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 final inner class Test10 /*captured type parameters: /*0*/ T1*/ : test.GGInt<T1> /* = test.Generic<T1>.Generic<kotlin.Int> */ {
|
||||
public constructor Test10()
|
||||
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 final inner class Test11 /*captured type parameters: /*0*/ T1*/ : test.GG<T1, kotlin.Int> /* = test.Generic<T1>.Generic<kotlin.Int> */ {
|
||||
public constructor Test11()
|
||||
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 final inner class Test2 /*captured type parameters: /*0*/ T1*/ : test.GIInt /* = test.Generic<kotlin.Int>.Inner */ {
|
||||
public constructor Test2()
|
||||
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 final inner class Test3 /*captured type parameters: /*0*/ T1*/ : test.GIStar /* = test.Generic<*>.Inner */ {
|
||||
public constructor Test3()
|
||||
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 final inner class Test3a /*captured type parameters: /*0*/ T1*/ : test.Generic<*>.Inner {
|
||||
public constructor Test3a()
|
||||
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 final inner class Test4</*0*/ T2> /*captured type parameters: /*1*/ T1*/ : test.GG<T1, T2> /* = test.Generic<T1>.Generic<T2> */ {
|
||||
public constructor Test4</*0*/ T2>()
|
||||
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 final inner class Test5 /*captured type parameters: /*0*/ T1*/ : test.GG<T1, kotlin.Int> /* = test.Generic<T1>.Generic<kotlin.Int> */ {
|
||||
public constructor Test5()
|
||||
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 final inner class Test6 /*captured type parameters: /*0*/ T1*/ : test.GG<kotlin.Int, T1> /* = test.Generic<kotlin.Int>.Generic<T1> */ {
|
||||
public constructor Test6()
|
||||
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 final inner class Test7 /*captured type parameters: /*0*/ T1*/ : test.GG<kotlin.Int, kotlin.Int> /* = test.Generic<kotlin.Int>.Generic<kotlin.Int> */ {
|
||||
public constructor Test7()
|
||||
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 final inner class Test8 /*captured type parameters: /*0*/ T1*/ : test.GIntG<kotlin.Int> /* = test.Generic<kotlin.Int>.Generic<kotlin.Int> */ {
|
||||
public constructor Test8()
|
||||
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 final inner class Test9 /*captured type parameters: /*0*/ T1*/ : test.GGInt<kotlin.Int> /* = test.Generic<kotlin.Int>.Generic<kotlin.Int> */ {
|
||||
public constructor Test9()
|
||||
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 final class Outer {
|
||||
public constructor Outer()
|
||||
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 open inner class Inner {
|
||||
public constructor Inner()
|
||||
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 final inner class Test : test.OI /* = test.Outer.Inner */ {
|
||||
public constructor Test()
|
||||
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 GG</*0*/ T1, /*1*/ T2> = test.Generic<T1>.Generic<T2>
|
||||
public typealias GGInt</*0*/ T1> = test.Generic<T1>.Generic<kotlin.Int>
|
||||
public typealias GI</*0*/ T> = test.Generic<T>.Inner
|
||||
public typealias GIInt = test.Generic<kotlin.Int>.Inner
|
||||
public typealias GIStar = test.Generic<*>.Inner
|
||||
public typealias GIntG</*0*/ T2> = test.Generic<kotlin.Int>.Generic<T2>
|
||||
public typealias OI = test.Outer.Inner
|
||||
}
|
||||
+2
-2
@@ -29,6 +29,6 @@ typealias Test5 = Outer.Inner
|
||||
val test5 = <!UNRESOLVED_REFERENCE!>Test5<!>()
|
||||
val test5a = Outer.<!UNRESOLVED_REFERENCE!>Inner<!>()
|
||||
val test5b = Outer.<!UNRESOLVED_REFERENCE!>TestInner<!>()
|
||||
val test5c = Outer().<!UNRESOLVED_REFERENCE!>TestInner<!>() // TODO extension type alias constructors?
|
||||
val test5c = Outer().<!UNRESOLVED_REFERENCE!>TestInner<!>()
|
||||
val test5d = Outer().Inner()
|
||||
val test5e = Outer().<!UNRESOLVED_REFERENCE!>Test5<!>() // TODO extension type alias constructors?
|
||||
val test5e = Outer().Test5()
|
||||
+1
-1
@@ -13,7 +13,7 @@ public val test5a: [ERROR : Type for Outer.Inner()]
|
||||
public val test5b: [ERROR : Type for Outer.TestInner()]
|
||||
public val test5c: [ERROR : Type for Outer().TestInner()]
|
||||
public val test5d: Outer.Inner
|
||||
public val test5e: [ERROR : Type for Outer().Test5()]
|
||||
public val test5e: Outer.Inner
|
||||
|
||||
public abstract class AbstractClass {
|
||||
public constructor AbstractClass()
|
||||
|
||||
+12
@@ -16193,6 +16193,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructor.kt")
|
||||
public void testInnerClassTypeAliasConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructorInSupertypes.kt")
|
||||
public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");
|
||||
|
||||
@@ -20926,6 +20926,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructor.kt")
|
||||
public void testInnerClassTypeAliasConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructorInSupertypes.kt")
|
||||
public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerClassTypeAliasConstructorInSupertypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerTypeAliasAsType.kt")
|
||||
public void testInnerTypeAliasAsType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.kt");
|
||||
|
||||
@@ -16193,6 +16193,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructor.kt")
|
||||
public void testInnerClassTypeAliasConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructorInSupertypes.kt")
|
||||
public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");
|
||||
|
||||
+21
-20
@@ -108,42 +108,43 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun create(
|
||||
fun createIfAvailable(
|
||||
typeAliasDescriptor: TypeAliasDescriptor,
|
||||
constructor: ClassConstructorDescriptor,
|
||||
substitutor: TypeSubstitutor?
|
||||
substitutor: TypeSubstitutor,
|
||||
withDispatchReceiver: Boolean = false
|
||||
): TypeAliasConstructorDescriptor? {
|
||||
val actualSubstitutor = substitutor ?: TypeSubstitutor.EMPTY
|
||||
|
||||
val typeAliasConstructor =
|
||||
TypeAliasConstructorDescriptorImpl(typeAliasDescriptor, constructor, null, constructor.annotations,
|
||||
constructor.kind, typeAliasDescriptor.source)
|
||||
|
||||
val valueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, actualSubstitutor, false)
|
||||
val valueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, substitutor, false)
|
||||
?: return null
|
||||
|
||||
val returnType = actualSubstitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||
val returnType = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||
?: return null
|
||||
|
||||
val containingDeclaration = constructor.containingDeclaration
|
||||
val dispatchReceiverParameter =
|
||||
if (containingDeclaration.isInner)
|
||||
containingDeclaration.thisAsReceiverParameter
|
||||
else
|
||||
null
|
||||
val receiverParameterType =
|
||||
if (withDispatchReceiver) null
|
||||
else constructor.dispatchReceiverParameter?.let { substitutor.safeSubstitute(it.type, Variance.INVARIANT) }
|
||||
|
||||
typeAliasConstructor.initialize(null,
|
||||
dispatchReceiverParameter,
|
||||
typeAliasDescriptor.declaredTypeParameters,
|
||||
valueParameters,
|
||||
returnType,
|
||||
Modality.FINAL,
|
||||
typeAliasDescriptor.visibility)
|
||||
val dispatchReceiver =
|
||||
if (withDispatchReceiver) constructor.dispatchReceiverParameter?.let { it.substitute(substitutor) }
|
||||
else null
|
||||
|
||||
typeAliasConstructor.initialize(
|
||||
receiverParameterType,
|
||||
dispatchReceiver,
|
||||
typeAliasDescriptor.declaredTypeParameters,
|
||||
valueParameters,
|
||||
returnType,
|
||||
Modality.FINAL,
|
||||
typeAliasDescriptor.visibility
|
||||
)
|
||||
|
||||
return typeAliasConstructor
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -21098,6 +21098,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructor.kt")
|
||||
public void testInnerClassTypeAliasConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("innerClassTypeAliasConstructorInSupertypes.kt")
|
||||
public void testInnerClassTypeAliasConstructorInSupertypes() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/innerClassTypeAliasConstructorInSupertypes.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/simple.kt");
|
||||
|
||||
+2
@@ -206,6 +206,8 @@ object ConstructorCallCase : FunctionCallCase() {
|
||||
|
||||
override fun FunctionCallInfo.dispatchReceiver() = doTranslate { argsWithReceiver(dispatchReceiver!!) }
|
||||
|
||||
override fun FunctionCallInfo.extensionReceiver() = doTranslate { argsWithReceiver(extensionReceiver!!) }
|
||||
|
||||
private inline fun FunctionCallInfo.doTranslate(
|
||||
getArguments: CallArgumentTranslator.ArgumentsInfo.() -> List<JsExpression>
|
||||
): JsExpression {
|
||||
|
||||
+5
-1
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.js.translate.initializer;
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.callTranslator.CallTranslator;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
@@ -170,6 +171,9 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
List<JsExpression> arguments = new ArrayList<JsExpression>();
|
||||
|
||||
ConstructorDescriptor superDescriptor = (ConstructorDescriptor) superCall.getResultingDescriptor();
|
||||
if (superDescriptor instanceof TypeAliasConstructorDescriptor) {
|
||||
superDescriptor = ((TypeAliasConstructorDescriptor) superDescriptor).getUnderlyingConstructorDescriptor();
|
||||
}
|
||||
|
||||
List<DeclarationDescriptor> superclassClosure = context.getClassOrConstructorClosure(superDescriptor);
|
||||
if (superclassClosure != null) {
|
||||
@@ -182,7 +186,7 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
if (superDescriptor.getContainingDeclaration().isInner() && classDescriptor.isInner()) {
|
||||
if (superDescriptor.getConstructedClass().isInner() && classDescriptor.isInner()) {
|
||||
arguments.add(pureFqn(Namer.OUTER_FIELD_NAME, JsLiteral.THIS));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user