|
1 | 1 | /* |
2 | | - * Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * The Universal Permissive License (UPL), Version 1.0 |
@@ -87,21 +87,26 @@ public enum Trait { |
87 | 87 | // The type field is only set for cases which are already implemented. |
88 | 88 |
|
89 | 89 | // First in MRO |
| 90 | + // Interop types first as they are the most concrete/specific types |
| 91 | + NULL("None", PythonBuiltinClassType.PNone), |
90 | 92 | BOOLEAN("Boolean", PythonBuiltinClassType.ForeignBoolean), |
91 | 93 | NUMBER("Number", PythonBuiltinClassType.ForeignNumber), // int, float, complex |
92 | 94 | STRING("String", PythonBuiltinClassType.PString), |
| 95 | + EXCEPTION("Exception", PythonBuiltinClassType.PBaseException), |
| 96 | + META_OBJECT("AbstractClass"), // PythonBuiltinClassType.PythonClass ? |
| 97 | + |
| 98 | + // Interop traits |
| 99 | + EXECUTABLE("Executable"), |
| 100 | + INSTANTIABLE("Instantiable"), |
| 101 | + |
| 102 | + // Container traits/types must be last, see comment above |
93 | 103 | // Hash before Array so that foreign dict+list prefers dict.[] |
94 | 104 | HASH("Dict", PythonBuiltinClassType.PDict), |
95 | 105 | // Array before Iterable so that foreign list+iterable prefers list.__iter__ |
96 | 106 | ARRAY("List", PythonBuiltinClassType.PList), |
97 | | - EXCEPTION("Exception", PythonBuiltinClassType.PBaseException), |
98 | | - EXECUTABLE("Executable"), |
99 | | - INSTANTIABLE("Instantiable"), |
100 | 107 | // Iterator before Iterable so that foreign iterator+iterable prefers iterator.__iter__ |
101 | 108 | ITERATOR("Iterator", PythonBuiltinClassType.PIterator), |
102 | | - ITERABLE("Iterable"), |
103 | | - META_OBJECT("AbstractClass"), // PythonBuiltinClassType.PythonClass ? |
104 | | - NULL("None", PythonBuiltinClassType.PNone); |
| 109 | + ITERABLE("Iterable"); |
105 | 110 | // Last in MRO |
106 | 111 |
|
107 | 112 | public static final Trait[] VALUES = Trait.values(); |
@@ -217,14 +222,14 @@ private PythonManagedClass resolvePolyglotForeignClass(int traits) { |
217 | 222 | traitsList.add(classForTraits(trait.bit)); |
218 | 223 | } |
219 | 224 |
|
220 | | - if (trait == Trait.INSTANTIABLE && Trait.META_OBJECT.isSet(traits)) { |
221 | | - // Deal with it when we are at trait META_OBJECT |
222 | | - } else if (trait == Trait.META_OBJECT) { |
| 225 | + if (trait == Trait.META_OBJECT) { |
223 | 226 | if (Trait.INSTANTIABLE.isSet(traits)) { |
224 | 227 | nameBuilder.append("Class"); |
225 | 228 | } else { |
226 | 229 | nameBuilder.append("AbstractClass"); |
227 | 230 | } |
| 231 | + } else if (trait == Trait.INSTANTIABLE && Trait.META_OBJECT.isSet(traits)) { |
| 232 | + // Dealt with above |
228 | 233 | } else { |
229 | 234 | nameBuilder.append(trait.name); |
230 | 235 | } |
|
0 commit comments