From 6781ec105f43bb98fd165c4ba86c76ebc1fb9587 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 18 Oct 2016 12:42:35 +0200 Subject: Add a test for #1151 --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 7eedbefa..35d09d23 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -854,6 +854,23 @@ BOOST_AUTO_TEST_CASE(implicit_base_to_derived_conversion) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(super_excludes_current_contract) +{ + char const* text = R"( + contract A { + function b() {} + } + + contract B is A { + function f() { + super.f(); + } + } + )"; + + BOOST_CHECK(expectError(text) == Error::Type::TypeError); +} + BOOST_AUTO_TEST_CASE(function_modifier_invocation) { char const* text = R"( -- cgit v1.2.3 From ff9039b2a82f5679cb79bf0a47f280283554ba89 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Mon, 17 Oct 2016 20:54:53 +0200 Subject: When a contract type is super, its members do not contain the functions of itself Fixes #1151 --- libsolidity/ast/Types.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index eb98047c..b28ae482 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1324,7 +1324,14 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con if (m_super) { // add the most derived of all functions which are visible in derived contracts - for (ContractDefinition const* base: m_contract.annotation().linearizedBaseContracts) + auto bases = m_contract.annotation().linearizedBaseContracts; + if (bases.size() < 1) + BOOST_THROW_EXCEPTION( + InternalCompilerError() << + errinfo_comment("linearizedBaseContracts should at least contain the most derived contract.") + ); + bases.erase(bases.begin()); // Remove the most derived contract, which should not be searchable from `super`. + for (ContractDefinition const* base: bases) for (FunctionDefinition const* function: base->definedFunctions()) { if (!function->isVisibleInDerivedContracts()) -- cgit v1.2.3 From 7887045a48545038298dbf7790a20a406b93f155 Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 20 Oct 2016 11:21:59 +0200 Subject: ast: simplifications suggested by @chriseth --- libsolidity/ast/Types.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index b28ae482..a412d421 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1325,13 +1326,9 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con { // add the most derived of all functions which are visible in derived contracts auto bases = m_contract.annotation().linearizedBaseContracts; - if (bases.size() < 1) - BOOST_THROW_EXCEPTION( - InternalCompilerError() << - errinfo_comment("linearizedBaseContracts should at least contain the most derived contract.") - ); - bases.erase(bases.begin()); // Remove the most derived contract, which should not be searchable from `super`. - for (ContractDefinition const* base: bases) + solAssert(bases.size() >= 1, "linearizedBaseContracts should at least contain the most derived contract."); + // `sliced(1, ...)` ignores the most derived contract, which should not be searchable from `super`. + for (ContractDefinition const* base: bases | boost::adaptors::sliced(1, bases.size())) for (FunctionDefinition const* function: base->definedFunctions()) { if (!function->isVisibleInDerivedContracts()) -- cgit v1.2.3 From 31ffe01463619ae4bd5fb910b98572ebd9c1a13b Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Thu, 20 Oct 2016 16:12:21 +0200 Subject: Changelog: add an entry about super.x lookup --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 343d8aa7..6358413a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Features: Bugfixes: * Disallow unknown options in ``solc``. * Proper type checking for bound functions. + * Type Checker: ``super.x`` does not look up ``x`` in the current contract. * Code Generator: expect zero stack increase after `super` as an expression. * Inline assembly: support the ``address`` opcode. * Inline assembly: fix parsing of assignment after a label. -- cgit v1.2.3