Skip to content

Commit b35dce2

Browse files
authored
Merge pull request #1186 from nevkontakte/generics1
Replace type-switch with a sequence of ifs.
2 parents aee1c1c + 16f5662 commit b35dce2

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/astutil/astutil.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ func FuncKey(d *ast.FuncDecl) string {
7272
if d.Recv == nil || len(d.Recv.List) == 0 {
7373
return d.Name.Name
7474
}
75+
// Each if-statement progressively unwraps receiver type expression.
7576
recv := d.Recv.List[0].Type
76-
switch r := recv.(type) {
77-
case *ast.StarExpr:
78-
recv = r.X
79-
case *ast.IndexExpr:
80-
recv = r.X
81-
case *ast.IndexListExpr:
82-
recv = r.X
77+
if star, ok := recv.(*ast.StarExpr); ok {
78+
recv = star.X
79+
}
80+
if index, ok := recv.(*ast.IndexExpr); ok {
81+
recv = index.X
82+
}
83+
if index, ok := recv.(*ast.IndexListExpr); ok {
84+
recv = index.X
8385
}
8486
return recv.(*ast.Ident).Name + "." + d.Name.Name
8587
}

0 commit comments

Comments
 (0)