Make positionInlineChildren assert much clearer#182093
Make positionInlineChildren assert much clearer#182093auto-submit[bot] merged 8 commits intoflutter:masterfrom
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request improves the clarity of an assertion message in positionInlineChildren. The change is correct and makes the error message much easier to understand. I've suggested a small improvement to make the assertion condition more explicit, which further enhances readability.
| assert( | ||
| false, | ||
| 'The length of boxes (${boxes.length}) should be greater than childCount ($childCount)', | ||
| boxes.length <= childCount, |
There was a problem hiding this comment.
I'm assuming the fact that we are in this if-block means there is an additional box not accounted for.
There was a problem hiding this comment.
In fact, yes, that's true.
But explicitly specifying the condition will make debugging easier for developers.
There was a problem hiding this comment.
I think I initially wrote the assert under the assumption that it wasn't going to be an app developer facing error message (so the error message was only useful for framework developers), but it looks like this is not the case. Was it because you didn't push placeholders in the custom InlineSpan in InlineSpan.build? In any case it might be helpful to expand the error message a little more to include the most probable cause (e.g. did you forget to push placeholders if you are using a custom InlineSpan subclass?)
LongCatIsLooong
left a comment
There was a problem hiding this comment.
LGTM but I think this may need a test, since you already have an implementation that would trigger the assert.
|
@BrainLUX Would you be able to add a test here that catches the logical change of when the error occurs? |
Yes, of course |
|
still LGTM, but maybe this should be expanded to a more detailed message, like the one over here: flutter/packages/flutter/lib/src/rendering/object.dart Lines 2224 to 2241 in 1e97fd3 so people ran into the same problem don't have to figure out what could have caused the assert to fire. |
LongCatIsLooong
left a comment
There was a problem hiding this comment.
Still LGTM, thank you for adding the detailed error message!
| 'The length of boxes (${boxes.length}) should be greater than childCount ($childCount)', | ||
| ); | ||
| assert(() { | ||
| if (boxes.length > childCount) { |
There was a problem hiding this comment.
nit: I feel this is no longer needed since there is now a detailed message.
…ldren-assert' into fix/misleading-positioninlinechildren-assert
fixes flutter/flutter#182090
The assertion message should clearly state the actual requirement of the code to help developers understand and fix the error.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.