aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-27 04:14:20 +0800
committerchriseth <chris@ethereum.org>2018-02-27 19:41:32 +0800
commitd64aa0eaad50741896020d31c0c93b64c3f03bc1 (patch)
tree189ad4cfbc487987aef0aaaea68d2944c3ea8b74 /test
parent6391a36a6c71c1e8177358bc3832e32504e73111 (diff)
downloaddexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar.gz
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar.bz2
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar.lz
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar.xz
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.tar.zst
dexon-solidity-d64aa0eaad50741896020d31c0c93b64c3f03bc1.zip
Some more scoping tests.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp28
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp75
2 files changed, 102 insertions, 1 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 7bae3cd6..c352a2c2 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -298,10 +298,38 @@ BOOST_AUTO_TEST_CASE(C99_scoping_activation)
}
return x;
}
+ function g() pure public returns (uint x) {
+ x = 7;
+ {
+ x = 3;
+ uint x;
+ return x; // This returns the new variable, i.e. 0
+ }
+ }
+ function h() pure public returns (uint x, uint a, uint b) {
+ x = 7;
+ {
+ x = 3;
+ a = x; // This should read from the outer
+ uint x = 4;
+ b = x;
+ }
+ }
+ function i() pure public returns (uint x, uint a) {
+ x = 7;
+ {
+ x = 3;
+ uint x = x; // This should read from the outer and assign to the inner
+ a = x;
+ }
+ }
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs(3));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(0));
+ ABI_CHECK(callContractFunction("h()"), encodeArgs(3, 3, 4));
+ ABI_CHECK(callContractFunction("i()"), encodeArgs(3, 3));
}
BOOST_AUTO_TEST_CASE(recursive_calls)
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index e5bd0103..419e46a7 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -106,6 +106,67 @@ BOOST_AUTO_TEST_CASE(double_variable_declaration_050)
}));
}
+BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope)
+{
+ string text = R"(
+ contract test {
+ function f() pure public {
+ { uint x; }
+ { uint x; }
+ }
+ }
+ )";
+ CHECK_ERROR(text, DeclarationError, "Identifier already declared");
+}
+
+BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_050)
+{
+ string text = R"(
+ pragma experimental "v0.5.0";
+ contract test {
+ function f() pure public {
+ { uint x; }
+ { uint x; }
+ }
+ }
+ )";
+ CHECK_WARNING_ALLOW_MULTI(text, (vector<string>{
+ "Experimental features",
+ "Unused local variable",
+ "Unused local variable"
+ }));
+}
+
+BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_activation)
+{
+ string text = R"(
+ contract test {
+ function f() pure public {
+ { uint x; }
+ uint x;
+ }
+ }
+ )";
+ CHECK_ERROR(text, DeclarationError, "Identifier already declared");
+}
+
+BOOST_AUTO_TEST_CASE(double_variable_declaration_disjoint_scope_activation_050)
+{
+ string text = R"(
+ pragma experimental "v0.5.0";
+ contract test {
+ function f() pure public {
+ { uint x; }
+ uint x;
+ }
+ }
+ )";
+ CHECK_WARNING_ALLOW_MULTI(text, (vector<string>{
+ "Experimental features",
+ "Unused local variable",
+ "Unused local variable"
+ }));
+}
BOOST_AUTO_TEST_CASE(scoping_old)
{
char const* text = R"(
@@ -165,9 +226,21 @@ BOOST_AUTO_TEST_CASE(scoping_activation)
BOOST_AUTO_TEST_CASE(scoping_self_use)
{
char const* text = R"(
+ contract test {
+ function f() pure public {
+ uint a = a;
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
+BOOST_AUTO_TEST_CASE(scoping_self_use_050)
+{
+ char const* text = R"(
pragma experimental "v0.5.0";
contract test {
- function f() public {
+ function f() pure public {
uint a = a;
}
}