Skip to content

Commit

Permalink
Merge pull request #672 from wilzbach/fix-671
Browse files Browse the repository at this point in the history
Fix #671 - False positive in infinite range check
merged-on-behalf-of: BBasile <[email protected]>
  • Loading branch information
dlang-bot authored Jun 26, 2018
2 parents 103a327 + cd545d5 commit 0ec1e95
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/dscanner/analysis/incorrect_infinite_range.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ final class IncorrectInfiniteRangeCheck : BaseAnalyzer

override void visit(const ReturnStatement rs)
{
if (inStruct == 0 || line == size_t.max) // not within a struct yet
return;
if (!rs.expression || rs.expression.items.length != 1)
return;
UnaryExpression unary = cast(UnaryExpression) rs.expression.items[0];
Expand All @@ -82,7 +84,7 @@ private:
uint inStruct;
enum string KEY = "dscanner.suspicious.incorrect_infinite_range";
enum string MESSAGE = "Use `enum bool empty = false;` to define an infinite range.";
size_t line;
size_t line = size_t.max;
size_t column;
}

Expand Down Expand Up @@ -123,8 +125,6 @@ class C { bool empty() { return false; } } // [warn]: %1$s

}c
.format(IncorrectInfiniteRangeCheck.MESSAGE), sac);

stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
}

// test for https://github.com/dlang-community/D-Scanner/issues/656
Expand All @@ -136,3 +136,23 @@ version(none) struct Foo
return;
}
}

unittest
{
import std.stdio : stderr;
import dscanner.analysis.config : StaticAnalysisConfig, Check, disabledConfig;
import std.format : format;

StaticAnalysisConfig sac = disabledConfig();
sac.incorrect_infinite_range_check = Check.enabled;
assertAnalyzerWarnings(q{
enum isAllZeroBits = ()
{
if (true)
return true;
else
return false;
}();
}, sac);
stderr.writeln("Unittest for IncorrectInfiniteRangeCheck passed.");
}

0 comments on commit 0ec1e95

Please sign in to comment.