Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

for errors out on solvable cycles #779

Closed
Ereski opened this issue Feb 17, 2021 · 2 comments
Closed

for errors out on solvable cycles #779

Ereski opened this issue Feb 17, 2021 · 2 comments
Labels
Milestone

Comments

@Ereski
Copy link

Ereski commented Feb 17, 2021

Current master (2c86835)

Similar to the previous issues I've opened, this time it's for that is having trouble with cycles:

X: Y.message

STATE: {
    for k, v in Y {
        if k != "message" {
            "\(k)": v
        }
    }
}

Y: STATE & {
    message: X
}

This is a simple stateful bidirectional projection expressed in CUE (STATE is saved and restored as needed). In one way, Y is forked into X and STATE. In the other way, X and STATE are joined into Y. Two usage examples are:

X: "test"

STATE: {
    code: 101
}

and

Y: {
    message: "test"
    code: 101
}

Both of which errors out with a cycle error. Even defining X, STATE, and Y all at the same time causes a cycle error.

@mpvl
Copy link
Contributor

mpvl commented Feb 21, 2021

Another interesting one. :)

The cycle here is detected here because the for comprehension iterators over the the very struct in which it embeds.

Arguably, of course, that should be okay as long as it does not add new fields that then should have been used during evaluation.

FTR, in v0.2 the cycle check did not work correctly and this construct would produce inaccurate results.

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#779.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
rogpeppe pushed a commit to rogpeppe-contrib/cue that referenced this issue Apr 7, 2023
Analogous to reference cycles, we allow comprehensions
to use the struct in which they are defined as source,
as long as they do not introduce new fields, which would
alter the source on which they iterate.

Fixes cuelang#779
Fixes #1934
Fixes #1881

Signed-off-by: Marcel van Lohuizen <[email protected]>
Change-Id: Id349de7738567d86bda3cbb137d5ad84aef5b551
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/544129
Reviewed-by: Roger Peppe <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants