You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The module Iterator(T) revolves around the abstract def #next which is expected to return T or a stop indicator (Iterator::Stop). This expectation is currently not expressed in a type restriction. But it should be: Iterator(T)#next : T | Iterator::Stop.
Without this type restriction, an Iterator implementation can return any type in its #next method, which is prone to cause issues further down the line (see #10857 (comment) for an example). Adding this type restriction makes it easy to spot any incorrect implemtnations.
Unfortunately, this is currently not possible without introducing a major breaking change, because all abstract def implementations would be forced to specify a return type restriction as well. And most Iterator implementations don't do that.
#10904 proposes a compiler change as an alternative to introduce this return type restriction without a breaking change.
The text was updated successfully, but these errors were encountered:
The module
Iterator(T)
revolves around the abstract def#next
which is expected to returnT
or a stop indicator (Iterator::Stop
). This expectation is currently not expressed in a type restriction. But it should be:Iterator(T)#next : T | Iterator::Stop
.Without this type restriction, an
Iterator
implementation can return any type in its#next
method, which is prone to cause issues further down the line (see #10857 (comment) for an example). Adding this type restriction makes it easy to spot any incorrect implemtnations.Unfortunately, this is currently not possible without introducing a major breaking change, because all abstract def implementations would be forced to specify a return type restriction as well. And most
Iterator
implementations don't do that.#10904 proposes a compiler change as an alternative to introduce this return type restriction without a breaking change.
The text was updated successfully, but these errors were encountered: