t4sk / hello-sway

learning sway
7 stars 2 forks source link

Raining of Errors! #1

Open shanb1605 opened 1 month ago

shanb1605 commented 1 month ago

I'm new to Sway. just started to writing sway from Counter counter.

When I compile Counter contract It throws 8 syntax errors. seeking help on this

  Creating a new `Forc.lock` file. (Cause: lock file did not exist)
    Adding core
    Adding std git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6
   Created new lock file at /Users/tmp/learn-sway/counter/Forc.lock
error
  --> /Users/tmp/learn-sway/counter/src/main.sw:21:9
   |
19 | 
20 |     fn get() -> u64 {
21 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Implicit return must match up with block's type.
22 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:21:9
   |
19 | 
20 |     fn get() -> u64 {
21 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Function body's return type does not match up with its return type annotation.
22 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:26:9
   |
24 | 
25 |     fn inc() -> u64 {
26 |         storage.count += 1;
   |         ^^^^^^^^^^^^^^^^^^ This expression is not valid on the left hand side of a reassignment.
27 |         storage.count
28 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:27:9
   |
25 | 
26 |         storage.count += 1;
27 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Implicit return must match up with block's type.
28 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:27:9
   |
25 | 
26 |         storage.count += 1;
27 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Function body's return type does not match up with its return type annotation.
28 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:32:9
   |
30 | 
31 |     fn dec() -> u64 {
32 |         storage.count -= 1;
   |         ^^^^^^^^^^^^^^^^^^ This expression is not valid on the left hand side of a reassignment.
33 |         storage.count
34 |     }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:33:9
   |
31 | 
32 |         storage.count -= 1;
33 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Implicit return must match up with block's type.
34 |     }
35 | }
   |
____

error
  --> /Users/tmp/learn-sway/counter/src/main.sw:33:9
   |
31 | 
32 |         storage.count -= 1;
33 |         storage.count
   |         ^^^^^^^^^^^^^ Mismatched types.
expected: u64
found:    StorageKey<u64>.
help: Function body's return type does not match up with its return type annotation.
34 |     }
35 | }
   |
____

  Aborting due to 8 errors.
Error: Failed to compile counter
shanb1605 commented 1 month ago

@t4sk could you pls help me with this?