disjunction type equals/hashCode, essential for new inference (IDEA-140150)

This commit is contained in:
Anna Kozlova
2015-05-12 11:39:47 +02:00
parent 6817171a69
commit 8b320ba8a7
3 changed files with 52 additions and 0 deletions
@@ -148,4 +148,24 @@ public class PsiDisjunctionType extends PsiType.Stub {
return new PsiType[]{lub};
}
}
@Override
public int hashCode() {
return myTypes.get(0).hashCode();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final PsiDisjunctionType that = (PsiDisjunctionType)o;
if (that.myTypes.size() != myTypes.size()) return false;
for (int i = 0; i < myTypes.size(); i++) {
if (!myTypes.get(i).equals(that.myTypes.get(i))) return false;
}
return true;
}
}
@@ -0,0 +1,28 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Optional;
class Main {
public static class Either<A, B> {
final public Optional<A> _1;
final public Optional<B> _2;
private Either(Optional<A> _1, Optional<B> _2) {
this._1 = _1;
this._2 = _2;
}
public static <A, B> Either<A, B> _2(B value) {
return null;
}
}
public Either<String, Exception> test1() {
try {
new FileOutputStream("").write(1);
return null;
} catch (NullPointerException | IOException e) {
return Either._2(e);
}
}
}
@@ -275,6 +275,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testDisjunctionTypeEquality() throws Exception {
doTest();
}
private void doTest() throws Exception {
doTest(false);
}