KT-2784 VerifyError when passing a value to a class object's super type constructor
#KT-2784 Fixed
This commit is contained in:
@@ -90,11 +90,9 @@ public class CodegenUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNonLiteralObject(JetClassOrObject myClass) {
|
public static boolean isNonLiteralObject(JetClassOrObject myClass) {
|
||||||
return myClass instanceof JetObjectDeclaration && !((JetObjectDeclaration) myClass).isObjectLiteral() &&
|
return myClass instanceof JetObjectDeclaration && !((JetObjectDeclaration) myClass).isObjectLiteral();
|
||||||
!(myClass.getParent() instanceof JetClassObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String createTmpVariableName(Collection<String> existingNames) {
|
public static String createTmpVariableName(Collection<String> existingNames) {
|
||||||
String prefix = "tmp";
|
String prefix = "tmp";
|
||||||
int i = RANDOM.nextInt(Integer.MAX_VALUE);
|
int i = RANDOM.nextInt(Integer.MAX_VALUE);
|
||||||
|
|||||||
@@ -936,8 +936,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
private void generateFieldForSingleton() {
|
private void generateFieldForSingleton() {
|
||||||
boolean hasClassObject = descriptor.getClassObjectDescriptor() != null;
|
boolean hasClassObject = descriptor.getClassObjectDescriptor() != null;
|
||||||
boolean isEnumClass = DescriptorUtils.isEnumClass(descriptor);
|
boolean isEnumClass = DescriptorUtils.isEnumClass(descriptor);
|
||||||
|
boolean isObjectDeclaration = descriptor.getKind() == ClassKind.OBJECT && isNonLiteralObject(myClass) ;
|
||||||
|
|
||||||
if (!(isNonLiteralObject(myClass) || hasClassObject) || isEnumClass) return;
|
if (!isObjectDeclaration && !hasClassObject || isEnumClass) return;
|
||||||
|
|
||||||
ClassDescriptor fieldTypeDescriptor = hasClassObject ? descriptor.getClassObjectDescriptor() : descriptor;
|
ClassDescriptor fieldTypeDescriptor = hasClassObject ? descriptor.getClassObjectDescriptor() : descriptor;
|
||||||
assert fieldTypeDescriptor != null;
|
assert fieldTypeDescriptor != null;
|
||||||
|
|||||||
@@ -187,16 +187,11 @@ public class CodegenBinding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSingleton(BindingContext bindingContext, @NotNull ClassDescriptor classDescriptor) {
|
public static boolean isSingleton(BindingContext bindingContext, @NotNull ClassDescriptor classDescriptor) {
|
||||||
ClassKind kind = classDescriptor.getKind();
|
if (isObjectDeclaration(bindingContext, classDescriptor)) {
|
||||||
if (kind == ClassKind.CLASS_OBJECT) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind == ClassKind.OBJECT && isObjectDeclaration(bindingContext, classDescriptor)) {
|
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == ClassKind.ENUM_ENTRY) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectSt
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isObjectLiteral() {
|
public boolean isObjectLiteral() {
|
||||||
return getNameAsDeclaration() == null;
|
return getParent() instanceof JetObjectLiteralExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
open class Factory(p: Int)
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object : Factory(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
A
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -955,6 +955,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest("compiler/testData/codegen/box/classes/kt2711.kt");
|
doTest("compiler/testData/codegen/box/classes/kt2711.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt2784.kt")
|
||||||
|
public void testKt2784() throws Exception {
|
||||||
|
doTest("compiler/testData/codegen/box/classes/kt2784.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt285.kt")
|
@TestMetadata("kt285.kt")
|
||||||
public void testKt285() throws Exception {
|
public void testKt285() throws Exception {
|
||||||
doTest("compiler/testData/codegen/box/classes/kt285.kt");
|
doTest("compiler/testData/codegen/box/classes/kt285.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user