diff options
author | chriseth <chris@ethereum.org> | 2017-03-07 00:18:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-07 00:18:39 +0800 |
commit | a2ac05e1a2cee0be25234d5f595e8adf2372fb88 (patch) | |
tree | 5b2a3781b9573f6c615a96935a47238b49ca3bb7 /test | |
parent | 2fcccb97d393cfc6eb5120029d1ec2d6526c0bd0 (diff) | |
parent | efdfacaaeca0bf5fd900ed885e05fb15b282d5cf (diff) | |
download | dexon-solidity-a2ac05e1a2cee0be25234d5f595e8adf2372fb88.tar.gz dexon-solidity-a2ac05e1a2cee0be25234d5f595e8adf2372fb88.tar.zst dexon-solidity-a2ac05e1a2cee0be25234d5f595e8adf2372fb88.zip |
Merge pull request #1733 from ethereum/selfReferentialConstant
Detect cyclic dependencies between constants.
Diffstat (limited to 'test')
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 02d81d14..3d82fc70 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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() } |