-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/cue: find packages by canonical path in get go
Most Go APIs like go/types.Package.Path and go/packages.Package.PkgPath use full canonical package paths, whereas go/packages.Package.Imports uses source import paths as they appear in the import declarations. We mixed the two, using paths from go/types to index into Imports, resulting in nil packages in the edge cases when they are different. One such instance is vendored packages, whose full path may be "vendor/foo/bar" when they are simply imported as "foo/bar". This also fixes a similar panic with some type aliases, in particular when an alias points to an indirectly imported package, as such a package would be missing from the Imports map. The two added testscripts reproduced both panics without the fix, and now work as expected with the fix. Fixes #1607. Fixes #2046. Change-Id: I51df3465da76b39f031855982b48552604817f80 Signed-off-by: Thomas Way <[email protected]> Co-authored-by: Daniel Martí <[email protected]> Signed-off-by: Daniel Martí <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1173100 Reviewed-by: Paul Jolly <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information
Showing
3 changed files
with
100 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Issue 1607 | ||
|
||
exec cue get go --local ./x | ||
cmp x/x_go_gen.cue x_go_gen.cue.golden | ||
|
||
-- go.mod -- | ||
module mod.test | ||
|
||
go 1.21 | ||
-- x/x.go -- | ||
package x | ||
|
||
import "mod.test/y" | ||
|
||
type X = y.Y | ||
|
||
-- y/y.go -- | ||
package y | ||
|
||
import "mod.test/z" | ||
|
||
type Y = z.Z | ||
|
||
-- z/z.go -- | ||
package z | ||
|
||
type Z int | ||
|
||
-- x_go_gen.cue.golden -- | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go mod.test/x | ||
|
||
package x | ||
|
||
import "mod.test/z" | ||
|
||
#X: z.#Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Issue 1607 | ||
|
||
exec cue get go --local ./x | ||
cmp x/x_go_gen.cue x_go_gen.cue.golden | ||
|
||
-- go.mod -- | ||
module mod.test | ||
|
||
go 1.21 | ||
-- x/x.go -- | ||
package x | ||
|
||
import "mod.test/y" | ||
|
||
type X = y.Y | ||
|
||
-- y/y.go -- | ||
package y | ||
|
||
import "mod.test/z" | ||
|
||
type Y = z.Z | ||
|
||
-- z/z.go -- | ||
package z | ||
|
||
type Z int | ||
|
||
-- x_go_gen.cue.golden -- | ||
// Code generated by cue get go. DO NOT EDIT. | ||
|
||
//cue:generate cue get go mod.test/x | ||
|
||
package x | ||
|
||
import "mod.test/z" | ||
|
||
#X: z.#Z |