Skip to content

Commit

Permalink
internal/core/adt: allow definitions in structs
Browse files Browse the repository at this point in the history
This old evaluator allowed new definitions in closed structs.
This is not according to the spec. However, mimic this
behavior in the new evaluator for now.

Issue #2884
Issue #543

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Ia0c37fb7c915426f13ed091f948749f7c9ac9fbb
  • Loading branch information
mpvl committed Apr 4, 2024
1 parent 421c428 commit b3feafe
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 114 deletions.
39 changes: 7 additions & 32 deletions cue/testdata/definitions/files.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,18 @@ Conjuncts: 69
Disjuncts: 26
-- out/evalalpha --
Errors:
#Config: field not allowed:
./in.cue:15:1
#theme: field not allowed:
./in.cue:3:1
dark: field not allowed:
./in.cue:7:1
light: field not allowed:
./in.cue:11:1

Result:
(_|_){
// [eval]
(#struct){
console: (#struct){
color: (string){ "dark" }
ctermbg: (string){ "239" }
}
#theme: (_|_){
// [eval] #theme: field not allowed:
// ./in.cue:3:1
#theme: (#struct){
color: (string){ string }
ctermbg: (string){ string }
}
Expand All @@ -72,9 +65,7 @@ Result:
color: (string){ "light" }
ctermbg: (string){ "254" }
}
#Config: (_|_){
// [eval] #Config: field not allowed:
// ./in.cue:15:1
#Config: (#struct){
console: (#struct){ |(*(#struct){
color: (string){ "light" }
ctermbg: (string){ "254" }
Expand All @@ -88,29 +79,20 @@ Result:
diff old new
--- old
+++ new
@@ -1,17 +1,41 @@
-(#struct){
- #theme: (#struct){
@@ -1,13 +1,28 @@
+Errors:
+#Config: field not allowed:
+ ./in.cue:15:1
+#theme: field not allowed:
+ ./in.cue:3:1
+dark: field not allowed:
+ ./in.cue:7:1
+light: field not allowed:
+ ./in.cue:11:1
+
+Result:
+(_|_){
+ // [eval]
(#struct){
+ console: (#struct){
+ color: (string){ "dark" }
+ ctermbg: (string){ "239" }
+ }
+ #theme: (_|_){
+ // [eval] #theme: field not allowed:
+ // ./in.cue:3:1
#theme: (#struct){
color: (string){ string }
ctermbg: (string){ string }
}
Expand All @@ -131,14 +113,7 @@ diff old new
color: (string){ "light" }
ctermbg: (string){ "254" }
}
- #Config: (#struct){
+ #Config: (_|_){
+ // [eval] #Config: field not allowed:
+ // ./in.cue:15:1
console: (#struct){ |(*(#struct){
color: (string){ "light" }
ctermbg: (string){ "254" }
@@ -20,8 +44,4 @@
@@ -20,8 +35,4 @@
ctermbg: (string){ "239" }
}) }
}
Expand Down
45 changes: 9 additions & 36 deletions cue/testdata/definitions/visibility.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,36 @@ Unifications: 8
Conjuncts: 10
Disjuncts: 8
-- out/evalalpha --
Errors:
foo.#name: field not allowed:
./in.cue:4:6
./in.cue:9:2

