From 3c7112ed2bd3d1d376c6a44b65387b0bfb2c75a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 2 Jun 2021 13:53:50 +0200 Subject: [PATCH] Remove the assertion against functions bound to types for which should not be possible - The list was wrong - we do support string and int literals - The assertion was meant to guard against silently skipping over types for which there is no special handling. The current code handles everything in a generic way though and likely will not have to be adjusted for newly added types so the risk of that happening is low. --- .../codegen/ir/IRGeneratorForStatements.cpp | 13 ---------- ...rnal_library_function_bound_to_literal.sol | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_literal.sol diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index a62f40abf..f4b3f06a6 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1576,19 +1576,6 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) if (memberFunctionType && memberFunctionType->bound()) { - solAssert((set{ - Type::Category::Contract, - Type::Category::Bool, - Type::Category::Integer, - Type::Category::Address, - Type::Category::Function, - Type::Category::Struct, - Type::Category::Enum, - Type::Category::Mapping, - Type::Category::Array, - Type::Category::FixedBytes, - }).count(objectCategory) > 0, ""); - define(IRVariable(_memberAccess).part("self"), _memberAccess.expression()); solAssert(*_memberAccess.annotation().requiredLookup == VirtualLookup::Static, ""); if (memberFunctionType->kind() == FunctionType::Kind::Internal) diff --git a/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_literal.sol b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_literal.sol new file mode 100644 index 000000000..632d52709 --- /dev/null +++ b/test/libsolidity/semanticTests/libraries/internal_library_function_bound_to_literal.sol @@ -0,0 +1,26 @@ +library L { + function double(uint a) internal pure returns (uint) { + return a * 2; + } + + function double(bytes memory a) internal pure returns (bytes memory) { + return bytes.concat(a, a); + } +} + +contract C { + using L for *; + + function double42() public returns (uint) { + return 42.double(); + } + + function doubleABC() public returns (bytes memory) { + return "abc".double(); + } +} +// ==== +// compileViaYul: also +// ---- +// double42() -> 84 +// doubleABC() -> 0x20, 6, "abcabc"