Skip to content

Commit b720861

Browse files
committed
typesutil: support alias
1 parent 84dd3c1 commit b720861

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

internal/typesutil/alias_go121.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package typesutil
55

66
import "go/types"
77

8+
const SupportAlias = false
9+
810
type Alias struct {
911
}
1012

internal/typesutil/alias_go122.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package typesutil
55

66
import "go/types"
77

8+
const SupportAlias = true
9+
810
type Alias = types.Alias
911

1012
func NewAlias(obj *types.TypeName, rhs types.Type) *Alias {

package_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3821,7 +3821,10 @@ func TestTypeAliasInFunc(t *testing.T) {
38213821
foo := cb.NewType("foo").InitType(pkg, typ)
38223822
cb.AliasType("bar", typ)
38233823
a := cb.AliasType("a", foo)
3824-
cb.AliasType("b", a)
3824+
alias := cb.AliasType("b", a)
3825+
if _, ok := alias.(*types.Named); ok {
3826+
t.Fatal("no named")
3827+
}
38253828
cb.End()
38263829
domTest(t, pkg, `package main
38273830

type_var_and_const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (p *TypeDefs) AliasType(name string, typ types.Type, src ...ast.Node) types
156156
if debugInstr {
157157
log.Println("AliasType", name, typ)
158158
}
159-
if p.pkg.conf.EnableTypesalias {
159+
if typesutil.SupportAlias && p.pkg.conf.EnableTypesalias {
160160
return p.pkg.doNewAlias(p, getPos(src), name, typ, 1)
161161
}
162162
return p.pkg.doNewType(p, getPos(src), name, typ, 1).typ

0 commit comments

Comments
 (0)