Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary null checks #39113

Merged
merged 8 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ analyzer:
# allow self-reference to deprecated members (we do this because otherwise we have
# to annotate every member in every test, assert, etc, when we deprecate something)
deprecated_member_use_from_same_package: ignore
# Turned off until null-safe rollout is complete.
unnecessary_null_comparison: ignore
exclude: # DIFFERENT FROM FLUTTER/FLUTTER
# Fixture depends on dart:ui and raises false positives.
- flutter_frontend_server/test/fixtures/lib/main.dart
Expand Down
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: 974dd21be7c0e97f436f3758b6de4cee
Signature: ccf8317fb6539998c8f4ff0a96d7f698

9 changes: 0 additions & 9 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
Clip clipBehavior = Clip.antiAlias,
ClipRectEngineLayer? oldLayer,
}) {
assert(clipBehavior != null);
assert(clipBehavior != Clip.none);
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRect'));
final EngineLayer engineLayer = EngineLayer._();
Expand Down Expand Up @@ -411,7 +410,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
Clip clipBehavior = Clip.antiAlias,
ClipRRectEngineLayer? oldLayer,
}) {
assert(clipBehavior != null);
assert(clipBehavior != Clip.none);
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipRRect'));
final EngineLayer engineLayer = EngineLayer._();
Expand Down Expand Up @@ -439,7 +437,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
Clip clipBehavior = Clip.antiAlias,
ClipPathEngineLayer? oldLayer,
}) {
assert(clipBehavior != null);
assert(clipBehavior != Clip.none);
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushClipPath'));
final EngineLayer engineLayer = EngineLayer._();
Expand Down Expand Up @@ -494,10 +491,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
ColorFilter filter, {
ColorFilterEngineLayer? oldLayer,
}) {
assert(filter != null);
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushColorFilter'));
final _ColorFilter nativeFilter = filter._toNativeColorFilter()!;
assert(nativeFilter != null);
final EngineLayer engineLayer = EngineLayer._();
_pushColorFilter(engineLayer, nativeFilter, oldLayer?._nativeLayer);
final ColorFilterEngineLayer layer = ColorFilterEngineLayer._(engineLayer);
Expand All @@ -523,10 +518,8 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
Offset offset = Offset.zero,
ImageFilterEngineLayer? oldLayer,
}) {
assert(filter != null);
assert(_debugCheckCanBeUsedAsOldLayer(oldLayer, 'pushImageFilter'));
final _ImageFilter nativeFilter = filter._toNativeImageFilter();
assert(nativeFilter != null);
final EngineLayer engineLayer = EngineLayer._();
_pushImageFilter(engineLayer, nativeFilter, offset.dx, offset.dy, oldLayer?._nativeLayer);
final ImageFilterEngineLayer layer = ImageFilterEngineLayer._(engineLayer);
Expand Down Expand Up @@ -799,7 +792,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
bool freeze = false,
FilterQuality filterQuality = FilterQuality.low,
}) {
assert(offset != null, 'Offset argument was null');
_addTexture(offset.dx, offset.dy, width, height, textureId, freeze, filterQuality.index);
}

Expand Down Expand Up @@ -828,7 +820,6 @@ class SceneBuilder extends NativeFieldWrapperClass1 {
double width = 0.0,
double height = 0.0,
}) {
assert(offset != null, 'Offset argument was null');
_addPlatformView(offset.dx, offset.dy, width, height, viewId);
}

