-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Breaking change request] RuneIterator.current
and .rawIndex
no longer returns null
.
#40674
Comments
cc @Hixie @matanlurey @dgrove @vsmenon for review and approval. |
LGTM with the same caveats as other similar changes (that we need to be ready to reconsider if the impact is found to be large). |
lgtm |
LGTM |
Approved |
Bug: #40674 Change-Id: Ie67ab796140e93667750055cc2623543cdafa702 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138000 Reviewed-by: Alexander Thomas <athom@google.com> Commit-Queue: Vijay Menon <vsm@google.com>
Landed. Close as discussed in SCRUM |
The discussed alternative is a nullable type. Have we had a discussion about throwing instead? It turns out that |
The co19 tests were fixed in the co19 and co19_2 suites. Change-Id: Ib71bfdcb90b0f4b77c77f3fc6ee74f47605b71af Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145580 Commit-Queue: Alexander Thomas <athom@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
Summary
The
RuneIterator
class has some members which returnnull
in the state where the iterator has no "current" element.Those are members which are not intended to be used in that state, and which has no right value to return. The
Iterator.current
getter inherited fromIterator
has this issue in general, and in the Null Safe SDK, theIterator.current
getter is no longer required to returnnull
when there is no current element.What is changing:
The
RuneIterator
now returns the following values when it has no current rune (before callingmoveNext
at the beginning or after callingreset
, or aftermoveNext
has returned false):current
: -1rawIndex
: -1currentAsString
: empty string.Why is this changing?
Because the alternative would be to make the return type nullable.
For
current
, even that is not possible becauseIterable<T>.current
returnsT
, and overriding it with something returningT?
is not allowed.Making the other return values nullable is highly annoying for users who only use these getters in the state where they are intended to be used, and where they have a meaningful value to return. Those users would have to check for null on every access, even though they know it will succeed.
Expected impact
Little to none. The [RuneIterator] class is not heavily used, and when iterated using
for
/in
or other normal iteration methods, the getters in question are not used at all.If someone is using those getters, and they are depending on reading them when there is no current value and using the the
null
to detect that there is no value, they will now fail.The impact is well worth the API improvement for Null Safe code.
The text was updated successfully, but these errors were encountered: