buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Prevent calling `collect` multiple times

Open giann opened this issue 3 months ago • 0 comments

Most of the time collect will clear external resources and should not be called more than once. Currently, we avoid this with flag:

object File {
    collected: bool = false,

    // ...

    mut fun collect() > void {
        if (!this.collected) {
            this.file.close();
            this.collected = true;
        }
    }    

    // ...
}

But this is not ideal, namely because nothing prevents collected to be modified by the user.

Buzz should itself enforce the fact that that special method is called once.

giann avatar Sep 17 '25 13:09 giann