Fix for KT-9711: Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
#KT-9711 Fixed
This commit is contained in:
@@ -2025,10 +2025,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
return StackValue.singleton(classDescriptor, typeMapper);
|
return StackValue.singleton(classDescriptor, typeMapper);
|
||||||
}
|
}
|
||||||
if (isEnumEntry(classDescriptor)) {
|
if (isEnumEntry(classDescriptor)) {
|
||||||
DeclarationDescriptor enumClass = classDescriptor.getContainingDeclaration();
|
return StackValue.enumEntry(classDescriptor, typeMapper);
|
||||||
assert DescriptorUtils.isEnumClass(enumClass) : "Enum entry should be declared in enum class: " + descriptor;
|
|
||||||
Type type = typeMapper.mapType((ClassDescriptor) enumClass);
|
|
||||||
return StackValue.field(type, type, descriptor.getName().asString(), true, StackValue.none(), classDescriptor);
|
|
||||||
}
|
}
|
||||||
ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
|
ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
|
||||||
if (companionObjectDescriptor != null) {
|
if (companionObjectDescriptor != null) {
|
||||||
@@ -2568,7 +2565,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return StackValue.thisOrOuter(this, receiverDescriptor, false, false);
|
return StackValue.thisOrOuter(this, receiverDescriptor, false, isEnumEntry(receiverDescriptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (receiverValue instanceof ScriptReceiver) {
|
else if (receiverValue instanceof ScriptReceiver) {
|
||||||
@@ -2638,6 +2635,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
!AnnotationUtilKt.isPlatformStaticInObjectOrClass(context.getContextDescriptor())) {
|
!AnnotationUtilKt.isPlatformStaticInObjectOrClass(context.getContextDescriptor())) {
|
||||||
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
|
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
|
||||||
}
|
}
|
||||||
|
else if (isEnumEntry(calleeContainingClass)) {
|
||||||
|
return StackValue.enumEntry(calleeContainingClass, typeMapper);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return StackValue.singleton(calleeContainingClass, typeMapper);
|
return StackValue.singleton(calleeContainingClass, typeMapper);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class FieldInfo {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper, boolean oldSingleton) {
|
public static FieldInfo createForSingleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper, boolean oldSingleton) {
|
||||||
if (!classDescriptor.getKind().isSingleton()) {
|
if (!classDescriptor.getKind().isSingleton() || DescriptorUtils.isEnumEntry(classDescriptor)) {
|
||||||
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
throw new UnsupportedOperationException("Can't create singleton field for class: " + classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor;
|
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.KtExpression;
|
import org.jetbrains.kotlin.psi.KtExpression;
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor;
|
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor;
|
||||||
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
@@ -575,7 +576,16 @@ public abstract class StackValue {
|
|||||||
return receiverWithParameter;
|
return receiverWithParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
@NotNull
|
||||||
|
public static Field enumEntry(@NotNull ClassDescriptor descriptor, @NotNull JetTypeMapper typeMapper) {
|
||||||
|
DeclarationDescriptor enumClass = descriptor.getContainingDeclaration();
|
||||||
|
assert DescriptorUtils.isEnumClass(enumClass) : "Enum entry should be declared in enum class: " + descriptor;
|
||||||
|
Type type = typeMapper.mapType((ClassDescriptor) enumClass);
|
||||||
|
return field(type, type, descriptor.getName().asString(), true, none(), descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static Field singleton(@NotNull ClassDescriptor classDescriptor, @NotNull JetTypeMapper typeMapper) {
|
||||||
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper));
|
return field(FieldInfo.createForSingleton(classDescriptor, typeMapper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
enum class X {
|
||||||
|
|
||||||
|
B {
|
||||||
|
val value2 = "OK"
|
||||||
|
override val value = { value2 }
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract val value: () -> String
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return X.B.value()
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
enum class IssueState {
|
||||||
|
|
||||||
|
FIXED {
|
||||||
|
override fun ToString() = D().k
|
||||||
|
|
||||||
|
fun s() = "OK"
|
||||||
|
|
||||||
|
class D {
|
||||||
|
val k = s()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
open fun ToString() : String = "fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
return IssueState.FIXED.ToString()
|
||||||
|
}
|
||||||
+12
@@ -3496,6 +3496,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt9711.kt")
|
||||||
|
public void testKt9711() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/kt9711.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt9711_2.kt")
|
||||||
|
public void testKt9711_2() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/kt9711_2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("name.kt")
|
@TestMetadata("name.kt")
|
||||||
public void testName() throws Exception {
|
public void testName() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/name.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/enum/name.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user