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

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

Open
ironcev opened this issue May 2, 2024 · 0 comments
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented May 2, 2024

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()
    }
}
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

1 participant