Unverified Commit 8d2aca38 authored by Chris Bobbe's avatar Chris Bobbe Committed by GitHub

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.
parent 84e1086c
......@@ -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;
}());
......
......@@ -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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment