encoding/yaml: consistently use cue.Concrete when calling Value.Syntax
The call to Value.Syntax without cue.Concrete means we don't use
export's ExpandReferences option, so we use the dep package,
which ends performing evaluations to finalize values.
It's these evaluations which then trigger the panic in the issue:
panic: runtime error: index out of range [25] with length 19 [recovered, repanicked]
goroutine 1 gp=0x1c42c03361c0 m=0 mp=0x1aa8e20 [running]:
panic({0x1086880?, 0x1c42c0370be8?})
/home/mvdan/tip/src/runtime/panic.go:877 +0x16f fp=0x1c42c0679af0 sp=0x1c42c0679a40 pc=0x49344f
cuelang.org/go/internal/core/dep.(*visitor).visit.func1()
/home/mvdan/src/c/cue/internal/core/dep/dep.go:235 +0xd8 fp=0x1c42c0679b38 sp=0x1c42c0679af0 pc=0x8cd378
[...]
cuelang.org/go/internal/core/adt.(*nodeContext).addReplacement(...)
/home/mvdan/src/c/cue/internal/core/adt/typocheck.go:272
cuelang.org/go/internal/core/adt.(*nodeContext).insertConstraint.func1({0x1c42c0645520, {0x12c95e0, 0x1c42c06891d0}, {0x1, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, ...}})
/home/mvdan/src/c/cue/internal/core/adt/constraints.go:109 +0x1b1 fp=0x1c42c0679f08 sp=0x1c42c0679e98 pc=0x881e91
Luckily, given that the YAML encoder never uses anchors currently,
we can avoid using dep entirely by using the cue.Concrete option,
meaning that we will marshal a fully expanded value as YAML.
This should result in the same encoded YAML, but reduce the amount
of required work, and sidestep this bug entirely.
There is still likely an underlying bug in either typocheck.go
or the dep package, but given that we are currently rethinking
typo checking via the explicitopen experiment, adding a regression test
for now seems like it's enough. If we ever stopped the YAML encoding
from expanding references again, the bug would surface via the test
if it still existed.
Fixes #4131.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I881b4f4f5f12399a4c257bf1406fb039c1e8d530
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1224352
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>