From 88946f9f03625fab345572c66b33ee3e05a07159 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 27 Jun 2017 12:15:51 +0100 Subject: Add tests for function type sigs --- test/libsolidity/SolidityEndToEndTest.cpp | 24 +++++++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 81 ++++++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 73dd7d22..f3d0fde3 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -10051,6 +10051,30 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value) BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1))); } +BOOST_AUTO_TEST_CASE(function_types_sig) +{ + char const* sourceCode = R"( + contract C { + function f() returns (bytes4) { + return this.f.sig; + } + function g() returns (bytes4) { + function () external returns (bytes4) fun = this.f; + return fun.sig; + } + function h() returns (bytes4) { + function () external returns (bytes4) fun = this.f; + var funvar = fun; + return funvar.sig; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == fromHex("0x26121ff0")); + BOOST_CHECK(callContractFunction("g()") == fromHex("0x26121ff0")); + BOOST_CHECK(callContractFunction("h()") == fromHex("0x26121ff0")); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 1fbc55a2..6576634f 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -6285,6 +6285,87 @@ BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer) CHECK_SUCCESS_NO_WARNINGS(text); } +BOOST_AUTO_TEST_CASE(function_types_sig) +{ + char const* text = R"( + contract C { + function f() returns (bytes4) { + return f.sig; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + text = R"( + contract C { + function g() internal { + } + function f() returns (bytes4) { + return g.sig; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + text = R"( + contract C { + function f() returns (bytes4) { + function () g; + return g.sig; + } + } + )"; + CHECK_ERROR(text, TypeError, "Member \"sig\" not found"); + text = R"( + contract C { + function f() returns (bytes4) { + return this.f.sig; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function f() external returns (bytes4) { + return this.f.sig; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + var g = this.h; + return g.sig; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + function () external g = this.h; + return g.sig; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); + text = R"( + contract C { + function h() external { + } + function f() external returns (bytes4) { + function () external g = this.h; + var i = g; + return i.sig; + } + } + )"; + CHECK_SUCCESS_NO_WARNINGS(text); +} + BOOST_AUTO_TEST_CASE(using_this_in_constructor) { char const* text = R"( -- cgit