cue: fix crash on alias use in lists
Change-Id: Ied56dd7c1c971f6ad9fcb8bec2bca28075481521
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4022
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/ast.go b/cue/ast.go
index 4b9b193..c2bb876 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -297,8 +297,15 @@
arcs := []arc{}
for i, e := range elts {
+ elem := v1.walk(e)
+ if elem == nil {
+ // TODO: it would be consistent to allow aliasing in lists
+ // as well, with a similar meaning as alias declarations in
+ // structs.
+ return v.errf(n, "alias not allowed in list")
+ }
v1.sel = strconv.Itoa(i)
- arcs = append(arcs, arc{feature: label(i), v: v1.walk(e)})
+ arcs = append(arcs, arc{feature: label(i), v: elem})
}
s := &structLit{baseValue: newExpr(n), arcs: arcs}
list := &list{baseValue: newExpr(n), elem: s}
diff --git a/cue/ast_test.go b/cue/ast_test.go
index 7772fcb..9417ea6 100644
--- a/cue/ast_test.go
+++ b/cue/ast_test.go
@@ -370,6 +370,14 @@
out: `<0>{` +
`def :: (<1>C{Size: int, Type: string, Text: string} & (<2>C{Size: 0, Type: "B"} | <3>C{Size: 1, Type: "A"}))` +
`}`,
+ }, {
+ // Issue #172
+ in: `
+ package testenv
+ env_:: [NAME=_]: [VALUE=_]
+ env_:: foo: "bar"
+ `,
+ out: "env_.*: alias not allowed in list:\n test:3:20\n<0>{}",
}}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {