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

Fix sample analysis build jobs #2575

Merged
merged 18 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ env:

matrix:
allow_failures:
- env: TASK="./tool/analyze-and-test-examples.sh"
dart: stable #TEMPORARY FIX
- env: TASK="./tool/analyze-and-test-examples.sh"
dart: beta
- env: TASK="./tool/analyze-and-test-examples.sh"
Expand Down
5 changes: 4 additions & 1 deletion examples/analysis/analyzer-results.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Analyzing analysis_options.yaml, lib...
error • A value of type 'Object' can't be assigned to a variable of type 'String'. • lib/assignment.dart:11:14 • invalid_assignment
error • A value of type 'String' can't be assigned to a variable of type 'int'. • lib/assignment.dart:19:11 • invalid_assignment
error • A value of type 'String' can't be assigned to a variable of type 'int'. • lib/assignment.dart:26:11 • invalid_assignment
error • Const variables must be initialized with a constant value. • lib/assignment.dart:34:13 • const_initialized_with_non_constant_value
lint • Avoid empty statements. • lib/lint.dart:9:19 • empty_statements
lint • Close instances of `dart.core.Sink`. • lib/lint.dart:16:7 • close_sinks
1 error and 2 lints found.
4 errors and 2 lints found.
4 changes: 1 addition & 3 deletions examples/misc/analyzer-results.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Analyzing analysis_options.yaml, bin, lib, test...
# https://github.com/dart-lang/sdk/issues/32236 - flow analysis can't yet figure out that the variable is of type Person.
error • 'Object' doesn't extend 'SomeBaseClass'. • lib/language_tour/generics/misc.dart:29:19 • type_argument_not_matching_bounds
error • The argument type 'int' can't be assigned to the parameter type 'String'. • lib/library_tour/core/collections.dart:5:14 • argument_type_not_assignable
error • A value of type 'dynamic' can't be assigned to a variable of type 'Person'. • lib/library_tour/core/hash_code.dart:24:21 • invalid_assignment
3 errors found.
2 errors found.
4 changes: 2 additions & 2 deletions examples/misc/bin/try_dart/functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ int timesTwo(int x) {
int timesFour(int x) => timesTwo(timesTwo(x));

// Functions are objects.
int runTwice(int x, Function f) {
int runTwice(int x, int Function(int) f) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just FYI I just merged a change that moves this snippet into dartpad_picker_main. I created an issue to track: #2581

for (var i = 0; i < 2; i++) {
x = f(x); // ignore: invalid_assignment
x = f(x);
}
return x;
}
Expand Down
11 changes: 0 additions & 11 deletions examples/misc/lib/effective_dart/design_bad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ void miscDeclAnalyzedButNotTested() {
// #enddocregion omit-types-on-locals
}

// #docregion inferred-wrong
num highScore(List<num> scores) {
var highest = 0;
for (var score in scores) {
// ignore: invalid_assignment
if (score > highest) highest = score;
}
return highest;
}
// #enddocregion inferred-wrong

{
// #docregion redundant
Set<String> things = Set<String>();
Expand Down
12 changes: 0 additions & 12 deletions examples/misc/lib/effective_dart/usage_bad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,6 @@ class Box2 {

//----------------------------------------------------------------------------

// #docregion field-init-at-decl
class Folder {
final String name;
final List<Document> contents;

Folder(this.name) : contents = [];
Folder.temp() : name = 'temporary'; // Oops! Forgot contents.
}
// #enddocregion field-init-at-decl

//----------------------------------------------------------------------------

// #docregion field-init-as-param
class Point0 {
double x, y;
Expand Down
18 changes: 0 additions & 18 deletions examples/misc/lib/language_tour/generics/misc.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import 'base_class.dart';

// ignore_for_file: unused_local_variable
void miscDeclAnalyzedButNotTested() {
{
// #docregion why-generics
var names = List<String>();
names.addAll(['Seth', 'Kathy', 'Lars']);
names.add(42); // Error // ignore: argument_type_not_assignable
// #enddocregion why-generics
}

{
// #docregion collection-literals
var names = <String>['Seth', 'Kathy', 'Lars'];
Expand All @@ -21,12 +11,4 @@ void miscDeclAnalyzedButNotTested() {
};
// #enddocregion collection-literals
}

{
// ignore_for_file: stable, dev, type_argument_not_matching_bounds
// Specifying any non-SomeBaseClass type results in an error.
// #docregion Foo-Object-error
var foo = Foo<Object>(); //!analysis-issue
// #enddocregion Foo-Object-error
}
}
2 changes: 1 addition & 1 deletion examples/misc/lib/library_tour/core/collections.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
void miscDeclAnalyzedButNotTested() {
var fruits = List<String>();
// ignore_for_file: stable, dev, argument_type_not_assignable
// ignore_for_file: stable, dev, argument_type_not_assignable, unused_local_variable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add beta to this list? Or remove the release names?

(Is "beta" even supported? I don't see examples/strong/analyzer-results-beta.txt in this PR.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure? I can't quite figure out how that works. If there isn't a -beta.txt file it uses analyzer-results.txt, and I think most of the beta files that existed were fine.

// #docregion List-of-String
fruits.add(5); // Error: 'int' can't be assigned to 'String'
// #enddocregion List-of-String
Expand Down
19 changes: 6 additions & 13 deletions examples/strong/analyzer-results-dev.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
Analyzing analysis_options.yaml, lib, test...
error • 'HoneyBadger.parent' ('Root Function()') isn't a valid override of 'Animal.parent' ('Animal Function()'). • lib/animal_bad.dart:15:12 • invalid_override
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file different from analyzer-results-stable.txt? If not, then maybe we should remove one of these files and delete "-stable" from the name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's identical.

error • 'Cat.chase' ('void Function(Mouse)') isn't a valid override of 'Animal.chase' ('void Function(Animal)'). • lib/animal_bad.dart:26:8 • invalid_override
error • A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<Cat>'. • lib/animal_bad.dart:48:19 • invalid_assignment
error • The method 'add' isn't defined for the type 'Iterable'. • lib/bounded/instantiate_to_bound.dart:7:5 • undefined_method
error • A value of type 'Element' can't be assigned to a variable of type 'CanvasElement'. • lib/common_fixes_analysis.dart:21:28 • invalid_assignment
error • A value of type 'int' can't be assigned to a variable of type 'bool'. • lib/common_problems_analysis.dart:14:14 • invalid_assignment
error • The getter 'context2D' isn't defined for the type 'Element'. • lib/common_problems_analysis.dart:23:12 • undefined_getter
error • A value of type 'double' can't be assigned to a variable of type 'int'. • lib/common_problems_analysis.dart:38:16 • invalid_assignment
error • A value of type 'List<int>' can't be assigned to a variable of type 'List<String>'. • lib/common_problems_analysis.dart:46:27 • invalid_assignment
error • 'MyAdder.add' ('int Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)'). • lib/common_problems_analysis.dart:61:7 • invalid_override
error • 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)'). • lib/common_problems_analysis.dart:74:8 • invalid_override
error • The super call must be last in an initializer list (see https://goo.gl/EY6hDP): 'super(food)'. • lib/common_problems_analysis.dart:92:9 • invalid_super_invocation
error • The function expression type 'bool Function(String)' isn't of type 'bool Function(dynamic)'. This means its parameter or return type doesn't match what is expected. Consider changing parameter type(s) or the returned type(s). • lib/common_problems_analysis.dart:102:17 • invalid_cast_function_expr
error • A value of type 'bool Function(String)' can't be assigned to a variable of type 'bool Function(dynamic)'. • lib/common_problems_analysis.dart:102:17 • invalid_assignment
error • The class 'MyList' cannot implement both 'List<int*>*' and 'List<dynamic>*' because the type arguments are different. • lib/dart_1_my_list_hello_world.dart:11:1 • conflicting_generic_interfaces
error • Superinterfaces don't have a valid override for '+': ListMixin.+ (List<int> Function(List<int>)), List.+ (List<dynamic> Function(List<dynamic>)). • lib/dart_1_my_list_hello_world.dart:11:7 • inconsistent_inheritance
error • 'ListMixin.add' ('void Function(int)') isn't a valid override of 'List.add' ('void Function(dynamic)'). • lib/dart_1_my_list_hello_world.dart:11:7 • invalid_override
error • 'MyList.length' ('Object Function()') isn't a valid override of 'List.length' ('int Function()'). • lib/dart_1_my_list_hello_world.dart:12:10 • invalid_override
error • A value of type 'String' can't be returned from method '[]' because it has a return type of 'int'. • lib/dart_1_my_list_hello_world.dart:16:25 • return_of_invalid_type
error • The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<int>'. • lib/strong_analysis.dart:27:17 • argument_type_not_assignable
error • The argument type 'int' can't be assigned to the parameter type 'String'. • lib/strong_analysis.dart:38:15 • argument_type_not_assignable
error • The argument type 'int' can't be assigned to the parameter type 'String'. • lib/strong_analysis.dart:54:15 • argument_type_not_assignable
Expand All @@ -24,4 +17,4 @@ Analyzing analysis_options.yaml, lib, test...
error • A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'. • test/strong_test.dart:42:27 • invalid_assignment
error • A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. • test/strong_test.dart:64:26 • invalid_assignment
error • A value of type 'List<Object>' can't be assigned to a variable of type 'List<String>'. • test/strong_test.dart:178:26 • invalid_assignment
25 errors found.
18 errors found.
19 changes: 6 additions & 13 deletions examples/strong/analyzer-results-stable.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
Analyzing analysis_options.yaml, lib, test...
error • 'HoneyBadger.parent' ('Root Function()') isn't a valid override of 'Animal.parent' ('Animal Function()'). • lib/animal_bad.dart:15:12 • invalid_override
error • 'Cat.chase' ('void Function(Mouse)') isn't a valid override of 'Animal.chase' ('void Function(Animal)'). • lib/animal_bad.dart:26:8 • invalid_override
error • A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<Cat>'. • lib/animal_bad.dart:48:19 • invalid_assignment
error • The method 'add' isn't defined for the type 'Iterable'. • lib/bounded/instantiate_to_bound.dart:7:5 • undefined_method
error • A value of type 'Element' can't be assigned to a variable of type 'CanvasElement'. • lib/common_fixes_analysis.dart:21:28 • invalid_assignment
error • A value of type 'int' can't be assigned to a variable of type 'bool'. • lib/common_problems_analysis.dart:14:14 • invalid_assignment
error • The getter 'context2D' isn't defined for the type 'Element'. • lib/common_problems_analysis.dart:23:12 • undefined_getter
error • A value of type 'double' can't be assigned to a variable of type 'int'. • lib/common_problems_analysis.dart:38:16 • invalid_assignment
error • A value of type 'List<int>' can't be assigned to a variable of type 'List<String>'. • lib/common_problems_analysis.dart:46:27 • invalid_assignment
error • 'MyAdder.add' ('int Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)'). • lib/common_problems_analysis.dart:61:7 • invalid_override
error • 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)'). • lib/common_problems_analysis.dart:74:8 • invalid_override
error • The super call must be last in an initializer list (see https://goo.gl/EY6hDP): 'super(food)'. • lib/common_problems_analysis.dart:92:9 • invalid_super_invocation
error • The function expression type 'bool Function(String)' isn't of type 'bool Function(dynamic)'. This means its parameter or return type doesn't match what is expected. Consider changing parameter type(s) or the returned type(s). • lib/common_problems_analysis.dart:102:17 • invalid_cast_function_expr
error • A value of type 'bool Function(String)' can't be assigned to a variable of type 'bool Function(dynamic)'. • lib/common_problems_analysis.dart:102:17 • invalid_assignment
error • The class 'MyList' cannot implement both 'List<int*>*' and 'List<dynamic>*' because the type arguments are different. • lib/dart_1_my_list_hello_world.dart:11:1 • conflicting_generic_interfaces
error • Superinterfaces don't have a valid override for '+': ListMixin.+ (List<int> Function(List<int>)), List.+ (List<dynamic> Function(List<dynamic>)). • lib/dart_1_my_list_hello_world.dart:11:7 • inconsistent_inheritance
error • 'ListMixin.add' ('void Function(int)') isn't a valid override of 'List.add' ('void Function(dynamic)'). • lib/dart_1_my_list_hello_world.dart:11:7 • invalid_override
error • 'MyList.length' ('Object Function()') isn't a valid override of 'List.length' ('int Function()'). • lib/dart_1_my_list_hello_world.dart:12:10 • invalid_override
error • A value of type 'String' can't be returned from method '[]' because it has a return type of 'int'. • lib/dart_1_my_list_hello_world.dart:16:25 • return_of_invalid_type
error • The argument type 'List<dynamic>' can't be assigned to the parameter type 'List<int>'. • lib/strong_analysis.dart:27:17 • argument_type_not_assignable
error • The argument type 'int' can't be assigned to the parameter type 'String'. • lib/strong_analysis.dart:38:15 • argument_type_not_assignable
error • The argument type 'int' can't be assigned to the parameter type 'String'. • lib/strong_analysis.dart:54:15 • argument_type_not_assignable
Expand All @@ -24,4 +17,4 @@ Analyzing analysis_options.yaml, lib, test...
error • A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'. • test/strong_test.dart:42:27 • invalid_assignment
error • A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. • test/strong_test.dart:64:26 • invalid_assignment
error • A value of type 'List<Object>' can't be assigned to a variable of type 'List<String>'. • test/strong_test.dart:178:26 • invalid_assignment
25 errors found.
18 errors found.
51 changes: 0 additions & 51 deletions examples/strong/lib/animal_bad.dart

This file was deleted.

2 changes: 1 addition & 1 deletion examples/strong/lib/bounded/instantiate_to_bound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'my_collection.dart';
void cannotRunThis() {
// #docregion undefined_method
var c = C(Iterable.empty()).collection;
// ignore_for_file: stable, dev, undefined_method
// ignore_for_file: undefined_method
c.add(2); //!analysis-issue
// #enddocregion undefined_method
}
103 changes: 0 additions & 103 deletions examples/strong/lib/common_problems_analysis.dart

This file was deleted.

2 changes: 1 addition & 1 deletion src/_guides/language/analysis-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ String s2 = s.substring(1);
{% endprettify %}

{:.console-output}
<?code-excerpt "analysis/analyzer-results.txt" retain="lib/assignment.dart" replace="/. • (lib|test)\/\w+\.dart:\d+:\d+//g"?>
<?code-excerpt "analysis/analyzer-results.txt" retain="/'Object' can't be assigned to a variable of type 'String'/" replace="/. • (lib|test)\/\w+\.dart:\d+:\d+//g"?>
```nocode
error • A value of type 'Object' can't be assigned to a variable of type 'String' • invalid_assignment
```
Expand Down
4 changes: 3 additions & 1 deletion src/_guides/language/effective-dart/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,10 @@ num highScore(List<num> scores) {
}
{% endprettify %}

<!-- Q: As of 2.9, this code no longer works.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@munificent opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it work? Because we're getting rid of implicit downcasts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it work? Because we're getting rid of implicit downcasts?

Yes, I think so. Here's the message, which complains about highest (an int) being assigned score (a num).

error * A value of type 'num' can't be assigned to a variable of type 'int'. * lib/effective_dart/design_bad.dart:79:38 * invalid_assignment

  num highScore(List<num> scores) {
    var highest = 0;
    for (var score in scores) {
      // ignore: invalid_assignment
      if (score > highest) highest = score;
    }
    return highest;
  }

Should we change it or the recommendation? -->
{:.bad}
<?code-excerpt "misc/lib/effective_dart/design_bad.dart (inferred-wrong)" replace="/ +\/\/ ignore: .*?\n//g"?>
<!-- code-excerpt "misc/lib/effective_dart/design_bad.dart (inferred-wrong)" replace="/ +\/\/ ignore: .*?\n//g" -->
{% prettify dart tag=pre+code %}
num highScore(List<num> scores) {
var highest = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/_guides/language/effective-dart/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,10 @@ If a field doesn't depend on any constructor parameters, it can and should be
initialized at its declaration. It takes less code and makes sure you won't
forget to initialize it if the class has multiple constructors.

<!-- Q: As of 2.9, this code no longer works.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@munificent opinion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this elsewhere, but to close the loop here, I think we should make contents non-final (assuming I'm guessing correctly at what no longer works).

Should we change it or the recommendation? -->
{:.bad}
<?code-excerpt "misc/lib/effective_dart/usage_bad.dart (field-init-at-decl)"?>
<!-- code-excerpt "misc/lib/effective_dart/usage_bad.dart (field-init-at-decl)" -->
{% prettify dart tag=pre+code %}
class Folder {
final String name;
Expand Down
2 changes: 0 additions & 2 deletions src/_guides/language/language-tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,6 @@ you, your fellow programmers, and your tools can detect that assigning a non-str
the list is probably a mistake. Here’s an example:

{:.fails-sa}
<?code-excerpt "misc/lib/language_tour/generics/misc.dart (why-generics)"?>
```dart
var names = List<String>();
names.addAll(['Seth', 'Kathy', 'Lars']);
Expand Down Expand Up @@ -3673,7 +3672,6 @@ print(foo); // Instance of 'Foo<SomeBaseClass>'
Specifying any non-`SomeBaseClass` type results in an error:

{:.fails-sa}
<?code-excerpt "misc/lib/language_tour/generics/misc.dart (Foo-Object-error)" replace="/Foo.\w+./[!$&!]/g"?>
{% prettify dart tag=pre+code %}
var foo = [!Foo<Object>!]();
{% endprettify %}
Expand Down
Loading