Skip to content

Commit

Permalink
internal/core/adt: allow pattern constraints alongside fields
Browse files Browse the repository at this point in the history
This was already allowed, but now adjust examples to show
this. Note that this is just reverting to v0.2 behavior.

Change-Id: I77aacf3867dc118c075d9a57420f12f174c4df04
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8926
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Mar 12, 2021
1 parent b51368e commit bbe68e1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 34 deletions.
12 changes: 4 additions & 8 deletions cue/testdata/cycle/patterns.txtar
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Lots of cycle-reference goodness.

-- in.cue --
{[!~"^[.]"]: c}
[!~"^[.]"]: c
a: b
b: [string]: int
c: a: int
{[string]: c}
[string]: c
a: b
b: [string]: int
c: a: int
Expand All @@ -25,19 +25,15 @@ c: a: int
-- out/compile --
--- in.cue
{
{
[!~"^[.]"]: 〈1;c〉
}
[!~"^[.]"]: 〈0;c〉
a: 〈0;b〉
b: {
[string]: int
}
c: {
a: int
}
{
[string]: 〈1;c〉
}
[string]: 〈0;c〉
a: 〈0;b〉
b: {
[string]: int
Expand Down
45 changes: 45 additions & 0 deletions cue/testdata/eval/fields.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- in.cue --
bulkToSelf: {
a: {
foo: [string]: int
foo: bar: "3" // error
}
}
-- out/compile --
--- in.cue
{
bulkToSelf: {
a: {
foo: {
[string]: int
}
foo: {
bar: "3"
}
}
}
}
-- out/eval --
Errors:
bulkToSelf.a.foo.bar: conflicting values "3" and int (mismatched types string and int):
./in.cue:3:24
./in.cue:4:19

Result:
(_|_){
// [eval]
bulkToSelf: (_|_){
// [eval]
a: (_|_){
// [eval]
foo: (_|_){
// [eval]
bar: (_|_){
// [eval] bulkToSelf.a.foo.bar: conflicting values "3" and int (mismatched types string and int):
// ./in.cue:3:24
// ./in.cue:4:19
}
}
}
}
}
4 changes: 2 additions & 2 deletions cue/testdata/export/023.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ raw: true
#e: {
b: int
#f
{[string]: <100}
{[string]: <300}
[string]: <100
[string]: <300
}
-- out/export --

Expand Down
6 changes: 2 additions & 4 deletions cue/testdata/export/032.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
-- in.cue --
{
{[string]: _}
[string]: _
foo: 3
}
-- out/def --
Expand All @@ -18,9 +18,7 @@ foo: 3
--- in.cue
{
{
{
[string]: _
}
[string]: _
foo: 3
}
}
Expand Down
15 changes: 0 additions & 15 deletions doc/ref/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,21 +1103,6 @@ b: a & {
}
```

<!-- NOTE: pattern and default constraints can be made to apply to all
fields by embedding them as a struct:
x: {
a: 2
b: 3
{[string]: int}
}
or by writing
x: [string]: int
x: {
a: 2
b: 3
}
-->

Concrete field labels may be an identifier or string, the latter of which may be
interpolated.
Fields with identifier labels can be referred to within the scope they are
Expand Down
4 changes: 2 additions & 2 deletions internal/core/adt/optional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestOptionalTypes(t *testing.T) {
out: adt.HasPattern,
}, {
in: `
bar: 3 // Not counted, as it is not optional.
{[string]: int} // embedded into end result.
bar: 3 // Not counted, as it is not optional.
[string]: int // embedded into end result.
"\(bar)": int
`,
out: adt.HasPattern | adt.HasDynamic,
Expand Down
4 changes: 2 additions & 2 deletions internal/core/subsume/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ func TestValues(t *testing.T) {
631: {subsumes: false, in: `a: {a: 1}, b: {#a: 1}`},

// Subsuming final values.
700: {subsumes: true, in: `a: {[string]: 1}, b: {foo: 1}`, mode: subFinal},
701: {subsumes: true, in: `a: {[string]: int}, b: {foo: 1}`, mode: subFinal},
700: {subsumes: true, in: `a: [string]: 1, b: {foo: 1}`, mode: subFinal},
701: {subsumes: true, in: `a: [string]: int, b: {foo: 1}`, mode: subFinal},
702: {subsumes: true, in: `a: {["foo"]: int}, b: {foo: 1}`, mode: subFinal},
703: {subsumes: false, in: `a: close({["foo"]: 1}), b: {bar: 1}`, mode: subFinal},
704: {subsumes: false, in: `a: {foo: 1}, b: {foo?: 1}`, mode: subFinal},
Expand Down
2 changes: 1 addition & 1 deletion internal/filetypes/types.cue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package build
encoding: #Encoding
interpretation?: #Interpretation
form?: #Form
tags?: {[string]: string}
tags?: [string]: string
}

// Default is the file used for stdin and stdout. The settings depend
Expand Down

0 comments on commit bbe68e1

Please sign in to comment.