From 8c01fbbebde9b24cf03891dba2b1aa55e341eeb5 Mon Sep 17 00:00:00 2001 From: Daniil Kalinin Date: Wed, 31 Jul 2024 11:35:03 +0200 Subject: [PATCH] [python] fix a bug with obtaining ancestor classes in `com.jetbrains.python.psi.impl.PyClassImpl.mroLinearize` Fix a bug with a situation when two identical inctances of type `Generic` were stored in the map in `com.jetbrains.python.psi.impl.PyClassImpl.mroLinearize` and were processed separately due to not matching hashcodes and equals methods. This situation caused an `MROException` to be thrown so the class ancestors could not be defined properly. It affected generic types matching as an actually generic class was not recognized as generic because of the wrong list of ancestors. GitOrigin-RevId: 391390c5143b0c7247bd55f148d519f80063d5a8 --- .../src/com/jetbrains/python/PyCustomType.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/python-psi-impl/src/com/jetbrains/python/PyCustomType.java b/python/python-psi-impl/src/com/jetbrains/python/PyCustomType.java index 9e8a2c6496fa..5f9e14d10695 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/PyCustomType.java +++ b/python/python-psi-impl/src/com/jetbrains/python/PyCustomType.java @@ -252,6 +252,21 @@ public final class PyCustomType implements PyClassLikeType { } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PyCustomType type)) return false; + return myInstanceType == type.myInstanceType && + myTypesToMimicAsSuperTypes == type.myTypesToMimicAsSuperTypes && + Objects.equals(myTypesToMimic, type.myTypesToMimic) && + Objects.equals(myQualifiedName, type.myQualifiedName); + } + + @Override + public int hashCode() { + return Objects.hash(myInstanceType, myTypesToMimicAsSuperTypes, myQualifiedName, myTypesToMimic); + } + /** * Predicate that filters resolve candidates using {@link #myFilter}