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

Issue with hidden refs/lists/modules #1613

Closed
mattklein123 opened this issue Apr 1, 2022 · 9 comments
Closed

Issue with hidden refs/lists/modules #1613

mattklein123 opened this issue Apr 1, 2022 · 9 comments

Comments

@mattklein123
Copy link

I think this is a bug but I'm not completely sure. I found this issue in a much larger example and boiled it down to a much smaller case, that AFAICT seems to require the use of modules vs. putting everything in the same package and running all cue files together.

test.cue

package function

import "example.com/lib"

// Call transform
result: lib.#Transform & {_in: ["hello"]}

lib.cue

package lib

#Transform: {
	// Input for the caller
	_in: [...]
	// output for the caller
	out: [...]

	// set output
	out: _in
}
mklein@mklein-x1:~/Source/test$ cue eval test.cue 
result: {
    out: []
}

I would expect out to contain ["hello". And in fact if I switch _in_ to in it does.

I think this is a bug but I'm new to all of this so let me know. :) Thank you.

@mattklein123 mattklein123 added NeedsInvestigation Triage Requires triage/attention labels Apr 1, 2022
@verdverm
Copy link

verdverm commented Apr 1, 2022

Hidden values / fields do not cross package boundaries, similar to how private works in Go. That is why it works when they are in the same package, but does not when using imports (which themselves require a module setup).

Arguably, this could emit an error. #629 is related in that packages are left open after import, which is likely to change.

@verdverm
Copy link

verdverm commented Apr 1, 2022

@mattklein123, separately, CUE uses the txtar file format from Go's source to nice reproducers & examples

https://github.com/cue-lang/cue/wiki/Creating-test-or-performance-reproducers

@mattklein123
Copy link
Author

@mattklein123, separately, CUE uses the txtar file format from Go's source to nice reproducers & examples

Got it, OK. Sorry about that.

Arguably, this could emit an error. #629 is related in that packages are left open after import, which is likely to change.

OK, I see. FWIW this is not very intuitive, given that hidden variables are a way to hide input from the output. An error would be very nice here, thank you.

@mattklein123
Copy link
Author

I've been thinking about this more, and it seems like not being able to pass hidden "inputs" into a module makes modules much less powerful than they could be. Obviously, the caller could be aware of the "in" and "out" pattern, but then the caller has to do the filtering for fields that shouldn't be in the final output which breaks the abstraction. Any thoughts on this? Any other pattern I should be using?

@verdverm
Copy link

verdverm commented Apr 1, 2022

You can use #in for input, which will not be output and also puts a schema on the input value.

There is also the "function" pattern and proposed syntactic sugar (#943)

@mattklein123
Copy link
Author

You can use #in for input, which will not be output and also puts a schema on the input value.

I want to make sure I'm not missing something obvious, but I don't see any way to hide the input value from the ouput.

-- cue.mod/module.cue --
module: "example.com"
-- lib/lib.cue --
package lib

#in: string

#Transform: {
        in: #in
        out: in
}
-- test.cue --
import "example.com/lib"

lib.#Transform & { in: "hello" }
mklein@mklein-x1:~/Source/test$ cue export test.cue 
{
    "in": "hello",
    "out": "hello"
}

Obviously in this case "in" is part of the output. I understand that I can assign out to something at the callsite, I'm just trying to confirm that there is no other way to hide this from the caller. In general some sugar around this would be really nice.

@seh
Copy link
Contributor

seh commented Apr 3, 2022

I'd write the input field as a definition instead, per this example.

@mattklein123
Copy link
Author

Ah, thank you @seh. I think this is the piece I was conceptually missing. I didn't realize definitions could be nested in this way. Very cool!

@rogpeppe
Copy link
Member

@mattklein123 It seems like you no longer consider this an issue. I'll close it accordingly. Please re-open if you still think this is a bug, thanks.

@rogpeppe rogpeppe added WorkingAsIntended and removed NeedsInvestigation Triage Requires triage/attention labels Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants