Check for function parameters in mixins (#484)

* Check for function parameters in mixins

* Don't trigger errors on uncertain mesages
This commit is contained in:
Sebastian Wilzbach 2018-03-22 23:53:47 +01:00 committed by BBasile
parent 2be1a1f22f
commit 27b09eebfd

View file

@ -234,11 +234,16 @@ class UnusedVariableCheck : BaseAnalyzer
{ {
foreach (part; matchAll(primary.primary.text, re)) foreach (part; matchAll(primary.primary.text, re))
{ {
immutable size_t treeIndex = tree.length - 1; void checkTree(in size_t treeIndex)
auto uu = UnUsed(part.hit); {
auto r = tree[treeIndex].equalRange(&uu); auto uu = UnUsed(part.hit);
if (!r.empty) auto r = tree[treeIndex].equalRange(&uu);
r.front.uncertain = true; if (!r.empty)
r.front.uncertain = true;
}
checkTree(tree.length - 1);
if (tree.length >= 2)
checkTree(tree.length - 2);
} }
} }
} }
@ -407,6 +412,8 @@ private:
{ {
if (!uu.isRef && tree.length > 1) if (!uu.isRef && tree.length > 1)
{ {
if (uu.uncertain)
continue;
immutable string certainty = uu.uncertain ? " might not be used." immutable string certainty = uu.uncertain ? " might not be used."
: " is never used."; : " is never used.";
immutable string errorMessage = (uu.isParameter ? "Parameter " : "Variable ") immutable string errorMessage = (uu.isParameter ? "Parameter " : "Variable ")
@ -526,6 +533,11 @@ private:
auto cb2 = delegate(size_t a) {}; // [warn]: Parameter a is never used. auto cb2 = delegate(size_t a) {}; // [warn]: Parameter a is never used.
cb2(3); cb2(3);
} }
bool hasDittos(int decl)
{
mixin("decl++;");
}
}c, sac); }c, sac);
stderr.writeln("Unittest for UnusedVariableCheck passed."); stderr.writeln("Unittest for UnusedVariableCheck passed.");