From 42b672617392ecb294447f73fd011092cd58702b Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Fri, 2 Dec 2016 16:06:01 +0100 Subject: analysis: allow some shadowings explicitly --- test/libsolidity/SolidityEndToEndTest.cpp | 54 ---------------------- test/libsolidity/SolidityNameAndTypeResolution.cpp | 23 ++++++++- 2 files changed, 21 insertions(+), 56 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index d8539524..19161831 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -4869,60 +4869,6 @@ BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes) BOOST_CHECK(callContractFunction("ok()") == encodeArgs(false)); } -BOOST_AUTO_TEST_CASE(proper_overwriting_accessor_by_function) -{ - // bug #1798 - char const* sourceCode = R"( - contract attribute { - bool ok = false; - } - contract func { - function ok() returns (bool) { return true; } - } - - contract attr_func is attribute, func { - function checkOk() returns (bool) { return ok(); } - } - contract func_attr is func, attribute { - function checkOk() returns (bool) { return ok; } - } - )"; - compileAndRun(sourceCode, 0, "attr_func"); - BOOST_CHECK(callContractFunction("ok()") == encodeArgs(true)); - compileAndRun(sourceCode, 0, "func_attr"); - BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(false)); -} - - -BOOST_AUTO_TEST_CASE(overwriting_inheritance) -{ - // bug #1798 - char const* sourceCode = R"( - contract A { - function ok() returns (uint) { return 1; } - } - contract B { - function ok() returns (uint) { return 2; } - } - contract C { - uint ok = 6; - } - contract AB is A, B { - function ok() returns (uint) { return 4; } - } - contract reversedE is C, AB { - function checkOk() returns (uint) { return ok(); } - } - contract E is AB, C { - function checkOk() returns (uint) { return ok; } - } - )"; - compileAndRun(sourceCode, 0, "reversedE"); - BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(4)); - compileAndRun(sourceCode, 0, "E"); - BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(6)); -} - BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) { char const* sourceCode = R"( diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 576421fd..11ce9997 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1056,7 +1056,7 @@ BOOST_AUTO_TEST_CASE(modifier_overrides_function) contract A { modifier mod(uint a) { _; } } contract B is A { function mod(uint a) { } } )"; - CHECK_ERROR(text, TypeError, ""); + CHECK_ERROR(text, DeclarationError, ""); } BOOST_AUTO_TEST_CASE(function_overrides_modifier) @@ -1065,7 +1065,7 @@ BOOST_AUTO_TEST_CASE(function_overrides_modifier) contract A { function mod(uint a) { } } contract B is A { modifier mod(uint a) { _; } } )"; - CHECK_ERROR(text, TypeError, ""); + CHECK_ERROR(text, DeclarationError, ""); } BOOST_AUTO_TEST_CASE(modifier_returns_value) @@ -4304,6 +4304,25 @@ BOOST_AUTO_TEST_CASE(illegal_override_payable_nonpayable) CHECK_ERROR(text, TypeError, ""); } +BOOST_AUTO_TEST_CASE(function_variable_mixin) +{ + // bug #1798 (cpp-ethereum), related to #1286 (solidity) + char const* text = R"( + contract attribute { + bool ok = false; + } + contract func { + function ok() returns (bool) { return true; } + } + + contract attr_func is attribute, func { + function checkOk() returns (bool) { return ok(); } + } + )"; + CHECK_ERROR(text, DeclarationError, ""); +} + + BOOST_AUTO_TEST_CASE(payable_constant_conflict) { char const* text = R"( -- cgit From 9602318eab7affca78b8b5db018e9e646f40e84e Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Wed, 14 Dec 2016 14:18:11 +0100 Subject: test: allow multiple errors in modifier-function overriding --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 11ce9997..9f6ea2b3 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -1056,7 +1056,9 @@ BOOST_AUTO_TEST_CASE(modifier_overrides_function) contract A { modifier mod(uint a) { _; } } contract B is A { function mod(uint a) { } } )"; - CHECK_ERROR(text, DeclarationError, ""); + // Error: Identifier already declared. + // Error: Override changes modifier to function. + CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, ""); } BOOST_AUTO_TEST_CASE(function_overrides_modifier) @@ -1065,7 +1067,9 @@ BOOST_AUTO_TEST_CASE(function_overrides_modifier) contract A { function mod(uint a) { } } contract B is A { modifier mod(uint a) { _; } } )"; - CHECK_ERROR(text, DeclarationError, ""); + // Error: Identifier already declared. + // Error: Override changes function to modifier. + CHECK_ERROR_ALLOW_MULTI(text, DeclarationError, ""); } BOOST_AUTO_TEST_CASE(modifier_returns_value) -- cgit