Skip to content

Commit 153fc8a

Browse files
committed
cmd/cue: adjust the detection of Go standard library packages
"foo/bar.baz" is still part of the standard library, even if such a standard library package may never become a reality in practice. Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I051fed55743ac569c7fe1414182d77f4d371a11b Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1210517 TryBot-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
1 parent 97cbf7e commit 153fc8a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/cue/cmd/get_go.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1081,10 +1081,19 @@ func (e *extractor) makeType(typ types.Type) (result cueast.Expr) {
10811081
// fall back to whatever alternative type we can, or just "top".
10821082
// Otherwise we would end up generating "std" packages which clash with our
10831083
// own standard library, for example cue.mod/gen/time.
1084+
//
1085+
// Go defines standard library as "no dot in the first path element",
1086+
// such that "foo/bar.baz" is still technically part of the standard library.
1087+
// Note that "example" and "test" are reserved for users in Go, such that "test/foo"
1088+
// is not part of Go's standard library, but such exceptions do not exist in CUE.
1089+
// TODO: never place such packages under e.g. cue.mod/gen/example, as that clashes
1090+
// with CUE's own standard library namespace at the moment.
1091+
//
10841092
// TODO: for cases where the Go std type could be supported, we could still generate
10851093
// and import it under a non-std CUE package, such as cue.mod/gen/pkg.go.dev/time.
10861094
// TODO: Doc?
1087-
if !strings.ContainsAny(pkg.Path(), ".") {
1095+
firstElem, _, _ := strings.Cut(pkg.Path(), "/")
1096+
if !strings.ContainsAny(firstElem, ".") {
10881097
if s := e.altType(obj.Type()); s != nil {
10891098
return s
10901099
}

0 commit comments

Comments
 (0)