mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #4671 from ethereum/mappingTupleAssignment
Disallow assignments to mappings within tuple assignments; allow for local variables.
This commit is contained in:
@@ -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.
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
@@ -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.
|
||||
Reference in New Issue
Block a user