test case and fixes for object and classes inner for enum entry
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.asm4.Label;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.asm4.commons.Method;
|
||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
@@ -355,8 +356,21 @@ public abstract class StackValue {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public static StackValue singleton(ClassDescriptor aClass, JetTypeMapper typeMapper) {
|
||||
return new Singleton(aClass, typeMapper.mapType(aClass.getDefaultType(), JetTypeMapperMode.VALUE));
|
||||
public static StackValue singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||
final Type type = typeMapper.mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.VALUE);
|
||||
|
||||
final ClassKind kind = classDescriptor.getKind();
|
||||
if (kind == ClassKind.CLASS_OBJECT || kind == ClassKind.OBJECT) {
|
||||
return field(type, JvmClassName.byInternalName(type.getInternalName()), "$instance", true);
|
||||
}
|
||||
else if (kind == ClassKind.ENUM_ENTRY) {
|
||||
final JvmClassName owner = typeMapper.getBindingContext()
|
||||
.get(CodegenBinding.FQN, classDescriptor.getContainingDeclaration().getContainingDeclaration());
|
||||
return field(type, owner, classDescriptor.getName().getName(), true);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class None extends StackValue {
|
||||
@@ -1322,22 +1336,4 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Singleton extends StackValue {
|
||||
private final ClassDescriptor classDescriptor;
|
||||
|
||||
protected Singleton(ClassDescriptor classDescriptor, @NotNull Type type) {
|
||||
super(type);
|
||||
this.classDescriptor = classDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(Type type, InstructionAdapter v) {
|
||||
final ClassKind kind = classDescriptor.getKind();
|
||||
if (kind == ClassKind.CLASS_OBJECT || kind == ClassKind.OBJECT) {
|
||||
v.getstatic(this.type.getInternalName(), "$instance", this.type.getDescriptor());
|
||||
coerce(type, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package test
|
||||
|
||||
fun box() = IssueState.DEFAULT.ToString() + IssueState.FIXED.ToString()
|
||||
|
||||
enum class IssueState {
|
||||
DEFAULT {
|
||||
class D {
|
||||
val k = ToString()
|
||||
}
|
||||
}
|
||||
FIXED {
|
||||
override fun ToString() = "K"
|
||||
|
||||
object D {
|
||||
val k = ToString()
|
||||
}
|
||||
}
|
||||
|
||||
open fun ToString() : String = "O"
|
||||
}
|
||||
@@ -150,6 +150,9 @@ public class EnumGenTest extends CodegenTestCase {
|
||||
|
||||
public void testKt2350() {
|
||||
blackBoxFile("regressions/kt2350.kt");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testEntryWithInner() {
|
||||
blackBoxFile("enum/entrywithinner.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user