Skip to content

Commit

Permalink
Properly handle custom type package result types (#3553)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael authored Jul 8, 2024
1 parent 97d9799 commit 3cd0573
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion codegen/service/service_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -1383,12 +1383,16 @@ func buildViewedResultType(att, projected *expr.AttributeExpr, viewspkg string,
if err := initTypeCodeTmpl.Execute(buf, data); err != nil {
panic(err) // bug
}
pkg := ""
if loc := codegen.UserTypeLocation(att.Type); loc != nil {
pkg = loc.PackageName()
}
name := "NewViewed" + resvar
init = &InitData{
Name: name,
Description: fmt.Sprintf("%s initializes viewed result type %s from result type %s using the given view.", name, resvar, resvar),
Args: []*InitArgData{
{Name: "res", Ref: scope.GoTypeRef(att)},
{Name: "res", Ref: scope.GoFullTypeRef(att, pkg)},
{Name: "view", Ref: "string"},
},
ReturnTypeRef: vresref,
Expand All @@ -1399,6 +1403,9 @@ func buildViewedResultType(att, projected *expr.AttributeExpr, viewspkg string,
// build constructor to initialize result type from viewed result type
var resinit *InitData
{
if loc := codegen.UserTypeLocation(att.Type); loc != nil {
resref = scope.GoFullTypeRef(att, loc.PackageName())
}
data := map[string]any{
"ToResult": true,
"ArgVar": "vres",
Expand Down

0 comments on commit 3cd0573

Please sign in to comment.