Change default upper bound of Java type parameters to Any!

#KT-7672 Fixed
This commit is contained in:
Denis Zharkov
2015-07-17 12:11:56 +03:00
parent 0e69ebb288
commit 97af85da9c
119 changed files with 326 additions and 205 deletions
@@ -22,10 +22,13 @@ import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.load.java.lazy.types.LazyJavaTypeResolver
import org.jetbrains.kotlin.load.java.lazy.types.toFlexible
class LazyJavaTypeParameterDescriptor(
private val c: LazyJavaResolverContext,
@@ -45,7 +48,10 @@ class LazyJavaTypeParameterDescriptor(
override fun resolveUpperBounds(): Set<JetType> {
val bounds = javaTypeParameter.getUpperBounds()
if (bounds.isEmpty()) {
return setOf(c.module.builtIns.getDefaultBound())
return setOf(LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(
c.module.builtIns.getAnyType(),
c.module.builtIns.getNullableAnyType()
))
}
else {
return bounds.map {
@@ -923,6 +923,10 @@ public class KotlinBuiltIns {
return isAnyOrNullableAny(type) && type.isMarkedNullable();
}
public static boolean isDefaultBound(@NotNull JetType type) {
return isNullableAny(type);
}
public static boolean isUnit(@NotNull JetType type) {
return isNotNullConstructedFromGivenClass(type, FQ_NAMES.unit);
}
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedureCallbacks
import org.jetbrains.kotlin.types.typeUtil.getNestedArguments
import org.jetbrains.kotlin.types.typeUtil.isDefaultBound
import java.util.ArrayList
import java.util.HashMap
import java.util.HashSet
@@ -151,7 +152,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
}
for ((typeVariable, typeBounds) in allTypeParameterBounds) {
for (declaredUpperBound in typeVariable.getUpperBounds()) {
if (KotlinBuiltIns.isNullableAny(declaredUpperBound)) continue //todo remove this line (?)
if (declaredUpperBound.isDefaultBound()) continue //todo remove this line (?)
val position = TYPE_BOUND_POSITION.position(typeVariable.getIndex())
addBound(typeVariable, declaredUpperBound, UPPER_BOUND, position)
}
@@ -403,7 +404,7 @@ public class ConstraintSystemImpl : ConstraintSystem {
constraintPosition: ConstraintPosition
) {
val typeVariable = getMyTypeVariable(parameterType)!!
if (!KotlinBuiltIns.isNullableAny(typeVariable.getUpperBoundsAsType())
if (!typeVariable.getUpperBoundsAsType().isDefaultBound()
&& constrainingTypeProjection.getProjectionKind() == Variance.IN_VARIANCE) {
errors.add(CannotCapture(constraintPosition, typeVariable))
}
@@ -126,4 +126,6 @@ fun JetType.getNestedArguments(): List<TypeProjection> {
typeProjection.getType().getArguments().forEach { stack.add(it) }
}
return result
}
}
public fun JetType.isDefaultBound(): Boolean = KotlinBuiltIns.isDefaultBound(getSupertypeRepresentative())