Update code to review comments

This commit is contained in:
wechman
2022-09-28 13:06:25 +02:00
parent c1dc8df9c9
commit 3be5114fb0
10 changed files with 50 additions and 27 deletions
+2 -1
View File
@@ -416,7 +416,8 @@ bool ExpressionCompiler::visit(UnaryOperation const& _unaryOperation)
solAssert(function->isFree(), "Only free functions can be bound to a user type operator.");
FunctionType const* functionType = dynamic_cast<FunctionType const*>(
function->libraryFunction() ? function->typeViaContractName() : function->type());
function->libraryFunction() ? function->typeViaContractName() : function->type()
);
solAssert(functionType);
functionType = dynamic_cast<FunctionType const&>(*functionType).asBoundFunction();
@@ -694,21 +694,22 @@ bool IRGeneratorForStatements::visit(UnaryOperation const& _unaryOperation)
"Functions with parameters other than self parameter cannot be bound to a user type unary operator."
);
string parameter = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType());
solAssert(!parameter.empty());
string argument = expressionAsType(_unaryOperation.subExpression(), *functionType->selfType());
solAssert(!argument.empty());
solAssert(function->isImplemented(), "");
solAssert(
function->returnParameters().size() == 1,
"A function bound to the user type operator is supposed to return exactly one value."
);
solAssert(*_unaryOperation.annotation().type == *function->returnParameters().at(0)->type(),
solAssert(
*_unaryOperation.annotation().type == *function->returnParameters().at(0)->type(),
"A return type of the bound function is supposed to be same as a operator type."
);
define(_unaryOperation) <<
m_context.enqueueFunctionForCodeGeneration(*function) <<
("(" + parameter + ")\n");
("(" + argument + ")\n");
return false;
}