Lyricdev
GitHub

LYR-PAR0052

a 'using' that is not one 'let' with a value

error ยท spec 06-errors

using var is written, or a using binding takes a pattern or has no value.

Explanation

using let r = open(p); closes r when its scope is left. A var could be given another value, and the first one would never be closed; a pattern or a missing value leaves no single value to close.

Write using let name = value;.

Wrong

class Res :: [Closeable] {
    fn close(): void throws Error { }
}

fn main(): void throws Error {
    using var r = Res { };
}
class Res :: [Closeable] {
    fn close(): void throws Error { }
}

fn main(): void throws Error {
    using let r = Res { };
    let _ = r;
}