You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today a list literal is closed unless it ends in ..., while a struct literal is open unless it is in a definition or passed to close. This asymmetry shows up as soon as data is combined: y: [3] and y: [_, 4] conflict, although the struct equivalent merges fine. It also breaks round trips: unifying the output of cue export with its source can fail only because an exported data list is closed. In addition, there is no local way to state that one value is closed. close() is a builtin that does not carry a definition's recursive closedness into its argument, and lists have no explicit notation at all.
This proposal makes lists behave like structs with respect to closedness. A list literal outside a definition becomes open data that merges with other lists element by element. A list inside a definition is closed recursively, and a trailing ...T keeps a list open in either place. To close a value explicitly, the proposal adds closed literals: #[...] for a list and #{...} for a struct. Each closes one level only, so #[1, 2] means exactly what [1, 2] means today.
@experiment(openlists)
y: [3]
y: [_, 4] // [3, 4]; an error today#D: [1, 2]
d: #D& [1, 2, 3] // error: index 2 not allowedx: #[1, 2]
x: [_, _, 3] // error: incompatible list lengthsa: #[{name: "x"}]
a: [{name: "x", port: 80}] // fine: the element stays opens: #{a: 1} & {b: 2} // error: b not allowed
The result is one closedness model for lists and structs, and data lists that no longer block export(A) & A from succeeding. Observing a list does not change: len, ==, and export behave as they do today. Closing one level rather than recursively was chosen for two reasons:
Printing: a tool that prints evaluated values can mark the closedness of each value where it is printed, without affecting its children.
Migration: one level is what a data list means today, so rewritten data is not over-closed when a schema adds fields to its elements.
Everything is enabled per file with @experiment(openlists), available from language version v0.18.0; files without it are unaffected, and each list follows the file that created it. cue fix --exp=openlists adds the experiment and rewrites the file to keep its meaning: list literals become #[...], and slices and list-returning builtin calls are wrapped in close(...). On CUE's own test suite the rewrite preserved every outcome. On a corpus of 17 external projects, enabling the experiment without the rewrite changed one project (a JSON Schema oneOf over tuples), and the rewrite restored it.
With the experiment on, a few behaviors change:
Disjunctions by length: disjunctions such as [_] | [_, _] can become ambiguous for data lists, as the equivalent struct disjunctions are today.
Out-of-range index: indexing past the end of an open data list is incomplete rather than an error.
Definitions named #:#[ always starts a closed list, so indexing such a definition must be written (#)[0]; cue fix makes this change.
Open questions include when printers such as cue def should emit closed literals, whether close() can be deprecated, whether a recursive ##[...] / ##{...} form is needed, and how the JSON Schema and OpenAPI conversions should use the new forms.
[Summary generated by Claude AI]
Full Proposal
The complete proposal with all technical details, examples, and implementation notes can be found in the proposal document.
How to Comment
Please provide feedback on this proposal:
For general discussion: Comment in this GitHub discussion
For detailed code review: Comment on the Gerrit CL (link will be added when available)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
📋 Proposal Details:
Proposal: open lists and closed literals
Open lists and closed literals
Today a list literal is closed unless it ends in
..., while a struct literal is open unless it is in a definition or passed toclose. This asymmetry shows up as soon as data is combined:y: [3]andy: [_, 4]conflict, although the struct equivalent merges fine. It also breaks round trips: unifying the output ofcue exportwith its source can fail only because an exported data list is closed. In addition, there is no local way to state that one value is closed.close()is a builtin that does not carry a definition's recursive closedness into its argument, and lists have no explicit notation at all.This proposal makes lists behave like structs with respect to closedness. A list literal outside a definition becomes open data that merges with other lists element by element. A list inside a definition is closed recursively, and a trailing
...Tkeeps a list open in either place. To close a value explicitly, the proposal adds closed literals:#[...]for a list and#{...}for a struct. Each closes one level only, so#[1, 2]means exactly what[1, 2]means today.The result is one closedness model for lists and structs, and data lists that no longer block
export(A) & Afrom succeeding. Observing a list does not change:len,==, and export behave as they do today. Closing one level rather than recursively was chosen for two reasons:Everything is enabled per file with
@experiment(openlists), available from language version v0.18.0; files without it are unaffected, and each list follows the file that created it.cue fix --exp=openlistsadds the experiment and rewrites the file to keep its meaning: list literals become#[...], and slices and list-returning builtin calls are wrapped inclose(...). On CUE's own test suite the rewrite preserved every outcome. On a corpus of 17 external projects, enabling the experiment without the rewrite changed one project (a JSON SchemaoneOfover tuples), and the rewrite restored it.With the experiment on, a few behaviors change:
[_] | [_, _]can become ambiguous for data lists, as the equivalent struct disjunctions are today.#:#[always starts a closed list, so indexing such a definition must be written(#)[0];cue fixmakes this change.Open questions include when printers such as
cue defshould emit closed literals, whetherclose()can be deprecated, whether a recursive##[...]/##{...}form is needed, and how the JSON Schema and OpenAPI conversions should use the new forms.[Summary generated by Claude AI]
Full Proposal
The complete proposal with all technical details, examples, and implementation notes can be found in the proposal document.
How to Comment
Please provide feedback on this proposal:
Last updated: 2026-10-05 13:36:38 UTC
All reactions