Skip to content
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

Closed
lrhn opened this issue Feb 19, 2020 · 7 comments
Closed
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. breaking-change-request This tracks requests for feedback on breaking changes library-core NNBD Issues related to NNBD Release

Comments

@lrhn
Copy link
Member

lrhn commented Feb 19, 2020

Summary

The RuneIterator class has some members which return null 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 from Iterator has this issue in general, and in the Null Safe SDK, the Iterator.current getter is no longer required to return null when there is no current element.

What is changing:

The RuneIterator now returns the following values when it has no current rune (before calling moveNext at the beginning or after calling reset, or after moveNext has returned false):

  • current: -1
  • rawIndex: -1
  • currentAsString: empty string.

Why is this changing?

Because the alternative would be to make the return type nullable.
For current, even that is not possible because Iterable<T>.current returns T, and overriding it with something returning T? 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.

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-core breaking-change-request This tracks requests for feedback on breaking changes labels Feb 19, 2020
@mit-mit mit-mit added the NNBD Issues related to NNBD Release label Feb 19, 2020
@franklinyow
Copy link
Contributor

cc @Hixie @matanlurey @dgrove @vsmenon for review and approval.

@Hixie
Copy link
Contributor

Hixie commented Feb 19, 2020

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).

@vsmenon
Copy link
Member

vsmenon commented Feb 24, 2020

lgtm

@matanlurey
Copy link
Contributor

LGTM

@franklinyow
Copy link
Contributor

Approved

dart-bot pushed a commit that referenced this issue Mar 3, 2020
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>
@franklinyow
Copy link
Contributor

Landed. Close as discussed in SCRUM

@natebosch
Copy link
Member

The discussed alternative is a nullable type. Have we had a discussion about throwing instead?

It turns out that -1 happens to be easier to use for the code I had to migrate that was broken by this - but that's because this code is written in a really weird way and isn't using moveNext() the way we really should be. While trying to learn what this code was doing and fix it though, I was really surprised by the -1 - an exception with a clear message would be more actionable and the bugs less subtle.

dart-lang/test#1198

dart-bot pushed a commit that referenced this issue May 12, 2020
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. breaking-change-request This tracks requests for feedback on breaking changes library-core NNBD Issues related to NNBD Release
Projects
None yet
Development

No branches or pull requests

7 participants