Skip to content

fix(ast): avoid panic in ConstantNode.String on non-JSON floats#974

Open
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:constantnode-string-nan-panic
Open

fix(ast): avoid panic in ConstantNode.String on non-JSON floats#974
netliomax25-code wants to merge 1 commit into
expr-lang:masterfrom
netliomax25-code:constantnode-string-nan-panic

Conversation

@netliomax25-code

Copy link
Copy Markdown

ConstantNode.String panics when json.Marshal rejects the value, which happens for NaN and ±Inf. Constant folding produces these for array literals like [0/0], and predicateCombination calls String on the collection argument while optimizing, so any([0/0], # > 0) || any([0/0], # > 0) makes expr.Compile panic instead of returning a program. Compile does not recover, so the panic reaches the host. Fall back to fmt for values json cannot encode.

@netliomax25-code

Copy link
Copy Markdown
Author

any update?

@sanmaxdev sanmaxdev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the non-JSON float path through ConstantNode.String() and the optimizer regression cases. The fallback keeps the existing JSON output for marshalable constants while preventing the NaN/Inf panic path.

Verified locally:

  • go test ./ast ./optimizer
  • go test ./...
  • git diff --check

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

Successfully merging this pull request may close these issues.

2 participants