cairo icon indicating copy to clipboard operation
cairo copied to clipboard

bug: LSP doesn't check types in Storage

Open Chepelau opened this issue 2 years ago • 2 comments

Bug Report

I'm using latest scarb and cairo:

scarb 0.6.2 (c07fa6155 2023-08-15)
cairo: 2.1.1 (https://crates.io/crates/cairo-lang-compiler/2.1.1)

Also using LSP shipped with scarb(which is also the latest version provided by scarb).

Current behavior: When there are some unimported/wrongly named types in Storage used, the LSP does not report that, and pretends it's all alright even if we then use those storage vars in different module. This is problem because if we then try to build the contract it prints tens of errors which are hard debug and determine where they stem from. It might be simple on small contract, but when it contains several files and folders, it might prove quite difficult.

Expected behavior: LSP Should report that the type is missing/unknown.

Example code:

#[starknet::contract]
mod BugContract {

    // type my_felt = felt252;
    // type my_u256 = u256;

    #[storage]
    struct Storage {
        some_calculations_results: LegacyMap<(my_felt, some_completely_random_type), my_u256>
    }
}

Note the commented type aliases(if they are uncommented, then there is no problem).

First of all, with cairo-compile, the error is only one - but it points to LegacyMap:

error: Type not found.
 --> contract.cairo:9:36
        some_calculations_results: LegacyMap<(my_felt, some_completely_random_type), my_u256>
                                   ^*******^

Instead of the unknown types.

With scarb on the other hand it not only prints tens of errors, but some of them might seem kinda cryptic for some newcomer and if the project is large, it is almost impossible to determine what is going:

error: Candidate impl core::starknet::SyscallResultTraitImpl::<?0> has an unused generic parameter.
 --> contract:69:19
                ).unwrap_syscall()
                  ^************^

Other information:

 ->  cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

Also here is picture of the code, where LSP clearly doesn't report any bug: image

Chepelau avatar Aug 17 '23 14:08 Chepelau

The missing diags in the LSP are an issue - we are looking into it. About the cairo-compile call - do note that it runs without the starknet plugin - so all the attributes are ignored, and the LegacyMap is indeed note known at all. starknet-compile is the equivalent you were actually looking for there.

orizi avatar Aug 20 '23 10:08 orizi

Yes, sorry. Tried with starknet-compile and it results in the same errors as scarb build

Chepelau avatar Aug 21 '23 10:08 Chepelau

Errors are now optionally deduped and Map types are real types - getting proper diags.

orizi avatar Aug 26 '24 10:08 orizi