From f9e52c9db1ef23000f5721a462aba3fa8d681749 Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 27 Nov 2015 22:24:00 +0100 Subject: Also check the object type for bound functions. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 19ee9440..73a9b660 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2628,6 +2628,51 @@ BOOST_AUTO_TEST_CASE(using_for_by_name) BOOST_CHECK(success(text)); } +BOOST_AUTO_TEST_CASE(using_for_mismatch) +{ + char const* text = R"( + library D { function double(bytes32 self) returns (uint) { return 2; } } + contract C { + using D for uint; + function f(uint a) returns (uint) { + return a.double(); + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + +BOOST_AUTO_TEST_CASE(using_for_not_used) +{ + // This is an error because the function is only bound to uint. + // Had it been bound to *, it would have worked. + char const* text = R"( + library D { function double(uint self) returns (uint) { return 2; } } + contract C { + using D for uint; + function f(uint16 a) returns (uint) { + return a.double(); + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + +BOOST_AUTO_TEST_CASE(using_for_arbitrary_mismatch) +{ + // Bound to a, but self type does not match. + char const* text = R"( + library D { function double(bytes32 self) returns (uint) { return 2; } } + contract C { + using D for *; + function f(uint a) returns (uint) { + return a.double(); + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(bound_function_in_var) { char const* text = R"( -- cgit