From 27b09eebfd362b3d1cda644d49c55f9db468bf42 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 22 Mar 2018 23:53:47 +0100 Subject: [PATCH] Check for function parameters in mixins (#484) * Check for function parameters in mixins * Don't trigger errors on uncertain mesages --- src/dscanner/analysis/unused.d | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/dscanner/analysis/unused.d b/src/dscanner/analysis/unused.d index 856a1f0..319639a 100644 --- a/src/dscanner/analysis/unused.d +++ b/src/dscanner/analysis/unused.d @@ -234,11 +234,16 @@ class UnusedVariableCheck : BaseAnalyzer { foreach (part; matchAll(primary.primary.text, re)) { - immutable size_t treeIndex = tree.length - 1; - auto uu = UnUsed(part.hit); - auto r = tree[treeIndex].equalRange(&uu); - if (!r.empty) - r.front.uncertain = true; + void checkTree(in size_t treeIndex) + { + auto uu = UnUsed(part.hit); + auto r = tree[treeIndex].equalRange(&uu); + 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.uncertain) + continue; immutable string certainty = uu.uncertain ? " might not be used." : " is never used."; immutable string errorMessage = (uu.isParameter ? "Parameter " : "Variable ") @@ -526,6 +533,11 @@ private: auto cb2 = delegate(size_t a) {}; // [warn]: Parameter a is never used. cb2(3); } + + bool hasDittos(int decl) + { + mixin("decl++;"); + } }c, sac); stderr.writeln("Unittest for UnusedVariableCheck passed.");