Closed Simn closed 5 years ago
This works now. It's a bit stupid because we construct arrays when printing, but we can fix that later.
This is the current implementation of Enum.toString
:
public function toString() {
var baseName = Type.getEnumConstructs(Type.getEnum(cast this))[_hx_index];
var parameters = Type.enumParameters(cast this);
if (parameters.length == 0) {
return baseName;
}
return '$baseName(${@:privateAccess parameters.join(", ")})';
}
This is obviously not efficient because Type.enumParameters
does dynamic lookup on the enum fields. The alternative would be to have a custom toString
on every enum constructor class, but there can be lots of those and I'm worried about spamming the method storage area.
I'll go ahead and "this is fine" here because I don't care much about printing performance. If this proves to be an issue in some situation we can always improve on it later.
Enum values are currently not printed properly. This is related to #6 and we should make sure to generate the necessary information in a way that doesn't waste memory unnecessarily.