File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -1615,12 +1615,26 @@ func (v Value) FillPath(p Path, x interface{}) Value {
1615
1615
expr = convert .GoValueToValue (ctx , x , true )
1616
1616
}
1617
1617
for i := len (p .path ) - 1 ; i >= 0 ; i -- {
1618
- expr = & adt.StructLit {Decls : []adt.Decl {
1619
- & adt.Field {
1620
- Label : p .path [i ].sel .feature (v .idx ),
1621
- Value : expr ,
1622
- },
1623
- }}
1618
+ switch sel := p .path [i ]; {
1619
+ case sel .sel .kind () == adt .IntLabel :
1620
+ i := sel .sel .feature (ctx .Runtime ).Index ()
1621
+ list := & adt.ListLit {}
1622
+ any := & adt.Top {}
1623
+ // TODO(perf): make this a constant thing. This will be possible with the query extension.
1624
+ for k := 0 ; k < i ; k ++ {
1625
+ list .Elems = append (list .Elems , any )
1626
+ }
1627
+ list .Elems = append (list .Elems , expr , & adt.Ellipsis {})
1628
+ expr = list
1629
+
1630
+ default :
1631
+ expr = & adt.StructLit {Decls : []adt.Decl {
1632
+ & adt.Field {
1633
+ Label : p .path [i ].sel .feature (v .idx ),
1634
+ Value : expr ,
1635
+ },
1636
+ }}
1637
+ }
1624
1638
}
1625
1639
n := & adt.Vertex {}
1626
1640
n .AddConjunct (adt .MakeRootConjunct (nil , expr ))
Original file line number Diff line number Diff line change @@ -1134,6 +1134,11 @@ func TestFillPath(t *testing.T) {
1134
1134
` ,
1135
1135
x : ast .NewIdent ("#foo" ),
1136
1136
out : `{1, #foo: 1}` ,
1137
+ }, {
1138
+ in : `[...int]` ,
1139
+ x : 1 ,
1140
+ path : ParsePath ("0" ),
1141
+ out : `[1]` ,
1137
1142
}}
1138
1143
1139
1144
for _ , tc := range testCases {
You can’t perform that action at this time.
0 commit comments