KT-1892: initializers for extension properties

This commit is contained in:
Alex Tkachman
2012-08-04 22:07:21 +03:00
parent 186807a6d7
commit 4e0e7fb943
3 changed files with 16 additions and 10 deletions
@@ -223,22 +223,19 @@ public class NamespaceCodegen {
@Override
public void doSomething(@NotNull ClassBuilder v) {
MethodVisitor mv = v.newMethod(namespace, ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
for (JetFile file : files) {
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
mv.visitCode();
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
mv.visitCode();
FrameMap frameMap = new FrameMap();
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, CodegenContexts.STATIC, state);
FrameMap frameMap = new FrameMap();
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, CodegenContexts.STATIC, state);
for (JetFile file : files) {
for (JetDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof JetProperty) {
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
if (initializer != null && !(initializer instanceof JetConstantExpression)) {
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, declaration);
assert descriptor != null;
if (descriptor.getReceiverParameter().exists()) {
continue;
}
codegen.genToJVMStack(initializer);
StackValue.Property propValue = codegen.intermediateValueForProperty(descriptor, true, null);
propValue.store(propValue.type, new InstructionAdapter(mv));
@@ -246,9 +243,7 @@ public class NamespaceCodegen {
}
}
}
}
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
mv.visitInsn(RETURN);
FunctionCodegen.endVisit(mv, "static initializer for namespace", namespace);
mv.visitEnd();
@@ -0,0 +1,5 @@
val Int.ext : () -> Int = { 5 }
val Long.ext : Long = 4.ext().toLong() //(c.kt:4)
val y : Long = 10.toLong().ext
fun box() : String = if (y == 5.toLong()) "OK" else "fail"
@@ -232,6 +232,12 @@ public class PropertyGenTest extends CodegenTestCase {
blackBoxFile("regressions/kt2331.kt");
}
public void testKt1892() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1892.kt");
//System.out.println(generateToText());
}
public void testKt1846() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("regressions/kt1846.kt");