I think the covers the cases where it seems reasonable for the value
being cast to be null. In the other places where I see casts, it's
pretty clear that a null is an error.
Change-Id: I38e9b47da72579e7f3849284689d4c25b5b14af1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136725
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
In the legacy SDK these two methods in ListMixin take Object, not E.
When I migrated them to NNBD, I changed them to E to match the
declaration of the methods in List. This was an unintended breaking
change.
Fix that by changing them to "Object?", which is the NNBD equivalent of
the declarations in the legacy SDK.
Change-Id: I2a75e9f26a8198e4f51cb32a55055d5e64a69ed1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136412
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
It was migrated to null-safety by throwing, but that's an unnecessary breaking change.
Change-Id: I92c21d7518bf7c291b333b33a04eb4b21b7cc210
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134725
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
The List constructor has been disallowed in NNBD code, so the NNBD SDK
should not be using it.
This changes all uses, not just in the already migrated libraries.
(Also found some bad typing in the `RegExpMatch` class along the way).
Change-Id: Ic61bd64427c0961c23aaf7ce59af5c2c271890ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132282
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Since a growable list can be created using `[]`, you never need to call
`List.empty` with anything but `growable: false` or `growable: dynamicValue`.
That means that the default should be non-growable (which also matches
`List.filled` and apparently user expectations - since there is already one bug where
I assumed it would be non-grwowble while migrating List.generate).
Ensure it's implemented by dart2js too and used where there were comments
saying to use it when available.
Change-Id: Ied20d69346ecfb93640ee2cec718e30e6f8980e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132600
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Also caught a couple of mistakes I made in dart:collection which got
picked up by this because some classes in here use classes from there.
Change-Id: I799db57baf4ea97e8ad4700008918acf03956aff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123600
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
I ended up using nullable types and "!" (or "as E" because "!" has a
bug right now) in most cases to fix the nullability errors. There is
probably a more elegant refactoring one could do around things like the
sentinel nodes, but this preserves the existing behavior, doesn't break
any APIs and is minimally invasive.
It's not perfect, but it's progress and we can land and iterate on it.
Other changes:
- Filled in dynamic for raw types. No particular reason, but it seemed
clearer to me, and I noticed in places where I was getting errors
about implicit casts from dynamic.
- Added some "dynamic" type annotations on lambdas. I was surprised
those are needed since I expected inference to fill in the type, but
if I don't annotate, I get "Missing parameter type for '_'."
- Made optional parameters nullable. When the parameter was a function
type, I also switched to the new function type syntax since using "?"
on the old C-style syntax looks pretty strange to me.
- Fixed many many implicit downcast errors. In some cases, no cast was
needed and I could loosen the target type to get rid of the cast. In
other cases, I added an explicit cast.
- Got rid of "new" in doc comments.
There are still a few errors. They are either:
- Invalid override errors from stuff in dart:core. I think these will
go away once core is migrated too.
- Errors caused by #38813.
- An error that I think it caused by #38900.
Observations:
- I found a few cases where implicit downcasts were happening
unintentionally. They didn't fail but there was no need to use the
tighter type there.
- It was annoying to work around List<E>(size) being prohibited on a
nullable type, but not particularly painful. This library is probably
the most affected by that restriction and it wasn't that bad.
- Having both explicit downcasts *and* type annotated local variables
is really silly. It's a good thing most users use "var" and "final".
- Analyzer error messages were almost always precise, clear, and well
located. The one exception is that the invalid override errors are
really strange looking and don't tell you why the types don't match.
- Migrating code you're completely unfamiliar with is a little
uncomfortable, but still surprisingly doable. You can almost always
fix an error with some local change and little global context.
- I only used "late" once. That's probably mostly a consequence of me
not knowing the code well and trying to make minimal changes.
Change-Id: Ifaedd0d4203945fd0b5ce20145c6e10b8ac1d646
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121920
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>