Use type constructor when finding findStaticallyKnownSubtype
See InnerClasses.testBareTypes
This commit is contained in:
@@ -17,8 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.types;
|
package org.jetbrains.kotlin.types;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import kotlin.CollectionsKt;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
@@ -29,10 +32,7 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
|||||||
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure;
|
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CastDiagnosticsUtil {
|
public class CastDiagnosticsUtil {
|
||||||
|
|
||||||
@@ -166,20 +166,21 @@ public class CastDiagnosticsUtil {
|
|||||||
// in this case it will be Collection<T>
|
// in this case it will be Collection<T>
|
||||||
KotlinType supertypeWithVariables = TypeCheckingProcedure.findCorrespondingSupertype(subtypeWithVariables, supertype);
|
KotlinType supertypeWithVariables = TypeCheckingProcedure.findCorrespondingSupertype(subtypeWithVariables, supertype);
|
||||||
|
|
||||||
final List<TypeParameterDescriptor> variables = subtypeWithVariables.getConstructor().getParameters();
|
List<TypeParameterDescriptor> variables = subtypeWithVariables.getConstructor().getParameters();
|
||||||
|
Set<TypeConstructor> variableConstructors = CollectionsKt.toSet(
|
||||||
|
CollectionsKt.map(variables, new Function1<TypeParameterDescriptor, TypeConstructor>() {
|
||||||
|
@Override
|
||||||
|
public TypeConstructor invoke(TypeParameterDescriptor descriptor) {
|
||||||
|
return descriptor.getTypeConstructor();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
Map<TypeConstructor, TypeProjection> substitution;
|
Map<TypeConstructor, TypeProjection> substitution;
|
||||||
if (supertypeWithVariables != null) {
|
if (supertypeWithVariables != null) {
|
||||||
// Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo
|
// Now, let's try to unify Collection<T> and Collection<Foo> solution is a map from T to Foo
|
||||||
TypeUnifier.UnificationResult solution = TypeUnifier.unify(
|
TypeUnifier.UnificationResult solution = TypeUnifier.unify(
|
||||||
new TypeProjectionImpl(supertype), new TypeProjectionImpl(supertypeWithVariables),
|
new TypeProjectionImpl(supertype), new TypeProjectionImpl(supertypeWithVariables),
|
||||||
new Predicate<TypeConstructor>() {
|
Predicates.in(variableConstructors));
|
||||||
@Override
|
|
||||||
public boolean apply(TypeConstructor typeConstructor) {
|
|
||||||
ClassifierDescriptor descriptor = typeConstructor.getDeclarationDescriptor();
|
|
||||||
return descriptor instanceof TypeParameterDescriptor && variables.contains(descriptor);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
substitution = Maps.newHashMap(solution.getSubstitution());
|
substitution = Maps.newHashMap(solution.getSubstitution());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user