Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Don't overuse token.NoPos
Browse files Browse the repository at this point in the history
  • Loading branch information
esimonov committed Feb 20, 2021
1 parent 0ee1452 commit 17e1ecd
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (nom namedOccurrenceMap) checkStatement(stmt ast.Stmt, ifPos token.Pos) {
nom.checkStatement(v.Post, ifPos)
case *ast.GoStmt:
for _, a := range v.Call.Args {
nom.checkExpression(a, token.NoPos)
nom.checkExpression(a, ifPos)
}
case *ast.IfStmt:
for _, el := range v.Body.List {
Expand All @@ -124,21 +124,21 @@ func (nom namedOccurrenceMap) checkStatement(stmt ast.Stmt, ifPos token.Pos) {
case *ast.IncDecStmt:
nom.checkExpression(v.X, ifPos)
case *ast.RangeStmt:
nom.checkExpression(v.X, token.NoPos)
nom.checkExpression(v.X, ifPos)
if v.Body != nil {
for _, e := range v.Body.List {
nom.checkStatement(e, ifPos)
}
}
case *ast.ReturnStmt:
for _, r := range v.Results {
nom.checkExpression(r, token.NoPos)
nom.checkExpression(r, ifPos)
}
case *ast.SendStmt:
nom.checkExpression(v.Chan, token.NoPos)
nom.checkExpression(v.Value, token.NoPos)
nom.checkExpression(v.Chan, ifPos)
nom.checkExpression(v.Value, ifPos)
case *ast.SwitchStmt:
nom.checkExpression(v.Tag, token.NoPos)
nom.checkExpression(v.Tag, ifPos)

for _, el := range v.Body.List {
clauses, ok := el.(*ast.CaseClause)
Expand All @@ -149,25 +149,25 @@ func (nom namedOccurrenceMap) checkStatement(stmt ast.Stmt, ifPos token.Pos) {
for _, c := range clauses.List {
switch v := c.(type) {
case *ast.BinaryExpr:
nom.checkExpression(v.X, token.NoPos)
nom.checkExpression(v.Y, token.NoPos)
nom.checkExpression(v.X, ifPos)
nom.checkExpression(v.Y, ifPos)
case *ast.Ident:
nom.checkExpression(v, token.NoPos)
nom.checkExpression(v, ifPos)
}
}

for _, c := range clauses.Body {
if est, ok := c.(*ast.ExprStmt); ok {
nom.checkExpression(est.X, token.NoPos)
nom.checkExpression(est.X, ifPos)
}

switch v := c.(type) {
case *ast.AssignStmt:
for _, el := range v.Rhs {
nom.checkExpression(el, token.NoPos)
nom.checkExpression(el, ifPos)
}
case *ast.ExprStmt:
nom.checkExpression(v.X, token.NoPos)
nom.checkExpression(v.X, ifPos)
}
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (nom namedOccurrenceMap) checkExpression(candidate ast.Expr, ifPos token.Po
nom.checkStatement(el, ifPos)
}
case *ast.Ident:
if nom[v.Name].isEmponymousKey(ifPos) {
if _, ok := nom[v.Name]; !ok || nom[v.Name].isEmponymousKey(ifPos) {
return
}

Expand Down

0 comments on commit 17e1ecd

Please sign in to comment.