Don't warn about unused identifers named `_` (#511)

Fix #490
This commit is contained in:
Jan Jurzitza 2017-08-06 12:30:32 +02:00 committed by Basile Burg
parent 55ecfbe479
commit 0d48f27873
1 changed files with 11 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import std.container;
import std.regex : Regex, regex, matchAll;
import dsymbol.scope_ : Scope;
import std.algorithm.iteration : map;
import std.algorithm : all;
/**
* Checks for unused variables.
@ -372,7 +373,7 @@ private:
void variableDeclared(string name, size_t line, size_t column, bool isParameter, bool isRef)
{
if (inAggregateScope)
if (inAggregateScope || name.all!(a => a == '_'))
return;
tree[$ - 1].insert(new UnUsed(name, line, column, isParameter, isRef));
}
@ -506,6 +507,15 @@ private:
void f(Bat** bat) {*bat = bats.ptr + 8;}
}
// Issue 490
void test490()
{
auto cb1 = delegate(size_t _) {};
cb1(3);
auto cb2 = delegate(size_t a) {}; // [warn]: Parameter a is never used.
cb2(3);
}
}c, sac);
stderr.writeln("Unittest for UnusedVariableCheck passed.");
}