diff --git a/.travis.yml b/.travis.yml index 370e04e2d0..7f56f413fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/examples/analysis/analyzer-results.txt b/examples/analysis/analyzer-results.txt index f82c97ae98..333e97cd21 100644 --- a/examples/analysis/analyzer-results.txt +++ b/examples/analysis/analyzer-results.txt @@ -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. diff --git a/examples/misc/analyzer-results.txt b/examples/misc/analyzer-results.txt index 1fb5667487..ac3274e814 100644 --- a/examples/misc/analyzer-results.txt +++ b/examples/misc/analyzer-results.txt @@ -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. diff --git a/examples/misc/bin/try_dart/functions.dart b/examples/misc/bin/try_dart/functions.dart index 5a18f5f2b3..c4dc81e890 100644 --- a/examples/misc/bin/try_dart/functions.dart +++ b/examples/misc/bin/try_dart/functions.dart @@ -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) { for (var i = 0; i < 2; i++) { - x = f(x); // ignore: invalid_assignment + x = f(x); } return x; } diff --git a/examples/misc/lib/effective_dart/design_bad.dart b/examples/misc/lib/effective_dart/design_bad.dart index 5ac77bbc69..a15bd8b274 100644 --- a/examples/misc/lib/effective_dart/design_bad.dart +++ b/examples/misc/lib/effective_dart/design_bad.dart @@ -71,17 +71,6 @@ void miscDeclAnalyzedButNotTested() { // #enddocregion omit-types-on-locals } - // #docregion inferred-wrong - num highScore(List 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 things = Set(); diff --git a/examples/misc/lib/effective_dart/usage_bad.dart b/examples/misc/lib/effective_dart/usage_bad.dart index 60f7b4179e..c1edc59821 100644 --- a/examples/misc/lib/effective_dart/usage_bad.dart +++ b/examples/misc/lib/effective_dart/usage_bad.dart @@ -355,18 +355,6 @@ class Box2 { //---------------------------------------------------------------------------- -// #docregion field-init-at-decl -class Folder { - final String name; - final List 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; diff --git a/examples/misc/lib/language_tour/generics/misc.dart b/examples/misc/lib/language_tour/generics/misc.dart index b9e32137a3..4121cfdb99 100644 --- a/examples/misc/lib/language_tour/generics/misc.dart +++ b/examples/misc/lib/language_tour/generics/misc.dart @@ -1,15 +1,5 @@ -import 'base_class.dart'; - // ignore_for_file: unused_local_variable void miscDeclAnalyzedButNotTested() { - { - // #docregion why-generics - var names = List(); - names.addAll(['Seth', 'Kathy', 'Lars']); - names.add(42); // Error // ignore: argument_type_not_assignable - // #enddocregion why-generics - } - { // #docregion collection-literals var names = ['Seth', 'Kathy', 'Lars']; @@ -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(); //!analysis-issue - // #enddocregion Foo-Object-error - } } diff --git a/examples/misc/lib/library_tour/core/collections.dart b/examples/misc/lib/library_tour/core/collections.dart index 0916d644b2..7bdcfdfb6f 100644 --- a/examples/misc/lib/library_tour/core/collections.dart +++ b/examples/misc/lib/library_tour/core/collections.dart @@ -1,6 +1,6 @@ void miscDeclAnalyzedButNotTested() { var fruits = List(); - // ignore_for_file: stable, dev, argument_type_not_assignable + // ignore_for_file: stable, dev, argument_type_not_assignable, unused_local_variable // #docregion List-of-String fruits.add(5); // Error: 'int' can't be assigned to 'String' // #enddocregion List-of-String diff --git a/examples/strong/analyzer-results-dev.txt b/examples/strong/analyzer-results-dev.txt index 1771927c9c..b44f33b93d 100644 --- a/examples/strong/analyzer-results-dev.txt +++ b/examples/strong/analyzer-results-dev.txt @@ -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' can't be assigned to a variable of type 'List'. • 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' can't be assigned to a variable of type 'List'. • 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*' and 'List*' 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 Function(List)), List.+ (List Function(List)). • 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' can't be assigned to the parameter type 'List'. • 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 @@ -24,4 +17,4 @@ Analyzing analysis_options.yaml, lib, test... error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:42:27 • invalid_assignment error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:64:26 • invalid_assignment error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:178:26 • invalid_assignment -25 errors found. +18 errors found. diff --git a/examples/strong/analyzer-results-stable.txt b/examples/strong/analyzer-results-stable.txt index 1771927c9c..b44f33b93d 100644 --- a/examples/strong/analyzer-results-stable.txt +++ b/examples/strong/analyzer-results-stable.txt @@ -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' can't be assigned to a variable of type 'List'. • 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' can't be assigned to a variable of type 'List'. • 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*' and 'List*' 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 Function(List)), List.+ (List Function(List)). • 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' can't be assigned to the parameter type 'List'. • 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 @@ -24,4 +17,4 @@ Analyzing analysis_options.yaml, lib, test... error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:42:27 • invalid_assignment error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:64:26 • invalid_assignment error • A value of type 'List' can't be assigned to a variable of type 'List'. • test/strong_test.dart:178:26 • invalid_assignment -25 errors found. +18 errors found. diff --git a/examples/strong/lib/animal_bad.dart b/examples/strong/lib/animal_bad.dart deleted file mode 100644 index 9a5fc3b54e..0000000000 --- a/examples/strong/lib/animal_bad.dart +++ /dev/null @@ -1,51 +0,0 @@ -// NOTE: Declarations in this file are analyzed but not tested. -// ignore_for_file: annotate_overrides, unused_local_variable - -import 'package:examples_util/ellipsis.dart'; - -import 'animal.dart'; - -// https://en.wikipedia.org/wiki/Eukaryote -class Root {} - -// #docregion HoneyBadger -class HoneyBadger extends Animal { - void chase(Animal a) {/* ... */} - // ignore_for_file: stable, dev, invalid_override - Root get parent => ellipsis(); //!analysis-issue ret. type not covariant -} -// #enddocregion HoneyBadger - -//----------------------------------------------- - -// #docregion chase-Mouse -class Mouse extends Animal {/*...*/} - -class Cat extends Animal { - // ignore_for_file: stable, dev, invalid_override - void chase(Mouse x) {/* ... */} //!analysis-issue -} -// #enddocregion chase-Mouse - -// We can't test the following in Dart 2 because it won't compile -// due to the static type error on Cat.chase(). -void main() { - // #docregion chase-Alligator - Animal a = Cat(); - a.chase(Alligator()); // Not type safe or feline safe - // #enddocregion chase-Alligator -} - -//----------------------------------------------- - -// #docregion dynamic-list -class Cat1 extends Animal {/* ... */} - -class Dog1 extends Animal {/* ... */} - -void main1() { - // ignore_for_file: stable, dev, invalid_assignment - List foo = [Dog1()]; // Error//!analysis-issue - List bar = [Dog1(), Cat1()]; // OK -} -// #enddocregion dynamic-list diff --git a/examples/strong/lib/bounded/instantiate_to_bound.dart b/examples/strong/lib/bounded/instantiate_to_bound.dart index c4ff53ea58..c55defceb3 100644 --- a/examples/strong/lib/bounded/instantiate_to_bound.dart +++ b/examples/strong/lib/bounded/instantiate_to_bound.dart @@ -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 } diff --git a/examples/strong/lib/common_problems_analysis.dart b/examples/strong/lib/common_problems_analysis.dart deleted file mode 100644 index a3e8e4a587..0000000000 --- a/examples/strong/lib/common_problems_analysis.dart +++ /dev/null @@ -1,103 +0,0 @@ -// NOTE: Declarations in this file are analyzed but not tested. -// -// Include in this file only excerpts used to illustrate common problems. -// The specific errors generated by the analyzer are included in the markdown. -// -// ignore_for_file: sort_constructors_first, unused_element, unused_local_variable - -import 'dart:html'; - -void _samplesFromCommonProblemsPage() { - { - // #docregion is-strong-mode-enabled - // ignore_for_file: stable, dev, invalid_assignment - bool b = [0][0]; - // #enddocregion is-strong-mode-enabled - } - - { - double x, y; - // #docregion canvas-error - var canvas = querySelector('canvas'); - // ignore_for_file: stable, dev, undefined_getter - canvas.context2D.lineTo(x, y); //!analysis-issue - // #enddocregion canvas-error - } - - { - // #docregion unsafe-method-call - NumberAdder adder = MyAdder(); - adder.add(1.2, 3.4); - // #enddocregion unsafe-method-call - } - - { - // #docregion inferred-collection-types - // Inferred as Map - var map = {'a': 1, 'b': 2, 'c': 3}; - map['d'] = 1.5; // a double is not an int - // #enddocregion inferred-collection-types - } - - { - // #docregion int-not-string - List numbers = [1, 2, 3]; - // ignore_for_file: stable, dev, invalid_assignment - List string = numbers; - // #enddocregion int-not-string - } -} - -//----------------------------------------------- - -// ignore_for_file: annotate_overrides, one_member_abstracts -// #docregion invalid-method-override -abstract class NumberAdder { - num add(num a, num b); -} - -class MyAdder extends NumberAdder { - // ignore_for_file: stable, dev, invalid_override - int add(int a, int b) => a + b; -} -// #enddocregion invalid-method-override - -//----------------------------------------------- - -// #docregion missing-type-arguments -class Superclass { - void method(T t) {/* ... */} -} - -class Subclass extends Superclass { - // ignore_for_file: stable, dev, invalid_override - void method(int i) {/* ... */} -} -// #enddocregion missing-type-arguments - -//----------------------------------------------- - -class Eats {} - -abstract class Animal { - Animal(Eats food); -} - -// ignore_for_file: super_goes_last, unused_field -class HoneyBadger extends Animal { - String _name; - // #docregion super-goes-last - HoneyBadger(Eats food, String name) - // ignore_for_file: stable, dev, invalid_super_invocation - : super(food), - _name = name {/* ... */} - // #enddocregion super-goes-last -} - -//----------------------------------------------- - -// #docregion func-dynamic -typedef Filter = bool Function(dynamic any); -// ignore_for_file: stable, dev, invalid_cast_function_expr -Filter filter = (String x) => x.contains('Hello'); -// #enddocregion func-dynamic diff --git a/src/_guides/language/analysis-options.md b/src/_guides/language/analysis-options.md index 4c51776ff2..2416d69137 100644 --- a/src/_guides/language/analysis-options.md +++ b/src/_guides/language/analysis-options.md @@ -181,7 +181,7 @@ String s2 = s.substring(1); {% endprettify %} {:.console-output} - + ```nocode error • A value of type 'Object' can't be assigned to a variable of type 'String' • invalid_assignment ``` diff --git a/src/_guides/language/effective-dart/design.md b/src/_guides/language/effective-dart/design.md index a77ba4b2e6..909f2afd24 100644 --- a/src/_guides/language/effective-dart/design.md +++ b/src/_guides/language/effective-dart/design.md @@ -1281,8 +1281,10 @@ num highScore(List scores) { } {% endprettify %} + {:.bad} - + {% prettify dart tag=pre+code %} num highScore(List scores) { var highest = 0; diff --git a/src/_guides/language/effective-dart/usage.md b/src/_guides/language/effective-dart/usage.md index 9aba7bfe1b..45db4566a4 100644 --- a/src/_guides/language/effective-dart/usage.md +++ b/src/_guides/language/effective-dart/usage.md @@ -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. + {:.bad} - + {% prettify dart tag=pre+code %} class Folder { final String name; diff --git a/src/_guides/language/language-tour.md b/src/_guides/language/language-tour.md index 6018a2ecbe..aa8472ff5d 100644 --- a/src/_guides/language/language-tour.md +++ b/src/_guides/language/language-tour.md @@ -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} - ```dart var names = List(); names.addAll(['Seth', 'Kathy', 'Lars']); @@ -3673,7 +3672,6 @@ print(foo); // Instance of 'Foo' Specifying any non-`SomeBaseClass` type results in an error: {:.fails-sa} - {% prettify dart tag=pre+code %} var foo = [!Foo!](); {% endprettify %} diff --git a/src/_guides/language/sound-problems.md b/src/_guides/language/sound-problems.md index 5668346348..1567b9d10c 100644 --- a/src/_guides/language/sound-problems.md +++ b/src/_guides/language/sound-problems.md @@ -29,7 +29,6 @@ make sure that you're using the latest version of Dart. Alternatively, try adding the following code to a file: {:.fails-sa} - {% prettify dart tag=pre+code %} bool b = [0][0]; {% endprettify %} @@ -37,7 +36,7 @@ bool b = [0][0]; With type-safe Dart, the analyzer produces the following error: {:.console-output} - + ```nocode error • A value of type 'int' can't be assigned to a variable of type 'bool' • invalid_assignment ``` @@ -55,7 +54,7 @@ see [Runtime errors](#common-errors-and-warnings). ### Undefined member - + ```nocode error • The '...' isn't defined for the type '...' • undefined_ ``` @@ -71,14 +70,13 @@ These errors can appear under the following conditions: In the following code, the analyzer complains that `context2D` is undefined: {:.fails-sa} - {% prettify dart tag=pre+code %} var canvas = querySelector('canvas'); canvas.[!context2D!].lineTo(x, y); {% endprettify %} {:.console-output} - + ```nocode error • The getter 'context2D' isn't defined for the type 'Element' • undefined_getter ``` @@ -139,7 +137,6 @@ The following code creates a new instance of this class (omitting the type argument) and accesses its `collection` member: {:.fails-sa} - {% prettify dart tag=pre+code %} var c = C(Iterable.empty()).collection; [!c.add(2);!] @@ -196,7 +193,7 @@ var c = C(Iterable.empty()).collection; ### Invalid method override - + ```nocode error • '...' isn't a valid override of '...' • invalid_override ``` @@ -215,7 +212,6 @@ In the following example, the parameters to the `add()` method are of type `int` a subtype of `num`, which is the parameter type used in the parent class. {:.fails-sa} - {% prettify dart tag=pre+code %} abstract class NumberAdder { num add(num a, num b); @@ -227,7 +223,7 @@ class MyAdder extends NumberAdder { {% endprettify %} {:.console-output} - + ```nocode error • 'MyAdder.add' ('int Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)') • invalid_override ``` @@ -236,7 +232,6 @@ Consider the following scenario where floating point values are passed to an MyAdder: {:.runtime-fail} - {% prettify dart tag=pre+code %} NumberAdder adder = MyAdder(); adder.add([!1.2!], [!3.4!]); @@ -274,7 +269,7 @@ For more information, see [Use proper input parameter types when overriding meth ### Missing type arguments - + ```nocode error • '...' isn't a valid override of '...' • invalid_override ``` @@ -286,7 +281,6 @@ specify a type argument. The analyzer infers `Subclass`, which results in an invalid override error on `method(int)`. {:.fails-sa} - {% prettify dart tag=pre+code %} class Superclass { void method(T t) { ... } @@ -298,7 +292,7 @@ class Subclass extends Superclass { {% endprettify %} {:.console-output} - + ```nocode error • 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)') • invalid_override ``` @@ -328,7 +322,7 @@ class Subclass extends Superclass[!!] { ### Unexpected collection element type - + ```nocode error • A value of type '...' can't be assigned to a variable of type '...' • invalid_assignment ``` @@ -345,7 +339,6 @@ The following code initializes a map with several When the code adds a (String, float) pair, the analyzer complains: {:.fails-sa} - {% prettify dart tag=pre+code %} // Inferred as Map var map = {'a': 1, 'b': 2, 'c': 3}; @@ -355,7 +348,6 @@ map['d'] = [!1.5!]; // a double is not an int {:.console-output} ```nocode -error • A value of type 'double' can't be assigned to a variable of type 'int' • invalid_assignment ``` #### Fix: Specify the type explicitly @@ -379,7 +371,6 @@ Alternatively, if you want this map to accept any value, specify the type as ` ```nocode -error • The super call must be last in an initializer list (see https://goo.gl/EY6hDP): '...' • invalid_super_invocation ``` This error occurs when the `super()` call is not last in a constructor's @@ -388,7 +379,6 @@ initialization list. #### Example {:.fails-sa} - {% prettify dart tag=pre+code %} HoneyBadger(Eats food, String name) : [!super!](food), @@ -398,7 +388,6 @@ HoneyBadger(Eats food, String name) {:.console-output} ```nocode -error • The super call must be last in an initializer list (see https://goo.gl/EY6hDP): 'super(food)' • invalid_super_invocation ``` #### Fix: Put the `super()` call last @@ -422,7 +411,6 @@ HoneyBadger(Eats food, String name) ```nocode -error • The function expression type '...' isn't of type '...'. This means its parameter or return type doesn't match what is expected. Consider changing parameter type(s) or the returned type(s) • invalid_cast_function_expr ``` In Dart 1.x `dynamic` was both a [top type][] (supertype of all types) and a @@ -438,7 +426,6 @@ in a compile-time error. #### Example {:.fails-sa} - {% prettify dart tag=pre+code %} typedef Filter = bool Function(dynamic any); Filter filter = ([!String!] x) => x.contains('Hello'); @@ -447,7 +434,6 @@ Filter filter = ([!String!] x) => x.contains('Hello'); {:.console-output} ```nocode -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) • invalid_cast_function_expr ``` #### Fix: Add type parameters _or_ cast from dynamic explicitly @@ -485,7 +471,6 @@ For example, the following type error is detected at compile-time (when the [implicit casts][] option is disabled): {:.fails-sa} - {% prettify dart tag=pre+code %} List numbers = [1, 2, 3]; List [!string = numbers!]; diff --git a/src/_guides/language/type-system.md b/src/_guides/language/type-system.md index dc1ac5141e..053522d710 100644 --- a/src/_guides/language/type-system.md +++ b/src/_guides/language/type-system.md @@ -161,7 +161,6 @@ class HoneyBadger extends Animal { {% endprettify %} {:.fails-sa} - {% prettify dart tag=pre+code %} class HoneyBadger extends Animal { void chase(Animal a) { ... } @@ -208,7 +207,6 @@ The following code tightens the parameter on the `chase()` method from Animal to Mouse, a subclass of Animal. {:.fails-sa} - {% prettify dart tag=pre+code %} class Mouse extends Animal {...} @@ -220,7 +218,6 @@ class Cat extends Animal { This code is not type safe because it would then be possible to define a cat and send it after an alligator: - {% prettify dart tag=pre+code %} Animal a = Cat(); a.chase([!Alligator!]()); // Not type safe or feline safe @@ -238,7 +235,6 @@ The following code creates a dynamic list of Dog, and assigns it to a list of type Cat, which generates an error during static analysis. {:.fails-sa} - {% prettify dart tag=pre+code %} class Cat extends Animal { ... } diff --git a/src/_try-dart-examples.md b/src/_try-dart-examples.md index 97378b184d..4b884d5dda 100644 --- a/src/_try-dart-examples.md +++ b/src/_try-dart-examples.md @@ -26,7 +26,7 @@ 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) { for (var i = 0; i < 2; i++) { x = f(x); } diff --git a/tool/analyze-and-test-examples.sh b/tool/analyze-and-test-examples.sh index ad7b9d22e4..4132d06380 100755 --- a/tool/analyze-and-test-examples.sh +++ b/tool/analyze-and-test-examples.sh @@ -73,24 +73,6 @@ function analyze_and_test() { EXPECTED_FILE=$PROJECT_ROOT/analyzer-results.txt fi travis_fold start analyzeAndTest.analyze - if [[ -e $EXPECTED_FILE && -z $QUICK ]]; then - # Run the analyzer a first time to ensure that there are no errors. - # - # Note: catch non-zero exit codes to avoid aborting this script when the - # analyzer reports "foo.dart is a part and cannot be analyzed": - echo "$ $ANALYZE ${DIR[*]}" - $ANALYZE ${DIR[*]} > $LOG_FILE || { - echo "WARNING: Ignoring Analyzer exit code $?" - } - if grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then - cat $LOG_FILE - echo "No analysis errors or warnings should be present in original source files." - echo "Ensure that these issues are disabled using appropriate markers like: " - echo " // ignore_for_file: $DART_CHAN, some_analyzer_error_or_warning_id" - EXIT_STATUS=1 - return 1; - fi - fi toggleInFileAnalyzerFlags disable ${DIR[*]} echo "$ $ANALYZE ${DIR[*]}" $ANALYZE ${DIR[*]} > $LOG_FILE || { @@ -108,6 +90,10 @@ function analyze_and_test() { fi elif grep -qvE '^Analyzing|^No issues found' $LOG_FILE; then cat $LOG_FILE + echo "No analysis errors or warnings should be present in original source files." + echo "Ensure that these issues are disabled using appropriate markers like: " + echo " // ignore_for_file: $DART_CHAN, some_analyzer_error_or_warning_id" + echo "Or if the errors are expected, create an analyzer-results.txt file." EXIT_STATUS=1 if [[ -n $SAVE_LOGS ]]; then cp $LOG_FILE $EXPECTED_FILE; fi else