未验证 提交 2ef2c861 编写于 作者: P Paul Berry 提交者: GitHub

Fix engine in preparation for implementing...

Fix engine in preparation for implementing https://github.com/dart-lang/language/issues/1274 (#23131)

When https://github.com/dart-lang/language/issues/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.
上级 ade75e08
......@@ -1092,7 +1092,17 @@ abstract class PersistedContainerSurface extends PersistedSurface {
for (int indexInOld = 0; indexInOld < oldChildCount; indexInOld += 1) {
final PersistedSurface? oldChild = oldChildren[indexInOld];
final bool childAlreadyClaimed = oldChild == null;
if (childAlreadyClaimed || !newChild.canUpdateAsMatch(oldChild!)) {
// After https://github.com/dart-lang/language/issues/1274 is
// implemented, `oldChild` will be promoted to non-nullable on the RHS
// of the `||`, so we won't need to null check it (and it will cause a
// build failure to try to do so). Until then, we need to null check it
// in such a way that won't cause a build failure once the feature is
// implemented. We can do that by casting to `dynamic`, and then
// relying on the call to `canUpdateAsMatch` implicitly downcasting to
// PersistentSurface.
// TODO(paulberry): remove this workaround once the feature is
// implemented.
if (childAlreadyClaimed || !newChild.canUpdateAsMatch(oldChild as dynamic)) {
continue;
}
allMatches.add(_PersistedSurfaceMatch(
......
......@@ -889,7 +889,17 @@ class SemanticsObject {
effectiveTransformIsIdentity = effectiveTransform.isIdentity();
}
} else if (!hasIdentityTransform) {
effectiveTransform = Matrix4.fromFloat32List(transform!);
// After https://github.com/dart-lang/language/issues/1274 is implemented,
// `transform` will be promoted to non-nullable so we won't need to null
// check it (and it will cause a build failure to try to do so). Until
// then, we need to null check it in such a way that won't cause a build
// failure once the feature is implemented. We can do that using an
// explicit "if" test.
// TODO(paulberry): remove this check once the feature is implemented.
if (transform == null) { // ignore: unnecessary_null_comparison
throw 'impossible';
}
effectiveTransform = Matrix4.fromFloat32List(transform);
effectiveTransformIsIdentity = false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册