Unverified Commit d80aa480 authored by Paul Berry's avatar Paul Berry Committed by GitHub

Ignore/fix dead_code checks for weak-only null checks. (#63794)

Now that https://github.com/dart-lang/sdk/issues/41985 is fixed, the
analyzer detects dead code due to "unnecessary" null checks.  Since we
want to retain null checks in Flutter even when they appear
unnecessary (in order to preserve runtime behavior in weak mode), we
need to suppress these dead code hints.

Note that one assertion is removed by this PR (`heightFactor != null
|| (heightFactor == 1.0 && heightDelta == 0.0)`).  This is because
`heightFactor == 1.0 && heightDelta == 0.0` can only be true if
`heightFactor != null`, so this assertion is equivalent to simply
asserting that `heightFactor != null`, which is already asserted two
lines above.
parent 8d4aef0d
......@@ -366,7 +366,10 @@ class TextSpan extends InlineSpan {
assert(() {
if (children != null) {
for (final InlineSpan child in children!) {
if (child == null) {
// `child` has a non-nullable return type, but might be null when
// running with weak checking, so we need to null check it anyway (and
// ignore the warning that the null-handling logic is dead code).
if (child == null) { // ignore: dead_code
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('TextSpan contains a null child.'),
ErrorDescription(
......@@ -474,9 +477,12 @@ class TextSpan extends InlineSpan {
if (children == null)
return const <DiagnosticsNode>[];
return children!.map<DiagnosticsNode>((InlineSpan child) {
// `child` has a non-nullable return type, but might be null when running
// with weak checking, so we need to null check it anyway (and ignore the
// warning that the null-handling logic is dead code).
if (child != null) {
return child.toDiagnosticsNode();
} else {
} else { // ignore: dead_code
return DiagnosticsNode.message('<null child>');
}
}).toList();
......
......@@ -821,7 +821,6 @@ class TextStyle with Diagnosticable {
assert(wordSpacing != null || (wordSpacingFactor == 1.0 && wordSpacingDelta == 0.0));
assert(heightFactor != null);
assert(heightDelta != null);
assert(heightFactor != null || (heightFactor == 1.0 && heightDelta == 0.0));
assert(decorationThicknessFactor != null);
assert(decorationThicknessDelta != null);
assert(decorationThickness != null || (decorationThicknessFactor == 1.0 && decorationThicknessDelta == 0.0));
......
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