aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests/variableDeclaration
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-09-04 23:24:06 +0800
committerGitHub <noreply@github.com>2018-09-04 23:24:06 +0800
commit9daac90cf7d0a28f5d631b9f5234e4268b5b61b7 (patch)
tree4a65232241445b00e29977b8e958f0b34be1ff8b /test/libsolidity/syntaxTests/variableDeclaration
parentcc7daf7b476f498c4dcde7bdb342974097ffe9bf (diff)
parentac8892e0e3ab4e0152ba74c5857b79aec54e7f1b (diff)
downloaddexon-solidity-9daac90cf7d0a28f5d631b9f5234e4268b5b61b7.tar.gz
dexon-solidity-9daac90cf7d0a28f5d631b9f5234e4268b5b61b7.tar.zst
dexon-solidity-9daac90cf7d0a28f5d631b9f5234e4268b5b61b7.zip
Merge pull request #4888 from ethereum/disallow_single_statement_vardecl_if_while_for
Disallow single statement var decl in if/while/for without blocks
Diffstat (limited to 'test/libsolidity/syntaxTests/variableDeclaration')
-rw-r--r--test/libsolidity/syntaxTests/variableDeclaration/do_while.sol12
-rw-r--r--test/libsolidity/syntaxTests/variableDeclaration/else.sol13
-rw-r--r--test/libsolidity/syntaxTests/variableDeclaration/for.sol11
-rw-r--r--test/libsolidity/syntaxTests/variableDeclaration/if.sol11
-rw-r--r--test/libsolidity/syntaxTests/variableDeclaration/while.sol11
5 files changed, 58 insertions, 0 deletions
diff --git a/test/libsolidity/syntaxTests/variableDeclaration/do_while.sol b/test/libsolidity/syntaxTests/variableDeclaration/do_while.sol
new file mode 100644
index 00000000..8fc48b33
--- /dev/null
+++ b/test/libsolidity/syntaxTests/variableDeclaration/do_while.sol
@@ -0,0 +1,12 @@
+pragma solidity >0.4.24;
+
+contract C
+{
+ function f(uint x) public pure {
+ do
+ uint y;
+ while (x > 0);
+ }
+}
+// ----
+// SyntaxError: (81-87): Variable declarations can only be used inside blocks.
diff --git a/test/libsolidity/syntaxTests/variableDeclaration/else.sol b/test/libsolidity/syntaxTests/variableDeclaration/else.sol
new file mode 100644
index 00000000..914e0c0c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/variableDeclaration/else.sol
@@ -0,0 +1,13 @@
+pragma solidity >0.4.24;
+
+contract C
+{
+ function f(uint x) public pure {
+ if (x > 0)
+ {uint y;}
+ else
+ uint z;
+ }
+}
+// ----
+// SyntaxError: (109-115): Variable declarations can only be used inside blocks.
diff --git a/test/libsolidity/syntaxTests/variableDeclaration/for.sol b/test/libsolidity/syntaxTests/variableDeclaration/for.sol
new file mode 100644
index 00000000..bc137f93
--- /dev/null
+++ b/test/libsolidity/syntaxTests/variableDeclaration/for.sol
@@ -0,0 +1,11 @@
+pragma solidity >0.4.24;
+
+contract C
+{
+ function f(uint x) public pure {
+ for (uint i = 0; i < x; ++i)
+ uint y;
+ }
+}
+// ----
+// SyntaxError: (107-113): Variable declarations can only be used inside blocks.
diff --git a/test/libsolidity/syntaxTests/variableDeclaration/if.sol b/test/libsolidity/syntaxTests/variableDeclaration/if.sol
new file mode 100644
index 00000000..75ab2026
--- /dev/null
+++ b/test/libsolidity/syntaxTests/variableDeclaration/if.sol
@@ -0,0 +1,11 @@
+pragma solidity >0.4.24;
+
+contract C
+{
+ function f(uint x) public pure {
+ if (x > 0)
+ uint y;
+ }
+}
+// ----
+// SyntaxError: (89-95): Variable declarations can only be used inside blocks.
diff --git a/test/libsolidity/syntaxTests/variableDeclaration/while.sol b/test/libsolidity/syntaxTests/variableDeclaration/while.sol
new file mode 100644
index 00000000..2997d80c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/variableDeclaration/while.sol
@@ -0,0 +1,11 @@
+pragma solidity >0.4.24;
+
+contract C
+{
+ function f(uint x) public pure {
+ while (x > 0)
+ uint y;
+ }
+}
+// ----
+// SyntaxError: (92-98): Variable declarations can only be used inside blocks.