Merge pull request #661 from BBasile/issue-658
fix #658 - warning about non-const should not be emitted if the metho… merged-on-behalf-of: Brian Schott <Hackerpilot@users.noreply.github.com>
This commit is contained in:
commit
40a0a9d9be
|
@ -51,14 +51,26 @@ final class ObjectConstCheck : BaseAnalyzer
|
||||||
constBlock = true;
|
constBlock = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inAggregate && d.functionDeclaration !is null && !constColon && !constBlock
|
bool containsDisable(A)(const A[] attribs)
|
||||||
&& isInteresting(d.functionDeclaration.name.text)
|
{
|
||||||
&& !hasConst(d.functionDeclaration.memberFunctionAttributes))
|
import std.algorithm.searching : canFind;
|
||||||
|
return attribs.canFind!(a => a.atAttribute !is null &&
|
||||||
|
a.atAttribute.identifier.text == "disable");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (const FunctionDeclaration fd = d.functionDeclaration)
|
||||||
|
{
|
||||||
|
const isDeclationDisabled = containsDisable(d.attributes) ||
|
||||||
|
containsDisable(fd.memberFunctionAttributes);
|
||||||
|
|
||||||
|
if (inAggregate && !constColon && !constBlock && !isDeclationDisabled
|
||||||
|
&& isInteresting(fd.name.text) && !hasConst(fd.memberFunctionAttributes))
|
||||||
{
|
{
|
||||||
addErrorMessage(d.functionDeclaration.name.line,
|
addErrorMessage(d.functionDeclaration.name.line,
|
||||||
d.functionDeclaration.name.column, "dscanner.suspicious.object_const",
|
d.functionDeclaration.name.column, "dscanner.suspicious.object_const",
|
||||||
"Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.");
|
"Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
d.accept(this);
|
d.accept(this);
|
||||||
|
|
||||||
|
@ -130,6 +142,16 @@ unittest
|
||||||
const{ override string toString() { return "foo"; }} // ok
|
const{ override string toString() { return "foo"; }} // ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Rat
|
||||||
|
{
|
||||||
|
bool opEquals(Object a, Object b) @disable; // ok
|
||||||
|
}
|
||||||
|
|
||||||
|
class Ant
|
||||||
|
{
|
||||||
|
@disable bool opEquals(Object a, Object b); // ok
|
||||||
|
}
|
||||||
|
|
||||||
// Will warn, because none are const
|
// Will warn, because none are const
|
||||||
class Dog
|
class Dog
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue