mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1733 from ethereum/selfReferentialConstant
Detect cyclic dependencies between constants.
This commit is contained in:
@@ -20,19 +20,23 @@
|
||||
* Unit tests for the name and type resolution of the solidity parser.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <test/libsolidity/ErrorCheck.h>
|
||||
|
||||
#include <test/TestHelper.h>
|
||||
|
||||
#include <libdevcore/SHA3.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
||||
#include <libsolidity/analysis/StaticAnalyzer.h>
|
||||
#include <libsolidity/analysis/PostTypeChecker.h>
|
||||
#include <libsolidity/analysis/SyntaxChecker.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/analysis/GlobalContext.h>
|
||||
#include <libsolidity/analysis/TypeChecker.h>
|
||||
#include "../TestHelper.h"
|
||||
#include "ErrorCheck.h"
|
||||
|
||||
#include <libdevcore/SHA3.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -93,10 +97,11 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false,
|
||||
BOOST_CHECK(success || !errors.empty());
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
StaticAnalyzer staticAnalyzer(errors);
|
||||
staticAnalyzer.analyze(*sourceUnit);
|
||||
}
|
||||
if (!PostTypeChecker(errors).check(*sourceUnit))
|
||||
success = false;
|
||||
if (success)
|
||||
if (!StaticAnalyzer(errors).analyze(*sourceUnit))
|
||||
success = false;
|
||||
if (errors.size() > 1 && !_allowMultipleErrors)
|
||||
BOOST_FAIL("Multiple errors found");
|
||||
for (auto const& currentError: errors)
|
||||
@@ -5180,6 +5185,34 @@ BOOST_AUTO_TEST_CASE(address_methods)
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cyclic_dependency_for_constants)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
uint constant a = a;
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR(text, TypeError, "cyclic dependency via a");
|
||||
text = R"(
|
||||
contract C {
|
||||
uint constant a = b * c;
|
||||
uint constant b = 7;
|
||||
uint constant c = b + uint(sha3(d));
|
||||
uint constant d = 2 + a;
|
||||
}
|
||||
)";
|
||||
CHECK_ERROR_ALLOW_MULTI(text, TypeError, "a has a cyclic dependency via c");
|
||||
text = R"(
|
||||
contract C {
|
||||
uint constant a = b * c;
|
||||
uint constant b = 7;
|
||||
uint constant c = 4 + uint(sha3(d));
|
||||
uint constant d = 2 + b;
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user