Check for opCast being non-const

This commit is contained in:
Hackerpilot 2015-11-09 17:35:13 -08:00
parent f04ede1d91
commit ef46a70d9a
1 changed files with 7 additions and 7 deletions

View File

@ -14,7 +14,7 @@ import analysis.helpers;
import dsymbol.scope_ : Scope; import dsymbol.scope_ : Scope;
/** /**
* Checks that opEquals, opCmp, toHash, and toString are either const, * Checks that opEquals, opCmp, toHash, 'opCast', and toString are either const,
* immutable, or inout. * immutable, or inout.
*/ */
class ObjectConstCheck : BaseAnalyzer class ObjectConstCheck : BaseAnalyzer
@ -40,7 +40,7 @@ class ObjectConstCheck : BaseAnalyzer
{ {
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', and 'toString' are non-const."); "Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.");
} }
d.accept(this); d.accept(this);
} }
@ -62,7 +62,7 @@ class ObjectConstCheck : BaseAnalyzer
private static bool isInteresting(string name) private static bool isInteresting(string name)
{ {
return name == "opCmp" || name == "toHash" || name == "opEquals" return name == "opCmp" || name == "toHash" || name == "opEquals"
|| name == "toString"; || name == "toString" || name == "opCast";
} }
private bool looking = false; private bool looking = false;
@ -104,22 +104,22 @@ unittest
// Will warn, because none are const // Will warn, because none are const
class Dog class Dog
{ {
bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. bool opEquals(Object a, Object b) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.
{ {
return true; return true;
} }
int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. int opCmp(Object o) // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.
{ {
return 1; return 1;
} }
hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. hash_t toHash() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.
{ {
return 0; return 0;
} }
string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', and 'toString' are non-const. string toString() // [warn]: Methods 'opCmp', 'toHash', 'opEquals', 'opCast', and/or 'toString' are non-const.
{ {
return "Dog"; return "Dog";
} }