E81070: 'default operator close' with nothing to close - no closeable property and no super class close - would only make the type closeable, forcing every caller into a 'try'; remove it
What went wrong
A type asks for 'default operator close' but has nothing for it to close: no closeable property, no capture it owns, and no super class with a close of its own. The generated close would do nothing - yet it would make the type closeable, and every caller of a closeable type must then acquire it in a 'try' (E81056). A close that closes nothing only adds that burden.
'default operator close' closes the type's own closeable properties (last acquired first) and then calls the super class's close. It is never added by the bare 'default operator', so a type is closeable only when it asks to be.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 1880 (How do I release the resources my class holds - and what does 'default operator close' close for me?)
How to fix it
Remove the 'default operator close' (the [EXAMPLE] section below: a Settings type holding only a String path, with and without it).
If the type really is a resource (it wraps something that must be released), give it the closeable property that holds that resource, or write an 'operator close' that does the work.
Common causes
- Adding 'default operator close' to every type "to be safe".
- A holder whose closeable property was removed, leaving its close behind.
- Expecting 'default operator close' to close an INJECTED property - the application owns those, so they are never closed by the holder.
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E81070: 'default operator close' with nothing to close - no closeable property and no super class close - would only make the type closeable, forcing every caller into a 'try'; remove it
#!ek9 defines module error.e81070.bad defines class Settings path as String: "settings.txt" default operator ? default operator close
Fixed: Remove it - a type with nothing to close is not closeable
#!ek9 defines module error.e81070.good defines class Settings path as String: "settings.txt" default operator ?
Questions and answers
These Q&A entries show E81070 and its fix: