Skip to content

Commit 2c21d79

Browse files
authored
Deploy @checked (flutter#6244)
This patch adds `@checked` everywhere is needed to remove the `strong_mode_invalid_method_override` strong mode error.
1 parent 8c8be6b commit 2c21d79

31 files changed

+91
-56
lines changed

.analysis_options

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ analyzer:
2121
# allow overriding fields (if they use super, ideally...)
2222
strong_mode_invalid_field_override: ignore
2323
# allow type narrowing
24-
strong_mode_invalid_method_override: ignore
2524
strong_mode_static_type_error: ignore
2625
strong_mode_down_cast_composite: ignore
2726
# allow having TODOs in the code

.analysis_options_repo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ analyzer:
2222
# allow overriding fields (if they use super, ideally...)
2323
strong_mode_invalid_field_override: ignore
2424
# allow type narrowing
25-
strong_mode_invalid_method_override: ignore
2625
strong_mode_static_type_error: ignore
2726
strong_mode_down_cast_composite: ignore
2827
# allow having TODOs in the code

.analysis_options_user

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ analyzer:
2323
# allow overriding fields (if they use super, ideally...)
2424
strong_mode_invalid_field_override: ignore
2525
# allow type narrowing
26-
strong_mode_invalid_method_override: ignore
2726
strong_mode_static_type_error: ignore
2827
strong_mode_down_cast_composite: ignore
2928
# allow having TODOs in the code

packages/flutter/lib/src/material/tabs.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
925925
}
926926

927927
@override
928-
ScrollBehavior<double, double> createScrollBehavior() {
928+
ExtentScrollBehavior createScrollBehavior() {
929929
return new _TabsScrollBehavior()
930930
..isScrollable = config.isScrollable;
931931
}

packages/flutter/lib/src/rendering/auto_layout.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/cassowary.dart' as al; // "auto layout"
6+
import 'package:meta/meta.dart';
67

78
import 'box.dart';
89
import 'object.dart';
@@ -144,7 +145,7 @@ abstract class AutoLayoutDelegate {
144145
List<al.Constraint> getConstraints(AutoLayoutRect parent);
145146

146147
/// Override this method to return true when new constraints need to be generated.
147-
bool shouldUpdateConstraints(AutoLayoutDelegate oldDelegate);
148+
bool shouldUpdateConstraints(@checked AutoLayoutDelegate oldDelegate);
148149
}
149150

150151
/// A render object that uses the cassowary constraint solver to automatically size and position children.

packages/flutter/lib/src/rendering/binding.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ abstract class RendererBinding extends BindingBase implements SchedulerBinding,
223223
assert(renderView != null);
224224
renderView.hitTest(result, position: position);
225225
// This super call is safe since it will be bound to a mixed-in declaration.
226-
super.hitTest(result, position); //ignore: abstract_super_member_reference
226+
super.hitTest(result, position); // ignore: abstract_super_member_reference
227227
}
228228

