Skip to content

Commit

Permalink
Fix ICE caused by an array of mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
a3d4 committed Aug 30, 2020
1 parent 98cc1d9 commit cb49b91
Show file tree
Hide file tree
Showing 25 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (auto contractType = dynamic_cast<ContractType const*>(varType))
if (contractType->contractDefinition().isLibrary())
m_errorReporter.typeError(1273_error, _variable.location(), "The type of a variable cannot be a library.");
if (auto arrayType = dynamic_cast<ArrayType const*>(varType))
if (arrayType->containsNestedMapping())
m_errorReporter.typeError(1946_error, _variable.location(), "Arrays containing (nested) mappings are not allowed.");

if (_variable.value())
{
if (_variable.isStateVariable() && varType->containsNestedMapping())
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(struct_with_mapping_in_library)
{
char const* text = R"(
library Test {
struct Nested { mapping(uint => uint)[2][] a; uint y; }
struct Nested { mapping(uint => uint) a; uint y; }
struct X { Nested n; }
function f(X storage x) external {}
}
Expand Down
1 change: 1 addition & 0 deletions test/libsolidity/syntaxTests/array/function_mapping.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ contract Test {
}
// ----
// TypeError 4103: (66-98): Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
// TypeError 1946: (66-98): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (66-98): Type mapping(uint256 => uint256)[] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ library L {
function f(mapping(uint => uint)[2] memory a) external pure returns (mapping(uint => uint)[2] memory) {}
}
// ----
// TypeError 1946: (61-94): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (61-94): Type mapping(uint256 => uint256)[2] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ contract C {
function ( ) internal returns ( bytes [ ] storage , mapping ( bytes => mapping ( bytes => mapping ( uint => mapping ( bytes => mapping ( string => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( string => mapping ( string => mapping ( uint => mapping ( bytes => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( bytes => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( uint => mapping ( string => mapping ( uint => string ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) [ ] storage ) constant c = c ;
}
// ----
// TypeError 6161: (43-643): The value of the constant c has a cyclic dependency via c.
// TypeError 1946: (95-626): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
}
}
// ----
// TypeError 1946: (91-136): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (91-136): Type mapping(string => uint24)[1] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ contract Test {
}
// ----
// DeclarationError 2333: (157-198): Identifier already declared.
// TypeError 1946: (268-300): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (268-300): Type struct Test.RecursiveStruct[1] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ contract Test {
}
}
// ----
// TypeError 1946: (38-64): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (99-106): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (161-172): Type struct Test.S2 is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ contract C {
function f(S memory) public {}
}
// ----
// TypeError 1946: (105-113): Arrays containing (nested) mappings are not allowed.
// TypeError 4103: (132-140): Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
// TypeError 4061: (132-140): Type struct C.S is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ contract C {
function f(S memory) public {}
}
// ----
// TypeError 1946: (105-113): Arrays containing (nested) mappings are not allowed.
// TypeError 4103: (132-140): Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
// TypeError 4061: (132-140): Type struct C.S is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ contract C {
}
}
// ----
// TypeError 1946: (47-77): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (47-77): Type mapping(uint256 => uint256)[] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ contract C {
}
}
// ----
// TypeError 3464: (95-96): This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
// TypeError 1946: (52-85): Arrays containing (nested) mappings are not allowed.
3 changes: 3 additions & 0 deletions test/libsolidity/syntaxTests/parsing/arrays_in_storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ contract c {
struct x { uint[2**20] b; y[1] c; }
struct y { uint d; mapping(uint=>x)[] e; }
}
// ----
// TypeError 1946: (74-80): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (107-127): Arrays containing (nested) mappings are not allowed.
2 changes: 2 additions & 0 deletions test/libsolidity/syntaxTests/parsing/multi_arrays.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
contract c {
mapping(uint => mapping(uint => int8)[8][][9])[] x;
}
// ----
// TypeError 1946: (17-67): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ contract C {
}
}
// ----
// TypeError 1946: (28-59): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ contract C {
}
}
// ----
// TypeError 1946: (28-59): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ contract test {
}
}
// ----
// TypeError 1946: (31-64): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (31-64): Type mapping(uint256 => uint256)[2] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ library L {
}
}
// ----
// TypeError 1946: (27-58): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ library L {
function f(mapping(uint => uint)[] storage) internal pure {
}
}
// ----
// TypeError 1946: (27-58): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ library L {
function f(mapping(uint => uint)[] storage) private pure {
}
}
// ----
// TypeError 1946: (27-58): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ library L {
}
}
// ----
// TypeError 1946: (27-58): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ library Test {
function f(X storage x) external {}
}
// ----
// TypeError 1946: (35-63): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ contract c {
}
// ----
// TypeError 4103: (29-61): Types containing (nested) mappings can only be parameters or return variables of internal or library functions.
// TypeError 1946: (29-61): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (29-61): Type mapping(uint256 => uint256)[] is only valid in storage because it contains a (nested) mapping.
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ contract C {
}
}
// ----
// TypeError 1946: (17-40): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (82-111): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (178-207): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (275-306): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (370-401): Arrays containing (nested) mappings are not allowed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ contract Test {
}
}
// ----
// TypeError 1946: (30-35): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (55-60): Arrays containing (nested) mappings are not allowed.
// TypeError 1946: (80-85): Arrays containing (nested) mappings are not allowed.
// TypeError 4061: (143-153): Type struct Test.S is only valid in storage because it contains a (nested) mapping.

0 comments on commit cb49b91

Please sign in to comment.