diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index a9899382216..ee299f77419 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2220,7 +2220,10 @@ public class ExpressionCodegen extends JetVisitor implem } } - propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor); + if (!isStaticBackingField) { + propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor); + } + Type backingFieldOwner = typeMapper.mapOwner(changeOwnerOnTypeMapping ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor); diff --git a/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Child.java b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Child.java new file mode 100644 index 00000000000..ae4ce7d842b --- /dev/null +++ b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Child.java @@ -0,0 +1,6 @@ +class Child extends Parent { + public static int b = 3; + public static int c = 4; + public static void bar() {} + public static void baz() {} +} diff --git a/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Parent.java b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Parent.java new file mode 100644 index 00000000000..9bd273555e5 --- /dev/null +++ b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/Parent.java @@ -0,0 +1,6 @@ +class Parent { + public static int a = 1; + public static int b = 2; + public static void foo() {} + public static void baz() {} +} diff --git a/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/test.kt b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/test.kt new file mode 100644 index 00000000000..ba303590256 --- /dev/null +++ b/compiler/testData/codegen/bytecodeTextMultifile/javaStatics/test.kt @@ -0,0 +1,25 @@ +fun test() { + Parent.a + Parent.b + Parent.foo() + Parent.baz() + + Child.a + Child.b + Child.c + Child.foo() + Child.bar() + Child.baz() +} + +// @TestKt.class: +// 1 GETSTATIC Parent.a : I +// 1 GETSTATIC Parent.b : I +// 1 INVOKESTATIC Parent.foo() +// 1 INVOKESTATIC Parent.baz() +// 1 GETSTATIC Child.a : I +// 1 GETSTATIC Child.b : I +// 1 GETSTATIC Child.c : I +// 1 INVOKESTATIC Child.foo() +// 1 INVOKESTATIC Child.bar() +// 1 INVOKESTATIC Child.baz() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.java index d809dd777cf..d6685437dde 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/AbstractBytecodeTextTest.java @@ -71,6 +71,7 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase { public void doTestMultiFile(@NotNull String folderName) throws Exception { final List files = new ArrayList(2); + FileUtil.processFilesRecursively(new File(folderName), new Processor() { @Override public boolean process(File file) { @@ -81,11 +82,11 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase { } }); + createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, new File(folderName)); doTestMultiFile(files); } - public void doTestMultiFile(@NotNull List filenames) throws Exception { - createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL); + private void doTestMultiFile(@NotNull List filenames) throws Exception { Collections.sort(filenames); String[] sortedFilenames = ArrayUtil.toStringArray(filenames); loadFiles(sortedFilenames); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextMultifileTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextMultifileTestGenerated.java index edb2fb2e70c..0fc80163725 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextMultifileTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextMultifileTestGenerated.java @@ -35,6 +35,12 @@ public class BytecodeTextMultifileTestGenerated extends AbstractBytecodeTextTest JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeTextMultifile"), Pattern.compile("^([^\\.]+)$"), false); } + @TestMetadata("javaStatics") + public void testJavaStatics() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeTextMultifile/javaStatics/"); + doTestMultiFile(fileName); + } + @TestMetadata("partMembersCall") public void testPartMembersCall() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeTextMultifile/partMembersCall/"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 6fb9734baba..8b3ec66bee7 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -20,15 +20,19 @@ import com.google.common.collect.Lists; import com.intellij.openapi.util.io.FileUtil; import com.intellij.testFramework.TestDataFile; import com.intellij.testFramework.UsefulTestCase; +import com.intellij.util.SmartList; import kotlin.Charsets; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.backend.common.output.OutputFile; +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; +import org.jetbrains.kotlin.config.CompilerConfiguration; import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils; import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.test.ConfigurationKind; import org.jetbrains.kotlin.test.JetTestUtils; +import org.jetbrains.kotlin.test.TestJdkKind; import org.jetbrains.kotlin.utils.UtilsPackage; import org.jetbrains.org.objectweb.asm.ClassReader; import org.jetbrains.org.objectweb.asm.tree.ClassNode; @@ -47,12 +51,15 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; +import java.util.Collections; import java.util.List; import java.util.Map; import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.getJvmClasspathRoots; import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*; import static org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassFqName; +import static org.jetbrains.kotlin.test.JetTestUtils.compilerConfigurationForTests; +import static org.jetbrains.kotlin.test.JetTestUtils.getAnnotationsJar; public abstract class CodegenTestCase extends UsefulTestCase { @@ -64,11 +71,19 @@ public abstract class CodegenTestCase extends UsefulTestCase { protected GeneratedClassLoader initializedClassLoader; protected ConfigurationKind configurationKind; - protected void createEnvironmentWithMockJdkAndIdeaAnnotations(@NotNull ConfigurationKind configurationKind) { + final protected void createEnvironmentWithMockJdkAndIdeaAnnotations(@NotNull ConfigurationKind configurationKind, File... javaSourceRoot) { if (myEnvironment != null) { throw new IllegalStateException("must not set up myEnvironment twice"); } - myEnvironment = JetTestUtils.createEnvironmentWithMockJdkAndIdeaAnnotations(getTestRootDisposable(), configurationKind); + + CompilerConfiguration configuration = + compilerConfigurationForTests(configurationKind, TestJdkKind.MOCK_JDK, + Collections.singletonList(getAnnotationsJar()), new SmartList(javaSourceRoot)); + + myEnvironment = KotlinCoreEnvironment.createForTests( + getTestRootDisposable(), + configuration, + EnvironmentConfigFiles.JVM_CONFIG_FILES); } @Override