cue: cmd/cue: unclear how to validate selector and qualified identifier errors

_Originally opened by @myitcv in https://github.com/cuelang/cue/issues/629_

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

$ cue version
cue version +40d9da31-dirty linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Consider the following:

exec cue eval x.cue

-- cue.mod/module.cue --
module: "mod.com"
-- fn/fn.cue --
package fn
-- x.cue --
package x

import "mod.com/fn"

s: {}

a: y    // ERROR: reference "y" not found
b: s.y  // not an error
c: fn.y // not an error

gives the following:

a: reference "y" not found:
    ./x.cue:7:8

This error above is as expected.

~According to my reading of the spec, both s.y and fn.y evaluate to _|_. Hence, strictly speaking, the output above is correct.~

But the lack of errors for lines 8 and 9 are tricky as the author of this code. I have no way of knowing that I have referenced non-existent fields until evaluation time. ~My error has been masked by the use of a disjunction.~

Note: this repro is derived from a real-world example where this typo was made across tens of files.

What did you expect to see?

Unclear, because it’s conceivable that a different user might have intended the above behaviour, and so not expect to see errors for s.y or fn.y

cc @jlongtine

2022-05-03 edit: removed use of disjunctions, because this issue is primarily being referenced because of the lack of errors/UX issues that come with incomplete references. The disjunction case is an interesting extension of that same problem, but is one we necessarily need to solve second.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

In relation to this issue, I have been using struct.MinFields(X) function expecting to throw errors when the condition was not satisfied. However It didn’t happen in contrast to struct.MaxFields(X) that actually reported errors. I’d expect the same behavior for struct.MinFields. It looks like the return arguments are even different for both functions which looks weird.