From 4e0e7fb9439083149c819c9a29f4a7f104a9a5fe Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sat, 4 Aug 2012 22:07:21 +0300 Subject: [PATCH] KT-1892: initializers for extension properties --- .../jetbrains/jet/codegen/NamespaceCodegen.java | 15 +++++---------- compiler/testData/codegen/regressions/kt1892.kt | 5 +++++ .../jetbrains/jet/codegen/PropertyGenTest.java | 6 ++++++ 3 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt1892.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java index d6a345f863c..da0314565b7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/NamespaceCodegen.java @@ -223,22 +223,19 @@ public class NamespaceCodegen { @Override public void doSomething(@NotNull ClassBuilder v) { MethodVisitor mv = v.newMethod(namespace, ACC_PUBLIC | ACC_STATIC, "", "()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(); diff --git a/compiler/testData/codegen/regressions/kt1892.kt b/compiler/testData/codegen/regressions/kt1892.kt new file mode 100644 index 00000000000..8f1ff172a20 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1892.kt @@ -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" \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 54ac061a8e0..ff9fa95edef 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -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");