Expand Down
4 changes: 1 addition & 3 deletions lib/ui/experiments/scene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ class SceneNode extends NativeFieldWrapperClass1 {
<String, WeakReference<SceneNodeValue>>{};

static Future<void> _reinitializeScene(String assetKey) async {
final WeakReference<SceneNodeValue>? sceneRef = _ipsceneRegistry == null
? null
: _ipsceneRegistry[assetKey];
final WeakReference<SceneNodeValue>? sceneRef = _ipsceneRegistry[assetKey];

// If a scene for the asset isn't already registered, then there's no
// need to reinitialize it.
Expand Down
29 changes: 3 additions & 26 deletions lib/ui/geometry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ abstract class OffsetBase {
///
/// The first argument sets the horizontal component, and the second the
/// vertical component.
const OffsetBase(this._dx, this._dy)
: assert(_dx != null),
assert(_dy != null);
const OffsetBase(this._dx, this._dy);

final double _dx;
final double _dy;
Expand Down Expand Up @@ -314,7 +312,6 @@ class Offset extends OffsetBase {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static Offset? lerp(Offset? a, Offset? b, double t) {
assert(t != null);
if (b == null) {
if (a == null) {
return null;
Expand Down Expand Up @@ -590,7 +587,6 @@ class Size extends OffsetBase {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static Size? lerp(Size? a, Size? b, double t) {
assert(t != null);
if (b == null) {
if (a == null) {
return null;
Expand Down Expand Up @@ -637,11 +633,7 @@ class Rect {
/// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb.png#gh-light-mode-only)
/// ![](https://flutter.github.io/assets-for-api-docs/assets/dart-ui/rect_from_ltrb_dark.png#gh-dark-mode-only)
@pragma('vm:entry-point')
const Rect.fromLTRB(this.left, this.top, this.right, this.bottom)
: assert(left != null),
assert(top != null),
assert(right != null),
assert(bottom != null);
const Rect.fromLTRB(this.left, this.top, this.right, this.bottom);

/// Construct a rectangle from its left and top edges, its width, and its
/// height.
Expand Down Expand Up @@ -891,7 +883,6 @@ class Rect {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static Rect? lerp(Rect? a, Rect? b, double t) {
assert(t != null);
if (b == null) {
if (a == null) {
return null;
Expand Down Expand Up @@ -1059,7 +1050,6 @@ class Radius {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static Radius? lerp(Radius? a, Radius? b, double t) {
assert(t != null);
if (b == null) {
if (a == null) {
return null;
Expand Down Expand Up @@ -1268,19 +1258,7 @@ class RRect {
this.brRadiusY = 0.0,
this.blRadiusX = 0.0,
this.blRadiusY = 0.0,
}) : assert(left != null),
assert(top != null),
assert(right != null),
assert(bottom != null),
assert(tlRadiusX != null),
assert(tlRadiusY != null),
assert(trRadiusX != null),
assert(trRadiusY != null),
assert(brRadiusX != null),
assert(brRadiusY != null),
assert(blRadiusX != null),
assert(blRadiusY != null),
assert(tlRadiusX >= 0),
}) : assert(tlRadiusX >= 0),
assert(tlRadiusY >= 0),
assert(trRadiusX >= 0),
assert(trRadiusY >= 0),
Expand Down Expand Up @@ -1661,7 +1639,6 @@ class RRect {
/// Values for `t` are usually obtained from an [Animation<double>], such as
/// an [AnimationController].
static RRect? lerp(RRect? a, RRect? b, double t) {
assert(t != null);
if (b == null) {
if (a == null) {
return null;
Expand Down
12 changes: 0 additions & 12 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ void _invoke(void Function()? callback, Zone zone) {
if (callback == null) {
return;
}

assert(zone != null);

if (identical(zone, Zone.current)) {
callback();
} else {
Expand All @@ -157,9 +154,6 @@ void _invoke1<A>(void Function(A a)? callback, Zone zone, A arg) {
if (callback == null) {
return;
}

assert(zone != null);

if (identical(zone, Zone.current)) {
callback(arg);
} else {
Expand All @@ -176,9 +170,6 @@ void _invoke2<A1, A2>(void Function(A1 a1, A2 a2)? callback, Zone zone, A1 arg1,
if (callback == null) {
return;
}

assert(zone != null);

if (identical(zone, Zone.current)) {
callback(arg1, arg2);
} else {
Expand All @@ -197,9 +188,6 @@ void _invoke3<A1, A2, A3>(void Function(A1 a1, A2 a2, A3 a3)? callback, Zone zon
if (callback == null) {
return;
}

assert(zone != null);

if (identical(zone, Zone.current)) {
callback(arg1, arg2, arg3);
} else {
Expand Down
4 changes: 0 additions & 4 deletions lib/ui/isolate_name_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class IsolateNameServer {
///
/// The `name` argument must not be null.
static SendPort? lookupPortByName(String name) {
assert(name != null, "'name' cannot be null.");
return _lookupPortByName(name);
}

Expand All @@ -49,8 +48,6 @@ class IsolateNameServer {
///
/// The `port` and `name` arguments must not be null.
static bool registerPortWithName(SendPort port, String name) {
assert(port != null, "'port' cannot be null.");
assert(name != null, "'name' cannot be null.");
return _registerPortWithName(port, name);
}

Expand All @@ -66,7 +63,6 @@ class IsolateNameServer {
///
/// The `name` argument must not be null.
static bool removePortNameMapping(String name) {
assert(name != null, "'name' cannot be null.");
return _removePortNameMapping(name);
}

Expand Down
Loading