cue: allow setting list elements in FillPath

This is a quick-n-dirty implementation, but it works for now.

Fixes #923

Change-Id: Idbc6dac2d0403db86a7853d2100e0a85acc08812
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9526
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
diff --git a/cue/types.go b/cue/types.go
index f2b2b09..e1e267a 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1615,12 +1615,26 @@
 		expr = convert.GoValueToValue(ctx, x, true)
 	}
 	for i := len(p.path) - 1; i >= 0; i-- {
-		expr = &adt.StructLit{Decls: []adt.Decl{
-			&adt.Field{
-				Label: p.path[i].sel.feature(v.idx),
-				Value: expr,
-			},
-		}}
+		switch sel := p.path[i]; {
+		case sel.sel.kind() == adt.IntLabel:
+			i := sel.sel.feature(ctx.Runtime).Index()
+			list := &adt.ListLit{}
+			any := &adt.Top{}
+			// TODO(perf): make this a constant thing. This will be possible with the query extension.
+			for k := 0; k < i; k++ {
+				list.Elems = append(list.Elems, any)
+			}
+			list.Elems = append(list.Elems, expr, &adt.Ellipsis{})
+			expr = list
+
+		default:
+			expr = &adt.StructLit{Decls: []adt.Decl{
+				&adt.Field{
+					Label: p.path[i].sel.feature(v.idx),
+					Value: expr,
+				},
+			}}
+		}
 	}
 	n := &adt.Vertex{}
 	n.AddConjunct(adt.MakeRootConjunct(nil, expr))
diff --git a/cue/types_test.go b/cue/types_test.go
index 1768baa..27c2339 100644
--- a/cue/types_test.go
+++ b/cue/types_test.go
@@ -1134,6 +1134,11 @@
 		`,
 		x:   ast.NewIdent("#foo"),
 		out: `{1, #foo: 1}`,
+	}, {
+		in:   `[...int]`,
+		x:    1,
+		path: ParsePath("0"),
+		out:  `[1]`,
 	}}
 
 	for _, tc := range testCases {