Fix nullability check (in case of explicitly nullable types constructed from ype variables)
This commit is contained in:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user