Skip to content

[BUG] Chaining .? (optional select) produces nested Optional(Optional(...)) #1083

@LouisCaubet

Description

@LouisCaubet

Describe the bug
Chaining multiple .? (optional field select) operations does not work correctly. Each .? in the chain wraps the result in an additional Optional, producing Optional(Optional(Optional(...))) instead of a flat Optional.

For example:

a.?b.?c.?d.orValue("default")

fails at runtime, while the equivalent [?] index syntax works fine:

a[?"b"][?"c"][?"d"].orValue("default")

cel-go seems to handle this correctly: The Go reference implementation unwraps an optional operand before applying qualifiers: https://github.com/google/cel-go/blob/master/interpreter/attributes.go#L1298

To Reproduce
Check which components this affects:

  • parser
  • checker
  • runtime

Sample expression and input that reproduces the issue:

a.?b.?c.?d.orValue("default")

Expected behavior
A clear and concise description of what you expected to happen.

a.?b.?c.?d.orValue("default") should behave the same way as a[?"b"][?"c"][?"d"].orValue("default"), not throw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions