Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cueckoo opened this issue Jul 3, 2021 · 5 comments
Labels

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @mpvl in cuelang/cue#152

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

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @mpvl in cuelang/cue#152 (comment)

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.

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @rudolph9 in cuelang/cue#152 (comment)

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.

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @rudolph9 in cuelang/cue#152 (comment)

Relevant comment to this this issue here

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @mpvl in cuelang/cue#152 (comment)

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.

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @mpvl in cuelang/cue#152 (comment)

Closing for now.

ptMcGit pushed a commit to ptMcGit/cue that referenced this issue Jan 22, 2023
There's a nested <pre> here and I don't understand the generation logic of it. I'm changing these code blocks into markdown-style backtick blocks and converting tabs to spaces to see if that fixes it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant