cue
cue copied to clipboard
cue: ParsePath does not understand optional fields
What version of CUE are you using (cue version)?
$ cue version v0.9.0
Does this issue reproduce with the latest release?
Yes
What did you do?
go mod tidy
go run .
cmp stdout stdout.golden
-- go.mod --
module mod.example
go 1.22.3
require cuelang.org/go v0.9.0
-- main.go --
package main
import (
"fmt"
"log"
"cuelang.org/go/cue"
)
func main() {
path := cue.MakePath(cue.Def("values"), cue.Str("api").Optional())
fmt.Printf("path: %v\n", path)
roundTrip := cue.ParsePath(path.String())
if err := roundTrip.Err(); err != nil {
log.Fatal(err)
}
fmt.Printf("roundTrip: %v\n", roundTrip)
}
-- stdout.golden --
path: #values.api?
roundTrip: #values.api?
What did you expect to see?
Passing test. The documentation for cue.ParsePath does not call out an exception for optional fields, so it seems reasonable to assume they can be parsed.
What did you see instead?
> go mod tidy
> go run .
[stdout]
path: #values.api?
[stderr]
main.go:15: expected 'EOF', found '?'
exit status 1
[exit status 1]
FAIL: /tmp/testscript1658982306/repro.txtar/script.txtar:2: unexpected go command failure
Note that required fields are likely affected by this as well.
And when the query extension is added (https://github.com/cue-lang/cue/issues/165) we will need to be careful with this as well.