Skip to content

Make positionInlineChildren assert much clearer#182093

Merged
auto-submit[bot] merged 8 commits intoflutter:masterfrom
BrainLUX:fix/misleading-positioninlinechildren-assert
Feb 25, 2026
Merged

Make positionInlineChildren assert much clearer#182093
auto-submit[bot] merged 8 commits intoflutter:masterfrom
BrainLUX:fix/misleading-positioninlinechildren-assert

Conversation

@BrainLUX
Copy link
Contributor

@BrainLUX BrainLUX commented Feb 9, 2026

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

@flutter-dashboard
Copy link

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.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Feb 9, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming the fact that we are in this if-block means there is an additional box not accounted for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, yes, that's true.
But explicitly specifying the condition will make debugging easier for developers.

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

LGTM but I think this may need a test, since you already have an implementation that would trigger the assert.

@justinmc
Copy link
Contributor

@BrainLUX Would you be able to add a test here that catches the logical change of when the error occurs?

@BrainLUX
Copy link
Contributor Author

BrainLUX commented Feb 18, 2026

@BrainLUX Would you be able to add a test here that catches the logical change of when the error occurs?

Yes, of course

@LongCatIsLooong
Copy link
Contributor

LongCatIsLooong commented Feb 18, 2026

still LGTM, but maybe this should be expanded to a more detailed message, like the one over here:

if (activeLayoutRoot == null) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A $runtimeType was mutated in $culpritFullMethodName.'),
ErrorDescription(
'The RenderObject was mutated when none of its ancestors is actively performing layout.',
),
DiagnosticsProperty<RenderObject>(
'The RenderObject being mutated was',
this,
style: DiagnosticsTreeStyle.errorProperty,
),
DiagnosticsProperty<RenderObject>(
'The RenderObject that was mutating the said $runtimeType was',
debugActiveLayout,
style: DiagnosticsTreeStyle.errorProperty,
),
]);
}

so people ran into the same problem don't have to figure out what could have caused the assert to fire.

Copy link
Contributor

@LongCatIsLooong LongCatIsLooong left a comment

Choose a reason for hiding this comment

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

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I feel this is no longer needed since there is now a detailed message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

@justinmc justinmc requested a review from victorsanni February 24, 2026 23:07
@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 24, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Feb 25, 2026
Merged via the queue into flutter:master with commit 7f3e961 Feb 25, 2026
72 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Feb 25, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading error message in positionInlineChildren assert

4 participants