Skip to content

feat: warn on constant/one-sided predicate in Filter and Join (#2795)#3058

Open
anderson-joyle wants to merge 2 commits into
mainfrom
a-team/2795-join-predicate-warning
Open

feat: warn on constant/one-sided predicate in Filter and Join (#2795)#3058
anderson-joyle wants to merge 2 commits into
mainfrom
a-team/2795-join-predicate-warning

Conversation

@anderson-joyle
Copy link
Copy Markdown
Contributor

Summary

Fixes #2795. Extends Power Fx's static analysis to warn users when a Filter or Join predicate will produce surprising results because it doesn't reference the expected record symbols.

Two improvements:

  1. Filter compound constant detection — The existing warning for literal true is extended via a recursive IsConstantExpression() helper to also catch compound constant expressions like Filter([10,20,30], true && true).

  2. Join one-sided predicate warning — A new CheckSemantics override in Join.cs detects when the predicate fails to reference one or both of the join scope sides (LeftRecord/RightRecord, or user aliases), emitting WarnJoinPredicateDoesNotUseScope.

Both warnings are Warning severity: IsSuccess remains true and evaluation proceeds normally.

Files changed

File Change
FunctionScopeInfo.cs Added IsConstantExpression() recursive helper; CheckLiteralPredicates calls it instead of checking bare NodeKind
Join.cs New CheckSemantics override with PredicateReferencesScope() private helper
Strings.cs New WarnJoinPredicateDoesNotUseScope key
PowerFxResources.en-US.resx en-US string for the new warning
RecalcEngineTests.cs 3 new tests: compound-constant Filter (warns), one-sided Join (warns), both-sides Join (no warn)

Test results

Interpreter suite:  64,949 passed  /  0 failed  /  318 skipped
Core suite:          3,631 passed  /  0 failed
New tests:               3 passed  /  0 failed

Design notes

  • IsConstantExpression returns false for Call nodes (conservative) — avoids false positives on stateful or side-effecting functions like Rand().
  • Two warnings fire when a Join predicate references neither side (e.g., a constant predicate). Intentional.
  • CheckSemantics is only reached when CheckTypes succeeds, so existing Join.txt tests with type errors are unaffected.
  • The expression test framework ignores warnings when IsSuccess=true, so no .txt file updates are needed.

A-TEAM pipeline confidence: 9 / 10

Reason: The strongest fix in this batch. Purely additive — new warnings only, zero change to existing formula evaluation semantics. All 5 acceptance criteria verified, 68,580+ tests green with zero failures. Key design decisions are correct: conservative IsConstantExpression, two warnings for fully-constant Join predicates (right behavior), and the non-impact on existing .txt expression tests is well-understood. The only minor caveat is the .Net7.0 test project TFM change, which is a local environment accommodation and has no bearing on correctness.

🤖 Generated with Claude Code via A-TEAM pipeline

- Extend FunctionScopeInfo.CheckLiteralPredicates to detect compound
  constant expressions (e.g. true && true) via new IsConstantExpression()
  recursive helper, not just bare literals.
- Add JoinFunction.CheckSemantics override with PredicateReferencesScope()
  AST walker; emits WarnJoinPredicateDoesNotUseScope when the predicate
  does not reference one of the two scope symbols (LeftRecord/RightRecord
  or their user-defined aliases).
- Add WarnJoinPredicateDoesNotUseScope resource key and en-US string.
- Add three new unit tests: FilterCompoundConstantPredicateWarning,
  JoinOneSidedPredicateWarning, JoinBothSidesPredicateNoWarning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@anderson-joyle anderson-joyle force-pushed the a-team/2795-join-predicate-warning branch from cf5d4e6 to cf509b9 Compare April 30, 2026 16:53
The CI pipeline runs on .NET SDK 7.0 and cannot target net8.0.
These csproj files are inside src/tests/.Net7.0/ and must stay at net7.0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@anderson-joyle anderson-joyle marked this pull request as ready for review April 30, 2026 17:15
@anderson-joyle anderson-joyle requested a review from a team as a code owner April 30, 2026 17:15
@jas-valgotar
Copy link
Copy Markdown
Contributor

✅ No public API change.

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.

Join - warn if predicate doesn't use both LeftRecord and RightRecord

2 participants