removed stored systemWithoutExpectedTypeConstraint
now we can filter out constraints of special type if necessary
This commit is contained in:
@@ -3,9 +3,39 @@ package typeInferenceExpectedTypeMismatch
|
||||
import java.util.*
|
||||
|
||||
fun test() {
|
||||
val <!UNUSED_VARIABLE!>s<!> : Set<Int> = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>newList<!>()
|
||||
val s : Set<Int> = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>newList<!>()
|
||||
use(s)
|
||||
}
|
||||
|
||||
fun newList<S>() : ArrayList<S> {
|
||||
return ArrayList<S>()
|
||||
}
|
||||
|
||||
trait Out<out T>
|
||||
trait In<in T>
|
||||
|
||||
trait Two<T, R>
|
||||
|
||||
trait A
|
||||
trait B: A
|
||||
trait C: A
|
||||
|
||||
fun <T, R> foo(o: Out<T>, i: In<R>): Two<T, R> = throw Exception("$o $i")
|
||||
|
||||
fun test1(outA: Out<A>, inB: In<B>) {
|
||||
foo(outA, inB)
|
||||
|
||||
val b: Two<A, C> = <!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>foo<!>(outA, inB)
|
||||
use(b)
|
||||
}
|
||||
|
||||
fun <T> bar(o: Out<T>, i: In<T>): Two<T, T> = throw Exception("$o $i")
|
||||
|
||||
fun test2(outA: Out<A>, inC: In<C>) {
|
||||
<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>bar<!>(outA, inC)
|
||||
|
||||
val b: Two<A, B> = <!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>bar<!>(outA, inC)
|
||||
use(b)
|
||||
}
|
||||
|
||||
fun use(vararg a: Any?) = a
|
||||
+17
-14
@@ -39,6 +39,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition.EXPECTED_TYPE_POSITION;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.EQUAL;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl.ConstraintKind.SUB_TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeBoundsImpl.BoundKind.*;
|
||||
@@ -58,9 +59,6 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
private final TypeSubstitutor currentSubstitutor;
|
||||
private boolean hasErrorInConstrainingTypes;
|
||||
|
||||
@Nullable
|
||||
private ConstraintSystem systemWithoutExpectedTypeConstraint;
|
||||
|
||||
private final ConstraintSystemStatus constraintSystemStatus = new ConstraintSystemStatus() {
|
||||
@Override
|
||||
public boolean isSuccessful() {
|
||||
@@ -109,14 +107,12 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
|
||||
@Override
|
||||
public boolean hasOnlyExpectedTypeMismatch() {
|
||||
if (systemWithoutExpectedTypeConstraint == null) {
|
||||
// the expected type constraint isn't added, there can't be an error with it
|
||||
return false;
|
||||
}
|
||||
if (!isSuccessful() && systemWithoutExpectedTypeConstraint.getStatus().isSuccessful()) {
|
||||
if (isSuccessful()) return false;
|
||||
ConstraintSystem systemWithoutExpectedTypeConstraint = filterConstraintsOut(EXPECTED_TYPE_POSITION);
|
||||
if (systemWithoutExpectedTypeConstraint.getStatus().isSuccessful()) {
|
||||
return true;
|
||||
}
|
||||
if (errorConstraintPositions.size() == 1 && errorConstraintPositions.contains(ConstraintPosition.EXPECTED_TYPE_POSITION)) {
|
||||
if (errorConstraintPositions.size() == 1 && errorConstraintPositions.contains(EXPECTED_TYPE_POSITION)) {
|
||||
// if systemWithoutExpectedTypeConstraint has unknown type parameters, it's not successful,
|
||||
// but there can be expected type mismatch after expected type is added
|
||||
return true;
|
||||
@@ -215,6 +211,17 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
Conditions.<ConstraintPosition>alwaysTrue());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConstraintSystem filterConstraintsOut(@NotNull ConstraintPosition... excludePositions) {
|
||||
final Set<ConstraintPosition> positions = Sets.newHashSet(excludePositions);
|
||||
return filterConstraints(new Condition<ConstraintPosition>() {
|
||||
@Override
|
||||
public boolean value(ConstraintPosition constraintPosition) {
|
||||
return !positions.contains(constraintPosition);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConstraintSystem filterConstraints(@NotNull final Condition<ConstraintPosition> condition) {
|
||||
return replaceTypeVariables(Functions.<TypeParameterDescriptor>identity(),
|
||||
@@ -273,9 +280,6 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
) {
|
||||
if (constrainingType != null && TypeUtils.noExpectedType(constrainingType)) return;
|
||||
|
||||
if (constraintPosition == ConstraintPosition.EXPECTED_TYPE_POSITION) {
|
||||
systemWithoutExpectedTypeConstraint = copy();
|
||||
}
|
||||
addConstraint(SUB_TYPE, subjectType, constrainingType, constraintPosition);
|
||||
}
|
||||
|
||||
@@ -483,8 +487,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
|
||||
@Override
|
||||
public TypeSubstitutor getResultingSubstitutor() {
|
||||
if (getStatus().hasOnlyExpectedTypeMismatch()) {
|
||||
assert systemWithoutExpectedTypeConstraint != null;
|
||||
return systemWithoutExpectedTypeConstraint.getResultingSubstitutor();
|
||||
return filterConstraintsOut(EXPECTED_TYPE_POSITION).getResultingSubstitutor();
|
||||
}
|
||||
return resultingSubstitutor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user