Skip to content

Commit

Permalink
internal/code: Unalias element of pointer (#3250)
Browse files Browse the repository at this point in the history
* codegen: Revert Unalias before lookup type (#3247)

This reverts commit 4c4be0a.

* code: `Unalias` element of pointer

* chore: added comment
  • Loading branch information
giautm authored Sep 5, 2024
1 parent 4c4be0a commit 86ac6b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codegen/templates/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *Imports) Lookup(path string) string {
}

func (s *Imports) LookupType(t types.Type) string {
return types.TypeString(code.Unalias(t), func(i *types.Package) string {
return types.TypeString(t, func(i *types.Package) string {
return s.Lookup(i.Path())
})
}
Expand Down
7 changes: 7 additions & 0 deletions internal/code/alias_1.23.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ import (

// Unalias unwraps an alias type
func Unalias(t types.Type) types.Type {
if p, ok := t.(*types.Pointer); ok {
// If the type come from auto-binding,
// it will be a pointer to an alias type.
// (e.g: `type Cursor = entgql.Cursor[int]`)
// *ent.Cursor is the type we got from auto-binding.
return types.NewPointer(Unalias(p.Elem()))
}
return types.Unalias(t)
}

0 comments on commit 86ac6b3

Please sign in to comment.