Merge pull request #634 from BBasile/issue633-632
fix #632, fix #633 - false positive for static and package methods in… merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
This commit is contained in:
commit
9434a75e31
|
@ -7,10 +7,7 @@ module dscanner.analysis.vcall_in_ctor;
|
||||||
import dscanner.analysis.base;
|
import dscanner.analysis.base;
|
||||||
import dscanner.utils;
|
import dscanner.utils;
|
||||||
import dparse.ast, dparse.lexer;
|
import dparse.ast, dparse.lexer;
|
||||||
import std.algorithm: among;
|
import std.algorithm.searching : canFind;
|
||||||
import std.algorithm.iteration : filter;
|
|
||||||
import std.algorithm.searching : find;
|
|
||||||
import std.range.primitives : empty;
|
|
||||||
import std.range: retro;
|
import std.range: retro;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,16 +180,21 @@ public:
|
||||||
bool pop;
|
bool pop;
|
||||||
scope(exit) if (pop)
|
scope(exit) if (pop)
|
||||||
popVirtual;
|
popVirtual;
|
||||||
|
|
||||||
|
const bool hasAttribs = d.attributes !is null;
|
||||||
|
const bool hasStatic = hasAttribs ? d.attributes.canFind!(a => a.attribute.type == tok!"static") : false;
|
||||||
|
const bool hasFinal = hasAttribs ? d.attributes.canFind!(a => a.attribute.type == tok!"final") : false;
|
||||||
|
|
||||||
if (d.attributes) foreach (attr; d.attributes.retro)
|
if (d.attributes) foreach (attr; d.attributes.retro)
|
||||||
{
|
{
|
||||||
if (attr.attribute == tok!"public" || attr.attribute == tok!"protected" ||
|
if (!hasStatic &&
|
||||||
attr.attribute == tok!"package")
|
(attr.attribute == tok!"public" || attr.attribute == tok!"protected"))
|
||||||
{
|
{
|
||||||
pushVirtual(true);
|
pushVirtual(true);
|
||||||
pop = true;
|
pop = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (attr.attribute == tok!"private")
|
else if (hasStatic || attr.attribute == tok!"private" || attr.attribute == tok!"package")
|
||||||
{
|
{
|
||||||
pushVirtual(false);
|
pushVirtual(false);
|
||||||
pop = true;
|
pop = true;
|
||||||
|
@ -201,13 +203,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// final class... final function
|
// final class... final function
|
||||||
const bool pf = !d.attributes.find!(a => a.attribute.type == tok!"final").empty;
|
if ((d.classDeclaration || d.functionDeclaration) && hasFinal)
|
||||||
if ((d.classDeclaration || d.functionDeclaration) && pf)
|
|
||||||
pushIsFinal(true);
|
pushIsFinal(true);
|
||||||
|
|
||||||
d.accept(this);
|
d.accept(this);
|
||||||
|
|
||||||
if ((d.classDeclaration || d.functionDeclaration) && pf)
|
if ((d.classDeclaration || d.functionDeclaration) && hasFinal)
|
||||||
popIsFinal;
|
popIsFinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,11 +243,14 @@ public:
|
||||||
bool virtualOnce;
|
bool virtualOnce;
|
||||||
bool notVirtualOnce;
|
bool notVirtualOnce;
|
||||||
|
|
||||||
|
const bool hasAttribs = d.attributes !is null;
|
||||||
|
const bool hasStatic = hasAttribs ? d.attributes.canFind!(a => a.attribute.type == tok!"static") : false;
|
||||||
|
|
||||||
// handle "private", "public"... for this declaration
|
// handle "private", "public"... for this declaration
|
||||||
if (d.attributes) foreach (attr; d.attributes.retro)
|
if (d.attributes) foreach (attr; d.attributes.retro)
|
||||||
{
|
{
|
||||||
if (attr.attribute == tok!"public" || attr.attribute == tok!"protected" ||
|
if (!hasStatic &&
|
||||||
attr.attribute == tok!"package")
|
(attr.attribute == tok!"public" || attr.attribute == tok!"protected"))
|
||||||
{
|
{
|
||||||
if (!isVirtual)
|
if (!isVirtual)
|
||||||
{
|
{
|
||||||
|
@ -254,7 +258,7 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (attr.attribute == tok!"private")
|
else if (hasStatic || attr.attribute == tok!"private" || attr.attribute == tok!"package")
|
||||||
{
|
{
|
||||||
if (isVirtual)
|
if (isVirtual)
|
||||||
{
|
{
|
||||||
|
@ -382,6 +386,22 @@ unittest
|
||||||
}
|
}
|
||||||
}, sac);
|
}, sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
static void nonVirtual();
|
||||||
|
this(){nonVirtual();}
|
||||||
|
}
|
||||||
|
}, sac);
|
||||||
|
|
||||||
|
assertAnalyzerWarnings(q{
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
package void nonVirtual();
|
||||||
|
this(){nonVirtual();}
|
||||||
|
}
|
||||||
|
}, sac);
|
||||||
|
|
||||||
import std.stdio: writeln;
|
import std.stdio: writeln;
|
||||||
writeln("Unittest for VcallCtorChecker passed");
|
writeln("Unittest for VcallCtorChecker passed");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue