TextStyle: In copyWith, stop ignoring debugLabel when receiver has none (#141141)

Fixes #141140.

This ensures that if you call `.copyWith` and pass a `debugLabel`, the `debugLabel` won't be ignored, even if the receiver (the TextStyle you're calling `.copyWith` on) doesn't have a `debugLabel`.

The debugLabel field was added in #12552. I skimmed the discussion there and didn't find anything indicating that the param was being ignored on purpose.

I added a test case that passes with the new code and fails with the old code.
This commit is contained in:
Chris Bobbe 2024-01-09 15:21:24 -08:00 committed by GitHub
parent 84e1086c4e
commit 8d2aca385f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -893,8 +893,10 @@ class TextStyle with Diagnosticable {
assert(backgroundColor == null || background == null, _kColorBackgroundWarning);
String? newDebugLabel;
assert(() {
if (this.debugLabel != null) {
newDebugLabel = debugLabel ?? '(${this.debugLabel}).copyWith';
if (debugLabel != null) {
newDebugLabel = debugLabel;
} else if (this.debugLabel != null) {
newDebugLabel = '(${this.debugLabel}).copyWith';
}
return true;
}());

View file

@ -374,6 +374,7 @@ void main() {
expect(unknown.debugLabel, null);
expect(unknown.toString(), 'TextStyle(<all styles inherited>)');
expect(unknown.copyWith().debugLabel, null);
expect(unknown.copyWith(debugLabel: '123').debugLabel, '123');
expect(unknown.apply().debugLabel, null);
expect(foo.debugLabel, 'foo');