Skip to content

Commit

Permalink
implicit casts and add missing docs (flutter#15698)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored Jan 17, 2020
1 parent 1f4c593 commit 1970c06
Show file tree
Hide file tree
Showing 17 changed files with 284 additions and 246 deletions.
3 changes: 2 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ analyzer:
# positives.
exclude: [ testing/dart/window_hooks_integration_test.dart ]
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
# treat missing required parameters as a warning (not a hint)
Expand All @@ -39,7 +40,7 @@ linter:
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as
# - avoid_as # required for implicit-casts: false
# - avoid_bool_literals_in_conditional_expressions # not yet tested
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
Expand Down
6 changes: 3 additions & 3 deletions flutter_frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ Future<int> starter(
return 1;
}

if (options['train']) {
if (options['train'] as bool) {
if (!options.rest.isNotEmpty) {
throw Exception('Must specify input.dart');
}

final String input = options.rest[0];
final String sdkRoot = options['sdk-root'];
final String sdkRoot = options['sdk-root'] as String;
final Directory temp =
Directory.systemTemp.createTempSync('train_frontend_server');
try {
Expand Down Expand Up @@ -143,7 +143,7 @@ Future<int> starter(

compiler ??= _FlutterFrontendCompiler(output,
transformer: transformer,
unsafePackageSerialization: options['unsafe-package-serialization']);
unsafePackageSerialization: options['unsafe-package-serialization'] as bool);

if (options.rest.isNotEmpty) {
return await compiler.compile(options.rest[0], options) ? 0 : 254;
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
void addRetained(EngineLayer retainedLayer) {
assert(retainedLayer is _EngineLayerWrapper);
assert(() {
final _EngineLayerWrapper layer = retainedLayer;
final _EngineLayerWrapper layer = retainedLayer as _EngineLayerWrapper;

void recursivelyCheckChildrenUsedOnce(_EngineLayerWrapper parentLayer) {
_debugCheckUsedOnce(parentLayer, 'retained layer');
Expand All @@ -600,7 +600,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
return true;
}());

final _EngineLayerWrapper wrapper = retainedLayer;
final _EngineLayerWrapper wrapper = retainedLayer as _EngineLayerWrapper;
_addRetained(wrapper._nativeLayer);
}

Expand Down
66 changes: 31 additions & 35 deletions lib/ui/geometry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ abstract class OffsetBase {
/// the right-hand-side operand respectively. Returns false otherwise.
@override
bool operator ==(dynamic other) {
if (other is! OffsetBase)
return false;
final OffsetBase typedOther = other;
return _dx == typedOther._dx &&
_dy == typedOther._dy;
return other is OffsetBase
&& other._dx == _dx
&& other._dy == _dy;
}

@override
Expand Down Expand Up @@ -327,11 +325,9 @@ class Offset extends OffsetBase {
/// Compares two Offsets for equality.
@override
bool operator ==(dynamic other) {
if (other is! Offset)
return false;
final Offset typedOther = other;
return dx == typedOther.dx &&
dy == typedOther.dy;
return other is Offset
&& other.dx == dx
&& other.dy == dy;
}

@override
Expand Down Expand Up @@ -595,11 +591,9 @@ class Size extends OffsetBase {
// We don't compare the runtimeType because of _DebugSize in the framework.
@override
bool operator ==(dynamic other) {
if (other is! Size)
return false;
final Size typedOther = other;
return _dx == typedOther._dx &&
_dy == typedOther._dy;
return other is Size
&& other._dx == _dx
&& other._dy == _dy;
}

@override
Expand Down Expand Up @@ -877,11 +871,11 @@ class Rect {
return true;
if (runtimeType != other.runtimeType)
return false;
final Rect typedOther = other;
return left == typedOther.left &&
top == typedOther.top &&
right == typedOther.right &&
bottom == typedOther.bottom;
return other is Rect
&& other.left == left
&& other.top == top
&& other.right == right
&& other.bottom == bottom;
}

@override
Expand Down Expand Up @@ -999,8 +993,10 @@ class Radius {
return true;
if (runtimeType != other.runtimeType)
return false;
final Radius typedOther = other;
return typedOther.x == x && typedOther.y == y;

return other is Radius
&& other.x == x
&& other.y == y;
}

@override
Expand Down Expand Up @@ -1594,19 +1590,19 @@ class RRect {
return true;
if (runtimeType != other.runtimeType)
return false;
final RRect typedOther = other;
return left == typedOther.left &&
top == typedOther.top &&
right == typedOther.right &&
bottom == typedOther.bottom &&
tlRadiusX == typedOther.tlRadiusX &&
tlRadiusY == typedOther.tlRadiusY &&
trRadiusX == typedOther.trRadiusX &&
trRadiusY == typedOther.trRadiusY &&
blRadiusX == typedOther.blRadiusX &&
blRadiusY == typedOther.blRadiusY &&
brRadiusX == typedOther.brRadiusX &&
brRadiusY == typedOther.brRadiusY;
return other is RRect
&& other.left == left
&& other.top == top
&& other.right == right
&& other.bottom == bottom
&& other.tlRadiusX == tlRadiusX
&& other.tlRadiusY == tlRadiusY
&& other.trRadiusX == trRadiusX
&& other.trRadiusY == trRadiusY
&& other.blRadiusX == blRadiusX
&& other.blRadiusY == blRadiusY
&& other.brRadiusX == brRadiusX
&& other.brRadiusY == brRadiusY;
}

@override
Expand Down
9 changes: 5 additions & 4 deletions lib/ui/hooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ void _updateLocales(List<String> locales) {
@pragma('vm:entry-point')
// ignore: unused_element
void _updateUserSettingsData(String jsonData) {
final Map<String, dynamic> data = json.decode(jsonData);
final Map<String, dynamic> data = json.decode(jsonData) as Map<String, dynamic>;
if (data.isEmpty) {
return;
}
_updateTextScaleFactor(data['textScaleFactor'].toDouble());
_updateAlwaysUse24HourFormat(data['alwaysUse24HourFormat']);
_updatePlatformBrightness(data['platformBrightness']);
_updateTextScaleFactor((data['textScaleFactor'] as num).toDouble());
_updateAlwaysUse24HourFormat(data['alwaysUse24HourFormat'] as bool);
_updatePlatformBrightness(data['platformBrightness'] as String);
}

@pragma('vm:entry-point')
Expand Down Expand Up @@ -149,6 +149,7 @@ void _updateAccessibilityFeatures(int values) {
}

@pragma('vm:entry-point')
// ignore: unused_element
void _dispatchPlatformMessage(String name, ByteData data, int responseId) {
if (name == ChannelBuffers.kControlChannelName) {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/lerp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ double lerpDouble(num a, num b, double t) {
return null;
a ??= 0.0;
b ??= 0.0;
return a + (b - a) * t;
return a + (b - a) * t as double;
}
2 changes: 1 addition & 1 deletion lib/ui/natives.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ List<int> saveCompilationTrace() {
final dynamic result = _saveCompilationTrace();
if (result is Error)
throw result;
return result;
return result as List<int>;
}

dynamic _saveCompilationTrace() native 'SaveCompilationTrace';
Expand Down
Loading

0 comments on commit 1970c06

Please sign in to comment.