diff --git a/cue/load/loader_common.go b/cue/load/loader_common.go index 87a48f390..3c0ec127e 100644 --- a/cue/load/loader_common.go +++ b/cue/load/loader_common.go @@ -243,15 +243,13 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) { return } if q == nil { - q = &build.Instance{ - PkgName: pkg, - - Dir: p.Dir, - DisplayPath: p.DisplayPath, - ImportPath: p.ImportPath + ":" + pkg, - Root: p.Root, - Module: p.Module, - } + // Copy the original instance including private fields, + // because the private fields include the loadFunc, without which + // the import logic will not work. + q0 := *p + q = &q0 + q.PkgName = pkg + q.ImportPath += ":" + pkg fp.pkgs[pkg] = q } p = q diff --git a/cue/load/loader_test.go b/cue/load/loader_test.go index e07601a77..aef230a5a 100644 --- a/cue/load/loader_test.go +++ b/cue/load/loader_test.go @@ -635,8 +635,10 @@ root: $CWD/testdata/testmod dir: $CWD/testdata/testmod display:. files: - $CWD/testdata/testmod/test.cue`, - }} + $CWD/testdata/testmod/anon.cue + $CWD/testdata/testmod/test.cue +imports: + mod.test/test/sub: $CWD/testdata/testmod/sub/sub.cue`}} tdtest.Run(t, testCases, func(t *tdtest.T, tc *loadTest) { pkgs := Instances(tc.args, tc.cfg)