Generic type with Nothing in arguments compiles to raw type

This commit is contained in:
Zalim Bashorov
2015-10-12 22:41:05 +03:00
parent 8e9f1ac31a
commit 9acf3e40de
5 changed files with 127 additions and 6 deletions
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.codegen.state;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import kotlin.CollectionsKt;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.BuiltinsPackageFragment;
@@ -595,6 +597,11 @@ public class JetTypeMapper {
boolean projectionsAllowed
) {
if (signatureVisitor != null) {
if (hasNothingInArguments(jetType)) {
signatureVisitor.writeAsmType(asmType);
return;
}
signatureVisitor.writeClassBegin(asmType);
List<TypeProjection> arguments = jetType.getArguments();
@@ -622,6 +629,24 @@ public class JetTypeMapper {
}
}
private static boolean hasNothingInArguments(JetType jetType) {
boolean hasNothingInArguments = CollectionsKt.any(jetType.getArguments(), new Function1<TypeProjection, Boolean>() {
@Override
public Boolean invoke(TypeProjection projection) {
return KotlinBuiltIns.isNothingOrNullableNothing(projection.getType());
}
});
if (hasNothingInArguments) return true;
return CollectionsKt.any(jetType.getArguments(), new Function1<TypeProjection, Boolean>() {
@Override
public Boolean invoke(TypeProjection projection) {
return !projection.isStarProjection() && hasNothingInArguments(projection.getType());
}
});
}
private static Variance getEffectiveVariance(Variance parameterVariance, Variance projectionKind, Variance howThisTypeIsUsed) {
// Return type must not contain wildcards
if (howThisTypeIsUsed == Variance.OUT_VARIANCE) return projectionKind;