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

Should optional.none() == null ? #361

Open
dmateusp opened this issue Jun 12, 2024 · 2 comments
Open

Should optional.none() == null ? #361

dmateusp opened this issue Jun 12, 2024 · 2 comments

Comments

@dmateusp
Copy link

I've been trying Optionals through cel-go.

It's confusing as a user to have equality checking optional.none() against null return false. This is the current implementation in cel-go and it seems "correct" looking at the spec.

However, for a user of CEL, not intimate with the internals of the language, would it make more sense to have optional.none() == null return true?

I'm planning on exposing CEL to non-technical users and I feel like this would be a common culprit.

@TristonianJones
Copy link
Collaborator

Hi @dmateusp,

For legacy reasons, the types are comparable; however, I don't think they should be and I would prefer to restrict the comparison. CEL should be null hostile since null can really only occur when the value comes from JSON or from a protobuf wrapper type such as google.protobuf.Int32Value. I may add a restriction as one of the canonical, extended validations.

That said, we've had a different conversation about optional.of(null) == optional.none(), which we feel is a change we need to make as well.

@dmateusp
Copy link
Author

thanks for the clarifications! That makes a lot of sense, it'd be great if the compiler returned something like:

cannot compare optional and null, use .hasValue() instead for example

--

I may add a restriction as one of the canonical, extended validations.

Awesome! I was unaware of the "extended validations"

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

2 participants