github cue-lang/cue v0.3.1
Bug fixes and API work

latest releases: v0.11.0-rc.1, v0.11.0-alpha.5, v0.11.0-alpha.4...
3 years ago

This release contains several bug fixes, API additions, some API deprecations, and a language addition. One of the bug fixes may lead to unexpected behavior (see below).

Backwards Incompatible Bug Fix

One common use case of cmd/cue involves combining CUE and non-CUE files. Consider the following example:

// check.cue
package check

map: {for n in nodes {"\(n.name)": n}}
# data.yaml
nodes:
- name: bar
  parent: foo

- name: baz
  parent: foo

With v0.3.0 and earlier, cue eval would happily combine these two files:

$ cue eval data.yaml check.cue
map: {
    bar: {
        name:   "bar"
        parent: "foo"
    }
    baz: {
        name:   "baz"
        parent: "foo"
    }
}
nodes: [{
    name:   "bar"
    parent: "foo"
}, {
    name:   "baz"
    parent: "foo"
}]

But cue vet would complain:

$ cue vet data.yaml check.cue
map: reference "nodes" not found:
    ./check.cue:3:16

cue vet is actually correct here. Identifier resolution should only happen across files that belong to the same package: non-CUE files are equivalent to a CUE file without a package clause or an anonymous package clause (package _), hence cue eval should really fail in this instance.

v0.3.1 makes cue eval and other commands consistent with cue vet. This was deemed a sufficiently breaking change to warrant its own release.

The fix in this case is to define nodes in the scope of package check:

// check.cue

package check

nodes: _
map: {for n in nodes {"\(n.name)": n}}

at which point cue eval succeeds as before.

An upcoming change will also ensure this condition of identifier resolution is satisfied for all non-package CUE file arguments.

API changes

The cue.Selector model has been extended to allow querying optional fields and arbitrary elements.

Deprecations

The following methods of Value have now been deprecated:
FieldByName
Elem
Template

Really, you should only need LookupPath for your lookup needs. For the most part, these old methods have been reimplemented using the new API.

Also, updated the doc that one really, really should not use Merge.

If you are a user of the API we strongly recommend running staticcheck: it will raise errors where you are using deprecated parts of the API.

Language Additions

CUE now allows parenthesized expressions as labels. This is not (yet) published in the spec, but part of the query proposal. So "\(x)": foo, where x is a string, may now be written as (x): foo.

Changelog

a8ae7d1 cmd/cue/cmd: allow "exec" in commands for TestX
460357b cue/ast: allow parentheses as labels
e70a1db cue/build: remove unused Scope field
f0adb4e cue: deprecate Value.Elem and Value.Template
f063a61 cue: deprecate Value.FieldByName
6a1ae9c cue: move LookupPath to query
e440183 cue: remove error type aliases
4459434 cue: resolve identifiers in an ast.Expr for FillPath
c505c19 cue: separate closedness for lists and structs
957003c cue: support optional field lookup in LookupPath
ad4d1a1 cue: update Merge comment to REALLY NOT USE IT
5c2b281 internal/core: don't resolve values into anonymous packages
72e8fb4 internal/diff: fix printing and top-level diffs

Don't miss a new cue release

NewReleases is sending notifications on new releases.