KT-13836: fix generation of FQN of secondary constructor when it's called via typealias. Fix #KT-13836
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
object O {
|
||||
val x = "OK"
|
||||
|
||||
operator fun invoke() = x
|
||||
}
|
||||
|
||||
typealias A = O
|
||||
|
||||
fun box(): String = A()
|
||||
@@ -0,0 +1,11 @@
|
||||
class C(val x: String) {
|
||||
constructor(n: Int) : this(n.toString())
|
||||
}
|
||||
|
||||
typealias Alias = C
|
||||
|
||||
fun box(): String {
|
||||
val c = Alias(23)
|
||||
if (c.x != "23") return "fail: $c"
|
||||
return "OK"
|
||||
}
|
||||
@@ -15603,6 +15603,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasObjectCallable.kt")
|
||||
public void testTypeAliasObjectCallable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObjectCallable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasSecondaryConstructor.kt")
|
||||
public void testTypeAliasSecondaryConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasSecondaryConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/unaryOp")
|
||||
|
||||
+12
@@ -76,4 +76,16 @@ public class TypeAliasesTestsGenerated extends AbstractTypeAliasesTests {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasObjectCallable.kt")
|
||||
public void testTypeAliasObjectCallable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasObjectCallable.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeAliasSecondaryConstructor.kt")
|
||||
public void testTypeAliasSecondaryConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/typealias/typeAliasSecondaryConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.ReflectionTypes;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
|
||||
import org.jetbrains.kotlin.js.config.JsConfig;
|
||||
import org.jetbrains.kotlin.js.config.LibrarySourcesConfig;
|
||||
import org.jetbrains.kotlin.js.translate.context.generator.Generator;
|
||||
@@ -266,6 +267,20 @@ public final class StaticContext {
|
||||
private final class NameGenerator extends Generator<JsName> {
|
||||
|
||||
public NameGenerator() {
|
||||
Rule<JsName> typeAliasConstructor = new Rule<JsName>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JsName apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof TypeAliasConstructorDescriptor) {
|
||||
TypeAliasConstructorDescriptor constructorDescriptor = (TypeAliasConstructorDescriptor) descriptor;
|
||||
return getNameForDescriptor(constructorDescriptor.getUnderlyingConstructorDescriptor());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Rule<JsName> namesForDynamic = new Rule<JsName>() {
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -422,6 +437,7 @@ public final class StaticContext {
|
||||
}
|
||||
};
|
||||
|
||||
addRule(typeAliasConstructor);
|
||||
addRule(namesForDynamic);
|
||||
addRule(localClasses);
|
||||
addRule(namesForStandardClasses);
|
||||
|
||||
Reference in New Issue
Block a user