Skip to content

Conversation

ludweeg
Copy link
Contributor

@ludweeg ludweeg commented Aug 4, 2018

  1. Fix print 'binaryExpr' as second argument
  2. Add detection NaNCheckExpr: 'x != x' and InfCheckExpr: 'x + x == x'.
    Result: less false-positives.

@coveralls
Copy link

coveralls commented Aug 4, 2018

Coverage Status

Coverage increased (+0.04%) to 97.142% when pulling 016eb6e on ludweeg/update_floatCompare_checker into 5dae1c0 on master.

cristaloleg
cristaloleg previously approved these changes Aug 4, 2018
Copy link
Member

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

return astp.IsBinaryExpr(exprx) || astp.IsBinaryExpr(expry)
}

func identExpr(x ast.Node, y ast.Node) (ast.Expr, *ast.BinaryExpr, bool) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be better to make it as a floatCompareChecker method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it might be a identExpr(x, y ast.Node) ;D

@@ -30,20 +34,66 @@ func (c *floatCompareChecker) VisitLocalExpr(expr ast.Expr) {
return
}
if binexpr.Op == token.EQL || binexpr.Op == token.NEQ {
typx, ok := c.ctx.typesInfo.TypeOf(binexpr.X).(*types.Basic)
if ok && typx.Info()&types.IsFloat != 0 {
if c.isFloatExpr(binexpr) && c.isMultiBinaryExpr(binexpr) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylish: expressions can be splitted by lines 😉

func (c *floatCompareChecker) warn(expr *ast.BinaryExpr) {
var op string
op := ">="
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So...we do not support <=, am I right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this comment :)

Copy link
Member

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ludweeg ludweeg merged commit 90e5360 into master Aug 4, 2018
@ludweeg ludweeg deleted the ludweeg/update_floatCompare_checker branch August 4, 2018 16:00
ludweeg added 4 commits August 4, 2018 19:11
1. Fix print 'binaryExpr' as second argument
2. Add detection NaNCheckExpr: 'x != x' and InfCheckExpr: 'x + x == x'.
Result: less false-positives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants