mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6028 from ethereum/warn-about-unused-struct-array-expr
Detect custom type expressions that have no effect
This commit is contained in:
commit
2949bd14dd
@ -4,6 +4,7 @@ Language Features:
|
|||||||
|
|
||||||
|
|
||||||
Compiler Features:
|
Compiler Features:
|
||||||
|
* Static Analyzer: Warn about expressions with custom types when they have no effect.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -2320,8 +2320,13 @@ bool TypeChecker::visit(Identifier const& _identifier)
|
|||||||
if (auto variableDeclaration = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration))
|
if (auto variableDeclaration = dynamic_cast<VariableDeclaration const*>(annotation.referencedDeclaration))
|
||||||
annotation.isPure = annotation.isConstant = variableDeclaration->isConstant();
|
annotation.isPure = annotation.isConstant = variableDeclaration->isConstant();
|
||||||
else if (dynamic_cast<MagicVariableDeclaration const*>(annotation.referencedDeclaration))
|
else if (dynamic_cast<MagicVariableDeclaration const*>(annotation.referencedDeclaration))
|
||||||
|
{
|
||||||
if (dynamic_cast<FunctionType const*>(annotation.type.get()))
|
if (dynamic_cast<FunctionType const*>(annotation.type.get()))
|
||||||
annotation.isPure = true;
|
annotation.isPure = true;
|
||||||
|
}
|
||||||
|
else if (dynamic_cast<TypeType const*>(annotation.type.get()))
|
||||||
|
annotation.isPure = true;
|
||||||
|
|
||||||
|
|
||||||
// Check for deprecated function names.
|
// Check for deprecated function names.
|
||||||
// The check is done here for the case without an actual function call.
|
// The check is done here for the case without an actual function call.
|
||||||
|
@ -4,3 +4,4 @@ contract Test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ----
|
// ----
|
||||||
|
// Warning: (78-88): Statement has no effect.
|
||||||
|
@ -2,3 +2,5 @@ contract test {
|
|||||||
uint256 variable;
|
uint256 variable;
|
||||||
function f(uint256) public returns (uint out) { f(variable); test; out; }
|
function f(uint256) public returns (uint out) { f(variable); test; out; }
|
||||||
}
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (103-107): Statement has no effect.
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
contract test {
|
||||||
|
struct s { uint a; uint b;}
|
||||||
|
function f() pure public returns (byte) {
|
||||||
|
s;
|
||||||
|
s(1,2);
|
||||||
|
s[7];
|
||||||
|
uint;
|
||||||
|
uint[7];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (93-94): Statement has no effect.
|
||||||
|
// Warning: (98-104): Statement has no effect.
|
||||||
|
// Warning: (108-112): Statement has no effect.
|
||||||
|
// Warning: (116-120): Statement has no effect.
|
||||||
|
// Warning: (124-131): Statement has no effect.
|
Loading…
Reference in New Issue
Block a user