Add CodegenUtil.isNullableType(), fix assertions
JetType.isNullable() is not accurate when the type denotes a type parameter: a parameter can be not null (isNullable=false), but its upper bound can be nullable (<T: Any?>), so null may appear in the value of such type. Therefore it's preferred to use a special check (isNullableType()) in codegen from now on Do not generate assertion for parameters of not-null types which have a nullable upper bound + the same with Java method calls Also fix Intrinsics class internal name in tests #KT-3313 Fixed
This commit is contained in:
@@ -47,6 +47,7 @@ import java.util.Set;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.isInterface;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.isNullableType;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||
|
||||
@@ -532,7 +533,7 @@ public class AsmUtil {
|
||||
|
||||
for (ValueParameterDescriptor parameter : descriptor.getValueParameters()) {
|
||||
JetType type = parameter.getReturnType();
|
||||
if (type == null || type.isNullable()) continue;
|
||||
if (type == null || isNullableType(type)) continue;
|
||||
|
||||
int index = frameMap.getIndex(parameter);
|
||||
Type asmType = state.getTypeMapper().mapReturnType(type);
|
||||
@@ -574,7 +575,7 @@ public class AsmUtil {
|
||||
if (!isDeclaredInJava(descriptor, state.getBindingContext())) return;
|
||||
|
||||
JetType type = descriptor.getReturnType();
|
||||
if (type == null || type.isNullable()) return;
|
||||
if (type == null || isNullableType(type)) return;
|
||||
|
||||
Type asmType = state.getTypeMapper().mapReturnType(type);
|
||||
if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
@@ -278,5 +279,16 @@ public class CodegenUtil {
|
||||
return ((MemberDescriptor) declaration).getModality() == ABSTRACT;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A work-around of the generic nullability problem in the type checker
|
||||
* @return true if a value of this type can be null
|
||||
*/
|
||||
public static boolean isNullableType(@NotNull JetType type) {
|
||||
if (type.getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor) {
|
||||
return TypeUtils.hasNullableSuperType(type);
|
||||
}
|
||||
return type.isNullable();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user