Fix nullability check (in case of explicitly nullable types constructed from ype variables)

This commit is contained in:
Alexey Sedunov
2013-02-13 18:15:23 +04:00
parent fc62a7dfa0
commit 1f8d42ab49
3 changed files with 19 additions and 1 deletions
@@ -286,9 +286,12 @@ public class CodegenUtil {
* @return true if a value of this type can be null
*/
public static boolean isNullableType(@NotNull JetType type) {
if (type.isNullable()) {
return true;
}
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
return TypeUtils.hasNullableSuperType(type);
}
return type.isNullable();
return false;
}
}
@@ -0,0 +1,7 @@
import java.util.HashMap
class A<T: Any> {
fun main() {
HashMap<String, T>()[""]
}
}
@@ -154,6 +154,14 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
assertNoIntrinsicsMethodIsCalled(PackageClassUtils.getPackageClassName(FqName.ROOT));
}
public void testNoAssertionForNullableGenericMethodCall() {
setUpEnvironment(true, false);
loadFile("notNullAssertions/noAssertionForNullableGenericMethodCall.kt");
assertNoIntrinsicsMethodIsCalled("A");
}
private void assertNoIntrinsicsMethodIsCalled(String className) {
ClassFileFactory classes = generateClassesInFile();
ClassReader reader = new ClassReader(classes.asBytes(className + ".class"));