Class CloseableReturnOrError

java.lang.Object
org.ek9lang.compiler.phase5.CloseableReturnOrError
All Implemented Interfaces:
Consumer<MutatedOnlyVariables.ReturningCallable>

final class CloseableReturnOrError extends Object implements Consumer<MutatedOnlyVariables.ReturningCallable>
R5 (Steve, 2026-10-05): a method, operator, function or dynamic function whose DECLARED return type is closeable must return a NEW instance (E81057). Returning a closeable hands its ownership to the caller, who closes it - so it must not be anything somebody else will also close or still uses: a property (this's interior), a parameter (the caller's), a capture, a local (a try resource is closed as the try ends), or a call result that may be one of those (list.get(0), iterator.next()).

Provably new (ReturnSourceKind.NEW) is a constructor call, or a call of a callable whose declared return type is closeable - new by this same rule, so the declaration is the proof and no fixpoint is needed. Every source of the returning variable is checked (MutatedOnlyVariables collects them: the initialiser, pointer assignments (pre-flows included), and through arm-shaped values). To LEND a held resource, return a non-closeable view type instead (StringInput, as TCPConnection.input() does).

Reported once per callable, at its definition, naming the first source that is not new. A bare type parameter T is not a closeable type (CloseableResourceToBeChecked.isManagedCloseableType(ISymbol)), so a generic returning T is not judged per parameterisation here.