FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.

Home Page:https://fuellabs.github.io/sway

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing semicolon error reported at the following token and not at the actual source of issue

ironcev opened this issue · comments

As reported by @SilentCicero, "Sway incorrectly errors when there is a missing semicolon after a use statement. It thinks the semicolon is missing in the ABI, when in fact it was missing after the use statement. In this example, the semicolon is missing after the use statement, but it wrongly states its missing in the ABI. This was very confusing to debug."

contract;

use std::{
    identity::Identity,
    block::timestamp
}  // <<< Error should be reported here...

abi Counter {   // <<< ... and not here
    #[storage(read, write)]
    fn constructor(amount: u64);

    #[storage(read, write)]
    fn increment(amount: u64) -> u64;

    #[storage(read)]
    fn get() -> u64;
}

configurable {
    CONSTRUCTED_TIMESTAMP: u64 = 1714578941,
    OWNER: b256 = 0x0000000000000000000000000000000000000000000000000000000000000000
}

storage {
    counter: u64 = 0,
}

fn constructor_check() {
    assert(timestamp() >= CONSTRUCTED_TIMESTAMP || Identity::Address(Address::from(OWNER)) == msg_sender().unwrap());
}

impl Counter for Contract {
    #[storage(read, write)]
    fn constructor(amount: u64) {
        constructor_check();
        storage.counter.write(amount);
    }

    #[storage(read, write)]
    fn increment(amount: u64) -> u64 {
        constructor_check();
        let incremented = storage.counter.read() + amount;
        storage.counter.write(incremented);
        incremented
    }

    #[storage(read)]
    fn get() -> u64 {
        storage.counter.read()
    }
}