cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.02k stars 287 forks source link

Nested Packages concrete value evaluation #2620

Open lswith opened 11 months ago

lswith commented 11 months ago

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

$ cue version
cue version v0.6.0

go version go1.20.6
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 0
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

Yes.

What did you do?

I've created a minimal example of the issue at https://github.com/lswith/breaking_cue

If you run cue eval -c in the bar/ folder, the following error occurs:

error in call to list.Range: non-concrete value int:
    ../fizzbuzz/fizzbuzz.cue:13:10
    ../fizzbuzz/fizzbuzz.cue:8:8

What did you expect to see?

I expected that he list would be evaluated since the value is concrete in the bar package. Something like:

bar: {
    "x-1": "1"
    c: {
        Test: 2
    }
}

What did you see instead?

error in call to list.Range: non-concrete value int:
    ../fizzbuzz/fizzbuzz.cue:13:10
    ../fizzbuzz/fizzbuzz.cue:8:8
lswith commented 11 months ago

For reference, this is fixed if I don't nest 3 packages. It only happens with 3 or more.

lswith commented 11 months ago

This could be related to https://github.com/cue-lang/cue/issues/1446

verdverm commented 11 months ago
  1. The foo package has only 2 fields, why would we expect "x-1" get lifted to the same level as bar.c?
  2. The error is isolated to a single file
package fizzbuzz

import (
    "list"
)

#C: {
    Test: int
}

c: #C

for i in list.Range(1, c.Test, 1) {
    "x-\(i)": "\(i)"
}

You are referencing the c in this file in the list.Range, so the c.Test is incomplete as I expect it would be

I do not think you can (or should be able to) inject data into an import, which is what it looks like you are trying to do?

There is an outstanding issue to ensure that imports are closed.

lswith commented 11 months ago

I wasn't aware that injecting data into an import was a no go.

For reference, I was creating a package that contained a bunch of "template" objects and then passing in configuration into those packages using imports. I guess I should be inverting this?

The only large cue codebase example I can find is https://github.com/cue-lang/proposal/tree/main/internal/ci. I'll try and use the inversion similar to how the "base" and "repo" packages do it.