Skip to content

Commit

Permalink
qf1001: handle expressions that have no type
Browse files Browse the repository at this point in the history
Closes: gh-1484
Closes: gh-1510
  • Loading branch information
dominikh committed May 21, 2024
1 parent 5ad0e5f commit 5275b91
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
10 changes: 6 additions & 4 deletions quickfix/qf1001/qf1001.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ func CheckDeMorgan(pass *analysis.Pass) (interface{}, error) {
found := false
ast.Inspect(expr, func(node ast.Node) bool {
if expr, ok := node.(ast.Expr); ok {
if basic, ok := pass.TypesInfo.TypeOf(expr).Underlying().(*types.Basic); ok {
if (basic.Info() & types.IsFloat) != 0 {
found = true
return false
if typ := pass.TypesInfo.TypeOf(expr); typ != nil {
if basic, ok := typ.Underlying().(*types.Basic); ok {
if (basic.Info() & types.IsFloat) != 0 {
found = true
return false
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions quickfix/qf1001/testdata/src/example.com/CheckDeMorgan/kvexpr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pkg

func do() bool {
type Info struct {
idx int
}

var state map[Info]int
// Don't crash on KeyValueExpr
return !(state[Info{idx: 6}] == 6 || false) //@ diag(`could apply De Morgan's law`)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Apply De Morgan's law --
package pkg

func do() bool {
type Info struct {
idx int
}

var state map[Info]int
// Don't crash on KeyValueExpr
return state[Info{idx: 6}] != 6 && !false //@ diag(`could apply De Morgan's law`)
}

0 comments on commit 5275b91

Please sign in to comment.