Fix the accessing to static field from Parent through Child

This commit is contained in:
Zalim Bashorov
2015-10-06 23:15:36 +03:00
parent ae2831338b
commit c8f54b3ccb
7 changed files with 67 additions and 5 deletions
@@ -2220,7 +2220,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor);
if (!isStaticBackingField) {
propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor);
}
Type backingFieldOwner =
typeMapper.mapOwner(changeOwnerOnTypeMapping ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor);
@@ -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() {}
}
@@ -0,0 +1,6 @@
class Parent {
public static int a = 1;
public static int b = 2;
public static void foo() {}
public static void baz() {}
}
@@ -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()
@@ -71,6 +71,7 @@ public abstract class AbstractBytecodeTextTest extends CodegenTestCase {
public void doTestMultiFile(@NotNull String folderName) throws Exception {
final List<String> files = new ArrayList<String>(2);
FileUtil.processFilesRecursively(new File(folderName), new Processor<File>() {
@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<String> filenames) throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
private void doTestMultiFile(@NotNull List<String> filenames) throws Exception {
Collections.sort(filenames);
String[] sortedFilenames = ArrayUtil.toStringArray(filenames);
loadFiles(sortedFilenames);
@@ -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/");
@@ -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<File>(javaSourceRoot));
myEnvironment = KotlinCoreEnvironment.createForTests(
getTestRootDisposable(),
configuration,
EnvironmentConfigFiles.JVM_CONFIG_FILES);
}
@Override