[Sol -> Yul] Enable function pointer comparison

This commit is contained in:
Mathias Baumann 2019-05-21 14:40:28 +02:00
parent e5902c58a4
commit 81702717b0
2 changed files with 29 additions and 1 deletions

View File

@ -356,7 +356,12 @@ bool IRGeneratorForStatements::visit(BinaryOperation const& _binOp)
"\n";
else if (TokenTraits::isCompareOp(op))
{
solUnimplementedAssert(commonType->category() != Type::Category::Function, "");
if (auto type = dynamic_cast<FunctionType const*>(commonType))
{
solAssert(op == Token::Equal || op == Token::NotEqual, "Invalid function pointer comparison!");
solAssert(type->kind() != FunctionType::Kind::External, "External function comparison not allowed!");
}
solAssert(commonType->isValueType(), "");
bool isSigned = false;
if (auto type = dynamic_cast<IntegerType const*>(commonType))

View File

@ -0,0 +1,23 @@
contract C {
function internal1() internal pure returns (bool) {
return true;
}
function internal2() internal pure returns (bool) {
return true;
}
function equal() public pure returns (bool same, bool diff) {
same = internal1 == internal1;
diff = internal1 == internal2;
}
function unequal() public pure returns (bool same, bool diff) {
same = internal1 != internal1;
diff = internal1 != internal2;
}
}
// ====
// compileViaYul: true
// ----
// equal() -> true, false
// unequal() -> false, true