-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICE on push to array with storage mapping #7410
Comments
A bit simplified:
|
If you manage to push the map to the array, popping it will cause another internal compiler error. In general, supporting mappings within reference types seems to raise many issues and unexpected results. It would seem more consistent to just disallow it except as a top-level storage member, with no assignment and no delete. |
@leonardoalt Yes, it seem like no ICE i 0.5.12. I'm still not a big fan. The semantics are bizarre and will eventually get someone in trouble. Like example below (using resize instead for push). contract C {
mapping (address => int)[] m;
function whats_going_on() public {
// Put something in the array
m.length = 1;
m[0][msg.sender] = 1;
// Get the reference to first elemnet
mapping (address => int) storage ref = m[0];
// Oh, let's pop the element
m.pop();
assert(m.length == 0);
// Reference still works?
assert(ref[msg.sender] == 1);
// Seems so, let's put something in
ref[msg.sender] = 2;
ref[address(0)] = 3;
// Let's put something in the array and see what's in the new mapping?
m.length = 1;
assert(m[0][msg.sender] == 2);
assert(m[0][address(0)] == 3);
}
} |
I agree that this is dangerous. The tests added in https://github.com/ethereum/solidity/pull/7431/files make this behavior explicit. |
I'd also tend to re-think this behavior. Assigning to |
Still a problem:
|
Maybe related to #8278 |
This can be fixed in TypeChecker for But I actually wonder if push makes sense for mapping types? The following code should be valid: contract C {
mapping (uint => uint) map1;
mapping (uint => mapping(uint => uint)[]) mapToMapArray;
function f() public {
mapping (uint => uint)[] storage maps = mapToMapArray[1];
maps.push(map1);
}
} But there is an exception:
There are
What's a good fix for this? @chriseth @leonardoalt |
I thought the idea was to disallow arrays of mappings in general? |
@leonardoalt did we reach a conclusion there yet? |
@chriseth I thought so, but maybe it was just me wanting it :p |
Related: #8535 |
Description
The following internal compiler error is thrown in the scenario below:
Steps to Reproduce
The text was updated successfully, but these errors were encountered: