Skip to content

Commit 222cdde

Browse files
adonovangopherbot
authored andcommitted
internal/analysisinternal: ZeroValue: support materialized aliases
My previous audit of this file contained a mistake in the order in which constructors were tested; it was revealed by testing with gotypesalias=1. Updates golang/go#65294 Change-Id: I80f6f0bb24bceb2c69b9919e9c482b780c0d546a Reviewed-on: https://go-review.googlesource.com/c/tools/+/575699 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 0a4fc72 commit 222cdde

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

internal/analysisinternal/analysis.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos
3232
func ZeroValue(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
3333
// TODO(adonovan): think about generics, and also generic aliases.
3434
under := aliases.Unalias(typ)
35-
// Don't call Underlying unconditionally: although it removed
35+
// Don't call Underlying unconditionally: although it removes
3636
// Named and Alias, it also removes TypeParam.
37-
if n, ok := typ.(*types.Named); ok {
37+
if n, ok := under.(*types.Named); ok {
3838
under = n.Underlying()
3939
}
40-
switch u := under.(type) {
40+
switch under := under.(type) {
4141
case *types.Basic:
4242
switch {
43-
case u.Info()&types.IsNumeric != 0:
43+
case under.Info()&types.IsNumeric != 0:
4444
return &ast.BasicLit{Kind: token.INT, Value: "0"}
45-
case u.Info()&types.IsBoolean != 0:
45+
case under.Info()&types.IsBoolean != 0:
4646
return &ast.Ident{Name: "false"}
47-
case u.Info()&types.IsString != 0:
47+
case under.Info()&types.IsString != 0:
4848
return &ast.BasicLit{Kind: token.STRING, Value: `""`}
4949
default:
50-
panic(fmt.Sprintf("unknown basic type %v", u))
50+
panic(fmt.Sprintf("unknown basic type %v", under))
5151
}
5252
case *types.Chan, *types.Interface, *types.Map, *types.Pointer, *types.Signature, *types.Slice, *types.Array:
5353
return ast.NewIdent("nil")
@@ -178,7 +178,7 @@ func TypeExpr(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
178178
List: returns,
179179
},
180180
}
181-
case *types.Named:
181+
case interface{ Obj() *types.TypeName }: // *types.{Alias,Named,TypeParam}
182182
if t.Obj().Pkg() == nil {
183183
return ast.NewIdent(t.Obj().Name())
184184
}

0 commit comments

Comments
 (0)