229229
void _forceRepaint() {
@@ -289,7 +289,7 @@ class SemanticsServer extends mojom.SemanticsServer {
289289
}
290290

291291
@override
292-
void addSemanticsListener(mojom.SemanticsListenerProxy listener) {
292+
void addSemanticsListener(@checked mojom.SemanticsListenerProxy listener) {
293293
_listeners.add(listener);
294294
}
295295

packages/flutter/lib/src/rendering/custom_layout.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:meta/meta.dart';
6+
57
import 'box.dart';
68
import 'object.dart';
79

@@ -186,7 +188,7 @@ abstract class MultiChildLayoutDelegate {
186188
/// laid out. This should compare the fields of the current delegate
187189
/// and the given oldDelegate and return true if the fields are such
188190
/// that the layout would be different.
189-
bool shouldRelayout(MultiChildLayoutDelegate oldDelegate);
191+
bool shouldRelayout(@checked MultiChildLayoutDelegate oldDelegate);
190192

191193
/// Override this method to include additional information in the
192194
/// debugging data printed by [debugDumpRenderTree] and friends.

packages/flutter/lib/src/rendering/flow.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'package:flutter/foundation.dart';
6+
import 'package:meta/meta.dart';
67
import 'package:vector_math/vector_math_64.dart';
78

89
import 'box.dart';
@@ -107,7 +108,7 @@ abstract class FlowDelegate {
107108
/// This should compare the fields of the current delegate and the given
108109
/// oldDelegate and return true if the fields are such that the layout would
109110
/// be different.
110-
bool shouldRelayout(FlowDelegate oldDelegate) => false;
111+
bool shouldRelayout(@checked FlowDelegate oldDelegate) => false;
111112

112113
/// Override this method to return true when the children need to be
113114
/// repainted. This should compare the fields of the current delegate and the
@@ -122,7 +123,7 @@ abstract class FlowDelegate {
122123
/// The flow container might repaint even if this function returns false, for
123124
/// example if layout triggers painting (e.g., if [shouldRelayout] returns
124125
/// true).
125-
bool shouldRepaint(FlowDelegate oldDelegate);
126+
bool shouldRepaint(@checked FlowDelegate oldDelegate);
126127

127128
/// Override this method to include additional information in the
128129
/// debugging data printed by [debugDumpRenderTree] and friends.

packages/flutter/lib/src/rendering/grid.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ abstract class GridDelegate {
196196
/// [placementData] associated with that child as context. The returned
197197
/// [GridChildPlacement] is then used to determine the size and position of
198198
/// that child within the grid.
199-
GridChildPlacement getChildPlacement(GridSpecification specification, int index, Object placementData);
199+
GridChildPlacement getChildPlacement(GridSpecification specification, int index, @checked Object placementData);
200200

201201
/// Override this method to return true when the children need to be laid out.
202-
bool shouldRelayout(GridDelegate oldDelegate) => true;
202+
bool shouldRelayout(@checked GridDelegate oldDelegate) => true;
203203

204204
Size _getGridSize(BoxConstraints constraints, int childCount) {
205205
return getGridSpecification(constraints, childCount).gridSize;

packages/flutter/lib/src/rendering/node.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class AbstractNode {
8080
/// Subclasses with children should attach all their children to the same
8181
/// [owner] whenever this method is called.
8282
@mustCallSuper
83-
void attach(Object owner) {
83+
void attach(@checked Object owner) {
8484
assert(owner != null);
8585
assert(_owner == null);
8686
_owner = owner;
@@ -106,7 +106,7 @@ class AbstractNode {
106106
/// Subclasses should call this function when they acquire a new child.
107107
@protected
108108
@mustCallSuper
109-
void adoptChild(AbstractNode child) {
109+
void adoptChild(@checked AbstractNode child) {
110110
assert(child != null);
111111
assert(child._parent == null);
112112
assert(() {
@@ -125,7 +125,7 @@ class AbstractNode {
125125
/// Subclasses should call this function when they lose a child.
126126
@protected
127127
@mustCallSuper
128-
void dropChild(AbstractNode child) {
128+
void dropChild(@checked AbstractNode child) {
129129
assert(child != null);
130130
assert(child._parent == this);
131131
assert(child.attached == attached);

packages/flutter/lib/src/rendering/object.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
10741074
///
10751075
/// You can call this function to set up the parent data for child before the
10761076
/// child is added to the parent's child list.
1077-
void setupParentData(RenderObject child) {
1077+
void setupParentData(@checked RenderObject child) {
10781078
assert(_debugCanPerformMutations);
10791079
if (child.parentData is! ParentData)
10801080
child.parentData = new ParentData();
@@ -1931,7 +1931,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
19311931
///
19321932
/// Used by coordinate conversion functions to translate coordinates local to
19331933
/// one render object into coordinates local to another render object.
1934-
void applyPaintTransform(RenderObject child, Matrix4 transform) {
1934+
void applyPaintTransform(@checked RenderObject child, Matrix4 transform) {
19351935
assert(child.parent == this);
19361936
}
19371937

@@ -1943,7 +1943,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
19431943
///
19441944
/// This is used in the semantics phase to avoid including children
19451945
/// that are not physically visible.
1946-
Rect describeApproximatePaintClip(RenderObject child) => null;
1946+
Rect describeApproximatePaintClip(@checked RenderObject child) => null;
19471947

19481948

19491949
// SEMANTICS
@@ -2174,7 +2174,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
21742174

21752175
/// Override this method to handle pointer events that hit this render object.
21762176
@override
2177-
void handleEvent(PointerEvent event, HitTestEntry entry) { }
2177+
void handleEvent(PointerEvent event, @checked HitTestEntry entry) { }
21782178

21792179

21802180
// HIT TESTING

packages/flutter/lib/src/rendering/proxy_box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ abstract class CustomClipper<T> {
873873

874874
/// Returns `true` if the new instance will result in a different clip
875875
/// than the oldClipper instance.
876-
bool shouldRepaint(CustomClipper<T> oldClipper);
876+
bool shouldRepaint(@checked CustomClipper<T> oldClipper);
877877
}
878878

879879
abstract class _RenderCustomClip<T> extends RenderProxyBox {
@@ -1679,7 +1679,7 @@ abstract class CustomPainter {
16791679
/// repaints should be avoided as much as possible, a [RepaintBoundary] or
16801680
/// [RenderRepaintBoundary] (or other render object with [isRepaintBoundary]
16811681
/// set to `true`) might be helpful.
1682-
bool shouldRepaint(CustomPainter oldDelegate);
1682+
bool shouldRepaint(@checked CustomPainter oldDelegate);
16831683

16841684
/// Called whenever a hit test is being performed on an object that is using
16851685
/// this custom paint delegate.

packages/flutter/lib/src/rendering/shifted_box.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'dart:math' as math;
66

7+
import 'package:meta/meta.dart';
8+
79
import 'box.dart';
810
import 'debug.dart';
911
import 'object.dart';
@@ -745,7 +747,7 @@ class SingleChildLayoutDelegate {
745747
Offset getPositionForChild(Size size, Size childSize) => Offset.zero;
746748

747749
/// Override this method to return true when the child needs to be laid out.
748-
bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) => true;
750+
bool shouldRelayout(@checked SingleChildLayoutDelegate oldDelegate) => true;
749751
}
750752

751753
/// Defers the layout of its single child to a delegate.

packages/flutter/lib/src/services/asset_bundle.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class AssetBundle {
5858
///
5959
/// Implementations may cache the result, so a particular key should only be
6060
/// used with one parser for the lifetime of the asset bundle.
61-
Future<dynamic> loadStructuredData(String key, dynamic parser(String value));
61+
Future<dynamic> loadStructuredData(String key, Future<dynamic> parser(String value));
6262

6363
/// If this is a caching asset bundle, and the given key describes a cached
6464
/// asset, then evict the asset from the cache so that the next time it is

packages/flutter/lib/src/widgets/editable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class RawInputLineState extends ScrollableState<RawInputLine> {
247247
TextSelectionOverlay _selectionOverlay;
248248

249249
@override
250-
ScrollBehavior<double, double> createScrollBehavior() => new BoundedBehavior(platform: config.platform);
250+
ExtentScrollBehavior createScrollBehavior() => new BoundedBehavior(platform: config.platform);
251251

252252
@override
253253
BoundedBehavior get scrollBehavior => super.scrollBehavior;

packages/flutter/lib/src/widgets/framework.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ abstract class State<T extends StatefulWidget> {
744744
/// super.didUpdateConfig(oldConfig).
745745
// TODO(abarth): Add @mustCallSuper.
746746
@protected
747-
void didUpdateConfig(T oldConfig) { }
747+
void didUpdateConfig(@checked T oldConfig) { }
748748

749749
/// Called whenever the application is reassembled during debugging.
750750
///
@@ -1098,7 +1098,7 @@ abstract class InheritedWidget extends ProxyWidget {
10981098
/// The given widget is guaranteed to have the same [runtimeType] as this
10991099
/// object.
11001100
@protected
1101-
bool updateShouldNotify(InheritedWidget oldWidget);
1101+
bool updateShouldNotify(@checked InheritedWidget oldWidget);
11021102
}
11031103

11041104
/// RenderObjectWidgets provide the configuration for [RenderObjectElement]s,
@@ -1123,13 +1123,13 @@ abstract class RenderObjectWidget extends Widget {
11231123
/// given [RenderObject], which will be of the same type as returned by this
11241124
/// object's [createRenderObject].
11251125
@protected
1126-
void updateRenderObject(BuildContext context, RenderObject renderObject) { }
1126+
void updateRenderObject(BuildContext context, @checked RenderObject renderObject) { }
11271127

11281128
/// A render object previously associated with this widget has been removed
11291129
/// from the tree. The given [RenderObject] will be of the same type as
11301130
/// returned by this object's [createRenderObject].
11311131
@protected
1132-
void didUnmountRenderObject(RenderObject renderObject) { }
1132+
void didUnmountRenderObject(@checked RenderObject renderObject) { }
11331133
}
11341134

11351135
/// A superclass for RenderObjectWidgets that configure RenderObject subclasses
@@ -2010,7 +2010,7 @@ abstract class Element implements BuildContext {
20102010
///
20112011
/// This function is called only during the "active" lifecycle state.
20122012
@mustCallSuper
2013-
void update(Widget newWidget) {
2013+
void update(@checked Widget newWidget) {
20142014
assert(_debugLifecycleState == _ElementLifecycle.active);
20152015
assert(widget != null);
20162016
assert(newWidget != null);
@@ -2910,7 +2910,7 @@ abstract class ProxyElement extends ComponentElement {
29102910
/// Called during [update] after changing the widget associated with this
29112911
/// element but before rebuilding this element.
29122912
@protected
2913-
void notifyClients(ProxyWidget oldWidget);
2913+
void notifyClients(@checked ProxyWidget oldWidget);
29142914
}
29152915

29162916
/// An element that uses a [ParentDataWidget] as its configuration.
@@ -3318,7 +3318,7 @@ abstract class RenderObjectElement extends BuildableElement {
33183318
/// element has a list of children, the previous sibling is a convenient value
33193319
/// for the slot.
33203320
@protected
3321-
void insertChildRenderObject(RenderObject child, dynamic slot);
3321+
void insertChildRenderObject(@checked RenderObject child, @checked dynamic slot);
33223322

33233323
/// Move the given child to the given slot.
33243324
///
@@ -3329,13 +3329,13 @@ abstract class RenderObjectElement extends BuildableElement {
33293329
/// element has a list of children, the previous sibling is a convenient value
33303330
/// for the slot.
33313331
@protected
3332-
void moveChildRenderObject(RenderObject child, dynamic slot);
3332+
void moveChildRenderObject(@checked RenderObject child, @checked dynamic slot);
33333333

33343334
/// Remove the given child from [renderObject].
33353335
///
33363336
/// The given child is guaranteed to have [renderObject] as its parent.
33373337
@protected
3338-
void removeChildRenderObject(RenderObject child);
3338+
void removeChildRenderObject(@checked RenderObject child);
33393339

33403340
@override
33413341
void debugFillDescription(List<String> description) {

packages/flutter/lib/src/widgets/lazy_block.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract class LazyBlockDelegate {
4848
///
4949
/// When calling this function, [LazyBlock] will always pass an argument that
5050
/// matches the runtimeType of the receiver.
51-
bool shouldRebuild(LazyBlockDelegate oldDelegate);
51+
bool shouldRebuild(@checked LazyBlockDelegate oldDelegate);
5252

5353
/// Returns the estimated total height of the children, in pixels.
5454
///

packages/flutter/lib/src/widgets/scroll_configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class ScrollConfigurationDelegate {
3333
/// Overrides should return true if this ScrollConfigurationDelegate differs
3434
/// from the provided old delegate in a way that requires rebuilding its
3535
/// scrolling container descendants.
36-
bool updateShouldNotify(ScrollConfigurationDelegate old);
36+
bool updateShouldNotify(@checked ScrollConfigurationDelegate old);
3737
}
3838

3939
class _DefaultScrollConfigurationDelegate extends ScrollConfigurationDelegate {

packages/flutter/lib/src/widgets/unique_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:meta/meta.dart';
77
import 'framework.dart';
88

99
/// A widget that has exactly one inflated instance in the tree.
10-
abstract class UniqueWidget<T extends State> extends StatefulWidget {
10+
abstract class UniqueWidget<T extends State<StatefulWidget>> extends StatefulWidget {
1111
/// Creates a widget that has exactly one inflated instance in the tree.
1212
///
1313
/// The [key] argument cannot be null because it identifies the unique

packages/flutter/lib/src/widgets/virtual_viewport.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract class VirtualViewport extends RenderObjectWidget {
2929
}
3030

3131
abstract class _WidgetProvider {
32-
void didUpdateWidget(VirtualViewport oldWidget, VirtualViewport newWidget);
32+
void didUpdateWidget(@checked VirtualViewport oldWidget, @checked VirtualViewport newWidget);
3333
int get virtualChildCount;
3434
void prepareChildren(VirtualViewportElement context, int base, int count);
3535
Widget getChild(int i);
@@ -146,7 +146,7 @@ abstract class VirtualViewportElement extends RenderObjectElement {
146146
/// Copies the configuration described by [widget] to this element's [renderObject].
147147
@protected
148148
@mustCallSuper
149-
void updateRenderObject(VirtualViewport oldWidget) {
149+
void updateRenderObject(@checked VirtualViewport oldWidget) {
150150
renderObject.virtualChildCount = _widgetProvider.virtualChildCount;
151151

152152
if (startOffsetBase != null) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:test/test.dart';
6+
7+
class X {}
8+
9+
class Y extends X {}
10+
11+
class A<U extends X> {
12+
U u;
13+
}
14+
15+
void main() {
16+
test('Assignment through a covariant template throws exception', () {
17+
A<Y> ay = new A<Y>();
18+
A<X> ayAsAx = ay;
19+
expect(() {
20+
ayAsAx.u = new X();
21+
}, throws);
22+
});
23+
}

0 commit comments

Comments
 (0)