mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Syntax for custom errors.
This commit is contained in:
@@ -792,7 +792,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
{
|
||||
// function-sel(Error(string)) + encoding
|
||||
solAssert(arguments.size() == 1, "");
|
||||
solAssert(function.parameterTypes().size() == 1, "");
|
||||
solUnimplementedAssert(arguments.front()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
||||
if (m_context.revertStrings() == RevertStrings::Strip)
|
||||
{
|
||||
if (!*arguments.front()->annotation().isPure)
|
||||
@@ -908,6 +908,10 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
m_context << logInstruction(numIndexed);
|
||||
break;
|
||||
}
|
||||
case FunctionType::Kind::Error:
|
||||
{
|
||||
solAssert(false, "");
|
||||
}
|
||||
case FunctionType::Kind::BlockHash:
|
||||
{
|
||||
acceptAndConvert(*arguments[0], *function.parameterTypes()[0], true);
|
||||
@@ -1076,7 +1080,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
case FunctionType::Kind::Assert:
|
||||
case FunctionType::Kind::Require:
|
||||
{
|
||||
acceptAndConvert(*arguments.front(), *function.parameterTypes().front(), false);
|
||||
acceptAndConvert(*arguments.front(), *TypeProvider::boolean(), false);
|
||||
|
||||
bool haveReasonString = arguments.size() > 1 && m_context.revertStrings() != RevertStrings::Strip;
|
||||
|
||||
@@ -1087,6 +1091,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
||||
// 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)
|
||||
@@ -1381,6 +1386,11 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
||||
solAssert(false, "event not found");
|
||||
// no-op, because the parent node will do the job
|
||||
break;
|
||||
case FunctionType::Kind::Error:
|
||||
if (!dynamic_cast<ErrorDefinition const*>(_memberAccess.annotation().referencedDeclaration))
|
||||
solAssert(false, "error not found");
|
||||
// no-op, because the parent node will do the job
|
||||
break;
|
||||
case FunctionType::Kind::DelegateCall:
|
||||
_memberAccess.expression().accept(*this);
|
||||
m_context << funType->externalIdentifier();
|
||||
@@ -2052,6 +2062,10 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
else if (dynamic_cast<ErrorDefinition const*>(declaration))
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
else if (dynamic_cast<EnumDefinition const*>(declaration))
|
||||
{
|
||||
// no-op
|
||||
|
||||
@@ -1051,11 +1051,20 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
m_code << templ.render();
|
||||
break;
|
||||
}
|
||||
case FunctionType::Kind::Error:
|
||||
{
|
||||
solAssert(false, "");
|
||||
}
|
||||
case FunctionType::Kind::Assert:
|
||||
case FunctionType::Kind::Require:
|
||||
{
|
||||
solAssert(arguments.size() > 0, "Expected at least one parameter for require/assert");
|
||||
solAssert(arguments.size() <= 2, "Expected no more than two parameters for require/assert");
|
||||
if (arguments.size() == 2)
|
||||
solAssert(functionType->kind() == FunctionType::Kind::Require, "");
|
||||
|
||||
if (arguments.size() == 2)
|
||||
solUnimplementedAssert(arguments.back()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
||||
|
||||
Type const* messageArgumentType =
|
||||
arguments.size() > 1 && m_context.revertStrings() != RevertStrings::Strip ?
|
||||
@@ -1202,12 +1211,12 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
|
||||
}
|
||||
case FunctionType::Kind::Revert:
|
||||
{
|
||||
solAssert(arguments.size() == parameterTypes.size(), "");
|
||||
if (arguments.empty())
|
||||
m_code << "revert(0, 0)\n";
|
||||
else
|
||||
{
|
||||
solAssert(arguments.size() == 1, "");
|
||||
solUnimplementedAssert(arguments.front()->annotation().type->isImplicitlyConvertibleTo(*TypeProvider::stringMemory()), "");
|
||||
|
||||
if (m_context.revertStrings() == RevertStrings::Strip)
|
||||
m_code << "revert(0, 0)\n";
|
||||
@@ -1957,6 +1966,13 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
||||
);
|
||||
// the call will do the resolving
|
||||
break;
|
||||
case FunctionType::Kind::Error:
|
||||
solAssert(
|
||||
dynamic_cast<ErrorDefinition const*>(_memberAccess.annotation().referencedDeclaration),
|
||||
"Error not found"
|
||||
);
|
||||
// the call will do the resolving
|
||||
break;
|
||||
case FunctionType::Kind::DelegateCall:
|
||||
define(IRVariable(_memberAccess).part("address"), _memberAccess.expression());
|
||||
define(IRVariable(_memberAccess).part("functionSelector")) << formatNumber(memberFunctionType->externalIdentifier()) << "\n";
|
||||
@@ -2285,6 +2301,11 @@ void IRGeneratorForStatements::endVisit(Identifier const& _identifier)
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
else if (dynamic_cast<ErrorDefinition const*>(declaration))
|
||||
{
|
||||
// TODO should this rather be an assertion? Can we get here?
|
||||
// no-op
|
||||
}
|
||||
else if (dynamic_cast<EnumDefinition const*>(declaration))
|
||||
{
|
||||
// no-op
|
||||
|
||||
Reference in New Issue
Block a user