Skip to content

Commit

Permalink
register Enum#compareTo correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Nov 29, 2024
1 parent ce3cf51 commit e782c6a
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}


}
}

Expand Down

0 comments on commit e782c6a

Please sign in to comment.