Fix for KT-9711: Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE

#KT-9711 Fixed
This commit is contained in:
Michael Bogdanov
2015-10-23 13:49:07 +03:00
parent 882827bf04
commit b0efcec392
6 changed files with 60 additions and 7 deletions
@@ -2025,10 +2025,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return StackValue.singleton(classDescriptor, typeMapper);
}
if (isEnumEntry(classDescriptor)) {
DeclarationDescriptor enumClass = classDescriptor.getContainingDeclaration();
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);
return StackValue.enumEntry(classDescriptor, typeMapper);
}
ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
if (companionObjectDescriptor != null) {
@@ -2568,7 +2565,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
}
}
else {
return StackValue.thisOrOuter(this, receiverDescriptor, false, false);
return StackValue.thisOrOuter(this, receiverDescriptor, false, isEnumEntry(receiverDescriptor));
}
}
else if (receiverValue instanceof ScriptReceiver) {
@@ -2638,6 +2635,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
!AnnotationUtilKt.isPlatformStaticInObjectOrClass(context.getContextDescriptor())) {
return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
}
else if (isEnumEntry(calleeContainingClass)) {
return StackValue.enumEntry(calleeContainingClass, typeMapper);
}
else {
return StackValue.singleton(calleeContainingClass, typeMapper);
}
@@ -38,7 +38,7 @@ public class FieldInfo {
@NotNull
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);
}
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor;
import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
@@ -575,7 +576,16 @@ public abstract class StackValue {
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));
}