aboutsummaryrefslogtreecommitdiffstats
path: root/prog/expr.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-06-23 14:22:26 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-06-24 15:02:59 +0000
commit26d77996cd6057592f0d7212c9017e8b62be66e8 (patch)
treeb4e5079ba6490b60915ae357cc2e202afe5bc7ea /prog/expr.go
parent80dc82961e63dcbee9fc31bcce5b74ab8a9f0b2e (diff)
prog: use consistent default values for conditional unions
We used to assume that the default value was the last, yet when it was not specified in the serialized program, the first union option whose condition is satisfied was chosen. Let's be consistent and use the last value in both cases. Also, remember that there's a case when there's no valid default value - this happens when pkg/compiler wraps a conditional field into a union with two conditional fields. Explicitly check for this case and assume that, whatever value is set, is the correct default because in this particular case the conditions of the two union options must be mutually exclusive. Fixes #6105.
Diffstat (limited to 'prog/expr.go')
-rw-r--r--prog/expr.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/prog/expr.go b/prog/expr.go
index fbffd3578..699adff3a 100644
--- a/prog/expr.go
+++ b/prog/expr.go
@@ -205,8 +205,11 @@ func (c *Call) setDefaultConditions(target *Target, transientOnly bool) bool {
if transientOnly && !unionArg.transient {
return
}
- // If several union options match, take the first one.
idx := okIndices[0]
+ if defIdx, ok := unionType.defaultField(); ok {
+ // If there's a default value available, use it.
+ idx = defIdx
+ }
field := unionType.Fields[idx]
replace[unionArg] = MakeUnionArg(unionType,
unionArg.Dir(),