From 0d5816fd5121db186d2fbfcde1afb38491a2596d Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Fri, 6 Sep 2024 00:24:52 +0700 Subject: [PATCH 1/3] codegen: Revert Unalias before lookup type (#3247) This reverts commit 4c4be0aeaaad758e703724fe4a6575768017ac53. --- codegen/templates/import.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/templates/import.go b/codegen/templates/import.go index eb26ea79682..c26bdeab7f5 100644 --- a/codegen/templates/import.go +++ b/codegen/templates/import.go @@ -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()) }) } From 7797e91c74c3abdb799d9f5dd42bcdfde9e52e32 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Fri, 6 Sep 2024 00:27:00 +0700 Subject: [PATCH 2/3] code: `Unalias` element of pointer --- internal/code/alias_1.23.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/code/alias_1.23.go b/internal/code/alias_1.23.go index e3645decdea..4066e06be6e 100644 --- a/internal/code/alias_1.23.go +++ b/internal/code/alias_1.23.go @@ -8,5 +8,8 @@ import ( // Unalias unwraps an alias type func Unalias(t types.Type) types.Type { + if p, ok := t.(*types.Pointer); ok { + return types.NewPointer(Unalias(p.Elem())) + } return types.Unalias(t) } From 98de8095ba3a4533d647630980b5b12275d7668c Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Fri, 6 Sep 2024 00:35:06 +0700 Subject: [PATCH 3/3] chore: added comment --- internal/code/alias_1.23.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/code/alias_1.23.go b/internal/code/alias_1.23.go index 4066e06be6e..fa0b216c7f0 100644 --- a/internal/code/alias_1.23.go +++ b/internal/code/alias_1.23.go @@ -9,6 +9,10 @@ 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)