LYR-SEM0143
'using' on a value that is not Closeable
'using let' binds a value whose type does not conform to 'Closeable' (and is no coroutine).
Explanation
using let x = …; closes x when the scope is left, through the Closeable interface. A type that merely has a method named close() does not conform: the conformance is what promises that close releases the resource and may be called on every exit path.
Declare the conformance (class Plain :: [Closeable] { … }), or use a plain let with a defer { x.close(); }.
Wrong
class Plain {
fn close(): void { }
}
fn main(): void {
using let p = Plain { };
let _ = p;
}
Right
class Plain :: [Closeable] {
fn close(): void { }
}
fn main(): void {
using let p = Plain { };
let _ = p;
}