Skip to content

fix: suppress PrecedenceWarning when nullish fallback is parenthesized#96

Merged
lbliii merged 1 commit intomainfrom
lbliii/fix-nullish-paren-warn
Apr 13, 2026
Merged

fix: suppress PrecedenceWarning when nullish fallback is parenthesized#96
lbliii merged 1 commit intomainfrom
lbliii/fix-nullish-paren-warn

Conversation

@lbliii
Copy link
Copy Markdown
Owner

@lbliii lbliii commented Apr 13, 2026

Summary

  • The PrecedenceWarning for ?? + | fired even when the fallback expression was already parenthesized (e.g., x ?? (y | upper)), producing false positives
  • Adds a parenthesized flag to Filter AST nodes, set by the parser when returning from grouped expressions
  • The compiler now skips the warning when the flag is True, while still warning on ambiguous x ?? y | filter

Test plan

  • New test test_no_precedence_warning_when_fallback_parenthesized verifies parenthesized fallback suppresses warning and unparenthesized still warns
  • All 3760 tests pass, linter and type checker clean

🤖 Generated with Claude Code

`x ?? (y | filter)` already disambiguates intent via explicit parens,
but the compiler warned anyway because the AST didn't track grouping.
Add a `parenthesized` flag to `Filter` nodes, set it in the parser
when returning from `(expr)`, and skip the warning when the flag is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 13, 2026 22:49
@lbliii lbliii merged commit 6c0ade4 into main Apr 13, 2026
12 checks passed
@lbliii lbliii deleted the lbliii/fix-nullish-paren-warn branch April 13, 2026 22:52
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a false-positive PrecedenceWarning emitted for null-coalescing (??) expressions where the fallback side already disambiguates precedence via parentheses (e.g., x ?? (y | upper)).

Changes:

  • Adds a parenthesized flag to Filter AST nodes and sets it when a filter expression is returned from a grouped/parenthesized expression.
  • Updates null-coalesce compilation to skip the filter/?? precedence warning when the RHS Filter is explicitly parenthesized.
  • Adds a regression test ensuring parenthesized fallbacks don’t warn while unparenthesized cases still do.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/test_kida_modern_syntax.py Adds a regression test for suppressing PrecedenceWarning when the RHS filter is parenthesized.
src/kida/parser/expressions.py Marks Filter nodes as parenthesized=True when parsed from grouped expressions.
src/kida/nodes/expressions.py Extends the Filter AST node with a parenthesized boolean flag.
src/kida/compiler/expressions.py Suppresses the ?? + `

from kida.nodes.expressions import Filter

if isinstance(node.right, Filter):
if isinstance(node.right, Filter) and not node.right.parenthesized:
env.from_string("{{ x ?? fallback | upper }}")
prec_warnings = [x for x in w if issubclass(x.category, PrecedenceWarning)]
assert len(prec_warnings) == 1

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