Skip to content

fix: scope W1028 to enclosing Fn::If pins - #4690

Merged
kddejong merged 3 commits into
aws-cloudformation:mainfrom
kddejong:fix/issue/4673
Sep 9, 2026
Merged

kddejong merged 3 commits into
aws-cloudformation:mainfrom
kddejong:fix/issue/4673

Conversation

@kddejong

@kddejong kddejong commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available

Fixes #4673

Description of changes

W1028 reported both branches of an Fn::If as unreachable when a condition is used at two independent places in one resource and the resource schema forces condition-scenario enumeration. In the reported template, RequiresCompatibilities: [FARGATE] selects a conditional (if/then) sub-schema on AWS::ECS::TaskDefinition, which walks the property subtree once per condition scenario with the condition already pinned.

fn_if checks each branch's reachability by evolving the condition to True/False and reporting W1028 if that raises Unsatisfiable. When the enclosing scenario enumeration has already pinned that same condition, evolving it to the other value always contradicts the pin, so the check becomes a tautology rather than a reachability question — and each enumerated scenario flags the branch it is not currently exploring.

A branch is only truly unreachable when the condition was pinned by an enclosing Fn::If (structural nesting), not by ambient scenario enumeration. This change:

  • Adds Context.fn_if_conditions, a frozenset recording conditions pinned by an enclosing Fn::If as we descend into its branch.
  • Gates the W1028 report on membership in that set, so a condition pinned solely by scenario enumeration no longer produces a false positive.

The existing nested-same-condition case (where an inner Fn::If reuses a condition already fixed by an outer Fn::If) still correctly reports W1028.

Validated against real deployments: both condition branches of the reported ECS TaskDefinition template create successfully (CREATE_COMPLETE), confirming neither branch is unreachable.

Related PRs / Issues

N/A

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT-0 license.

W1028 reported both branches of an Fn::If as unreachable when a
condition was used at two independent places in one resource and the
resource schema forced condition-scenario enumeration (e.g. an if/then
sub-schema). During enumeration the subtree is walked once per scenario
with the condition already pinned, so evolving that condition to the
other value in fn_if always contradicted the pin. The check became a
tautology rather than a reachability question, and every enumerated
scenario flagged the branch it was not exploring.

Only a branch that contradicts a condition pinned by an *enclosing*
Fn::If (structural nesting) is truly dead. Track those pins on the
context via fn_if_conditions and gate the W1028 report on membership,
so a condition pinned solely by scenario enumeration no longer fires.

Verified against real deployments: both condition branches of the
reported ECS TaskDefinition template create successfully, confirming
neither branch is unreachable.

aws-cloudformation#4673
The first cut of the aws-cloudformation#4673 fix keyed W1028 off conditions pinned by an
enclosing Fn::If. That wrongly suppressed legitimate findings whenever
the condition was forced by another real source -- a resource/output
Condition, or a condition that logically implies it (e.g. an And
condition). test_cfn_json's vpc.json regressed from 5 findings to 1.

Separate forced facts from enumeration assumptions in the conditions
context. Conditions.evolve gains assumed=; scenario enumeration
(_build_conditions) pins with assumed=True, recording the pin only in
cnf (used to prune impossible scenarios) and not in the new hard_cnf.
fn_if now reports W1028 only when Conditions.is_reachable -- evaluated
against hard_cnf -- says the branch value is impossible, so implication
via And/Or conditions is handled correctly while pure enumeration
hypotheses are ignored.

aws-cloudformation#4673
@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.64%. Comparing base (a4ed5bb) to head (3d3c74d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4690   +/-   ##
=======================================
  Coverage   94.64%   94.64%           
=======================================
  Files         434      434           
  Lines       15530    15543   +13     
  Branches     3012     3015    +3     
=======================================
+ Hits        14698    14711   +13     
  Misses        454      454           
  Partials      378      378           
Flag Coverage Δ
unittests 94.64% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kddejong
kddejong merged commit 3a3a240 into aws-cloudformation:main Sep 9, 2026
21 checks passed
@kddejong
kddejong deleted the fix/issue/4673 branch September 9, 2026 22:36
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.

W1028 reports both branches of an Fn::If as unreachable when a condition is used twice in one resource

1 participant