From aef95180392fcff5f339655754535a34c8564599 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 4 Jan 2018 11:45:44 -0300 Subject: Add more test cases for reference resolving error handling --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'test') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 65f5a647..86424696 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -122,6 +122,20 @@ BOOST_AUTO_TEST_CASE(undeclared_name) CHECK_ERROR(text, DeclarationError, "Undeclared identifier."); } +BOOST_AUTO_TEST_CASE(undeclared_name_is_not_fatal) +{ + char const* text = R"( + contract test { + uint256 variable; + function f(uint256 arg) public { + f(notfound); + f(notfound); + } + } + )"; + CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, "Undeclared identifier."); +} + BOOST_AUTO_TEST_CASE(reference_to_later_declaration) { char const* text = R"( @@ -4067,6 +4081,21 @@ BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename) CHECK_ERROR(text, TypeError, "Name has to refer to a struct, enum or contract."); } +BOOST_AUTO_TEST_CASE(modifier_is_not_a_valid_typename_is_not_fatal) +{ + char const* text = R"( + contract test { + modifier mod() { _; } + + function f() public { + mod g; + g = f; + } + } + )"; + CHECK_ERROR_ALLOW_MULTI(text, TypeError, "Name has to refer to a struct, enum or contract."); +} + BOOST_AUTO_TEST_CASE(function_is_not_a_valid_typename) { char const* text = R"( @@ -5132,6 +5161,20 @@ BOOST_AUTO_TEST_CASE(payable_internal_function_type) CHECK_ERROR(text, TypeError, "Only external function types can be payable."); } +BOOST_AUTO_TEST_CASE(payable_internal_function_type_is_not_fatal) +{ + char const* text = R"( + contract C { + function (uint) internal payable returns (uint) x; + + function g() { + x = g; + } + } + )"; + CHECK_ERROR_ALLOW_MULTI(text, TypeError, "Only external function types can be payable."); +} + BOOST_AUTO_TEST_CASE(call_value_on_non_payable_function_type) { char const* text = R"( @@ -6650,6 +6693,28 @@ BOOST_AUTO_TEST_CASE(warn_unspecified_storage) CHECK_ERROR(text, TypeError, "Storage location must be specified as either \"memory\" or \"storage\"."); } +BOOST_AUTO_TEST_CASE(storage_location_non_array_or_struct_disallowed) +{ + char const* text = R"( + contract C { + function f(uint storage a) public { } + } + )"; + CHECK_ERROR(text, TypeError, "Storage location can only be given for array or struct types."); +} + +BOOST_AUTO_TEST_CASE(storage_location_non_array_or_struct_disallowed_is_not_fatal) +{ + char const* text = R"( + contract C { + function f(uint storage a) public { + a = f; + } + } + )"; + CHECK_ERROR_ALLOW_MULTI(text, TypeError, "Storage location can only be given for array or struct types."); +} + BOOST_AUTO_TEST_CASE(implicit_conversion_disallowed) { char const* text = R"( -- cgit v1.2.3