Result:
(_|_){
// [eval]
(struct){
#foo: (#struct){
name: (string){ string }
}
foo: (_|_){
// [eval]
foo: (#struct){
_name: (string){ "foo" }
_#name: (string){ "bar" }
#name: (_|_){
// [eval] foo.#name: field not allowed:
// ./in.cue:4:6
// ./in.cue:9:2
}
#name: (string){ "baz" }
name: (string){ string }
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,11 +1,23 @@
-(struct){
+Errors:
+foo.#name: field not allowed:
+ ./in.cue:4:6
+ ./in.cue:9:2
+
+Result:
+(_|_){
+ // [eval]
#foo: (#struct){
@@ -3,9 +3,9 @@
name: (string){ string }
}
- foo: (#struct){
foo: (#struct){
- name: (string){ string }
+ foo: (_|_){
+ // [eval]
_name: (string){ "foo" }
_#name: (string){ "bar" }
- #name: (string){ "baz" }
+ #name: (_|_){
+ // [eval] foo.#name: field not allowed:
+ // ./in.cue:4:6
+ // ./in.cue:9:2
+ }
#name: (string){ "baz" }
+ name: (string){ string }
}
}
-- diff/todo/p3 --
Reordering.
-- diff/explanation --
New evaluator now disallows new definitions in closed structs.
New evaluator should ultimately disallow new definitions in closed structs.
-- out/eval --
(struct){
#foo: (#struct){
Expand Down
72 changes: 27 additions & 45 deletions cue/testdata/export/issue2244.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ Unifications: 24
Conjuncts: 58
Disjuncts: 40
-- out/evalalpha --
Errors:
m.if.#pattern: field not allowed:
./in.cue:11:24
./in.cue:8:2
./in.cue:24:35

Result:
(_|_){
// [eval]
(struct){
_#matchPattern(:x): (_|_){
// [incomplete] _#matchPattern: error in call to strings.HasSuffix: non-concrete value string:
// ./in.cue:11:6
Expand All @@ -65,56 +57,46 @@ Result:
#step: (#struct){
if: ((string|number)){ |((number){ number }, (string){ string }) }
}
m: (_|_){
// [eval]
if: (_|_){
// [eval] m.if.#pattern: field not allowed:
// ./in.cue:11:24
// ./in.cue:8:2
// ./in.cue:24:35
#pattern: (string){ "refs/tags/v*" }
}
m: (#struct){
if: ((string|number)){ |((number){
number
#pattern: (string){ "refs/tags/v*" }
}, (string){
string
#pattern: (string){ "refs/tags/v*" }
}) }
}
}
-- diff/-out/evalalpha<==>+out/eval --
diff old new
--- old
+++ new
@@ -1,4 +1,12 @@
-(struct){
+Errors:
+m.if.#pattern: field not allowed:
+ ./in.cue:11:24
+ ./in.cue:8:2
+ ./in.cue:24:35
+
+Result:
+(_|_){
+ // [eval]
_#matchPattern(:x): (_|_){
// [incomplete] _#matchPattern: error in call to strings.HasSuffix: non-concrete value string:
// ./in.cue:11:6
@@ -13,11 +21,14 @@
#step: (#struct){
@@ -14,10 +14,12 @@
if: ((string|number)){ |((number){ number }, (string){ string }) }
}
- m: (#struct){
m: (#struct){
- if: (string){
- "refs/tags/v"
+ m: (_|_){
+ // [eval]
+ if: (_|_){
+ // [eval] m.if.#pattern: field not allowed:
+ // ./in.cue:11:24
+ // ./in.cue:8:2
+ // ./in.cue:24:35
#pattern: (string){ "refs/tags/v*" }
- #pattern: (string){ "refs/tags/v*" }
- let prefix#1 = (string){ "refs/tags/v" }
}
- }
+ if: ((string|number)){ |((number){
+ number
+ #pattern: (string){ "refs/tags/v*" }
+ }, (string){
+ string
+ #pattern: (string){ "refs/tags/v*" }
+ }) }
}
}
-- diff/todo/p0 --
disjunction with number is not properly eliminated. The issue seems to be that
the embedded string scalar is not properly propagated. This, in turn, is related
to tasks starting before, while ending after, the start of processing
disjunctions.
-- diff/explanation --
New definition semantics: #pattern is not allowed in #step
New evaluator should ultimately disallow new definitions in closed structs
and not allow #pattern in #step
-- out/eval --
(struct){
_#matchPattern(:x): (_|_){
Expand Down
3 changes: 2 additions & 1 deletion internal/core/adt/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@ outer:
for _, a := range dst.arcs {
ca := a.cc
f := ca.Label()
if f.IsHidden() || f.IsLet() {
// TODO: disallow new definitions in closed structs.
if f.IsHidden() || f.IsLet() || f.IsDef() {
continue
}
for _, b := range closed.arcs {
Expand Down

0 comments on commit b3feafe

Please sign in to comment.