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
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201036
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mvdan committed Sep 16, 2024
1 parent 67f9dfa commit 7a26789
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,16 @@ func (g *generator) callCtxtGetter(typ types.Type) string {
case "io.Reader":
return "Reader"
case "error":
return "Bottom" // for [generator.cueTypeExpression]
return "Bottom" // for [generator.adtKind]

// Some builtin functions return custom types, like [cuelang.org/go/pkg/time.Split].
// TODO: we can simplify this once the CUE API declarations in ./pkg/...
// use CUE function signatures to validate their parameters and results.
case "*cuelang.org/go/pkg/time.Parts":
return "Struct"
}
return "Value" // for [generator.cueTypeExpression]
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 7a26789

Please sign in to comment.