Skip to content

Commit a9c5ac3

Browse files
authored
Fix build and update strong problems page (#1717)
Fixed some problems that broke the build when we released 2.4: * Update analyzer messages for 2.4. This affects the strong problems page. * Add return statements to a few examples, to avoid new hints. * Update a source file to make 2.4 dartfmt happy.
1 parent c60b0e0 commit a9c5ac3

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

examples/httpserver/test/httpserver_test.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ void main() {
100100

101101
expect(
102102
() async => Future.any([
103-
server,
104-
_test(),
105-
]),
103+
server,
104+
_test(),
105+
]),
106106
prints(''),
107107
);
108108
});
@@ -120,9 +120,9 @@ void main() {
120120

121121
expect(
122122
() async => Future.any([
123-
server,
124-
_test(),
125-
]),
123+
server,
124+
_test(),
125+
]),
126126
prints('Wrote data for Han Solo.\n'),
127127
);
128128
});

examples/misc/lib/effective_dart/docs_good.dart

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ void miscDeclAnalyzedButNotTested() {
88
// Not if there is nothing before it.
99
if (_chunks.isEmpty) return false;
1010
// #enddocregion comments-like-sentences
11+
return true;
1112
};
1213

1314
// #docregion block-comments

examples/misc/lib/effective_dart/usage_bad.dart

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void miscDeclAnalyzedButNotTested() {
4747
if (lunchBox.length == 0) return 'so hungry...';
4848
if (!words.isEmpty) return words.join(' ');
4949
// #enddocregion dont-use-length
50+
return 'foo';
5051
};
5152

