Skip to content

Object comprehension can sometimes be parsed as object definition #2201

Closed
@patrick-east

Description

Expected Behavior

An expression like:

package example

p {
    x := {"foo": (1+2) | 1}
}

Should be defining an object comprehension (to be inline with behavior of array and set with these ambiguous | cases).

Actual Behavior

It gets parsed as an object where the value for "foo" has an or call.

$ opa parse /tmp/x.rego 'data'
module
 package
  ref
   data
   "example"
 rule
  head
   p
   true
  body
   expr index=0
    ref
     eq
    x
    object
     "foo"
     call
      ref
       or
      call
       ref
        plus
       1
       2
      1

Additional Info

Part of the inconsistency is that if there is no call (the 1+2) then it is parsed as an object comprehension.

package example

p {
    x = {"foo": 1 | 1}
}

Yields

$ opa parse /tmp/x.rego 'data'
module
 package
  ref
   data
   "example"
 rule
  head
   p
   true
  body
   expr index=0
    ref
     eq
    x
    objectcomprehension
     "foo"
     1
     body
      expr index=0
       1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions