From 81702717b032cc946b1d71e831abdcc91b13f2c3 Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 21 May 2019 14:40:28 +0200 Subject: [PATCH] [Sol -> Yul] Enable function pointer comparison --- .../codegen/ir/IRGeneratorForStatements.cpp | 7 +++++- .../viaYul/comparison_functions.sol | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/semanticTests/viaYul/comparison_functions.sol diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index c4e83bc9e..bb89474cb 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -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(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(commonType)) diff --git a/test/libsolidity/semanticTests/viaYul/comparison_functions.sol b/test/libsolidity/semanticTests/viaYul/comparison_functions.sol new file mode 100644 index 000000000..e2c3ec833 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/comparison_functions.sol @@ -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