cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

cmd/cue: hidden values cannot be referenced by tools defined in parent directory #1032

Closed timspeetjens closed 3 years ago

timspeetjens commented 3 years ago

What version of CUE are you using (cue version)?

$ cue version
cue version 0.4.0 linux/amd64

What did you do?

$ cat dir/ca.cue 
package abc

_name: "cue"

$ cat hello_tool.cue 
package abc
import (
    "tool/cli"
)

command: hello: {
    print: cli.Print & {
        text: "Hello \(_name)!"
    }
}

$ cue cmd hello ./...

What did you expect to see?

Hello cue!

What did you see instead?

command.hello.print.text: reference "_name" not found:
    ./echo_tool.cue:9:18

This seems to be related to #924. In this case, the cue file resides in a leaf directory. Moving the ca.cue file next to the hello_tool.cue file works as expected.

myitcv commented 3 years ago

@timspeetjens thanks for the reproducer above. Yes, definitely related to #924 and again seems like a valid request.

myitcv commented 3 years ago

(sorry, that last message sent too quickly)

@timspeetjens purely as an FYI (because your reproducer above is great) you can specify a reproducer as a single file that can be copy-pasted as a test case:

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

Not critical, but does make the job of fixing things that bit easier.

Here's such a txtar archive for this example:

exec cue cmd hello ./...
stdout 'Hello cue!'

-- dir/ca.cue --
package abc

_name: "cue"
-- hello_tool.cue --
package abc

import (
    "tool/cli"
)

command: hello: {
    print: cli.Print & {
        text: "Hello \(_name)!"
    }
}
timspeetjens commented 3 years ago

For completeness, the following also fails, but might be the same issue:

exec cue cmd hello ./...
stdout 'Hello cue!'

-- dir/ca.cue --
package abc

p: {
    _name: "cue"
}
-- hello_tool.cue --
package abc

import (
    "tool/cli"
)

command: hello: {
    print: cli.Print & {
        text: "Hello \(p._name)!"
    }
}

The output differs slightly:

command.hello.print.text: invalid string argument: invalid interpolation: undefined field: _name:
    ./hello_tool.cue:8:2
    ./hello_tool.cue:9:3
    ./hello_tool.cue:9:9
    ./hello_tool.cue:9:20
    tool/cli:4:3
myitcv commented 3 years ago

but might be the same issue:

Yes, it's the same issue.

cueckoo commented 3 years ago

This issue has been migrated to https://github.com/cue-lang/cue/issues/1032.

For more details about CUE's migration to a new home, please see https://github.com/cue-lang/cue/issues/1078.