Skip to content

implicit-casts:false in flutter/lib/src/rendering#45720

Merged
a14n merged 2 commits intoflutter:masterfrom
a14n:implicit-casts-false-flutter-lib-rendering
Dec 4, 2019
Merged

implicit-casts:false in flutter/lib/src/rendering#45720
a14n merged 2 commits intoflutter:masterfrom
a14n:implicit-casts-false-flutter-lib-rendering

Conversation

@a14n
Copy link
Copy Markdown
Contributor

@a14n a14n commented Nov 27, 2019

Description

Enable implicit-casts:false in flutter/lib/src/rendering

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 27, 2019
@fluttergithubbot
Copy link
Copy Markdown
Contributor

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another name for the function could be within.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this not just be
assert(other is BoxConstraints && other.debugAssertIsValid());?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

&& typedOther.viewportMainAxisExtent == viewportMainAxisExtent
&& typedOther.remainingCacheExtent == remainingCacheExtent
&& typedOther.cacheOrigin == cacheOrigin;
assert(() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a within extension method for int?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do the cast to RenderObject up here instead of on line 673 (we should already know that its a RenderObject up here).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

maxWidth == typedOther.maxWidth &&
minHeight == typedOther.minHeight &&
maxHeight == typedOther.maxHeight;
assert(() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I go this way:

  • to keep the pattern of is-check on other to promote its type and avoid introducing another variable.
  • to avoid triggering the lint test_types_in_equals when as is used without is 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to. I'll re-review them in a bit.

&& left == typedOther.left
&& horizontalInside == typedOther.horizontalInside
&& verticalInside == typedOther.verticalInside;
return other is TableBorder
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer as above.

Copy link
Copy Markdown
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@a14n a14n merged commit a5f9b3b into flutter:master Dec 4, 2019
@a14n a14n deleted the implicit-casts-false-flutter-lib-rendering branch December 4, 2019 09:27
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants