Fix assertions generation for substituted members
This commit is contained in:
@@ -571,7 +571,7 @@ public class AsmUtil {
|
|||||||
) {
|
) {
|
||||||
if (!state.isGenerateNotNullAssertions()) return;
|
if (!state.isGenerateNotNullAssertions()) return;
|
||||||
|
|
||||||
if (!Boolean.TRUE.equals(state.getBindingContext().get(BindingContext.IS_DECLARED_IN_JAVA, descriptor))) return;
|
if (!isDeclaredInJava(descriptor, state.getBindingContext())) return;
|
||||||
|
|
||||||
JetType type = descriptor.getReturnType();
|
JetType type = descriptor.getReturnType();
|
||||||
if (type == null || type.isNullable()) return;
|
if (type == null || type.isNullable()) return;
|
||||||
@@ -585,6 +585,19 @@ public class AsmUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isDeclaredInJava(@NotNull CallableDescriptor callableDescriptor, @NotNull BindingContext context) {
|
||||||
|
CallableDescriptor descriptor = callableDescriptor;
|
||||||
|
while (true) {
|
||||||
|
if (Boolean.TRUE.equals(context.get(BindingContext.IS_DECLARED_IN_JAVA, descriptor))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CallableDescriptor original = descriptor.getOriginal();
|
||||||
|
if (descriptor == original) break;
|
||||||
|
descriptor = original;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void pushDefaultValueOnStack(@NotNull Type type, @NotNull InstructionAdapter v) {
|
public static void pushDefaultValueOnStack(@NotNull Type type, @NotNull InstructionAdapter v) {
|
||||||
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
||||||
v.aconst(null);
|
v.aconst(null);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val a = ArrayList<String>()
|
||||||
|
a.get(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(a: ArrayList<String>) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
class A<T, U> {
|
||||||
|
@NotNull
|
||||||
|
T foo() { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class B<T> extends A<T, Integer> {
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
T foo() { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class C extends B<String> {
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
String foo() { return null; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun bar(a: A<String, Int>, b: B<String>, c: C) {
|
||||||
|
val sa: String = a.foo()
|
||||||
|
val sb: String = b.foo()
|
||||||
|
val sc: String = c.foo()
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import org.jetbrains.asm4.ClassReader;
|
import org.jetbrains.asm4.ClassReader;
|
||||||
import org.jetbrains.asm4.ClassVisitor;
|
import org.jetbrains.asm4.ClassVisitor;
|
||||||
import org.jetbrains.asm4.MethodVisitor;
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
@@ -116,6 +117,28 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
|
|||||||
assertNoIntrinsicsMethodIsCalled("A");
|
assertNoIntrinsicsMethodIsCalled("A");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testArrayListGet() {
|
||||||
|
setUpEnvironment(true, true);
|
||||||
|
|
||||||
|
loadFile("notNullAssertions/arrayListGet.kt");
|
||||||
|
String text = generateToText();
|
||||||
|
|
||||||
|
assertTrue(text.contains("checkReturnedValueIsNotNull"));
|
||||||
|
assertTrue(text.contains("checkParameterIsNotNull"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testJavaMultipleSubstitutions() {
|
||||||
|
File javaClassesTempDirectory = compileJava("notNullAssertions/javaMultipleSubstitutions.java");
|
||||||
|
setUpEnvironment(true, true, javaClassesTempDirectory);
|
||||||
|
|
||||||
|
loadFile("notNullAssertions/javaMultipleSubstitutions.kt");
|
||||||
|
String text = generateToText();
|
||||||
|
|
||||||
|
assertEquals(3, StringUtil.getOccurrenceCount(text, "checkReturnedValueIsNotNull"));
|
||||||
|
assertEquals(3, StringUtil.getOccurrenceCount(text, "checkParameterIsNotNull"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void assertNoIntrinsicsMethodIsCalled(String className) {
|
private void assertNoIntrinsicsMethodIsCalled(String className) {
|
||||||
ClassFileFactory classes = generateClassesInFile();
|
ClassFileFactory classes = generateClassesInFile();
|
||||||
ClassReader reader = new ClassReader(classes.asBytes(className + ".class"));
|
ClassReader reader = new ClassReader(classes.asBytes(className + ".class"));
|
||||||
|
|||||||
Reference in New Issue
Block a user