mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Require and Assert.
This commit is contained in:
@@ -66,9 +66,10 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{make_shared<
|
||||
make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Location::ECRecover)),
|
||||
make_shared<MagicVariableDeclaration>("ripemd160",
|
||||
make_shared<FunctionType>(strings(), strings{"bytes20"}, FunctionType::Location::RIPEMD160, true)),
|
||||
// Disabled until decision about semantics of assert is made.
|
||||
// make_shared<MagicVariableDeclaration>("assert",
|
||||
// make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Assert)),
|
||||
make_shared<MagicVariableDeclaration>("assert",
|
||||
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Assert)),
|
||||
make_shared<MagicVariableDeclaration>("require",
|
||||
make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Location::Require)),
|
||||
make_shared<MagicVariableDeclaration>("revert",
|
||||
make_shared<FunctionType>(strings(), strings(), FunctionType::Location::Revert))})
|
||||
{
|
||||
|
||||
@@ -847,7 +847,8 @@ public:
|
||||
ArrayPush, ///< .push() to a dynamically sized array in storage
|
||||
ByteArrayPush, ///< .push() to a dynamically sized byte array in storage
|
||||
ObjectCreation, ///< array creation using new
|
||||
Assert ///< assert()
|
||||
Assert, ///< assert()
|
||||
Require ///< require()
|
||||
};
|
||||
|
||||
virtual Category category() const override { return Category::Function; }
|
||||
|
||||
@@ -879,14 +879,18 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
break;
|
||||
}
|
||||
case Location::Assert:
|
||||
case Location::Require:
|
||||
{
|
||||
arguments.front()->accept(*this);
|
||||
utils().convertType(*arguments.front()->annotation().type, *function.parameterTypes().front(), false);
|
||||
// jump if condition was met
|
||||
m_context << Instruction::ISZERO << Instruction::ISZERO;
|
||||
auto success = m_context.appendConditionalJump();
|
||||
// condition was not met, flag an error
|
||||
m_context << Instruction::INVALID;
|
||||
if (function.location() == Location::Assert)
|
||||
// condition was not met, flag an error
|
||||
m_context << Instruction::INVALID;
|
||||
else
|
||||
m_context << u256(0) << u256(0) << Instruction::REVERT;
|
||||
// the success branch
|
||||
m_context << success;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user