Skip to content

Commit

Permalink
pkg: do not treat unknown Go types as adt.TopKind
Browse files Browse the repository at this point in the history
We had one of these cases with pkg/time.Split, which returned
the type Parts, which is a struct. Declaring the result kind as
adt.TopKind works, but declaring it as adt.StructKind is more precise.

We no longer have a catch-all default, forcing us to handle all types
in the best way we can, much like adtKind does now.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: Ie890f45c0918e0c2f18c5a60679fecebf7133fb4
Dispatch-Trailer: {"type":"trybot","CL":1201036,"patchset":3,"ref":"refs/changes/36/1201036/3","targetBranch":"master"}
  • Loading branch information
mvdan authored and cueckoo committed Sep 12, 2024
1 parent f748d02 commit ba156b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,17 @@ func (g *generator) callCtxtGetter(typ types.Type) string {
case "error":
return "Bottom" // for [generator.cueTypeExpression]
}
return "Value" // for [generator.cueTypeExpression]
// Some builtin functions return custom types, like [cuelang.org/go/pkg/time.Split].
// Inspect the underlying type behind any pointer and return an appropriate shape.
if ptr, ok := typ.(*types.Pointer); ok {
typ = ptr.Elem()
}
switch typ.Underlying().(type) {
case *types.Struct: // e.g. [cuelang.org/go/pkg/time.Parts]
return "Struct"
}
log.Fatal("unknown Go type: ", typ.String())
return ""
}

// adtKind provides a Go expression string which describes
Expand Down
2 changes: 1 addition & 1 deletion pkg/time/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ba156b0

Please sign in to comment.