Skip to content

Optional capture in an enum branch crashes materialization #493

Description

@zharinov

An enum branch whose only capture is optional can match zero nodes. When it does, the branch produces no value, so the enum materializes as null. The debug type verifier then panics because the declared type is an enum but the value is null.

Repro

cargo run -p plotnik -- run -l javascript --compact \
  -q 'Q = (program [A: (identifier)? @id B: (number) @num] @item)' -s 'x'

Branch A is (identifier)? @id. The program's child is an expression_statement, not an identifier, so (identifier)? matches zero nodes. Branch A still succeeds with nothing captured.

Output (debug build):

BUG: Type and value do not match
item: type: enum, value: null

In a release build the verifier is a no-op, so this materializes a malformed value instead of panicking.

Expected

The output must not be a bare null where an enum value is declared. Two ways to fix it:

  • an enum branch should not match on zero consumed nodes, or
  • it should materialize { "$tag": "A", "$data": { "id": null } }, following the "every declared field is present, optional fields are null" policy.

Related

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions