Skip to content

Commit d413bb8

Browse files
committed
internal/core/export: keep open lists open
When no default resolution is selected. In the future we may make lists open by default if they are not in definitions or within the scope of a close builtin (like with structs). Issue #867 Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: I2c946b3cc18894f96f83f788684618cd2ebfadfd Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/528464 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Paul Jolly <paul@myitcv.io>
1 parent 9a040dc commit d413bb8

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

internal/core/export/testdata/adt.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ _|_ // e3: index out of range [2] with length 2
312312
bar
313313
line
314314
"""
315-
l1: [3]
316-
l2: []
315+
l1: [3, ...int]
316+
l2: [...int]
317317
l3: []
318318
l4: [1, 2]
319319
l5: {

internal/core/export/testdata/issue1284.txtar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,22 @@ _|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and
8282
== All
8383
{
8484
a0: {
85-
l: ["a", "b"]
85+
l: ["a", "b", ...]
8686
}
8787
a1: {
88-
l: ["a", "b"]
88+
l: ["a", "b", ...]
8989
}
9090
a2: {
9191
l: _|_ // a2.l: conflicting values ["a","b",...] and {} (mismatched types list and struct)
9292
}
9393
a3: {
94-
l: ["a", "b"]
94+
l: ["a", "b", ...]
9595
}
9696
a4: {
9797
l: {
9898
@decl(1)
9999
#foo: 1
100-
["a", "b"]
100+
["a", "b", ...]
101101
}
102102
}
103103
}

internal/core/export/value.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,21 @@ func (e *exporter) listComposite(v *adt.Vertex) ast.Expr {
344344

345345
l.Elts = append(l.Elts, elem)
346346
}
347+
m, ok := v.BaseValue.(*adt.ListMarker)
348+
if !e.cfg.TakeDefaults && ok && m.IsOpen {
349+
ellipsis := &ast.Ellipsis{}
350+
typ := &adt.Vertex{
351+
Parent: v,
352+
Label: adt.AnyIndex,
353+
}
354+
v.MatchAndInsert(e.ctx, typ)
355+
typ.Finalize(e.ctx)
356+
if typ.Kind() != adt.TopKind {
357+
ellipsis.Type = e.value(typ)
358+
}
359+
360+
l.Elts = append(l.Elts, ellipsis)
361+
}
347362
return l
348363
}
349364

0 commit comments

Comments
 (0)