Skip to content

Commit f4f38bf

Browse files
committed
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 <[email protected]> Change-Id: I47e1a78ae4ac868966099bf85c0e5731aa7b78b6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200763 Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent 62b3cfa commit f4f38bf

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

internal/filetypes/types.cue

+4-13
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ modes: export: {
104104
docs: true | *false
105105
attributes: true | *false
106106
}
107-
encodings: cue: {
108-
*forms.data | _
109-
}
107+
encodings: cue: forms.data
110108
}
111109

112110
// TODO(mvdan): this "output" mode appears to be unused at the moment.
@@ -118,9 +116,7 @@ modes: output: {
118116
docs: true | *false
119117
attributes: true | *false
120118
}
121-
encodings: cue: {
122-
*forms.data | _
123-
}
119+
encodings: cue: forms.data
124120
}
125121

126122
// eval is a legacy mode
@@ -132,9 +128,7 @@ modes: eval: {
132128
docs: true | *false
133129
attributes: true | *false
134130
}
135-
encodings: cue: {
136-
*forms.final | _
137-
}
131+
encodings: cue: forms.final
138132
}
139133

140134
modes: def: {
@@ -145,9 +139,7 @@ modes: def: {
145139
docs: *true | false
146140
attributes: *true | false
147141
}
148-
encodings: cue: {
149-
*forms.schema | _
150-
}
142+
encodings: cue: forms.schema
151143
}
152144

153145
// A Encoding indicates a file format for representing a program.
@@ -266,7 +258,6 @@ forms: schema: {
266258
constraints: *true | false
267259
keepDefaults: *true | false
268260
imports: *true | false
269-
optional: *true | false
270261
}
271262

272263
forms: final: {

0 commit comments

Comments
 (0)