Only active variables at the point of their declaration.

This commit is contained in:
chriseth
2018-02-27 12:17:25 +01:00
parent 6b9dda06f3
commit 88a5c66f4a
8 changed files with 176 additions and 33 deletions
+20
View File
@@ -284,6 +284,26 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions)
ABI_CHECK(callContractFunction("f(bool)", false), encodeArgs(u256(2)));
}
BOOST_AUTO_TEST_CASE(C99_scoping_activation)
{
char const* sourceCode = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public returns (uint) {
uint x = 7;
{
x = 3; // This should still assign to the outer variable
uint x;
x = 4; // This should assign to the new one
}
return x;
}
}
)";
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("f()"), encodeArgs(3));
}
BOOST_AUTO_TEST_CASE(recursive_calls)
{
char const* sourceCode = R"(
@@ -135,19 +135,59 @@ BOOST_AUTO_TEST_CASE(scoping)
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_for)
BOOST_AUTO_TEST_CASE(scoping_activation_old)
{
char const* text = R"(
contract test {
function f() pure public {
x = 3;
uint x;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(scoping_activation)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
x = 3;
uint x;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_self_use)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() public {
uint a = a;
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_for)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
}
}
)";
CHECK_SUCCESS(text);
CHECK_WARNING(text, "Experimental features");
}
BOOST_AUTO_TEST_CASE(scoping_for2)
@@ -155,7 +195,21 @@ BOOST_AUTO_TEST_CASE(scoping_for2)
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() public {
function f() pure public {
for (uint x = 0; x < 10; x ++)
x = 2;
}
}
)";
CHECK_WARNING(text, "Experimental features");
}
BOOST_AUTO_TEST_CASE(scoping_for3)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (uint x = 0; x < 10; x ++){
x = 2;
}
@@ -166,6 +220,21 @@ BOOST_AUTO_TEST_CASE(scoping_for2)
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(scoping_for_decl_in_body)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract test {
function f() pure public {
for (;; y++){
uint y = 3;
}
}
}
)";
CHECK_ERROR(text, DeclarationError, "Undeclared identifier");
}
BOOST_AUTO_TEST_CASE(name_shadowing)
{
char const* text = R"(