diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 0520454ae4c..431fa5fbdc1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -625,7 +625,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { final ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor); - lookupConstructorExpressionsInClosureIfPresent(constructorContext); + if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { + lookupConstructorExpressionsInClosureIfPresent(constructorContext); + } MutableClosure closure = context.closure; boolean hasThis0 = closure != null && closure.getCaptureThis() != null; diff --git a/idea/testData/javaFacade/kt2764.kt b/idea/testData/javaFacade/kt2764.kt new file mode 100644 index 00000000000..28fb38f1014 --- /dev/null +++ b/idea/testData/javaFacade/kt2764.kt @@ -0,0 +1,8 @@ +fun main(args: Array) { +} + +class Foo(val b: Int) { + { + this.b + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/javaFacade/JetJavaFacadeTest.java b/idea/tests/org/jetbrains/jet/plugin/javaFacade/JetJavaFacadeTest.java index f53473cf2d0..3e6f6a52891 100644 --- a/idea/tests/org/jetbrains/jet/plugin/javaFacade/JetJavaFacadeTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/javaFacade/JetJavaFacadeTest.java @@ -74,6 +74,10 @@ public class JetJavaFacadeTest extends LightCodeInsightFixtureTestCase { doTestWrapMethod(true); } + public void testKt2764() { + doTestWrapClass(); + } + public void testInnerClass() throws Exception { myFixture.configureByFile(getTestName(true) + ".kt"); @@ -144,10 +148,31 @@ public class JetJavaFacadeTest extends LightCodeInsightFixtureTestCase { if (shouldBeWrapped) { assertNotNull(String.format("Failed to wrap jetFunction '%s' to method", jetFunction.getText()), psiMethod); assertInstanceOf(psiMethod, PsiCompiledElement.class); - assertEquals("Invalid original element for generated method", ((PsiCompiledElement)psiMethod).getMirror(), jetFunction); + assertEquals("Invalid original element for generated method", ((PsiCompiledElement) psiMethod).getMirror(), jetFunction); } else { assertNull("There should be no wrapper for given method", psiMethod); } } + + private void doTestWrapClass() { + myFixture.configureByFile(getTestName(true) + ".kt"); + + int offset = myFixture.getEditor().getCaretModel().getOffset(); + PsiElement elementAt = myFixture.getFile().findElementAt(offset); + + assertNotNull("Caret should be set for tested file", elementAt); + + JetClass jetClass = PsiTreeUtil.getParentOfType(elementAt, JetClass.class); + assertNotNull("Caret should be placed to class definition", jetClass); + + // Should not fail! + JetLightClass lightClass = JetLightClass.wrapDelegate(jetClass); + + assertNotNull(String.format("Failed to wrap jetClass '%s' to class", jetClass.getText()), lightClass); + + // This invokes codegen with ClassBuilderMode = SIGNATURES + // No exception/error should happen here + lightClass.getDelegate(); + } }