Skip to content

Commit e782c6a

Browse files
committed
register Enum#compareTo correctly
1 parent ce3cf51 commit e782c6a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeTemplate.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.openzen.zenscript.codemodel.ssa.CodeBlockStatement;
2020
import org.openzen.zenscript.codemodel.ssa.SSAVariableCollector;
2121
import org.openzen.zenscript.codemodel.type.ArrayTypeID;
22+
import org.openzen.zenscript.codemodel.type.BasicTypeID;
2223
import org.openzen.zenscript.codemodel.type.TypeID;
2324
import org.openzen.zenscript.codemodel.type.builtin.BuiltinMethodSymbol;
2425
import org.openzen.zenscript.javashared.JavaClass;
@@ -213,9 +214,9 @@ private void loadMethods() {
213214
if (class_.cls.isEnum()) {
214215
Stream.of(
215216
BuiltinMethodSymbol.ENUM_NAME,
216-
BuiltinMethodSymbol.ENUM_ORDINAL,
217+
BuiltinMethodSymbol.ENUM_ORDINAL
217218
//BuiltinMethodSymbol.ENUM_VALUES,
218-
BuiltinMethodSymbol.ENUM_COMPARE
219+
// BuiltinMethodSymbol.ENUM_COMPARE
219220
).forEach(method -> methods
220221
.computeIfAbsent(method.getID(), x -> new ArrayList<>())
221222
.add(method)
@@ -232,6 +233,18 @@ private void loadMethods() {
232233
throw new IllegalStateException("We found an enum class without values() method: " + class_.cls.getCanonicalName(), exception);
233234
}
234235

236+
try {
237+
MethodID id = MethodID.operator(OperatorType.COMPARE);
238+
FunctionHeader header = new FunctionHeader(BasicTypeID.INT, target);
239+
Method method = class_.cls.getMethod("compareTo", Enum.class);
240+
JavaRuntimeMethod runtimeMethod = new JavaRuntimeMethod(class_, target, method, id, header, false, false);
241+
methods.computeIfAbsent(id, x -> new ArrayList<>()).add(runtimeMethod);
242+
class_.module.getCompiled().setMethodInfo(runtimeMethod, runtimeMethod);
243+
} catch (ReflectiveOperationException exception) {
244+
throw new IllegalStateException("Error while registering Enum#compareTo for: " + class_.cls.getCanonicalName(), exception);
245+
}
246+
247+
235248
}
236249
}
237250

0 commit comments

Comments
 (0)