Skip to content

Fix ineffective if warnings in discarded case branches#550

Open
JSap0914 wants to merge 2 commits into
OpenVoxProject:mainfrom
JSap0914:fix-542-ineffective-if-warning
Open

Fix ineffective if warnings in discarded case branches#550
JSap0914 wants to merge 2 commits into
OpenVoxProject:mainfrom
JSap0914:fix-542-ineffective-if-warning

Conversation

@JSap0914

Copy link
Copy Markdown

What

  • inspect each case branch's final expression when the case result is discarded
  • report an ineffective final conditional even when earlier statements in that branch have side effects
  • preserve value-producing branch expressions when the case result is assigned or otherwise used

Why

The validator only checked whether the entire case expression was idempotent. An earlier assignment made the case look productive, so an ineffective if at the end of the branch escaped the existing "value was produced and then forgotten" diagnostic.

Fixes #542

Tests

  • bundle exec rspec spec/unit/pops/validator/validator_spec.rb: 359 examples, 0 failures
  • bundle exec rspec spec/unit/pops: 4,798 examples, 0 failures, 3 expected pending examples
  • bundle exec rubocop lib/puppet/pops/validation/checker4_0.rb: no offenses
  • ruby -wc on both changed Ruby files: syntax OK

JSap0914 added 2 commits July 16, 2026 07:37
Inspect the final expression of each case branch when the case result is discarded, so an ineffective conditional is reported even when earlier branch statements have side effects.

Signed-off-by: JSup <hanjisang0914@gmail.com>
Signed-off-by: JSup <hanjisang0914@gmail.com>
@JSap0914
JSap0914 force-pushed the fix-542-ineffective-if-warning branch from 5770999 to ac0c926 Compare July 15, 2026 22:37
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.

[Bug]: Sometimes Error "This 'if' statement has no effect", sometimes not

1 participant