Skip to content

Commit

Permalink
cue/load: do not consider anonymous packages when checking package qu…
Browse files Browse the repository at this point in the history
…alifier

When cue/load is loading a package with an explicit qualifier
we only want to load the files declaring that package name.
However, in the edge case where the qualifier wasn't specified,
we would always consider files which did not declare any package name,
which was an unintended regression from `CUE_EXPERIMENT=modules=0`.

Fixes #3244

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: I64e81bdba5c1be9b35b08af5e72e631adbae6a9d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196720
Reviewed-by: Daniel Martí <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
rogpeppe committed Jun 25, 2024
1 parent 9295a20 commit 5ab2d73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions cmd/cue/cmd/testdata/script/load_with_unnamed_pkg.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# path" logic works correctly in the presence of an
# non-package CUE file, which can never be part
# of a package.
# See https://cuelang.org/issue/3244

cd foo
# TODO(rog): this should succeed
! exec cue export
cmp stderr $WORK/want-stderr
-- want-stderr --
test.example/foo@v0: import failed: no dependency found for package "other.example/m":
./foo.cue:8:8
exec cue export
cmp stdout $WORK/want-stdout
-- want-stdout --
{
"x": 20
}
-- cue.mod/gen/other.example/m/m.cue --
package m
x: 20
Expand Down
2 changes: 1 addition & 1 deletion cue/load/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func appendExpandedUnqualifiedPackagePath(pkgPaths []resolvedPackageArg, origp s
pkgName := f.Syntax.PackageName()
// 2. if pkgQual is "_", it looks for a package file with no package name.
// 3. if there's a package named after ip.Qualifier it chooses that
if pkgName == ip.Qualifier || (pkgQual == "_" && pkgName == "") {
if (pkgName != "" && pkgName == ip.Qualifier) || (pkgQual == "_" && pkgName == "") {
foundQualifier = true
return false
}
Expand Down

0 comments on commit 5ab2d73

Please sign in to comment.