From e130bc7e7cc647b15c448133f725a060910da587 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 14 Jan 2016 01:58:09 +0000 Subject: check whether break/continue is in the loop --- test/libsolidity/SolidityEndToEndTest.cpp | 12 --------- test/libsolidity/SolidityNameAndTypeResolution.cpp | 31 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 34c5dffc..3ef5ebbe 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -166,18 +166,6 @@ BOOST_AUTO_TEST_CASE(while_loop) testSolidityAgainstCppOnRange("f(uint256)", while_loop_cpp, 0, 5); } -BOOST_AUTO_TEST_CASE(break_outside_loop) -{ - // break and continue outside loops should be simply ignored - char const* sourceCode = "contract test {\n" - " function f(uint x) returns(uint y) {\n" - " break; continue; return 2;\n" - " }\n" - "}\n"; - compileAndRun(sourceCode); - testSolidityAgainstCpp("f(uint256)", [](u256 const&) -> u256 { return 2; }, u256(0)); -} - BOOST_AUTO_TEST_CASE(nested_loops) { // tests that break and continue statements in nested loops jump to the correct place diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 4697e756..11e78d94 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,10 @@ parseAnalyseAndReturnError(string const& _source, bool _reportWarnings = false) if(!sourceUnit) return make_pair(sourceUnit, nullptr); + SyntaxChecker syntaxChecker(errors); + if (!syntaxChecker.checkSyntax(*sourceUnit)) + return make_pair(sourceUnit, std::make_shared(errors[0]->type())); + std::shared_ptr globalContext = make_shared(); NameAndTypeResolver resolver(globalContext->declarations(), errors); solAssert(Error::containsOnlyWarnings(errors), ""); @@ -2903,6 +2908,32 @@ BOOST_AUTO_TEST_CASE(lvalues_as_inline_array) BOOST_CHECK(expectError(text) == Error::Type::TypeError); } +BOOST_AUTO_TEST_CASE(break_not_in_loop) +{ + char const* text = R"( + contract C { + function f() { + if (true) + break; + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::SyntaxError); +} + +BOOST_AUTO_TEST_CASE(continue_not_in_loop) +{ + char const* text = R"( + contract C { + function f() { + if (true) + continue; + } + } + )"; + BOOST_CHECK(expectError(text) == Error::Type::SyntaxError); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit v1.2.3