aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-01-21 02:23:23 +0800
committerchriseth <c@ethdev.com>2016-01-21 02:23:23 +0800
commit67c855c583042ddee6261a9921239a3afd086c14 (patch)
tree4b1860c54315b75490c21b417c2b082a59a60275 /test/libsolidity
parentd21c4276b33ced75055e2fc6a37ac8019e95f032 (diff)
parentcb3e07acfcbd9a77b27bfbac600a40cd2725594b (diff)
downloaddexon-solidity-67c855c583042ddee6261a9921239a3afd086c14.tar.gz
dexon-solidity-67c855c583042ddee6261a9921239a3afd086c14.tar.zst
dexon-solidity-67c855c583042ddee6261a9921239a3afd086c14.zip
Merge pull request #356 from guanqun/break-not-in-loop
check whether break/continue is in the loop
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp12
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp46
2 files changed, 46 insertions, 12 deletions
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 7e030c7f..c8e901e4 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -27,6 +27,7 @@
#include <libsolidity/parsing/Scanner.h>
#include <libsolidity/parsing/Parser.h>
#include <libsolidity/analysis/NameAndTypeResolver.h>
+#include <libsolidity/analysis/SyntaxChecker.h>
#include <libsolidity/interface/Exceptions.h>
#include <libsolidity/analysis/GlobalContext.h>
#include <libsolidity/analysis/TypeChecker.h>
@@ -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<Error::Type const>(errors[0]->type()));
+
std::shared_ptr<GlobalContext> globalContext = make_shared<GlobalContext>();
NameAndTypeResolver resolver(globalContext->declarations(), errors);
solAssert(Error::containsOnlyWarnings(errors), "");
@@ -2914,6 +2919,47 @@ 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_CASE(continue_not_in_loop_2)
+{
+ char const* text = R"(
+ contract C {
+ function f() {
+ while (true)
+ {
+ }
+ continue;
+ }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::SyntaxError);
+}
+
BOOST_AUTO_TEST_SUITE_END()
}