Skip to content

Commit 9b22804

Browse files
committed
raise type error if not possible to get a consistent method resolution order
1 parent fe756ab commit 9b22804

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
import com.oracle.graal.python.PythonLanguage;
5454
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
55+
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.TypeError;
5556
import com.oracle.graal.python.builtins.objects.PNone;
5657
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
5758
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.GetTypeMemberNode;
@@ -773,10 +774,22 @@ private static PythonAbstractClass[] mergeMROs(MROMergeState[] toMerge, List<Pyt
773774
idx = -1;
774775
}
775776

777+
List<PythonAbstractClass> notMerged = new ArrayList<>();
776778
for (MROMergeState mergee : toMerge) {
777779
if (!mergee.isMerged()) {
778-
throw new IllegalStateException();
780+
PythonAbstractClass candidate = mergee.getCandidate();
781+
if (!notMerged.contains(candidate)) {
782+
notMerged.add(candidate);
783+
}
784+
}
785+
}
786+
if (!notMerged.isEmpty()) {
787+
Iterator<PythonAbstractClass> it = notMerged.iterator();
788+
StringBuilder bases = new StringBuilder(GetNameNode.doSlowPath(it.next()));
789+
while (it.hasNext()) {
790+
bases.append(", ").append(GetNameNode.doSlowPath(it.next()));
779791
}
792+
throw PRaiseNode.getUncached().raise(TypeError, ErrorMessages.CANNOT_GET_CONSISTEMT_METHOD_RESOLUTION, bases);
780793
}
781794

782795
return mro.toArray(new PythonAbstractClass[mro.size()]);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public abstract class ErrorMessages {
117117
public static final String CANNOT_CREATE_WEAK_REFERENCE_TO = "cannot create weak reference to '%p' object";
118118
public static final String CANNOT_DELETE_ATTRIBUTE = "can't delete %s.%s";
119119
public static final String CANNOT_GET_SHAPE_OF_NATIVE_CLS = "cannot get shape of native class";
120+
public static final String CANNOT_GET_CONSISTEMT_METHOD_RESOLUTION = "Cannot create a consistent method resolution order (MRO) for bases %p, %p";
120121
public static final String CANNOT_HANDLE_ZIP_FILE = "cannot handle Zip file: '%s'";
121122
public static final String CANNOT_IMPORT_NAME = "cannot import name '%s'";
122123
public static final String CANNOT_INITIALIZE_WITH = "cannot initialize %s with %s%s";

0 commit comments

Comments
 (0)