I suppose you could do something similar to Java’s fail-fast iterators: use a flag to detect that a method has been called and check for it everywhere to throw an IllegalStateException
explicitly. Small runtime cost but would avoid incorrect code that appears to be working fine until an internal implementation changes.
3 Likes