Browse Source

fixed the test

cl-refactor
Liana Husikyan 10 years ago
parent
commit
71c2c7da45
  1. 10
      libsolidity/NameAndTypeResolver.cpp
  2. 2
      libsolidity/NameAndTypeResolver.h
  3. 29
      test/libsolidity/SolidityEndToEndTest.cpp
  4. 19
      test/libsolidity/SolidityNameAndTypeResolution.cpp

10
libsolidity/NameAndTypeResolver.cpp

@ -130,12 +130,14 @@ vector<Declaration const*> NameAndTypeResolver::getNameFromCurrentScope(ASTStrin
return m_currentScope->resolveName(_name, _recursive); return m_currentScope->resolveName(_name, _recursive);
} }
vector<Declaration const*> NameAndTypeResolver::cleanupedDeclarations(Identifier const& _identifier) vector<Declaration const*> NameAndTypeResolver::cleanupedDeclarations(
Identifier const& _identifier,
vector<Declaration const*> const& _declarations
)
{ {
vector<Declaration const*> uniqueFunctions; vector<Declaration const*> uniqueFunctions;
auto declarations = m_currentScope->resolveName(_identifier.getName()); for (auto it = _declarations.begin(); it != _declarations.end(); ++it)
for (auto it = declarations.begin(); it != declarations.end(); ++it)
{ {
solAssert(*it, ""); solAssert(*it, "");
// the declaration is functionDefinition while declarations > 1 // the declaration is functionDefinition while declarations > 1
@ -480,7 +482,7 @@ bool ReferencesResolver::visit(Identifier& _identifier)
else if (declarations.size() == 1) else if (declarations.size() == 1)
_identifier.setReferencedDeclaration(*declarations.front(), m_currentContract); _identifier.setReferencedDeclaration(*declarations.front(), m_currentContract);
else else
_identifier.setOverloadedDeclarations(m_resolver.cleanupedDeclarations(_identifier)); _identifier.setOverloadedDeclarations(m_resolver.cleanupedDeclarations(_identifier, declarations));
return false; return false;
} }

2
libsolidity/NameAndTypeResolver.h

@ -62,7 +62,7 @@ public:
/// resolving phase. /// resolving phase.
std::vector<Declaration const*> getNameFromCurrentScope(ASTString const& _name, bool _recursive = true); std::vector<Declaration const*> getNameFromCurrentScope(ASTString const& _name, bool _recursive = true);
std::vector<Declaration const*> cleanupedDeclarations(Identifier const& _identifier); std::vector<Declaration const*> cleanupedDeclarations(Identifier const& _identifier, std::vector<Declaration const*> const& _declarations);
private: private:
void reset(); void reset();

29
test/libsolidity/SolidityEndToEndTest.cpp

@ -3910,6 +3910,35 @@ BOOST_AUTO_TEST_CASE(external_types_in_calls)
BOOST_CHECK(callContractFunction("nonexisting") == encodeArgs(u256(9))); BOOST_CHECK(callContractFunction("nonexisting") == encodeArgs(u256(9)));
} }
BOOST_AUTO_TEST_CASE(proper_order_of_overwriting_of_attributes)
{
// bug #1798
char const* sourceCode = R"(
contract init {
function isOk() returns (bool) { return false; }
bool public ok = false;
}
contract fix {
function isOk() returns (bool) { return true; }
bool public ok = true;
}
contract init_fix is init, fix {
function checkOk() returns (bool) { return ok; }
}
contract fix_init is fix, init {
function checkOk() returns (bool) { return ok; }
}
)";
compileAndRun(sourceCode, 0, "init_fix");
BOOST_CHECK(callContractFunction("isOk()") == encodeArgs(true));
BOOST_CHECK(callContractFunction("ok()") == encodeArgs(true));
compileAndRun(sourceCode, 0, "fix_init");
BOOST_CHECK(callContractFunction("isOk()") == encodeArgs(false));
BOOST_CHECK(callContractFunction("ok()") == encodeArgs(false));
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

19
test/libsolidity/SolidityNameAndTypeResolution.cpp

@ -1761,25 +1761,6 @@ BOOST_AUTO_TEST_CASE(uninitialized_var)
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError); BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
} }
BOOST_AUTO_TEST_CASE(deny_overwriting_of_attributes_when_deriving)
{
// bug #1798
char const* sourceCode = R"(
contract owned {
address owner;
}
contract reg {
function owner(bytes32 x) returns (address) {}
}
contract x is owned, reg {
}
)";
ETH_TEST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode), "Parsing and Name Resolving Failed");
//BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

Loading…
Cancel
Save