Skip to content

Commit 3cd0573

Browse files
authored
Properly handle custom type package result types (#3553)
1 parent 97d9799 commit 3cd0573

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

codegen/service/service_data.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,12 +1383,16 @@ func buildViewedResultType(att, projected *expr.AttributeExpr, viewspkg string,
13831383
if err := initTypeCodeTmpl.Execute(buf, data); err != nil {
13841384
panic(err) // bug
13851385
}
1386+
pkg := ""
1387+
if loc := codegen.UserTypeLocation(att.Type); loc != nil {
1388+
pkg = loc.PackageName()
1389+
}
13861390
name := "NewViewed" + resvar
13871391
init = &InitData{
13881392
Name: name,
13891393
Description: fmt.Sprintf("%s initializes viewed result type %s from result type %s using the given view.", name, resvar, resvar),
13901394
Args: []*InitArgData{
1391-
{Name: "res", Ref: scope.GoTypeRef(att)},
1395+
{Name: "res", Ref: scope.GoFullTypeRef(att, pkg)},
13921396
{Name: "view", Ref: "string"},
13931397
},
13941398
ReturnTypeRef: vresref,
@@ -1399,6 +1403,9 @@ func buildViewedResultType(att, projected *expr.AttributeExpr, viewspkg string,
13991403
// build constructor to initialize result type from viewed result type
14001404
var resinit *InitData
14011405
{
1406+
if loc := codegen.UserTypeLocation(att.Type); loc != nil {
1407+
resref = scope.GoFullTypeRef(att, loc.PackageName())
1408+
}
14021409
data := map[string]any{
14031410
"ToResult": true,
14041411
"ArgVar": "vres",

0 commit comments

Comments
 (0)