Skip to content

Commit 9ba4189

Browse files
committed
cue/load: use iterator range
Since we're about to update this logic, update to use the new iterator range syntax first. Signed-off-by: Roger Peppe <[email protected]> Change-Id: Ia97612e97fdd40d9a824ca58122dfd6766303bdb Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211240 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent 931fecb commit 9ba4189

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

cue/load/search.go

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func appendExpandedPackageArg(c *Config, pkgPaths []resolvedPackageArg, p string
389389
// 5. if there's more than one package in the directory, it returns a MultiplePackageError.
390390
// 6. if there are no package files in the directory, it just appends the import path as is, leaving it
391391
// to later logic to produce an error in this case.
392-
func appendExpandedUnqualifiedPackagePath(pkgPaths []resolvedPackageArg, origp string, ip ast.ImportPath, pkgQual string, mainModRoot module.SourceLoc, mainModPath string, tg *tagger) (_ []resolvedPackageArg, _err error) {
392+
func appendExpandedUnqualifiedPackagePath(pkgPaths []resolvedPackageArg, origp string, ip ast.ImportPath, pkgQual string, mainModRoot module.SourceLoc, mainModPath string, tg *tagger) ([]resolvedPackageArg, error) {
393393
ipRel, ok := cutModulePrefix(ip, mainModPath)
394394
if !ok {
395395
// Should never happen.
@@ -410,53 +410,42 @@ func appendExpandedUnqualifiedPackagePath(pkgPaths []resolvedPackageArg, origp s
410410
// 1. if pkgQual is "*", it appends all the packages present in the package directory.
411411
if pkgQual == "*" {
412412
wasAdded := make(map[string]bool)
413-
iter(func(f modimports.ModuleFile, err error) bool {
413+
for f, err := range iter {
414414
if err != nil {
415-
_err = err
416-
return false
415+
return nil, err
417416
}
418417
if err := shouldBuildFile(f.Syntax, tg.tagIsSet); err != nil {
419418
// Later build logic should pick up and report the same error.
420-
return true
419+
continue
421420
}
422421
pkgName := f.Syntax.PackageName()
423422
if wasAdded[pkgName] {
424-
return true
423+
continue
425424
}
426425
wasAdded[pkgName] = true
427426
ip := ip
428427
ip.Qualifier = pkgName
429428
p := ip.String()
430429
pkgPaths = append(pkgPaths, resolvedPackageArg{p, p})
431-
return true
432-
})
433-
if _err != nil {
434-
return nil, _err
435430
}
436431
return pkgPaths, nil
437432
}
438433
var files []modimports.ModuleFile
439434
foundQualifier := false
440-
// TODO(rog): for f, err := range iter {
441-
iter(func(f modimports.ModuleFile, err error) bool {
435+
for f, err := range iter {
442436
if err != nil {
443-
_err = err
444-
return false
437+
return nil, err
445438
}
446439
pkgName := f.Syntax.PackageName()
447440
// 2. if pkgQual is "_", it looks for a package file with no package name.
448441
// 3. if there's a package named after ip.Qualifier it chooses that
449442
if (pkgName != "" && pkgName == ip.Qualifier) || (pkgQual == "_" && pkgName == "") {
450443
foundQualifier = true
451-
return false
444+
break
452445
}
453446
if pkgName != "" {
454447
files = append(files, f)
455448
}
456-
return true
457-
})
458-
if _err != nil {
459-
return nil, _err
460449
}
461450
if foundQualifier {
462451
// We found the actual package that was implied by the import path (or pkgQual == "_").

0 commit comments

Comments
 (0)