KT-2841 Can't infer a type for function literal parameter if the return type is error
#KT-2841 fixed
This commit is contained in:
@@ -378,9 +378,7 @@ public class CallResolver {
|
||||
|
||||
|
||||
if (!constraintSystem.isSuccessful()) {
|
||||
if (constraintSystemWithoutExpectedTypeConstraint.isSuccessful()) {
|
||||
resolvedCall.setResultingSubstitutor(constraintSystemWithoutExpectedTypeConstraint.getResultingSubstitutor());
|
||||
}
|
||||
resolvedCall.setResultingSubstitutor(constraintSystemWithoutExpectedTypeConstraint.getResultingSubstitutor());
|
||||
List<JetType> argumentTypes = checkValueArgumentTypes(context, resolvedCall, resolvedCall.getTrace()).argumentTypes;
|
||||
JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null;
|
||||
context.tracing.typeInferenceFailed(resolvedCall.getTrace(),
|
||||
|
||||
+10
-5
@@ -40,6 +40,7 @@ import static org.jetbrains.jet.lang.types.Variance.*;
|
||||
public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
|
||||
public static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
||||
private static final JetType CANT_INFER = ErrorUtils.createErrorType("CANT_INFER");
|
||||
|
||||
private final Map<TypeParameterDescriptor, TypeConstraintsImpl> typeParameterConstraints = Maps.newLinkedHashMap();
|
||||
private final Set<ConstraintPosition> errorConstraintPositions = Sets.newHashSet();
|
||||
@@ -48,7 +49,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
private boolean hasErrorInConstrainingTypes;
|
||||
|
||||
public ConstraintSystemImpl() {
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(null);
|
||||
this.resultingSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(CANT_INFER));
|
||||
this.currentSubstitutor = createTypeSubstitutorWithDefaultForUnknownTypeParameter(new TypeProjection(DONT_CARE));
|
||||
}
|
||||
|
||||
@@ -154,16 +155,20 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
@Nullable JetType constrainingType,
|
||||
@NotNull ConstraintPosition constraintPosition) {
|
||||
|
||||
if (constrainingType == null || (ErrorUtils.isErrorType(constrainingType) && constrainingType != DONT_CARE)) {
|
||||
if (constrainingType == TypeUtils.NO_EXPECTED_TYPE
|
||||
|| TypeUtils.identityEqualsOrContainsAsArgument(constrainingType, DONT_CARE)
|
||||
|| TypeUtils.identityEqualsOrContainsAsArgument(constrainingType, CANT_INFER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (constrainingType == null || ErrorUtils.containsErrorType(constrainingType)) {
|
||||
hasErrorInConstrainingTypes = true;
|
||||
return;
|
||||
}
|
||||
|
||||
assert subjectType != TypeUtils.NO_EXPECTED_TYPE : "Subject type shouldn't be NO_EXPECTED_TYPE (in position " + constraintPosition + " )";
|
||||
if (ErrorUtils.isErrorType(subjectType)) return;
|
||||
|
||||
if (constrainingType == DONT_CARE || ErrorUtils.isErrorType(subjectType) || constrainingType == TypeUtils.NO_EXPECTED_TYPE) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeclarationDescriptor constrainingTypeDescriptor = constrainingType.getConstructor().getDeclarationDescriptor();
|
||||
DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor();
|
||||
|
||||
@@ -472,4 +472,14 @@ public class TypeUtils {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean identityEqualsOrContainsAsArgument(@Nullable JetType type, @NotNull JetType argumentType) {
|
||||
if (type == null) return false;
|
||||
if (type == argumentType) return true;
|
||||
if (type instanceof NamespaceType) return false;
|
||||
for (TypeProjection projection : type.getArguments()) {
|
||||
if (identityEqualsOrContainsAsArgument(projection.getType(), argumentType)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user