This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/testdata/cycle: fix another cycle bug
The special case here is that the cycle passes over a reference into a builtin. Fixes #655 Change-Id: Ibc650932ccdf63aa3163a81bf6af101c7d942271 Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8283 Reviewed-by: CUE cueckoo <cueckoo@gmail.com> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org> Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
- Loading branch information
Showing
2 changed files
with
213 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
-- in.cue -- | ||
import "regexp" | ||
|
||
// Issue #655 | ||
// When evaluating a value into a struct, and then back into a value, the | ||
// evaluation mode flips from Partial to AllArcs to Back. This is typically | ||
// not an issue, but if a referred field is within a struct generated by a | ||
// builtin, effectively the entire struct needs to be evaluated and special care | ||
// should be taking to not evaluate too early. | ||
builtinCyclePerm0: { | ||
X: "example.com" | ||
|
||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
|
||
X: Y.host | ||
} | ||
|
||
builtinCyclePerm1: { | ||
X: Y.host | ||
|
||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
|
||
X: "example.com" | ||
} | ||
|
||
builtinCyclePerm2: { | ||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
|
||
X: Y.host | ||
X: "example.com" | ||
} | ||
|
||
builtinCyclePerm3: { | ||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
|
||
X: "example.com" | ||
X: Y.host | ||
} | ||
|
||
builtinCyclePerm4: { | ||
X: "example.com" | ||
X: Y.host | ||
|
||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
} | ||
|
||
builtinCyclePerm5: { | ||
X: Y.host | ||
X: "example.com" | ||
|
||
Y: { | ||
#components: regexp.FindNamedSubmatch(#"^(?P<host>[[:alnum:].]+)$"#, X) | ||
host: #components.host | ||
} | ||
} | ||
-- out/eval -- | ||
(struct){ | ||
builtinCyclePerm0: (struct){ | ||
X: (string){ "example.com" } | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
} | ||
builtinCyclePerm1: (struct){ | ||
X: (string){ "example.com" } | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
} | ||
builtinCyclePerm2: (struct){ | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
X: (string){ "example.com" } | ||
} | ||
builtinCyclePerm3: (struct){ | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
X: (string){ "example.com" } | ||
} | ||
builtinCyclePerm4: (struct){ | ||
X: (string){ "example.com" } | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
} | ||
builtinCyclePerm5: (struct){ | ||
X: (string){ "example.com" } | ||
Y: (struct){ | ||
#components: (#struct){ | ||
host: (string){ "example.com" } | ||
} | ||
host: (string){ "example.com" } | ||
} | ||
} | ||
} | ||
-- out/compile -- | ||
--- in.cue | ||
{ | ||
builtinCyclePerm0: { | ||
X: "example.com" | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
X: 〈0;Y〉.host | ||
} | ||
builtinCyclePerm1: { | ||
X: 〈0;Y〉.host | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
X: "example.com" | ||
} | ||
builtinCyclePerm2: { | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
X: 〈0;Y〉.host | ||
X: "example.com" | ||
} | ||
builtinCyclePerm3: { | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
X: "example.com" | ||
X: 〈0;Y〉.host | ||
} | ||
builtinCyclePerm4: { | ||
X: "example.com" | ||
X: 〈0;Y〉.host | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
} | ||
builtinCyclePerm5: { | ||
X: 〈0;Y〉.host | ||
X: "example.com" | ||
Y: { | ||
#components: 〈import;regexp〉.FindNamedSubmatch("^(?P<host>[[:alnum:].]+)$", 〈1;X〉) | ||
host: 〈0;#components〉.host | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters