@@ -92,61 +92,12 @@ class FixOverriddenMethodsVisitation extends Visitation {
9292 }
9393 }
9494
95- void _fixCoavariantArgs (
96- ObjCInterface node,
97- ObjCMethod method,
98- ObjCInterface superType,
99- ObjCMethod superMethod,
100- ) {
101- // In Dart, method arg types are contravariant, but ObjC allows them to be
102- // covariant. So fix these cases by adding the `covariant` keyword to the
103- // parameter.
104- final logger = context.logger;
105- final n = method.params.length;
106- if (n != superMethod.params.length) {
107- logger.severe (
108- '${node .originalName } is a subtype of ${superType .originalName } but '
109- 'their ${method .originalName } methods have a different number of '
110- 'parameters' ,
111- );
112- return ;
113- }
114-
115- for (var i = 0 ; i < n; ++ i) {
116- final pt = method.params.elementAt (i).type;
117- final st = superMethod.params.elementAt (i).type;
118-
119- if (st.isSubtypeOf (pt)) {
120- // Contravariant param, nothing to fix.
121- continue ;
122- }
123-
124- if (! pt.isSubtypeOf (st)) {
125- // Types are unrelated, so this can't be sensibly fixed.
126- logger.severe (
127- '${node .originalName } is a subtype of ${superType .originalName } '
128- 'but their ${method .originalName } methods have a parameter at '
129- 'position ${i + 1 } with an unrelated type' ,
130- );
131- return ;
132- }
133-
134- logger.info (
135- 'Set the parameter of '
136- '${node .originalName }.${method .originalName } at position ${i + 1 } to '
137- 'be covariant' ,
138- );
139- method.params.elementAt (i).isCovariant = true ;
140- }
141- }
142-
14395 void _fixMethodVariance (ObjCInterface node) {
14496 for (final method in node.methods) {
14597 if (method.isClassMethod) continue ;
14698 final (superType, superMethod) = _findNearestWithMethod (node, method);
14799 if (superType != null && superMethod != null ) {
148100 _fixContravariantReturns (node, method, superType, superMethod);
149- _fixCoavariantArgs (node, method, superType, superMethod);
150101 }
151102 }
152103 }
0 commit comments