Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of enums #29

Open
snazy opened this issue Jul 2, 2021 · 0 comments
Open

Better handling of enums #29

snazy opened this issue Jul 2, 2021 · 0 comments

Comments

@snazy
Copy link
Member

snazy commented Jul 2, 2021

The current implementation, based on CEL-Go, implicitly converts every enum-value to a raw int type. "Raw int type" means, that it loses contextual information that the int value is actually the ordinal of an enum-type and therefore it is currently only possible to compare enum-type-properties against an int or the fully-qualified enum. For example these CEL expressions work: someobject.enum_field == 123 and someobject.enum_field == org.projectnessie.cel.demo.EnumType.ENUM_VALUE , but an expression like someobject.enum_field == 'ENUM_VALUE' does not work, because if would compare an int with a string.

Making enum-types first-class citizens in the type system, i.e. add an org.projectnessie.cel.common.types.EnumT, would allow comparing against a string and even iterate over its values.

The implementation of EnumT is somewhat similar to ObjectT. It returns the message (type) name of the enum as its type name.

It is important to maintain the current backward/forward compatibility with enum values at least for protobuf (with the ProtoTypeRegistry) - i.e. allow arbitrary enum ordnial values that are not defined or are negative.

For Java (with the JacksonRegistry) it probably does not make a lot of sense to allow querying enum-type attributes - i.e. JavaBean-getters defined in the Java enum. In fact, what such getters returns actually depends on the current enum implementation, which is not a portable thing.

With this change, the conformance tests for enums, which are currently skipped, should be enabled.

See also:

/cc @nastra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant