Skip to content

Commit 4a8aa35

Browse files
committed
Use NO_MATCH rule for false nodes instead
1 parent 7c5ee43 commit 4a8aa35

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/bdd/EndpointBddTrait.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ protected Node createNode() {
172172
Rule result = results.get(i);
173173
if (result instanceof NoMatchRule) {
174174
throw new IllegalStateException("NoMatch rules can only appear at rule index 0. Found at index " + i);
175+
} else if (result == null) {
176+
throw new IllegalStateException("BDD result is null at index " + i);
175177
}
176178
resultBuilder.withValue(result);
177179
}

smithy-rules-engine/src/main/java/software/amazon/smithy/rulesengine/logic/cfg/CfgBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import software.amazon.smithy.rulesengine.language.syntax.rule.Condition;
3535
import software.amazon.smithy.rulesengine.language.syntax.rule.EndpointRule;
3636
import software.amazon.smithy.rulesengine.language.syntax.rule.ErrorRule;
37+
import software.amazon.smithy.rulesengine.language.syntax.rule.NoMatchRule;
3738
import software.amazon.smithy.rulesengine.language.syntax.rule.Rule;
3839
import software.amazon.smithy.rulesengine.language.syntax.rule.TreeRule;
3940
import software.amazon.smithy.rulesengine.logic.ConditionReference;
@@ -66,7 +67,7 @@ public final class CfgBuilder {
6667
private int convergenceNodesCreated = 0;
6768
private int phiVariableCounter = 0;
6869

69-
private String version = "1.1";
70+
private String version;
7071

7172
public CfgBuilder(EndpointRuleSet ruleSet) {
7273
// Apply SSA transform to ensure globally unique variable names
@@ -297,9 +298,10 @@ private CfgNode buildConvergenceNode(
297298
Condition coalesceCondition = createCoalesceCondition(phiVar, versions);
298299
ConditionReference condRef = new ConditionReference(coalesceCondition, false);
299300

300-
// Use terminal (no match) as false branch to prevent BDD optimization
301-
// The coalesce always succeeds, so we never take the false branch
302-
resultNode = new ConditionNode(condRef, resultNode, ResultNode.terminal());
301+
// Use NO_MATCH as false branch since coalesce should always succeed
302+
// This ensures we get a valid result index instead of null that would result from FALSE.
303+
CfgNode noMatch = createResult(NoMatchRule.INSTANCE);
304+
resultNode = new ConditionNode(condRef, resultNode, noMatch);
303305

304306
// Log with deterministic ordering
305307
LOGGER.fine(() -> {

0 commit comments

Comments
 (0)