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

cue: references to ancestor nodes should be direct and not through outer scope #152

Closed
mpvl opened this issue Oct 8, 2019 · 6 comments
Closed
Labels

Comments

@mpvl
Copy link
Contributor

mpvl commented Oct 8, 2019

If a struct is referred to (and copied), any reference within this copy to the root of the struct should resolve to the root of the copied struct.

Both these cases below should work.

a: {
  b: int
  c: a.b  // workaround: use b, intstead of a.b
}
d: a & { b: 2 } // a.c == 2

Foo: {
   foo?: Foo
   bar:  string
}
foo: Foo & {
	foo: {
		bar: "a"
	}
	bar: "b"
}

See also Issue #145

@mpvl mpvl added the NeedsFix label Oct 8, 2019
mpvl added a commit that referenced this issue Oct 8, 2019
This is not fully correct, but is a trade-off between
two wrongs. See Issue #152.

The real underlying issue is an incorrect
forwarding/ copying of the root struct which is better
resolved as part of an overall performance overhaul.

Fixes #145

Change-Id: I7fa04d5f16ea6fb09686fb8a0c5864142635eb8c
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3581
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
@mpvl mpvl added Thinking and removed NeedsFix labels Oct 26, 2019
@mpvl
Copy link
Contributor Author

mpvl commented Oct 26, 2019

Or maybe the way it is now is actually correct. Depending on how a references is interpreted, a reference to root should bind to the copy or not, but it should probably be consistent.

@rudolph9
Copy link
Contributor

rudolph9 commented Nov 21, 2019

Or maybe the way it is now is actually correct. Depending on how a references is interpreted, a reference to root should bind to the copy or not, but it should probably be consistent.

@mpvl Agreed, either case is probably valid but needs to be consistent.

In either case, it should probably factor into the discussion around the @ notation on the Proposal: Querying extension.

@rudolph9
Copy link
Contributor

rudolph9 commented Nov 21, 2019

Relevant comment to this this issue here

@mpvl
Copy link
Contributor Author

mpvl commented Dec 1, 2019

I'm pretty convinced the current behavior is correct now. It is just unfortunate there is this dichotomy. Field aliases mitigate it a bit, as one can alias a possibly shadowed variable.

I think it will be possible to detect when users make a mistake and then warn them in a vet command, similar to what Go does.

@mpvl
Copy link
Contributor Author

mpvl commented Dec 1, 2019

Closing for now.

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

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

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

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

3 participants