aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/syntaxTests
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-06 18:59:16 +0800
committerGitHub <noreply@github.com>2018-08-06 18:59:16 +0800
commit9d03de1f250cecad2c5c796beb10d96c3c9b15cd (patch)
treeea93d83315c48f07b2efaf0d73c3b4a3b6f29d2e /test/libsolidity/syntaxTests
parent13d3006376c826495bad8a4c648e68a359fa1b41 (diff)
parentcbae02b514d7a9dd3845f2f731caec7defa29a66 (diff)
downloaddexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar.gz
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar.bz2
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar.lz
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar.xz
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.tar.zst
dexon-solidity-9d03de1f250cecad2c5c796beb10d96c3c9b15cd.zip
Merge pull request #4671 from ethereum/mappingTupleAssignment
Disallow assignments to mappings within tuple assignments; allow for local variables.
Diffstat (limited to 'test/libsolidity/syntaxTests')
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol12
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/assignment_local.sol11
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/assignment_state_variable.sol14
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/assignment_struct.sol17
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_return_external.sol7
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol21
-rw-r--r--test/libsolidity/syntaxTests/types/mapping/mapping_return_public.sol7
7 files changed, 77 insertions, 12 deletions
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol
deleted file mode 100644
index 27b1ea96..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/016_assignment_to_mapping.sol
+++ /dev/null
@@ -1,12 +0,0 @@
-contract test {
- struct str {
- mapping(uint=>uint) map;
- }
- str data;
- function fun() public {
- mapping(uint=>uint) storage a = data.map;
- data.map = a;
- }
-}
-// ----
-// TypeError: (172-184): Mappings cannot be assigned to.
diff --git a/test/libsolidity/syntaxTests/types/mapping/assignment_local.sol b/test/libsolidity/syntaxTests/types/mapping/assignment_local.sol
new file mode 100644
index 00000000..a329c91e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/assignment_local.sol
@@ -0,0 +1,11 @@
+contract test {
+ mapping(uint=>uint) map;
+ function fun() public view {
+ mapping(uint=>uint) storage a = map;
+ mapping(uint=>uint) storage b = map;
+ b = a;
+ (b) = a;
+ (b, b) = (a, a);
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/types/mapping/assignment_state_variable.sol b/test/libsolidity/syntaxTests/types/mapping/assignment_state_variable.sol
new file mode 100644
index 00000000..1323afe6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/assignment_state_variable.sol
@@ -0,0 +1,14 @@
+contract test {
+ mapping(uint=>uint) map;
+ function fun() public {
+ mapping(uint=>uint) storage a = map;
+ map = a;
+ (map) = a;
+ (map, map) = (a, a);
+ }
+}
+// ----
+// TypeError: (126-129): Mappings cannot be assigned to.
+// TypeError: (144-147): Mappings cannot be assigned to.
+// TypeError: (163-166): Mappings cannot be assigned to.
+// TypeError: (168-171): Mappings cannot be assigned to.
diff --git a/test/libsolidity/syntaxTests/types/mapping/assignment_struct.sol b/test/libsolidity/syntaxTests/types/mapping/assignment_struct.sol
new file mode 100644
index 00000000..b89241ed
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/assignment_struct.sol
@@ -0,0 +1,17 @@
+contract test {
+ struct str {
+ mapping(uint=>uint) map;
+ }
+ str data;
+ function fun() public {
+ mapping(uint=>uint) storage a = data.map;
+ data.map = a;
+ (data.map) = a;
+ (data.map, data.map) = (a, a);
+ }
+}
+// ----
+// TypeError: (172-180): Mappings cannot be assigned to.
+// TypeError: (195-203): Mappings cannot be assigned to.
+// TypeError: (219-227): Mappings cannot be assigned to.
+// TypeError: (229-237): Mappings cannot be assigned to.
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_return_external.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_return_external.sol
new file mode 100644
index 00000000..85121241
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_return_external.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() external pure returns (mapping(uint=>uint) storage m) {
+ }
+}
+// ----
+// TypeError: (53-82): Type is required to live outside storage.
+// TypeError: (53-82): Internal or recursive type is not allowed for public or external functions.
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol
new file mode 100644
index 00000000..a46003f8
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_return_internal.sol
@@ -0,0 +1,21 @@
+// This should be allowed in a future release.
+contract C {
+ mapping(uint=>uint) m;
+ function f() internal view returns (mapping(uint=>uint) storage) {
+ return m;
+ }
+ function g() private view returns (mapping(uint=>uint) storage) {
+ return m;
+ }
+ function h() internal view returns (mapping(uint=>uint) storage r) {
+ r = m;
+ }
+ function i() private view returns (mapping(uint=>uint) storage r) {
+ (r,r) = (m,m);
+ }
+}
+// ----
+// TypeError: (127-146): Type is required to live outside storage.
+// TypeError: (221-240): Type is required to live outside storage.
+// TypeError: (316-345): Type is required to live outside storage.
+// TypeError: (409-438): Type is required to live outside storage.
diff --git a/test/libsolidity/syntaxTests/types/mapping/mapping_return_public.sol b/test/libsolidity/syntaxTests/types/mapping/mapping_return_public.sol
new file mode 100644
index 00000000..383fa797
--- /dev/null
+++ b/test/libsolidity/syntaxTests/types/mapping/mapping_return_public.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f() public pure returns (mapping(uint=>uint) storage m) {
+ }
+}
+// ----
+// TypeError: (51-80): Type is required to live outside storage.
+// TypeError: (51-80): Internal or recursive type is not allowed for public or external functions.