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

[compiler-v2] Field selection after resource indexing not mutable #15224

Closed
wrwg opened this issue Nov 7, 2024 · 0 comments · Fixed by #15239
Closed

[compiler-v2] Field selection after resource indexing not mutable #15224

wrwg opened this issue Nov 7, 2024 · 0 comments · Fixed by #15239
Assignees
Labels
bug Something isn't working compiler-v2

Comments

@wrwg
Copy link
Contributor

wrwg commented Nov 7, 2024

Consider code as below:

    package fun deposit(account: address, coin: Coin) acquires Account {
        // What I have to write
        //(&mut Account[account].balance).merge(coin)
        // What I wish to write but got error message
        Account[account].balance.merge(coin)
    }

where fun merge(self: &mut Coin, Coin)

The produced error message is

error: cannot mutably borrow from an immutable ref
   ┌─ /Users/wrwg/move-demo/sources/account.move:20:9
   │
20 │         Account[account].balance.merge(coin)
   │         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It appears that the decision to imm-ref the index Account[account] is taken before its known that it needs to be mutable. This might be a difficult problem to fix, but its a bit of annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler-v2
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants