[dev.simd] simd/_gen/unify: fix some missing environments

There were a couples places where we failed to provide a reasonable
variable environment for YAML encoding. I think this only affects
encoding "!repeat" nodes, which aren't common in practice and a bit of
a disaster, which is how this went unnoticed.

Change-Id: I1a37c00d5eaa1ee8e86d119a2fd73f6a28d69008
Reviewed-on: https://go-review.googlesource.com/c/go/+/698115
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Austin Clements 2025-08-21 09:28:32 -04:00 committed by Gopher Robot
parent 7c84e984e6
commit f7c6fa709e
2 changed files with 6 additions and 1 deletions

View file

@ -132,10 +132,12 @@ func (t *tracer) traceUnify(v, w *Value, e envSet) {
return
}
t.enc.e = e // Interpret values w.r.t. e
t.logf("Unify\n%s\nwith\n%s\nin\n%s",
yamlf(" ", t.enc.value(v)),
yamlf(" ", t.enc.value(w)),
yamlf(" ", t.enc.env(e)))
t.enc.e = envSet{}
if t.saveTree {
if t.node == nil {

View file

@ -316,6 +316,9 @@ func (dec *yamlDecoder) value(node *yaml.Node) (vOut *Value, errOut error) {
// Undo any effects on the environment. We *do* keep any named
// variables that were added to the vars map in case they were
// introduced within the element.
//
// TODO: If we change how we implement repeat nodes, we might be
// able to drop yamlEncoder.env and yamlDecoder.env.
dec.env = origEnv
// Add a generator function
gen = append(gen, func(e envSet) (*Value, envSet) {
@ -444,7 +447,7 @@ func (c Closure) String() string {
}
func (v *Value) MarshalYAML() (any, error) {
enc := &yamlEncoder{}
enc := &yamlEncoder{e: topEnv}
return enc.value(v), nil
}