Made vararg parameters have Array<out T> type

instead of simply Array<T>
  #KT-1638 Fixed
  #KT-2163 Fixed
  #KT-3213 Fixed
  #KT-4172 Fixed
  #KT-5534 Fixed
This commit is contained in:
Svetlana Isakova
2014-12-09 14:11:11 +03:00
parent d893e8283e
commit 5b4f10e698
42 changed files with 266 additions and 65 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.Collections;
@@ -89,7 +90,7 @@ public class DescriptorFactory {
CallableMemberDescriptor.Kind.SYNTHESIZED, enumClass.getSource());
return values.initialize(null, NO_RECEIVER_PARAMETER, Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>emptyList(),
KotlinBuiltIns.getInstance().getArrayType(enumClass.getDefaultType()), Modality.FINAL,
KotlinBuiltIns.getInstance().getArrayType(Variance.INVARIANT, enumClass.getDefaultType()), Modality.FINAL,
Visibilities.PUBLIC);
}
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.calls.inference.TypeBounds.BoundKind.*
import org.jetbrains.jet.lang.resolve.calls.inference.constraintPosition.ConstraintPosition
import org.jetbrains.jet.utils.addIfNotNull
import org.jetbrains.jet.lang.types.singleBestRepresentative
import org.jetbrains.jet.lang.types.typeUtil.cannotBeReified
public class TypeBoundsImpl(
override val typeVariable: TypeParameterDescriptor,
@@ -159,6 +160,10 @@ public class TypeBoundsImpl(
// a captured type might be an answer
if (!possibleAnswer.getConstructor().isDenotable() && !possibleAnswer.isCaptured()) return false
// e.g. if T has a lower bound 'Nothing' and an upper bound 'String',
// by default 'Nothing' is inferred which can lead to an error for reified type variable
if (typeVariable.isReified() && possibleAnswer.cannotBeReified()) return false
for (bound in bounds) {
when (bound.kind) {
LOWER_BOUND -> if (!JetTypeChecker.DEFAULT.isSubtypeOf(bound.constrainingType, possibleAnswer)) {
@@ -26,6 +26,8 @@ import org.jetbrains.jet.lang.types.Flexibility
import org.jetbrains.jet.lang.types.TypeConstructor
import org.jetbrains.jet.utils.toReadOnlyList
import org.jetbrains.jet.lang.types.checker.JetTypeChecker
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.types.isDynamic
fun JetType.getContainedTypeParameters(): Collection<TypeParameterDescriptor> {
val declarationDescriptor = getConstructor().getDeclarationDescriptor()
@@ -62,4 +64,6 @@ public fun JetType.getContainedAndCapturedTypeParameterConstructors(): Collectio
public fun JetType.isSubtypeOf(superType: JetType): Boolean = JetTypeChecker.DEFAULT.isSubtypeOf(this, superType)
public fun JetType.cannotBeReified(): Boolean = KotlinBuiltIns.isNothingOrNullableNothing(this) || this.isDynamic()
@@ -664,11 +664,6 @@ public class KotlinBuiltIns {
);
}
@NotNull
public JetType getArrayType(@NotNull JetType argument) {
return getArrayType(Variance.INVARIANT, argument);
}
@NotNull
public JetType getEnumType(@NotNull JetType argument) {
Variance projectionType = Variance.INVARIANT;