Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/code: Unalias element of pointer #3250

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading