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

Improve error message when passing in the storage keyword as a type into a function #1946

Closed
Braqzen opened this issue Jun 12, 2022 · 2 comments
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen duplicate This issue or pull request already exists P: critical Should be looked at before anything else

Comments

@Braqzen
Copy link
Contributor

Braqzen commented Jun 12, 2022

Reproduce

contract;

storage {
    var: u64,
}

abi MyContract {
    fn test_function(s: storage) -> bool;
}

impl MyContract for Contract {
    fn test_function(s: storage) -> bool {
        let mut s = s;
        s.var = s.var + 1;
        true
    }
}

Error should state something similar to "storage" cannot be used as a type / Cannot pass in "storage" as a type into a function.

Screenshot

1

cc @FuelLabs/sway-compiler

@Braqzen Braqzen added enhancement New feature or request compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jun 12, 2022
@adlerjohn adlerjohn moved this to Todo in Fuel Network Jun 12, 2022
@mohammadfawaz mohammadfawaz self-assigned this Jun 14, 2022
@mohammadfawaz mohammadfawaz added bug Something isn't working P: critical Should be looked at before anything else and removed enhancement New feature or request labels Jun 14, 2022
@mohammadfawaz
Copy link
Contributor

So, we have almost no checks in the compiler against using keywords in places where they don't belong. This is just one example. There are may more such as:

let mut mut = 0;

which compiles without any errors. I think a full solution needs to be implemented in the parser that protects against using keywords where identifiers should go. cc @canndrew, what is the best way to do this?

@mohammadfawaz mohammadfawaz removed their assignment Jun 15, 2022
@mohammadfawaz mohammadfawaz added the duplicate This issue or pull request already exists label Jun 17, 2022
@mohammadfawaz
Copy link
Contributor

I'm closing this in favour of #1996 which is tracking a general solution for all keywords.

Repository owner moved this from Todo to Done in Fuel Network Jun 17, 2022
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: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen duplicate This issue or pull request already exists P: critical Should be looked at before anything else
Projects
Archived in project
Development

No branches or pull requests

2 participants