Skip to content

Commit 19782a6

Browse files
committed
internal/core/dep: prevent crash
Dep may sometimes assign an "empty" Vertex which has a nil BaseValue. The tasks processing assumed BaseValue to be non-nil. Fixed in dep to not pass `empty` to users. Fixes #1405 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: Ie49e309a567d0cfd4e972bf8c118008ee25ffd39 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/533475 Reviewed-by: Paul Jolly <paul@myitcv.io>
1 parent 195cdf7 commit 19782a6

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
exec cue cmd alias ./alias_tool.cue
2+
cmp stdout stdout-golden
3+
4+
-- alias_tool.cue --
5+
import (
6+
"tool/exec"
7+
"text/template"
8+
)
9+
10+
command: alias: {
11+
rendered: template.Execute(t, instance & {
12+
enabled: true
13+
})
14+
15+
echo: exec.Run & {
16+
cmd: ["echo", rendered]
17+
}
18+
}
19+
20+
t: """
21+
# {{ .name }}
22+
"""
23+
24+
#base: {
25+
enabled: bool | *false
26+
name: string
27+
value?: int
28+
}
29+
30+
#combined: X=#base & {
31+
name: "OK"
32+
if X.enabled {
33+
value: 123456
34+
}
35+
}
36+
37+
instance: #combined & {
38+
enabled: true
39+
}
40+
-- stdout-golden --
41+
# OK

internal/core/adt/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ func (c *OpContext) unifyNode(v Expr, state VertexStatus) (result Value) {
735735

736736
if v.isUndefined() || state > v.status {
737737
// Keep a minimum state of AllArcs.
738+
// TODO: AllArcs may still not be achieved if a node is currently
739+
// evaluating.
738740
state := state
739741
if state < AllArcs {
740742
state = AllArcs

internal/core/dep/dep.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func VisitFields(c *adt.OpContext, n *adt.Vertex, f VisitFunc) error {
9595
var empty *adt.Vertex
9696

9797
func init() {
98+
// TODO: Consider setting a non-nil BaseValue.
9899
empty = &adt.Vertex{}
99100
empty.UpdateStatus(adt.Finalized)
100101
}
@@ -222,7 +223,7 @@ func (c *visitor) markResolver(env *adt.Environment, r adt.Resolver) {
222223
}
223224

224225
if ref, _ := c.ctxt.Resolve(env, r); ref != nil {
225-
if ref != c.node {
226+
if ref != c.node && ref != empty {
226227
d := Dependency{
227228
Node: ref,
228229
Reference: r,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Issue: 1405
2+
-- in.cue --
3+
a: {
4+
command: alias: {
5+
// TODO: fix inner referene.
6+
val: (instance & { enabled: true }).value
7+
echo: cmd: val
8+
}
9+
10+
#base: {
11+
enabled: bool | *false
12+
value?: string
13+
}
14+
15+
#combined: X=#base & {
16+
if X.enabled {
17+
value: "123456"
18+
}
19+
}
20+
21+
instance: #combined & { enabled: true }
22+
}
23+
-- out/dependencies/field --
24+
-- out/dependencies/all --
25+
-- out/dependencies/dynamic --
26+
value
27+
a.command.alias.val
28+
a.#base
29+
a.#combined

0 commit comments

Comments
 (0)