5253
(Iterable people) {

examples/misc/lib/effective_dart/usage_good.dart

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void miscDeclAnalyzedButNotTested() {
5555
if (lunchBox.isEmpty) return 'so hungry...';
5656
if (words.isNotEmpty) return words.join(' ');
5757
// #enddocregion dont-use-length
58+
return 'foo';
5859
};
5960

6061
{

examples/strong/analyzer-2-results.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
Analyzing lib, test...
2-
error • 'HoneyBadger.parent' ('() → Root') isn't a valid override of 'Animal.parent' ('() → Animal') at lib/animal_bad.dart:15:3 • invalid_override
3-
error • 'Cat.chase' ('(Mouse) → void') isn't a valid override of 'Animal.chase' ('(Animal) → void') at lib/animal_bad.dart:26:3 • invalid_override
2+
error • 'HoneyBadger.parent' ('Root Function()') isn't a valid override of 'Animal.parent' ('Animal Function()') at lib/animal_bad.dart:15:3 • invalid_override
3+
error • 'Cat.chase' ('void Function(Mouse)') isn't a valid override of 'Animal.chase' ('void Function(Animal)') at lib/animal_bad.dart:26:3 • invalid_override
44
error • A value of type 'List' can't be assigned to a variable of type 'List<Cat>' at lib/animal_bad.dart:49:19 • invalid_assignment
55
error • The method 'add' isn't defined for the class 'Iterable' at lib/bounded/instantiate_to_bound.dart:7:5 • undefined_method
66
error • A value of type 'Element' can't be assigned to a variable of type 'CanvasElement' at lib/common_fixes_analysis.dart:21:28 • invalid_assignment
77
error • A value of type 'int' can't be assigned to a variable of type 'bool' at lib/common_problems_analysis.dart:14:14 • invalid_assignment
88
error • The getter 'context2D' isn't defined for the class 'Element' at lib/common_problems_analysis.dart:23:12 • undefined_getter
99
error • A value of type 'double' can't be assigned to a variable of type 'int' at lib/common_problems_analysis.dart:38:16 • invalid_assignment
1010
error • A value of type 'List<int>' can't be assigned to a variable of type 'List<String>' at lib/common_problems_analysis.dart:46:27 • invalid_assignment
11-
error • 'MyAdder.add' ('(int, int) → int') isn't a valid override of 'NumberAdder.add' ('(num, num) → num') at lib/common_problems_analysis.dart:61:3 • invalid_override
12-
error • 'Subclass.method' ('(int) → void') isn't a valid override of 'Superclass.method' ('(dynamic) → void') at lib/common_problems_analysis.dart:74:3 • invalid_override
11+
error • 'MyAdder.add' ('int Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)') at lib/common_problems_analysis.dart:61:3 • invalid_override
12+
error • 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)') at lib/common_problems_analysis.dart:74:3 • invalid_override
1313
error • super call must be last in an initializer list (see https://goo.gl/EY6hDP): 'super(food)' at lib/common_problems_analysis.dart:92:9 • strong_mode_invalid_super_invocation
14-
error • A value of type '(String) → bool' can't be assigned to a variable of type '(dynamic) → bool' at lib/common_problems_analysis.dart:102:17 • invalid_assignment
15-
error • The function expression type '(String) → bool' isn't of type '(dynamic) → bool'. This means its parameter or return type does not match what is expected. Consider changing parameter type(s) or the returned type(s) at lib/common_problems_analysis.dart:102:17 • strong_mode_invalid_cast_function_expr
14+
error • A value of type 'bool Function(String)' can't be assigned to a variable of type 'bool Function(dynamic)' at lib/common_problems_analysis.dart:102:17 • invalid_assignment
15+
error • The function expression type 'bool Function(String)' isn't of type 'bool Function(dynamic)'. This means its parameter or return type does not match what is expected. Consider changing parameter type(s) or the returned type(s) at lib/common_problems_analysis.dart:102:17 • strong_mode_invalid_cast_function_expr
1616
error • The argument type 'List' can't be assigned to the parameter type 'List<int>' at lib/strong_analysis.dart:27:17 • argument_type_not_assignable
1717
error • The argument type 'int' can't be assigned to the parameter type 'String' at lib/strong_analysis.dart:38:15 • argument_type_not_assignable
1818
error • The argument type 'int' can't be assigned to the parameter type 'String' at lib/strong_analysis.dart:54:15 • argument_type_not_assignable

src/_guides/language/sound-problems.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class MyAdder extends NumberAdder {
233233
{:.console-output}
234234
<?code-excerpt "strong/analyzer-2-results.txt" retain="/isn't a valid override of.*num.*common_problems/"?>
235235
```nocode
236-
error • 'MyAdder.add' ('(int, int) → int') isn't a valid override of 'NumberAdder.add' ('(num, num) → num') • invalid_override
236+
error • 'MyAdder.add' ('int Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)') • invalid_override
237237
```
238238

239239
Consider the following scenario where floating
@@ -304,7 +304,7 @@ class Subclass extends Superclass {
304304
{:.console-output}
305305
<?code-excerpt "strong/analyzer-2-results.txt" retain="/isn't a valid override of.*dynamic.*common_problems/"?>
306306
```nocode
307-
error • 'Subclass.method' ('(int) → void') isn't a valid override of 'Superclass.method' ('(dynamic) → void') • invalid_override
307+
error • 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)') • invalid_override
308308
```
309309

310310
#### Fix: Specify type arguments for the generic subclass
@@ -422,9 +422,9 @@ HoneyBadger(Eats food, String name)
422422
<hr>
423423

424424
<a name="uses-dynamic-as-bottom"></a>
425-
### A function of type ... can't be assigned
425+
### The function expression type ... isn't of type ...
426426

427-
<?code-excerpt "strong/analyzer-2-results.txt" retain="/The function expression type.*common_problems/" replace="/'\S+ → \S+'/'...'/g"?>
427+
<?code-excerpt "strong/analyzer-2-results.txt" retain="/The function expression type.*common_problems/" replace="/'bool.*?\)'/'...'/g"?>
428428
```nocode
429429
error • The function expression type '...' isn't of type '...'. This means its parameter or return type does not match what is expected. Consider changing parameter type(s) or the returned type(s) • strong_mode_invalid_cast_function_expr
430430
```
@@ -449,10 +449,9 @@ Filter filter = ([!String!] x) => x.contains('Hello');
449449
{% endprettify %}
450450

451451
{:.console-output}
452-
<?code-excerpt "strong/analyzer-2-results.txt" retain="/type '\(String\) → bool'.*common_problems/"?>
452+
<?code-excerpt "strong/analyzer-2-results.txt" retain="/The function expression type.*common_problems/"?>
453453
```nocode
454-
error • A value of type '(String) → bool' can't be assigned to a variable of type '(dynamic) → bool' • invalid_assignment
455-
error • The function expression type '(String) → bool' isn't of type '(dynamic) → bool'. This means its parameter or return type does not match what is expected. Consider changing parameter type(s) or the returned type(s) • strong_mode_invalid_cast_function_expr
454+
error • The function expression type 'bool Function(String)' isn't of type 'bool Function(dynamic)'. This means its parameter or return type does not match what is expected. Consider changing parameter type(s) or the returned type(s) • strong_mode_invalid_cast_function_expr
456455
```
457456

458457
#### Fix: Add type parameters _or_ cast from dynamic explicitly

0 commit comments

Comments
 (0)