Skip to content
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

Mappings cannot be returned from internal functions #4670

Closed
chriseth opened this issue Aug 3, 2018 · 6 comments
Closed

Mappings cannot be returned from internal functions #4670

chriseth opened this issue Aug 3, 2018 · 6 comments
Assignees
Labels

Comments

@chriseth
Copy link
Contributor

chriseth commented Aug 3, 2018

No description provided.

@ekpyron
Copy link
Member

ekpyron commented Aug 3, 2018

What about the following:

mapping(uint=>uint) m;
mapping(uint=>uint) n;
function f() internal returns (mapping(uint=>uint) storage r) {
  r = m;
  r[1] = 4;
  r = n;
  r[2] = 8;
}

Currently, if just allowing mapping returns syntactically, this will end up writing 4 to key 1 in n :).
Currently, this does not work as expected (further investigation required).

So we should:

If this construct is allowed for return values, that may be inconsistent with disallowing it for local variables (allowing it for local variables faces the same problems, though).

EDIT: In fact this does work as expected for local variables. #4671 will allow it syntactically. Therefore it should also work as expected for return types (but currently it doesn't without further changes).

@chriseth

This comment has been minimized.

@ekpyron

This comment has been minimized.

@ekpyron

This comment has been minimized.

@ekpyron
Copy link
Member

ekpyron commented Aug 3, 2018

I updated #4671 to allow assignments for local variables (this already works as verified by the added semantics test).

What remains is to allow returning mappings in internal functions and to verify that this works with semantics tests (I rechecked - allowing the returns syntactically alone will not result in the desired behaviour, so this will need some further investigation).

@ekpyron
Copy link
Member

ekpyron commented Aug 10, 2018

Not sure whether something changed or whether I was simply wrong before, but I checked again during #4635 and I don't experience any problems with internal mapping returns (and arguments) anymore. I'm considering fixing this together with #4635 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants