Skip to content

Commit

Permalink
internal/filetypes: avoid struct-valued defaults
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rogpeppe committed Sep 9, 2024
1 parent 62b3cfa commit f4f38bf
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions internal/filetypes/types.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -132,9 +128,7 @@ modes: eval: {
docs: true | *false
attributes: true | *false
}
encodings: cue: {
*forms.final | _
}
encodings: cue: forms.final
}

modes: def: {
Expand All @@ -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.
Expand Down Expand Up @@ -266,7 +258,6 @@ forms: schema: {
constraints: *true | false
keepDefaults: *true | false
imports: *true | false
optional: *true | false
}

forms: final: {
Expand Down

0 comments on commit f4f38bf

Please sign in to comment.