@@ -32,22 +32,22 @@ func TypeErrorEndPos(fset *token.FileSet, src []byte, start token.Pos) token.Pos
32
32
func ZeroValue (f * ast.File , pkg * types.Package , typ types.Type ) ast.Expr {
33
33
// TODO(adonovan): think about generics, and also generic aliases.
34
34
under := aliases .Unalias (typ )
35
- // Don't call Underlying unconditionally: although it removed
35
+ // Don't call Underlying unconditionally: although it removes
36
36
// Named and Alias, it also removes TypeParam.
37
- if n , ok := typ .(* types.Named ); ok {
37
+ if n , ok := under .(* types.Named ); ok {
38
38
under = n .Underlying ()
39
39
}
40
- switch u := under .(type ) {
40
+ switch under := under .(type ) {
41
41
case * types.Basic :
42
42
switch {
43
- case u .Info ()& types .IsNumeric != 0 :
43
+ case under .Info ()& types .IsNumeric != 0 :
44
44
return & ast.BasicLit {Kind : token .INT , Value : "0" }
45
- case u .Info ()& types .IsBoolean != 0 :
45
+ case under .Info ()& types .IsBoolean != 0 :
46
46
return & ast.Ident {Name : "false" }
47
- case u .Info ()& types .IsString != 0 :
47
+ case under .Info ()& types .IsString != 0 :
48
48
return & ast.BasicLit {Kind : token .STRING , Value : `""` }
49
49
default :
50
- panic (fmt .Sprintf ("unknown basic type %v" , u ))
50
+ panic (fmt .Sprintf ("unknown basic type %v" , under ))
51
51
}
52
52
case * types.Chan , * types.Interface , * types.Map , * types.Pointer , * types.Signature , * types.Slice , * types.Array :
53
53
return ast .NewIdent ("nil" )
@@ -178,7 +178,7 @@ func TypeExpr(f *ast.File, pkg *types.Package, typ types.Type) ast.Expr {
178
178
List : returns ,
179
179
},
180
180
}
181
- case * types.Named :
181
+ case interface { Obj () * types.TypeName }: // *types.{Alias,Named,TypeParam}
182
182
if t .Obj ().Pkg () == nil {
183
183
return ast .NewIdent (t .Obj ().Name ())
184
184
}
0 commit comments