Skip to content

Invalid Dereference Error with Mutable Reference #12

Description

@1-4200

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions