Fix for invoking abstract method in enum
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -43,6 +45,7 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.Modality.ABSTRACT;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
|
||||
/**
|
||||
@@ -267,4 +270,17 @@ public class CodegenUtil {
|
||||
(context.getParentContext() instanceof NamespaceContext && context.getParentContext().getContextDescriptor() == containingDeclaration))
|
||||
&& context.getContextKind() != OwnerKind.TRAIT_IMPL);
|
||||
}
|
||||
|
||||
public static boolean hasAbstractMembers(@NotNull ClassDescriptor classDescriptor) {
|
||||
return ContainerUtil.exists(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors(),
|
||||
new Condition<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public boolean value(DeclarationDescriptor declaration) {
|
||||
if (!(declaration instanceof MemberDescriptor)) {
|
||||
return false;
|
||||
}
|
||||
return ((MemberDescriptor) declaration).getModality() == ABSTRACT;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
signature.getInterfaces().add("java/lang/annotation/Annotation");
|
||||
}
|
||||
else if (jetClass.hasModifier(JetTokens.ENUM_KEYWORD)) {
|
||||
isAbstract = hasAbstractMembers(descriptor);
|
||||
isEnum = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
enum class A() {
|
||||
ENTRY: A(){ override fun t() = "OK"}
|
||||
|
||||
abstract fun t(): String
|
||||
}
|
||||
|
||||
fun f(a: A) = a.t()
|
||||
|
||||
fun box()= f(A.ENTRY)
|
||||
@@ -171,4 +171,8 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
public void testInnerWithExistingClassObject() {
|
||||
blackBoxFile("enum/innerWithExistingClassObject.kt");
|
||||
}
|
||||
|
||||
public void testAbstractMethodInEnum() {
|
||||
blackBoxFile("enum/abstractMethodInEnum.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user