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.
This commit is contained in:
Paul Berry
2020-08-14 14:18:38 -07:00
committed by GitHub
parent 8d4aef0d51
commit d80aa48001
2 changed files with 8 additions and 3 deletions

View File

@@ -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();

View File

@@ -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));