Merge pull request #7556 from ethereum/ice-7550

Check for use of modifiers in invalid contexts
This commit is contained in:
chriseth 2019-10-24 10:32:49 +02:00 committed by GitHub
commit 15e39f7d65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 7 deletions

View File

@ -524,7 +524,12 @@ void TypeChecker::visitManually(
_modifier.arguments() ? *_modifier.arguments() : std::vector<ASTPointer<Expression>>();
for (ASTPointer<Expression> const& argument: arguments)
argument->accept(*this);
_modifier.name()->accept(*this);
{
m_insideModifierInvocation = true;
ScopeGuard resetFlag{[&] () { m_insideModifierInvocation = false; }};
_modifier.name()->accept(*this);
}
auto const* declaration = &dereference(*_modifier.name());
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
@ -2378,15 +2383,24 @@ bool TypeChecker::visit(Identifier const& _identifier)
if (_identifier.name() == "sha3" && fType->kind() == FunctionType::Kind::KECCAK256)
m_errorReporter.typeError(
_identifier.location(),
"\"sha3\" has been deprecated in favour of \"keccak256\""
"\"sha3\" has been deprecated in favour of \"keccak256\"."
);
else if (_identifier.name() == "suicide" && fType->kind() == FunctionType::Kind::Selfdestruct)
m_errorReporter.typeError(
_identifier.location(),
"\"suicide\" has been deprecated in favour of \"selfdestruct\""
"\"suicide\" has been deprecated in favour of \"selfdestruct\"."
);
}
if (!m_insideModifierInvocation)
if (ModifierType const* type = dynamic_cast<decltype(type)>(_identifier.annotation().type))
{
m_errorReporter.typeError(
_identifier.location(),
"Modifier can only be referenced in function headers."
);
}
return false;
}

View File

@ -166,6 +166,9 @@ private:
/// Flag indicating whether we are currently inside a StructDefinition.
bool m_insideStruct = false;
/// Flag indicating whether we are currently inside the invocation of a modifier
bool m_insideModifierInvocation = false;
langutil::ErrorReporter& m_errorReporter;
};

View File

@ -8,5 +8,5 @@ contract test {
}
}
// ----
// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct"
// TypeError: (58-62): "sha3" has been deprecated in favour of "keccak256".
// TypeError: (101-108): "suicide" has been deprecated in favour of "selfdestruct".

View File

@ -5,4 +5,4 @@ contract C
}
}
// ----
// TypeError: (60-64): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (60-64): "sha3" has been deprecated in favour of "keccak256".

View File

@ -5,4 +5,4 @@ contract C
}
}
// ----
// TypeError: (60-67): "suicide" has been deprecated in favour of "selfdestruct"
// TypeError: (60-67): "suicide" has been deprecated in favour of "selfdestruct".

View File

@ -0,0 +1,9 @@
contract test {
modifier mod() { _; }
function f() public {
mod ;
}
}
// ----
// TypeError: (77-80): Modifier can only be referenced in function headers.