From e782c6a51b1cae60a604b3ce35a2a1c59730c3ca Mon Sep 17 00:00:00 2001 From: Jared Date: Fri, 29 Nov 2024 14:33:03 -0700 Subject: [PATCH] register Enum#compareTo correctly --- .../java/module/JavaNativeTypeTemplate.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeTemplate.java b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeTemplate.java index 8bd2a942..bd9ec2ac 100644 --- a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeTemplate.java +++ b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeTemplate.java @@ -19,6 +19,7 @@ import org.openzen.zenscript.codemodel.ssa.CodeBlockStatement; import org.openzen.zenscript.codemodel.ssa.SSAVariableCollector; import org.openzen.zenscript.codemodel.type.ArrayTypeID; +import org.openzen.zenscript.codemodel.type.BasicTypeID; import org.openzen.zenscript.codemodel.type.TypeID; import org.openzen.zenscript.codemodel.type.builtin.BuiltinMethodSymbol; import org.openzen.zenscript.javashared.JavaClass; @@ -213,9 +214,9 @@ private void loadMethods() { if (class_.cls.isEnum()) { Stream.of( BuiltinMethodSymbol.ENUM_NAME, - BuiltinMethodSymbol.ENUM_ORDINAL, + BuiltinMethodSymbol.ENUM_ORDINAL //BuiltinMethodSymbol.ENUM_VALUES, - BuiltinMethodSymbol.ENUM_COMPARE +// BuiltinMethodSymbol.ENUM_COMPARE ).forEach(method -> methods .computeIfAbsent(method.getID(), x -> new ArrayList<>()) .add(method) @@ -232,6 +233,18 @@ private void loadMethods() { throw new IllegalStateException("We found an enum class without values() method: " + class_.cls.getCanonicalName(), exception); } + try { + MethodID id = MethodID.operator(OperatorType.COMPARE); + FunctionHeader header = new FunctionHeader(BasicTypeID.INT, target); + Method method = class_.cls.getMethod("compareTo", Enum.class); + JavaRuntimeMethod runtimeMethod = new JavaRuntimeMethod(class_, target, method, id, header, false, false); + methods.computeIfAbsent(id, x -> new ArrayList<>()).add(runtimeMethod); + class_.module.getCompiled().setMethodInfo(runtimeMethod, runtimeMethod); + } catch (ReflectiveOperationException exception) { + throw new IllegalStateException("Error while registering Enum#compareTo for: " + class_.cls.getCanonicalName(), exception); + } + + } }