From 9290b4460cf0f5066ea1b6cac7247b5fd284f8ba Mon Sep 17 00:00:00 2001 From: Roger Peppe Date: Thu, 5 Sep 2024 14:50:44 +0100 Subject: [PATCH] internal/filetypes: avoid struct-valued defaults Various places in `internal/filetypes/types.cue` use a pattern like this: encodings: cue: { *forms.schema | _ } where the `*forms.schema` value is a struct. This seems unlikely to be what's intended: it means that if a single value inside `encoding.cue` is inconsistent with `forms.schema`, all the rest of the fields in `forms.schema` will be discarded, leaving no defaults at all. There are four places in the code that this pattern is used. As it happens, none of the attributes which are set by the struct-valued default can possibly conflict with anything (all values are set to false and there is nowhere that sets a non-default true value), so this change should not change observable behaviour in any way. Also remove a redundant field definition inside `forms.schema`. Signed-off-by: Roger Peppe Change-Id: I47e1a78ae4ac868966099bf85c0e5731aa7b78b6 Dispatch-Trailer: {"type":"trybot","CL":1200763,"patchset":7,"ref":"refs/changes/63/1200763/7","targetBranch":"master"} --- internal/filetypes/types.cue | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/internal/filetypes/types.cue b/internal/filetypes/types.cue index e30141d1e..803d8b8b8 100644 --- a/internal/filetypes/types.cue +++ b/internal/filetypes/types.cue @@ -104,9 +104,7 @@ modes: export: { docs: true | *false attributes: true | *false } - encodings: cue: { - *forms.data | _ - } + encodings: cue: forms.data } // TODO(mvdan): this "output" mode appears to be unused at the moment. @@ -118,9 +116,7 @@ modes: output: { docs: true | *false attributes: true | *false } - encodings: cue: { - *forms.data | _ - } + encodings: cue: forms.data } // eval is a legacy mode @@ -132,9 +128,7 @@ modes: eval: { docs: true | *false attributes: true | *false } - encodings: cue: { - *forms.final | _ - } + encodings: cue: forms.final } modes: def: { @@ -145,9 +139,7 @@ modes: def: { docs: *true | false attributes: *true | false } - encodings: cue: { - *forms.schema | _ - } + encodings: cue: forms.schema } // A Encoding indicates a file format for representing a program. @@ -266,7 +258,6 @@ forms: schema: { constraints: *true | false keepDefaults: *true | false imports: *true | false - optional: *true | false } forms: final: {