Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: fix crash on alias use in lists
Browse files Browse the repository at this point in the history
Change-Id: Ied56dd7c1c971f6ad9fcb8bec2bca28075481521
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4022
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Nov 16, 2019
1 parent a9fdbe7 commit 3d0b204
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cue/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,15 @@ func (v *astVisitor) walk(astNode ast.Node) (ret value) {

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}
Expand Down
8 changes: 8 additions & 0 deletions cue/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ b: preference mark not allowed at this position:
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) {
Expand Down

0 comments on commit 3d0b204

Please sign in to comment.