mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Code generation for errors.
This commit is contained in:
parent
4d1fd84150
commit
2deb2b370f
@ -103,6 +103,22 @@ void CompilerUtils::revertWithStringData(Type const& _argumentType)
|
|||||||
m_context << Instruction::REVERT;
|
m_context << Instruction::REVERT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CompilerUtils::revertWithError(
|
||||||
|
string const& _signature,
|
||||||
|
vector<Type const*> const& _parameterTypes,
|
||||||
|
vector<Type const*> const& _argumentTypes
|
||||||
|
)
|
||||||
|
{
|
||||||
|
fetchFreeMemoryPointer();
|
||||||
|
m_context << util::selectorFromSignature(_signature);
|
||||||
|
m_context << Instruction::DUP2 << Instruction::MSTORE;
|
||||||
|
m_context << u256(4) << Instruction::ADD;
|
||||||
|
// Stack: <arguments...> <mem pos of encoding start>
|
||||||
|
abiEncode(_argumentTypes, _parameterTypes);
|
||||||
|
toSizeAfterFreeMemoryPointer();
|
||||||
|
m_context << Instruction::REVERT;
|
||||||
|
}
|
||||||
|
|
||||||
void CompilerUtils::returnDataToArray()
|
void CompilerUtils::returnDataToArray()
|
||||||
{
|
{
|
||||||
if (m_context.evmVersion().supportsReturndata())
|
if (m_context.evmVersion().supportsReturndata())
|
||||||
|
|||||||
@ -69,6 +69,12 @@ public:
|
|||||||
/// Stack post:
|
/// Stack post:
|
||||||
void revertWithStringData(Type const& _argumentType);
|
void revertWithStringData(Type const& _argumentType);
|
||||||
|
|
||||||
|
void revertWithError(
|
||||||
|
std::string const& _errorName,
|
||||||
|
std::vector<Type const*> const& _parameterTypes,
|
||||||
|
std::vector<Type const*> const& _argumentTypes
|
||||||
|
);
|
||||||
|
|
||||||
/// Allocates a new array and copies the return data to it.
|
/// Allocates a new array and copies the return data to it.
|
||||||
/// If the EVM does not support return data, creates an empty array.
|
/// If the EVM does not support return data, creates an empty array.
|
||||||
void returnDataToArray();
|
void returnDataToArray();
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include <libsolidity/codegen/LValue.h>
|
#include <libsolidity/codegen/LValue.h>
|
||||||
|
|
||||||
#include <libsolidity/ast/AST.h>
|
#include <libsolidity/ast/AST.h>
|
||||||
|
#include <libsolidity/ast/ASTUtils.h>
|
||||||
#include <libsolidity/ast/TypeProvider.h>
|
#include <libsolidity/ast/TypeProvider.h>
|
||||||
|
|
||||||
#include <libevmasm/GasMeter.h>
|
#include <libevmasm/GasMeter.h>
|
||||||
@ -786,16 +787,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
break;
|
break;
|
||||||
case FunctionType::Kind::Revert:
|
case FunctionType::Kind::Revert:
|
||||||
{
|
{
|
||||||
if (arguments.empty())
|
bool usesString =
|
||||||
m_context.appendRevert();
|
!arguments.empty() &&
|
||||||
else
|
arguments.front()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory());
|
||||||
|
if (arguments.empty() || (usesString && m_context.revertStrings() == RevertStrings::Strip))
|
||||||
{
|
{
|
||||||
// function-sel(Error(string)) + encoding
|
if (!arguments.empty() && !*arguments.front()->annotation().isPure)
|
||||||
solAssert(arguments.size() == 1, "");
|
|
||||||
solUnimplementedAssert(arguments.front()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
|
||||||
if (m_context.revertStrings() == RevertStrings::Strip)
|
|
||||||
{
|
|
||||||
if (!*arguments.front()->annotation().isPure)
|
|
||||||
{
|
{
|
||||||
arguments.front()->accept(*this);
|
arguments.front()->accept(*this);
|
||||||
utils().popStackElement(*arguments.front()->annotation().type);
|
utils().popStackElement(*arguments.front()->annotation().type);
|
||||||
@ -804,9 +801,32 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
solAssert(arguments.size() == 1, "");
|
||||||
arguments.front()->accept(*this);
|
arguments.front()->accept(*this);
|
||||||
utils().revertWithStringData(*arguments.front()->annotation().type);
|
|
||||||
|
string signature;
|
||||||
|
vector<Type const*> parameterTypes;
|
||||||
|
vector<Type const*> argumentTypes;
|
||||||
|
if (usesString)
|
||||||
|
{
|
||||||
|
signature = "Error(string)";
|
||||||
|
parameterTypes.push_back(TypeProvider::stringMemory());
|
||||||
|
argumentTypes = vector<Type const*>{arguments.front()->annotation().type};
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ErrorDefinition const* error = nullptr;
|
||||||
|
FunctionCall const* errorCall = dynamic_cast<FunctionCall const*>(_functionCall.arguments().back().get());
|
||||||
|
solAssert(errorCall, "");
|
||||||
|
solAssert(*errorCall->annotation().kind == FunctionCallKind::FunctionCall, "");
|
||||||
|
error = dynamic_cast<ErrorDefinition const*>(referencedDeclaration(errorCall->expression()));
|
||||||
|
solAssert(error, "");
|
||||||
|
signature = error->functionType(true)->externalSignature();
|
||||||
|
parameterTypes = error->functionType(true)->parameterTypes();
|
||||||
|
for (ASTPointer<Expression const> const& arg: errorCall->sortedArguments())
|
||||||
|
argumentTypes.push_back(arg->annotation().type);
|
||||||
|
}
|
||||||
|
utils().revertWithError(signature, parameterTypes, argumentTypes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -910,7 +930,10 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
case FunctionType::Kind::Error:
|
case FunctionType::Kind::Error:
|
||||||
{
|
{
|
||||||
solAssert(false, "");
|
for (ASTPointer<Expression const> const& arg: arguments)
|
||||||
|
arg->accept(*this);
|
||||||
|
// will be consumed in the revert / require call.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::BlockHash:
|
case FunctionType::Kind::BlockHash:
|
||||||
{
|
{
|
||||||
@ -1082,49 +1105,72 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
acceptAndConvert(*arguments.front(), *TypeProvider::boolean(), false);
|
acceptAndConvert(*arguments.front(), *TypeProvider::boolean(), false);
|
||||||
|
|
||||||
bool haveReasonString = arguments.size() > 1 && m_context.revertStrings() != RevertStrings::Strip;
|
solAssert(arguments.size() == 1|| arguments.size() == 2, "");
|
||||||
|
|
||||||
if (arguments.size() > 1)
|
bool usesString =
|
||||||
|
arguments.size() >= 2 &&
|
||||||
|
arguments.at(1)->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory());
|
||||||
|
|
||||||
|
if (arguments.size() == 1 || (usesString && m_context.revertStrings() == RevertStrings::Strip))
|
||||||
{
|
{
|
||||||
// Users probably expect the second argument to be evaluated
|
// Shortcut without reason string.
|
||||||
// even if the condition is false, as would be the case for an actual
|
if (arguments.size() == 2 && !*arguments.at(1)->annotation().isPure)
|
||||||
// function call.
|
|
||||||
solAssert(arguments.size() == 2, "");
|
|
||||||
solAssert(function.kind() == FunctionType::Kind::Require, "");
|
|
||||||
solUnimplementedAssert(arguments.back()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
|
||||||
if (m_context.revertStrings() == RevertStrings::Strip)
|
|
||||||
{
|
|
||||||
if (!*arguments.at(1)->annotation().isPure)
|
|
||||||
{
|
{
|
||||||
arguments.at(1)->accept(*this);
|
arguments.at(1)->accept(*this);
|
||||||
utils().popStackElement(*arguments.at(1)->annotation().type);
|
utils().popStackElement(*arguments.at(1)->annotation().type);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arguments.at(1)->accept(*this);
|
|
||||||
utils().moveIntoStack(1, arguments.at(1)->annotation().type->sizeOnStack());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Stack: <error string (unconverted)> <condition>
|
|
||||||
// jump if condition was met
|
|
||||||
m_context << Instruction::ISZERO << Instruction::ISZERO;
|
m_context << Instruction::ISZERO << Instruction::ISZERO;
|
||||||
auto success = m_context.appendConditionalJump();
|
auto success = m_context.appendConditionalJump();
|
||||||
if (function.kind() == FunctionType::Kind::Assert)
|
if (function.kind() == FunctionType::Kind::Assert)
|
||||||
// condition was not met, flag an error
|
// condition was not met, flag an error
|
||||||
m_context.appendPanic(util::PanicCode::Assert);
|
m_context.appendPanic(util::PanicCode::Assert);
|
||||||
else if (haveReasonString)
|
|
||||||
{
|
|
||||||
utils().revertWithStringData(*arguments.at(1)->annotation().type);
|
|
||||||
// Here, the argument is consumed, but in the other branch, it is still there.
|
|
||||||
m_context.adjustStackOffset(static_cast<int>(arguments.at(1)->annotation().type->sizeOnStack()));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
m_context.appendRevert();
|
m_context.appendRevert();
|
||||||
// the success branch
|
|
||||||
m_context << success;
|
m_context << success;
|
||||||
if (haveReasonString)
|
}
|
||||||
utils().popStackElement(*arguments.at(1)->annotation().type);
|
else
|
||||||
|
{
|
||||||
|
solAssert(function.kind() == FunctionType::Kind::Require, "");
|
||||||
|
solAssert(arguments.size() == 2, "");
|
||||||
|
|
||||||
|
string signature;
|
||||||
|
vector<Type const*> parameterTypes;
|
||||||
|
vector<Type const*> argumentTypes;
|
||||||
|
if (usesString)
|
||||||
|
{
|
||||||
|
signature = "Error(string)";
|
||||||
|
parameterTypes.push_back(TypeProvider::stringMemory());
|
||||||
|
argumentTypes = vector<Type const*>{arguments.at(1)->annotation().type};
|
||||||
|
arguments.at(1)->accept(*this);
|
||||||
|
utils().moveIntoStack(1, argumentTypes.front()->sizeOnStack());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Cannot use the size of the argument itself because its type is wrong.
|
||||||
|
ErrorDefinition const* error = nullptr;
|
||||||
|
FunctionCall const* errorCall = dynamic_cast<FunctionCall const*>(arguments.at(1).get());
|
||||||
|
solAssert(errorCall, "");
|
||||||
|
solAssert(*errorCall->annotation().kind == FunctionCallKind::FunctionCall, "");
|
||||||
|
error = dynamic_cast<ErrorDefinition const*>(referencedDeclaration(errorCall->expression()));
|
||||||
|
solAssert(error, "");
|
||||||
|
signature = error->functionType(true)->externalSignature();
|
||||||
|
parameterTypes = error->functionType(true)->parameterTypes();
|
||||||
|
// This uses a different visiting order, but that's the case for all named function calls.
|
||||||
|
for (ASTPointer<Expression const> const& arg: errorCall->sortedArguments())
|
||||||
|
{
|
||||||
|
arg->accept(*this);
|
||||||
|
argumentTypes.push_back(arg->annotation().type);
|
||||||
|
utils().moveIntoStack(1, arg->annotation().type->sizeOnStack());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_context << Instruction::ISZERO << Instruction::ISZERO;
|
||||||
|
auto success = m_context.appendConditionalJump();
|
||||||
|
unsigned argSize = TupleType(argumentTypes).sizeOnStack();
|
||||||
|
utils().revertWithError(signature, parameterTypes, argumentTypes);
|
||||||
|
m_context.adjustStackOffset(static_cast<int>(argSize));
|
||||||
|
m_context << success;
|
||||||
|
utils().popStackSlots(argSize);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::ABIEncode:
|
case FunctionType::Kind::ABIEncode:
|
||||||
|
|||||||
@ -1053,33 +1053,24 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
case FunctionType::Kind::Error:
|
case FunctionType::Kind::Error:
|
||||||
{
|
{
|
||||||
solAssert(false, "");
|
// no-op
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::Assert:
|
case FunctionType::Kind::Assert:
|
||||||
|
{
|
||||||
|
solAssert(arguments.size() == 1, "");
|
||||||
|
m_code << m_utils.requireOrAssertFunction(true) << "(" << IRVariable(*arguments[0]).name() << ")";
|
||||||
|
break;
|
||||||
|
}
|
||||||
case FunctionType::Kind::Require:
|
case FunctionType::Kind::Require:
|
||||||
{
|
{
|
||||||
solAssert(arguments.size() > 0, "Expected at least one parameter for require/assert");
|
solAssert(arguments.size() <= 2, "");
|
||||||
solAssert(arguments.size() <= 2, "Expected no more than two parameters for require/assert");
|
m_code << "if iszero(" << IRVariable(*arguments[0]).name() << ") {\n";
|
||||||
if (arguments.size() == 2)
|
if (arguments.size() == 1)
|
||||||
solAssert(functionType->kind() == FunctionType::Kind::Require, "");
|
m_code << "revert(0, 0)\n";
|
||||||
|
else
|
||||||
if (arguments.size() == 2)
|
revertWithError(arguments.at(1));
|
||||||
solUnimplementedAssert(arguments.back()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
m_code << "}\n";
|
||||||
|
|
||||||
Type const* messageArgumentType =
|
|
||||||
arguments.size() > 1 && m_context.revertStrings() != RevertStrings::Strip ?
|
|
||||||
arguments[1]->annotation().type :
|
|
||||||
nullptr;
|
|
||||||
string requireOrAssertFunction = m_utils.requireOrAssertFunction(
|
|
||||||
functionType->kind() == FunctionType::Kind::Assert,
|
|
||||||
messageArgumentType
|
|
||||||
);
|
|
||||||
|
|
||||||
m_code << move(requireOrAssertFunction) << "(" << IRVariable(*arguments[0]).name();
|
|
||||||
if (messageArgumentType && messageArgumentType->sizeOnStack() > 0)
|
|
||||||
m_code << ", " << IRVariable(*arguments[1]).commaSeparatedList();
|
|
||||||
m_code << ")\n";
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FunctionType::Kind::ABIEncode:
|
case FunctionType::Kind::ABIEncode:
|
||||||
@ -1211,42 +1202,11 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
case FunctionType::Kind::Revert:
|
case FunctionType::Kind::Revert:
|
||||||
{
|
{
|
||||||
|
solAssert(arguments.size() <= 1, "");
|
||||||
if (arguments.empty())
|
if (arguments.empty())
|
||||||
m_code << "revert(0, 0)\n";
|
m_code << "revert(0, 0)\n";
|
||||||
else
|
else
|
||||||
{
|
revertWithError(arguments.front());
|
||||||
solAssert(arguments.size() == 1, "");
|
|
||||||
solUnimplementedAssert(arguments.front()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
|
||||||
|
|
||||||
if (m_context.revertStrings() == RevertStrings::Strip)
|
|
||||||
m_code << "revert(0, 0)\n";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
solAssert(type(*arguments.front()).isImplicitlyConvertibleTo(*TypeProvider::stringMemory()),"");
|
|
||||||
|
|
||||||
Whiskers templ(R"({
|
|
||||||
let <pos> := <allocateUnbounded>()
|
|
||||||
mstore(<pos>, <hash>)
|
|
||||||
let <end> := <encode>(add(<pos>, 4) <argumentVars>)
|
|
||||||
revert(<pos>, sub(<end>, <pos>))
|
|
||||||
})");
|
|
||||||
templ("pos", m_context.newYulVariable());
|
|
||||||
templ("end", m_context.newYulVariable());
|
|
||||||
templ("hash", util::selectorFromSignature("Error(string)").str());
|
|
||||||
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
|
||||||
templ(
|
|
||||||
"argumentVars",
|
|
||||||
joinHumanReadablePrefixed(IRVariable{*arguments.front()}.stackSlots())
|
|
||||||
);
|
|
||||||
templ("encode", m_context.abiFunctions().tupleEncoder(
|
|
||||||
{&type(*arguments.front())},
|
|
||||||
{TypeProvider::stringMemory()}
|
|
||||||
));
|
|
||||||
|
|
||||||
m_code << templ.render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Array creation using new
|
// Array creation using new
|
||||||
@ -3118,6 +3078,62 @@ void IRGeneratorForStatements::rethrow()
|
|||||||
m_code << "revert(0, 0) // rethrow\n"s;
|
m_code << "revert(0, 0) // rethrow\n"s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IRGeneratorForStatements::revertWithError(ASTPointer<Expression const> const& _error)
|
||||||
|
{
|
||||||
|
solAssert(_error, "");
|
||||||
|
|
||||||
|
bool usesString = _error->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory());
|
||||||
|
if (usesString && m_context.revertStrings() == RevertStrings::Strip)
|
||||||
|
{
|
||||||
|
m_code << "revert(0, 0)\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string signature;
|
||||||
|
vector<ASTPointer<Expression const>> errorArguments;
|
||||||
|
vector<Type const*> parameterTypes;
|
||||||
|
if (usesString)
|
||||||
|
{
|
||||||
|
signature = "Error(string)";
|
||||||
|
errorArguments.push_back(_error);
|
||||||
|
parameterTypes.push_back(TypeProvider::stringMemory());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FunctionCall const* errorCall = dynamic_cast<FunctionCall const*>(_error.get());
|
||||||
|
solAssert(errorCall, "");
|
||||||
|
solAssert(*errorCall->annotation().kind == FunctionCallKind::FunctionCall, "");
|
||||||
|
ErrorDefinition const* error = dynamic_cast<ErrorDefinition const*>(referencedDeclaration(errorCall->expression()));
|
||||||
|
solAssert(error, "");
|
||||||
|
signature = error->functionType(true)->externalSignature();
|
||||||
|
parameterTypes = error->functionType(true)->parameterTypes();
|
||||||
|
errorArguments = errorCall->sortedArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
Whiskers templ(R"({
|
||||||
|
let <pos> := <allocateUnbounded>()
|
||||||
|
mstore(<pos>, <hash>)
|
||||||
|
let <end> := <encode>(add(<pos>, 4) <argumentVars>)
|
||||||
|
revert(<pos>, sub(<end>, <pos>))
|
||||||
|
})");
|
||||||
|
templ("pos", m_context.newYulVariable());
|
||||||
|
templ("end", m_context.newYulVariable());
|
||||||
|
templ("hash", util::selectorFromSignature(signature).str());
|
||||||
|
templ("allocateUnbounded", m_utils.allocateUnboundedFunction());
|
||||||
|
|
||||||
|
vector<string> errorArgumentVars;
|
||||||
|
vector<Type const*> errorArgumentTypes;
|
||||||
|
for (ASTPointer<Expression const> const& arg: errorArguments)
|
||||||
|
{
|
||||||
|
errorArgumentVars += IRVariable(*arg).stackSlots();
|
||||||
|
errorArgumentTypes.push_back(arg->annotation().type);
|
||||||
|
}
|
||||||
|
templ("argumentVars", joinHumanReadablePrefixed(errorArgumentVars));
|
||||||
|
templ("encode", m_context.abiFunctions().tupleEncoder(errorArgumentTypes, parameterTypes));
|
||||||
|
|
||||||
|
m_code << templ.render();
|
||||||
|
}
|
||||||
|
|
||||||
bool IRGeneratorForStatements::visit(TryCatchClause const& _clause)
|
bool IRGeneratorForStatements::visit(TryCatchClause const& _clause)
|
||||||
{
|
{
|
||||||
_clause.block().accept(*this);
|
_clause.block().accept(*this);
|
||||||
|
|||||||
@ -106,6 +106,13 @@ private:
|
|||||||
/// Generates code to rethrow an exception.
|
/// Generates code to rethrow an exception.
|
||||||
void rethrow();
|
void rethrow();
|
||||||
|
|
||||||
|
/// Generates code to revert with an error, which might be a plain string
|
||||||
|
/// or an error instance. The error arguments and the strings are assumed to
|
||||||
|
/// be already evaluated and available in local IRVariables, but not yet
|
||||||
|
/// converted.
|
||||||
|
/// Honors the revert strings setting.
|
||||||
|
void revertWithError(ASTPointer<Expression const> const& _error);
|
||||||
|
|
||||||
void handleVariableReference(
|
void handleVariableReference(
|
||||||
VariableDeclaration const& _variable,
|
VariableDeclaration const& _variable,
|
||||||
Expression const& _referencingExpression
|
Expression const& _referencingExpression
|
||||||
|
|||||||
10
test/libsolidity/semanticTests/errors/named_error_args.sol
Normal file
10
test/libsolidity/semanticTests/errors/named_error_args.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
error E(uint a, uint b);
|
||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
revert(E({b: 7, a: 2}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f() -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000007"
|
||||||
11
test/libsolidity/semanticTests/errors/named_require.sol
Normal file
11
test/libsolidity/semanticTests/errors/named_require.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
error E(uint a, uint b);
|
||||||
|
contract C {
|
||||||
|
function f(bool c) public pure {
|
||||||
|
require(c, E({b: 7, a: 2}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(bool): true ->
|
||||||
|
// f(bool): false -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000007"
|
||||||
13
test/libsolidity/semanticTests/errors/require_conversion.sol
Normal file
13
test/libsolidity/semanticTests/errors/require_conversion.sol
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
error E(string a, uint[] b);
|
||||||
|
contract C {
|
||||||
|
uint[] x;
|
||||||
|
function f(bool c) public {
|
||||||
|
x.push(7);
|
||||||
|
require(c, E("abc", x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(bool): false -> FAILURE, hex"59e4d4df", 0x40, 0x80, 3, "abc", 1, 7
|
||||||
|
// f(bool): true ->
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
error E(uint a, uint b);
|
||||||
|
contract C {
|
||||||
|
uint public x;
|
||||||
|
function f(bool c) public {
|
||||||
|
require(c, E(g(), 7));
|
||||||
|
}
|
||||||
|
function g() public returns (uint) {
|
||||||
|
x++;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// x() -> 0
|
||||||
|
// f(bool): true ->
|
||||||
|
// x() -> 1
|
||||||
|
// f(bool): false -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000007"
|
||||||
|
// x() -> 1
|
||||||
12
test/libsolidity/semanticTests/errors/revert_conversion.sol
Normal file
12
test/libsolidity/semanticTests/errors/revert_conversion.sol
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
error E(string a, uint[] b);
|
||||||
|
contract C {
|
||||||
|
uint[] x;
|
||||||
|
function f() public {
|
||||||
|
x.push(7);
|
||||||
|
revert(E("abc", x));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f() -> FAILURE, hex"59e4d4df", 0x40, 0x80, 3, "abc", 1, 7
|
||||||
10
test/libsolidity/semanticTests/errors/simple.sol
Normal file
10
test/libsolidity/semanticTests/errors/simple.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
error E(uint a, uint b);
|
||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
revert(E(2, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f() -> FAILURE, hex"85208890", 2, 7
|
||||||
11
test/libsolidity/semanticTests/errors/simple_require.sol
Normal file
11
test/libsolidity/semanticTests/errors/simple_require.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
error E(uint a, uint b);
|
||||||
|
contract C {
|
||||||
|
function f(bool c) public pure {
|
||||||
|
require(c, E(2, 7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f(bool): true ->
|
||||||
|
// f(bool): false -> FAILURE, hex"85208890", hex"0000000000000000000000000000000000000000000000000000000000000002", hex"0000000000000000000000000000000000000000000000000000000000000007"
|
||||||
Loading…
Reference in New Issue
Block a user