-
Notifications
You must be signed in to change notification settings - Fork 348
Open
Labels
Description
What version of CUE are you using (cue version)?
$ cue version v0.15.4
Does this issue reproduce with the latest stable release?
Yes (v0.15.4)
What did you do?
exec go mod tidy
exec go run .
stdout '^1 import instances$'
-- go.mod --
module test
go 1.26
require cuelang.org/go v0.15.4
-- main.go --
package main
import (
"fmt"
"log"
"cuelang.org/go/cue/load"
)
func main() {
inst := load.Instances(nil, nil)[0]
if inst.Err != nil {
log.Fatalf("load.Instances: %v", inst.Err)
}
fmt.Printf("%d import instances\n", len(inst.Imports))
for _, inst := range inst.Imports {
fmt.Println(inst.ImportPath)
}
}
-- cue.mod/module.cue --
module: "foo.com"
language: version: "v0.9.0"
-- m.cue --
package m
import (
bar0 "foo.com/bar@v0"
bar1 "foo.com/bar"
bar2 "foo.com/bar@v0:bar"
bar3 "foo.com/bar:bar"
)
bar: bar0 & bar1 & bar2 & bar3
-- bar/bar.cue --
package bar
x: true
What did you expect to see?
A passing test. Even though we're using several different literal paths, they all refer to the same underlying instance. Since the underlying internal/core/runtime.Runtime.Build[https://github.com/cue-lang/cue/blob/50c137cdd1d9bc64c3f62c197dea20538a4f5fa8/internal/core/runtime/build.go#L45] package caches by instance, this means that the runtime will be doing unnecessary extra work.
What did you see instead?
> exec go mod tidy
> exec go run .
[stdout]
4 import instances
foo.com/bar
foo.com/bar:bar
foo.com/bar@v0
foo.com/bar@v0:bar
> stdout '^1 import instances$'
FAIL: /tmp/x.txtar:3: no match for `^1 import instances$` found in stdout
Note: it's probably not possible to fix this behaviour without breaking the cue/load API, as callers can currently assume a 1-1 correspondence between import path string literal values and instances, but de-duplicating with break that.
Reactions are currently unavailable