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

bug: LSP doesn't check types in Storage #3939

Closed
Chepelau opened this issue Aug 17, 2023 · 3 comments
Closed

bug: LSP doesn't check types in Storage #3939

Chepelau opened this issue Aug 17, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed ide This issue refers to CairoLS or editor extensions

Comments

@Chepelau
Copy link

Chepelau commented Aug 17, 2023

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 Chepelau added the bug Something isn't working label Aug 17, 2023
@Chepelau Chepelau changed the title bug: LSP doesn't check typed in LegacyMap bug: LSP doesn't check types in LegacyMap Aug 17, 2023
@Chepelau Chepelau changed the title bug: LSP doesn't check types in LegacyMap bug: LSP doesn't check types in Storage Aug 17, 2023
@orizi
Copy link
Collaborator

orizi commented Aug 20, 2023

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.

@Chepelau
Copy link
Author

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

@mkaput mkaput added the ide This issue refers to CairoLS or editor extensions label Jan 22, 2024
@mkaput mkaput added the help wanted Extra attention is needed label Jul 2, 2024
@orizi
Copy link
Collaborator

orizi commented Aug 26, 2024

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

@orizi orizi closed this as completed Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed ide This issue refers to CairoLS or editor extensions
Projects
Archived in project
Development

No branches or pull requests

3 participants