Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 2f51db3

Browse files
Iskander (Alex) Sharipovkeegancsmith
authored andcommitted
langserver: fix case order in a type switch (#346)
Concrete types should go before interfaces they implement, otherwise control will never reach them, since type switch matching is performen sequentially, from first case to the last one. Found using gocritic "caseOrder" diagnostic. Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
1 parent 87d2c04 commit 2f51db3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

langserver/ast.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func findInterestingNode(pkginfo *loader.PackageInfo, path []ast.Node) ([]ast.No
143143
path = append([]ast.Node{n.Name}, path...)
144144
continue
145145

146+
case *ast.Comment, *ast.CommentGroup, *ast.File, *ast.KeyValueExpr, *ast.CommClause:
147+
return path, actionUnknown // uninteresting
148+
146149
case ast.Stmt:
147150
return path, actionStmt
148151

@@ -154,9 +157,6 @@ func findInterestingNode(pkginfo *loader.PackageInfo, path []ast.Node) ([]ast.No
154157
*ast.ChanType:
155158
return path, actionType
156159

157-
case *ast.Comment, *ast.CommentGroup, *ast.File, *ast.KeyValueExpr, *ast.CommClause:
158-
return path, actionUnknown // uninteresting
159-
160160
case *ast.Ellipsis:
161161
// Continue to enclosing node.
162162
// e.g. [...]T in ArrayType

0 commit comments

Comments
 (0)