Skip to content

Commit bfac2a4

Browse files
committed
Fix engine in preparation for implementing dart-lang/language#1274
When dart-lang/language#1274 (Infer non-nullability from local boolean variables) is implemented, flow analysis will detect that code like this no longer needs to perform a null check: final bool hasIdentityTransform = transform == null || isIdentityFloat32ListTransform(transform); ... if (!hasIdentityTransform) { ... transform! ... // Null check unnecessary } To avoid a build failure due to the unnecessary null check, we need to temporarily write it in a way that we can ignore it. Once the feature is complete and rolled into flutter, I'll remove the null check entirely.
1 parent 95ba5ca commit bfac2a4

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/web_ui/lib/src/engine/html/surface.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,17 @@ abstract class PersistedContainerSurface extends PersistedSurface {
10921092
for (int indexInOld = 0; indexInOld < oldChildCount; indexInOld += 1) {
10931093
final PersistedSurface? oldChild = oldChildren[indexInOld];
10941094
final bool childAlreadyClaimed = oldChild == null;
1095-
if (childAlreadyClaimed || !newChild.canUpdateAsMatch(oldChild!)) {
1095+
// After https://github.com/dart-lang/language/issues/1274 is
1096+
// implemented, `oldChild` will be promoted to non-nullable on the RHS
1097+
// of the `||`, so we won't need to null check it (and it will cause a
1098+
// build failure to try to do so). Until then, we need to null check it
1099+
// in such a way that won't cause a build failure once the feature is
1100+
// implemented. We can do that by casting to `dynamic`, and then
1101+
// relying on the call to `canUpdateAsMatch` implicitly downcasting to
1102+
// PersistentSurface.
1103+
// TODO(paulberry): remove this workaround once the feature is
1104+
// implemented.
1105+
if (childAlreadyClaimed || !newChild.canUpdateAsMatch(oldChild as dynamic)) {
10961106
continue;
10971107
}
10981108
allMatches.add(_PersistedSurfaceMatch(

lib/web_ui/lib/src/engine/semantics/semantics.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,17 @@ class SemanticsObject {
889889
effectiveTransformIsIdentity = effectiveTransform.isIdentity();
890890
}
891891
} else if (!hasIdentityTransform) {
892-
effectiveTransform = Matrix4.fromFloat32List(transform!);
892+
// After https://github.com/dart-lang/language/issues/1274 is implemented,
893+
// `transform` will be promoted to non-nullable so we won't need to null
894+
// check it (and it will cause a build failure to try to do so). Until
895+
// then, we need to null check it in such a way that won't cause a build
896+
// failure once the feature is implemented. We can do that using an
897+
// explicit "if" test.
898+
// TODO(paulberry): remove this check once the feature is implemented.
899+
if (transform == null) { // ignore: unnecessary_null_comparison
900+
throw 'impossible';
901+
}
902+
effectiveTransform = Matrix4.fromFloat32List(transform);
893903
effectiveTransformIsIdentity = false;
894904
}
895905

0 commit comments

Comments
 (0)