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

Invalid Dereference Error with Mutable Reference #12

Open
1-4200 opened this issue Aug 30, 2024 · 0 comments
Open

Invalid Dereference Error with Mutable Reference #12

1-4200 opened this issue Aug 30, 2024 · 0 comments

Comments

@1-4200
Copy link

1-4200 commented Aug 30, 2024

Description:

I'm encountering an issue with the Sui Move plugin in WebStorm when working with a mutable reference in my code. Specifically, the plugin incorrectly reports an error on a dereference operation in the following line:

*value = *value + 1;

The error message shown by the plugin is:

Invalid dereference. Expected '&_' but found '<unknown>'

However, the code is valid and compiles without any issues. The dereference operation is expected to work as intended. Below is the full code snippet for context:

module playground::dereference {
    use sui::table::{Self, Table};
    
    public struct Counter has key {
        id: UID,
        entries: Table<address, u64>
    }
    
    public fun new_counter(ctx: &mut TxContext): Counter {
        Counter {
            id: object::new(ctx),
            entries: table::new(ctx),
        }
    }
    
    public fun increment_counter(counter: &mut Counter, sender: address) {
        if (!counter.entries.contains(sender)) {
            counter.entries.add(sender, 0);
        };
        let value = counter.entries.borrow_mut(sender);
        // it explicitly requires the type of the value to be dereferenced
        // let value: &mut u64 = counter.entries.borrow_mut(sender);
        *value = *value + 1;
    }
}

As shown, the line *value = *value + 1; is where the plugin throws the error, but it works perfectly when compiled.

Expected Behavior:

The plugin should recognize the dereference operation as valid and not throw an error.

Environment:

WebStorm version: 2024.2.1 RC
Sui Move Plugin version: 1.6.0.242

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

No branches or pull requests

1 participant