implicit-casts:false in flutter/lib/src/rendering#45720
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| maxWidth: maxWidth.clamp(constraints.minWidth, constraints.maxWidth), | ||
| minHeight: minHeight.clamp(constraints.minHeight, constraints.maxHeight), | ||
| maxHeight: maxHeight.clamp(constraints.minHeight, constraints.maxHeight), | ||
| minWidth: minWidth.clamp(constraints.minWidth, constraints.maxWidth) as double, |
There was a problem hiding this comment.
I wish clamp on a double would just always return a double.
Maybe we can add an extension method double clamp(double lowerLimit, double upperLimit) to foundation that implements that protocol instead of casting the clamp everywhere? It seems cluttery...
There was a problem hiding this comment.
Maybe we can add an extension method
That's what I planned to do in an upcoming PR (to avoid too much changes).
However I don't think clamp can be used as name. I was thinking to clampDouble and clampInt. (Note that the SDK could also make some changes dart-lang/sdk#30403 (comment) )
There was a problem hiding this comment.
Another name for the function could be within.
There was a problem hiding this comment.
I would prefer it if we did the clamp extension method before the implicit-cast:false change then, since the clamp stuff adds a lot of noise to them..
There was a problem hiding this comment.
I would prefer it if we did the clamp extension method before the implicit-cast:false change then, since the clamp stuff adds a lot of noise to them
Regarding all the changes I already made it would be a nightmare to handle merge conflits if I change clamp before implicit-casts now :-( Don't worry the extension clamp changes should be really easy/quick to do afterwards.
| maxWidth == typedOther.maxWidth && | ||
| minHeight == typedOther.minHeight && | ||
| maxHeight == typedOther.maxHeight; | ||
| assert(() { |
There was a problem hiding this comment.
Can this not just be
assert(other is BoxConstraints && other.debugAssertIsValid());?
| && typedOther.viewportMainAxisExtent == viewportMainAxisExtent | ||
| && typedOther.remainingCacheExtent == remainingCacheExtent | ||
| && typedOther.cacheOrigin == cacheOrigin; | ||
| assert(() { |
There was a problem hiding this comment.
This change doesn't seem to preserve the old logic. Previously, if other was not a SliverConstraints it would return false. Now, the assert would throw, no?
| final int oldLastIndex = indexOf(lastChild); | ||
| final int leadingGarbage = (firstIndex - oldFirstIndex).clamp(0, childCount); | ||
| final int trailingGarbage = targetLastIndex == null ? 0 : (oldLastIndex - targetLastIndex).clamp(0, childCount); | ||
| final int leadingGarbage = (firstIndex - oldFirstIndex).clamp(0, childCount) as int; |
There was a problem hiding this comment.
Maybe also add a within extension method for int?
There was a problem hiding this comment.
I will use a clampInt in an upcoming PR (once implicit-cast false is everywhere)
| bool onlySlivers = target is RenderSliver; // ... between viewport and `target` (`target` included). | ||
| while (child.parent != this) { | ||
| assert(child.parent != null, '$target must be a descendant of $this'); | ||
| final AbstractNode parent = child.parent; |
There was a problem hiding this comment.
Maybe do the cast to RenderObject up here instead of on line 673 (we should already know that its a RenderObject up here).
| maxWidth == typedOther.maxWidth && | ||
| minHeight == typedOther.minHeight && | ||
| maxHeight == typedOther.maxHeight; | ||
| assert(() { |
There was a problem hiding this comment.
I believe the code here would be clearer if this is expressed as:
final BoxConstraints typedOther = other as BoxConstraints;
assert(typedOther.debugAssertIsValid());
return minWidth == typedOther.minWidth && ...We know after the if (runtimeType != other.runtimeType) that it has to be castable to BoxConstraints, so there shouldn't be a need to check that again?
There was a problem hiding this comment.
I go this way:
- to keep the pattern of is-check on
otherto promote its type and avoid introducing another variable. - to avoid triggering the lint test_types_in_equals when
asis used withoutis Xxx
We know after the
if (runtimeType != other.runtimeType)
Unfortunately the type system don't. There is currently no way to derive type promotion from runtimeType checks
There was a problem hiding this comment.
Thanks for sharing your reasoning. It's unfortunate that test_types_in_equals can't be made smarter because of the runtimeType check constraint. I guess this is the best we can do then. (Sorry for leaving this comment everywhere on the other PRs as well)
There was a problem hiding this comment.
(Sorry for leaving this comment everywhere on the other PRs as well)
Should I put a comment on all PR with only the same kind of comments to request a LGTM?
There was a problem hiding this comment.
No need to. I'll re-review them in a bit.
| && left == typedOther.left | ||
| && horizontalInside == typedOther.horizontalInside | ||
| && verticalInside == typedOther.verticalInside; | ||
| return other is TableBorder |
There was a problem hiding this comment.
Same here (as above). We know after the if that other is castable to TableBorder, so we don't really have to check that again, no?
Description
Enable
implicit-casts:falseinflutter/lib/src/renderingRelated Issues
None
Tests
None because it's a refactoring.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?