fix #659 - has opEquals but not toHash warning even if opEquals is disabled
This commit is contained in:
parent
4b394c2a7d
commit
b5597e6bb6
|
@ -54,6 +54,19 @@ final class OpEqualsWithoutToHashCheck : BaseAnalyzer
|
||||||
if (!declaration || !declaration.functionDeclaration)
|
if (!declaration || !declaration.functionDeclaration)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
bool containsDisable(A)(const A[] attribs)
|
||||||
|
{
|
||||||
|
import std.algorithm.searching : canFind;
|
||||||
|
return attribs.canFind!(a => a.atAttribute !is null &&
|
||||||
|
a.atAttribute.identifier.text == "disable");
|
||||||
|
}
|
||||||
|
|
||||||
|
const isDeclationDisabled = containsDisable(declaration.attributes) ||
|
||||||
|
containsDisable(declaration.functionDeclaration.memberFunctionAttributes);
|
||||||
|
|
||||||
|
if (isDeclationDisabled)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Check if opEquals or toHash
|
// Check if opEquals or toHash
|
||||||
immutable string methodName = declaration.functionDeclaration.name.text;
|
immutable string methodName = declaration.functionDeclaration.name.text;
|
||||||
if (methodName == "opEquals")
|
if (methodName == "opEquals")
|
||||||
|
@ -146,6 +159,13 @@ unittest
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue #659, do not warn if one miss and the other is not callable
|
||||||
|
struct Fox {const nothrow @safe hash_t toHash() @disable;}
|
||||||
|
struct Bat {@disable const nothrow @safe hash_t toHash();}
|
||||||
|
struct Rat {const bool opEquals(Object a, Object b) @disable;}
|
||||||
|
struct Cat {@disable const bool opEquals(Object a, Object b);}
|
||||||
|
|
||||||
}c, sac);
|
}c, sac);
|
||||||
|
|
||||||
stderr.writeln("Unittest for OpEqualsWithoutToHashCheck passed.");
|
stderr.writeln("Unittest for OpEqualsWithoutToHashCheck passed.");
|
||||||
|
|
Loading…
Reference in New Issue