mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 09:19:13 +07:00
new inference: subtyping/equality constraints interoperability
This commit is contained in:
+3
-17
@@ -118,25 +118,11 @@ public class SubtypingConstraint implements ConstraintFormula {
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
InferenceVariable inferenceVariable = session.getInferenceVariable(myT);
|
||||
if (myS instanceof PsiWildcardType) {
|
||||
return inferenceVariable != null;
|
||||
} else {
|
||||
final InferenceVariable inferenceVariableS = session.getInferenceVariable(myS);
|
||||
if (inferenceVariableS != null) {
|
||||
inferenceVariableS.addBound(myT, InferenceBound.EQ);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (inferenceVariable != null) {
|
||||
inferenceVariable.addBound(myS, InferenceBound.EQ);
|
||||
return true;
|
||||
}
|
||||
if (myT != null && myS != null) {
|
||||
constraints.add(new TypeEqualityConstraint(myT, myS));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
constraints.add(new TypeEqualityConstraint(myT, myS));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -16,11 +16,11 @@
|
||||
package com.intellij.psi.impl.source.resolve.graphInference.constraints;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceBound;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class TypeEqualityConstraint implements ConstraintFormula {
|
||||
private PsiType myT;
|
||||
private PsiType myS;
|
||||
|
||||
public TypeEqualityConstraint(@NotNull PsiType t, @NotNull PsiType s) {
|
||||
public TypeEqualityConstraint(PsiType t, PsiType s) {
|
||||
myT = t;
|
||||
myS = s;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class TypeEqualityConstraint implements ConstraintFormula {
|
||||
}
|
||||
|
||||
if (session.isProperType(myT) && session.isProperType(myS)) {
|
||||
return myT.equals(myS);
|
||||
return Comparing.equal(myT, myS);
|
||||
}
|
||||
InferenceVariable inferenceVariable = session.getInferenceVariable(myS);
|
||||
if (inferenceVariable != null) {
|
||||
@@ -123,16 +123,19 @@ public class TypeEqualityConstraint implements ConstraintFormula {
|
||||
|
||||
TypeEqualityConstraint that = (TypeEqualityConstraint)o;
|
||||
|
||||
if (!myS.equals(that.myS)) return false;
|
||||
if (!myT.equals(that.myT)) return false;
|
||||
if (myS instanceof PsiCapturedWildcardType && myS != that.myS) return false;
|
||||
if (myT instanceof PsiCapturedWildcardType && myT != that.myT) return false;
|
||||
|
||||
if (myS != null ? !myS.equals(that.myS) : that.myS != null) return false;
|
||||
if (myT != null ? !myT.equals(that.myT) : that.myT != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myT.hashCode();
|
||||
result = 31 * result + myS.hashCode();
|
||||
int result = myT != null ? myT.hashCode() : 0;
|
||||
result = 31 * result + (myS != null ? myS.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@ class Node<NodeTypeT extends NodeType> {
|
||||
|
||||
class Main {
|
||||
public static void main(NodeProperty<NumberExpression, Integer> nval, Node<? extends NodeType> expr) {
|
||||
int val = expr.get<error descr="'get(NodeProperty<? super capture<? extends NodeType>,java.lang.Integer>)' in 'Node' cannot be applied to '(NodeProperty<NumberExpression,java.lang.Integer>)'">(nval)</error>;
|
||||
int val = expr.get<error descr="'get(NodeProperty<? super capture<? extends NodeType>,java.lang.Object>)' in 'Node' cannot be applied to '(NodeProperty<NumberExpression,java.lang.Integer>)'">(nval)</error>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user