sway icon indicating copy to clipboard operation
sway copied to clipboard

Warn on unnecessary storage annotations

Open mohammadfawaz opened this issue 3 years ago • 2 comments

Example:

contract;

abi MyContract {
    #[storage(write)] // Or any other storage annotation
    fn foo() -> u64;
}

impl MyContract for Contract {
    #[storage(write)] // Or any other storage annotation
    fn foo() -> u64 {
        0
    }
}

should emit a warning saying that the annotations are not necessary.

mohammadfawaz avatar Apr 07 '22 13:04 mohammadfawaz

@otrho have we decided against emitting warnings on unnecessary storage annotations? Or is this something that we want but hasn't been implemented yet? We don't seem to be emitting any warnings for the example above.

mohammadfawaz avatar Jul 31 '22 19:07 mohammadfawaz

This could be a regression? I would expect the above to emit warnings and for there to already be tests to confirm. There was a lot of debate around it though, so maybe I've forgotten whether we decided otherwise.

otrho avatar Aug 01 '22 02:08 otrho

Yeah no warning is generated with master. Could be a regression, but I think we would want the warning to be emitted? Seems like a useful warning to have because addressing makes the user code more readable.

mohammadfawaz avatar Aug 19 '22 13:08 mohammadfawaz

I think there should be warnings, yeah.

otrho avatar Aug 20 '22 02:08 otrho

Wait I do see a warning now 🤔 , but the warning does not seem that useful:

  --> /Users/mohammad/Desktop/fuel/sway/test/src/e2e_vm_tests/test_programs/should_pass/language/const_decl_and_use_in_library/src/main.sw:12:5
   |
10 |
11 |       #[storage(write)] // Or any other storage annotation
12 |       fn foo() -> u64 {
   |  _____-
13 | |         0
14 | |     }
   | |_____- The 'write' storage declaration for this function is never accessed and can be removed.
15 |   }
   |
____

Well, it is useful but it can be improved.

mohammadfawaz avatar Oct 31 '22 00:10 mohammadfawaz