Skip to content

Commit f8eb9b2

Browse files
authored
Merge null_safety_examples with examples (#3398)
1 parent d842fd1 commit f8eb9b2

File tree

297 files changed

+612
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+612
-620
lines changed

.github/workflows/build.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,17 @@ jobs:
3030
task:
3131
- ./tool/build.sh --check-links
3232
- ./tool/check-code.sh
33-
- ./tool/check-code.sh --null-safety
3433
experimental: [false]
3534
include:
3635
- sdk: dev
3736
task: ./tool/analyze-and-test-examples.sh
38-
experimental: true
37+
experimental: false
3938
- sdk: beta
4039
task: ./tool/analyze-and-test-examples.sh
41-
experimental: true
40+
experimental: false
4241
- sdk: stable
4342
task: ./tool/analyze-and-test-examples.sh
4443
experimental: false
45-
- sdk: dev
46-
task: ./tool/analyze-and-test-examples.sh --null-safety
47-
experimental: true
48-
- sdk: beta
49-
task: ./tool/analyze-and-test-examples.sh --null-safety
50-
experimental: true
51-
- sdk: stable
52-
task: ./tool/analyze-and-test-examples.sh --null-safety
53-
experimental: true
5444
steps:
5545
- uses: actions/checkout@v2
5646
with:

build.excerpt.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ targets:
33
sources:
44
include:
55
- 'examples/**'
6-
- 'null_safety_examples/**'
76
# Some default includes that aren't really used here but will prevent
87
# false-negative warnings:
98
- $package$
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Analyzing analysis...
2+
3+
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment
4+
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements
5+
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks
6+
7+
3 issues found.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Analyzing analysis...
2+
3+
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment
4+
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements
5+
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks
6+
7+
3 issues found.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Analyzing analysis...
2+
3+
error - lib/assignment.dart:11:14 - A value of type 'dynamic' can't be assigned to a variable of type 'String'. Try changing the type of the variable, or casting the right-hand type to 'String'. - invalid_assignment
4+
info - lib/lint.dart:9:19 - Avoid empty statements. - empty_statements
5+
info - lib/lint.dart:17:7 - Close instances of `dart.core.Sink`. - close_sinks
6+
7+
3 issues found.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

null_safety_examples/basics/pubspec.yaml examples/basics/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: null_safety_examples_basics
1+
name: basics_examples
22
description: dart.dev null-safety examples.
33
version: 0.0.1
44

File renamed without changes.

null_safety_examples/extension_methods/pubspec.yaml examples/extension_methods/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: create_libraries
1+
name: extension_methods_examples
22
description: dart.dev example code.
33
version: 1.0.0
44

null_safety_examples/fetch_data/pubspec.yaml examples/fetch_data/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: fetch_data_example
1+
name: fetch_data_examples
22
description: Fetch data example
33
version: 0.0.1
44

File renamed without changes.
File renamed without changes.

null_safety_examples/html/pubspec.yaml examples/html/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: html_library_sample
1+
name: html_library_examples
22
description: dart.dev example code.
33
version: 0.0.1
44

null_safety_examples/iterables/pubspec.yaml examples/iterables/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: iterables
1+
name: iterables_examples
22
description: dart.dev example code.
33

44
environment:
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Analyzing misc...
2+
3+
info - lib/effective_dart/usage_good.dart:481:9 - Use initializing formals when possible. - prefer_initializing_formals
4+
info - lib/language_tour/metadata/television.dart:4:3 - Provide a deprecation message, via @Deprecated("message"). - provide_deprecation_message
5+
error - lib/library_tour/core/collections.dart:5:14 - The argument type 'int' can't be assigned to the parameter type 'String'. - argument_type_not_assignable
6+
7+
3 issues found.
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Analyzing misc...
2+
3+
info - lib/effective_dart/usage_good.dart:481:9 - Use initializing formals when possible. - prefer_initializing_formals
4+
info - lib/language_tour/metadata/television.dart:4:3 - Provide a deprecation message, via @Deprecated("message"). - provide_deprecation_message
5+
error - lib/library_tour/core/collections.dart:5:14 - The argument type 'int' can't be assigned to the parameter type 'String'. - argument_type_not_assignable
6+
7+
3 issues found.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Analyzing misc...
2+
3+
info - lib/effective_dart/usage_good.dart:461:26 - Use initializing formals when possible. - prefer_initializing_formals
4+
info - lib/effective_dart/usage_good.dart:481:9 - Use initializing formals when possible. - prefer_initializing_formals
5+
info - lib/language_tour/metadata/television.dart:4:3 - Provide a deprecation message, via @Deprecated("message"). - provide_deprecation_message
6+
error - lib/library_tour/core/collections.dart:5:14 - The argument type 'int' can't be assigned to the parameter type 'String'. - argument_type_not_assignable
7+
8+
4 issues found.
File renamed without changes.
File renamed without changes.

null_safety_examples/misc/lib/samples/spacecraft.dart examples/misc/lib/samples/spacecraft.dart

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ class Spacecraft {
33
String name;
44
DateTime? launchDate;
55

6-
int? get launchYear => launchDate?.year; // read-only non-final property
6+
// Read-only non-final property
7+
int? get launchYear => launchDate?.year;
78

89
// Constructor, with syntactic sugar for assignment to members.
910
Spacecraft(this.name, this.launchDate) {
@@ -16,9 +17,11 @@ class Spacecraft {
1617
// Method.
1718
void describe() {
1819
print('Spacecraft: $name');
19-
var launchDate = this.launchDate; // Type promotion doesn't work on getters.
20+
// Type promotion doesn't work on getters.
21+
var launchDate = this.launchDate;
2022
if (launchDate != null) {
21-
int years = DateTime.now().difference(launchDate).inDays ~/ 365;
23+
int years =
24+
DateTime.now().difference(launchDate).inDays ~/ 365;
2225
print('Launched: $launchYear ($years years ago)');
2326
} else {
2427
print('Unlaunched');
@@ -49,8 +52,9 @@ mixin Piloted {
4952
// #docregion mixin-use
5053
class PilotedCraft extends Spacecraft with Piloted {
5154
// #enddocregion mixin-use
52-
PilotedCraft(String name, DateTime launchDate) : super(name, launchDate);
53-
// #docregion mixin-use
55+
PilotedCraft(String name, DateTime launchDate)
56+
: super(name, launchDate);
57+
// #docregion mixin-use
5458
}
5559
// #enddocregion mixin-use
5660

@@ -70,7 +74,7 @@ class MockSpaceship implements Spacecraft {
7074

7175
@override
7276
void describe() => print(name);
73-
// #docregion implements
77+
// #docregion implements
7478
}
7579
// #enddocregion implements
7680

File renamed without changes.
File renamed without changes.

null_safety_examples/misc/test/language_tour/classes_test.dart examples/misc/test/language_tour/classes_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ void main() {
8989
});
9090

9191
test('employee', () {
92-
expect(employee.main, m.prints(['in Person', 'in Employee']));
92+
expect(employee.main,
93+
m.prints(['in Person', 'in Employee', "Instance of 'Employee'"]));
9394
});
9495

9596
test('point_with_distance', () {

null_safety_examples/misc/test/language_tour/operators_test.dart examples/misc/test/language_tour/operators_test.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void main() {
8181
});
8282

8383
test('is-vs-as', () {
84-
expect(employee.main, m.prints(['in Person', 'in Employee']));
84+
expect(employee.main,
85+
m.prints(['in Person', 'in Employee', "Instance of 'Employee'"]));
8586
});
8687

8788
group('`=` vs `??=`:', () {
File renamed without changes.

null_safety_examples/misc/test/try_dart_test.dart examples/misc/test/try_dart_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void main() {
1616
});
1717

1818
test('strings', () {
19-
expect(strings.main, prints(endsWith('tau is 6.28\n')));
19+
expect(strings.main, prints(contains('tau is 6.28')));
2020
});
2121

2222
test('collection_literals', () {

null_safety_examples/non_promotion/pubspec.yaml examples/non_promotion/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: non_promotion
1+
name: non_promotion_examples
22
description: dart.dev non-promotion examples.
33
version: 0.0.1
44

null_safety_examples/null_safety_codelab/pubspec.yaml examples/null_safety_codelab/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: null_safety_codelab
1+
name: null_safety_codelab_examples
22
description: dart.dev example code for null safety codelab
33

44
environment:
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Analyzing strong...
1+
Analyzing type_system...
22

33
error - lib/bounded/instantiate_to_bound.dart:7:5 - The method 'add' isn't defined for the type 'Iterable'. Try correcting the name to the name of an existing method, or defining a method named 'add'. - undefined_method
4-
error - lib/common_fixes_analysis.dart:15:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5-
error - lib/common_fixes_analysis.dart:38:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
4+
error - lib/common_fixes_analysis.dart:16:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5+
error - lib/common_fixes_analysis.dart:39:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
66
error - lib/common_fixes_analysis.dart:61:7 - 'MyAdder.add' ('num Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)'). - invalid_override
77
error - lib/common_fixes_analysis.dart:80:8 - 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)'). - invalid_override
88
error - lib/common_fixes_analysis.dart:97:9 - The superclass call must be last in an initializer list: 'super(food)'. - invalid_super_invocation
@@ -15,8 +15,6 @@ Analyzing strong...
1515
error - lib/strong_analysis.dart:107:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
1616
error - lib/strong_analysis.dart:119:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
1717
error - lib/strong_analysis.dart:144:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
18-
error - test/strong_test.dart:36:27 - A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'. Try changing the type of the variable, or casting the right-hand type to 'List<int>'. - invalid_assignment
19-
error - test/strong_test.dart:53:26 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
20-
error - test/strong_test.dart:158:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
18+
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
2119

22-
18 issues found.
20+
16 issues found.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Analyzing strong...
1+
Analyzing type_system...
22

33
error - lib/bounded/instantiate_to_bound.dart:7:5 - The method 'add' isn't defined for the type 'Iterable'. Try correcting the name to the name of an existing method, or defining a method named 'add'. - undefined_method
4-
error - lib/common_fixes_analysis.dart:15:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5-
error - lib/common_fixes_analysis.dart:38:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
4+
error - lib/common_fixes_analysis.dart:16:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5+
error - lib/common_fixes_analysis.dart:39:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
66
error - lib/common_fixes_analysis.dart:61:7 - 'MyAdder.add' ('num Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)'). - invalid_override
77
error - lib/common_fixes_analysis.dart:80:8 - 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)'). - invalid_override
88
error - lib/common_fixes_analysis.dart:97:9 - The superclass call must be last in an initializer list: 'super(food)'. - invalid_super_invocation
@@ -15,8 +15,6 @@ Analyzing strong...
1515
error - lib/strong_analysis.dart:107:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
1616
error - lib/strong_analysis.dart:119:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
1717
error - lib/strong_analysis.dart:144:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
18-
error - test/strong_test.dart:36:27 - A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'. Try changing the type of the variable, or casting the right-hand type to 'List<int>'. - invalid_assignment
19-
error - test/strong_test.dart:53:26 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
20-
error - test/strong_test.dart:158:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
18+
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
2119

22-
18 issues found.
20+
16 issues found.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
Analyzing strong...
1+
Analyzing type_system...
22

33
error - lib/bounded/instantiate_to_bound.dart:7:5 - The method 'add' isn't defined for the type 'Iterable'. Try correcting the name to the name of an existing method, or defining a method named 'add'. - undefined_method
4-
error - lib/common_fixes_analysis.dart:15:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5-
error - lib/common_fixes_analysis.dart:38:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
4+
error - lib/common_fixes_analysis.dart:16:12 - The getter 'context2D' isn't defined for the type 'Element'. Try importing the library that defines 'context2D', correcting the name to the name of an existing getter, or defining a getter or field named 'context2D'. - undefined_getter
5+
error - lib/common_fixes_analysis.dart:39:16 - A value of type 'double' can't be assigned to a variable of type 'int'. Try changing the type of the variable, or casting the right-hand type to 'int'. - invalid_assignment
66
error - lib/common_fixes_analysis.dart:61:7 - 'MyAdder.add' ('num Function(int, int)') isn't a valid override of 'NumberAdder.add' ('num Function(num, num)'). - invalid_override
77
error - lib/common_fixes_analysis.dart:80:8 - 'Subclass.method' ('void Function(int)') isn't a valid override of 'Superclass.method' ('void Function(dynamic)'). - invalid_override
88
error - lib/common_fixes_analysis.dart:97:9 - The superclass call must be last in an initializer list: 'super(food)'. - invalid_super_invocation
@@ -15,8 +15,6 @@ Analyzing strong...
1515
error - lib/strong_analysis.dart:107:23 - A value of type 'String' can't be assigned to a variable of type 'double'. Try changing the type of the variable, or casting the right-hand type to 'double'. - invalid_assignment
1616
error - lib/strong_analysis.dart:119:19 - A value of type 'Cat' can't be assigned to a variable of type 'MaineCoon'. Try changing the type of the variable, or casting the right-hand type to 'MaineCoon'. - invalid_assignment
1717
error - lib/strong_analysis.dart:144:24 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
18-
error - test/strong_test.dart:36:27 - A value of type 'List<dynamic>' can't be assigned to a variable of type 'List<int>'. Try changing the type of the variable, or casting the right-hand type to 'List<int>'. - invalid_assignment
19-
error - test/strong_test.dart:53:26 - A value of type 'List<Animal>' can't be assigned to a variable of type 'List<Cat>'. Try changing the type of the variable, or casting the right-hand type to 'List<Cat>'. - invalid_assignment
20-
error - test/strong_test.dart:158:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
18+
error - test/strong_test.dart:120:26 - A value of type 'dynamic' can't be assigned to a variable of type 'List<String>'. Try changing the type of the variable, or casting the right-hand type to 'List<String>'. - invalid_assignment
2119

22-
18 issues found.
20+
16 issues found.

null_safety_examples/type_system/pubspec.yaml examples/type_system/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: examples_strong
1+
name: type_system_examples
22
description: dart.dev type system examples.
33

44
environment:

null_safety_examples/type_system/test/strong_test.dart examples/type_system/test/strong_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// ignore_for_file: unused_local_variable, strict_raw_type
22
import 'package:test/test.dart';
33

4-
import 'package:examples_strong/animal.dart';
5-
import 'package:examples_strong/bounded/my_collection.dart';
4+
import 'package:type_system_examples/animal.dart';
5+
import 'package:type_system_examples/bounded/my_collection.dart';
66

77
Matcher _throwsA<T>(String msg) => throwsA(
88
allOf(
@@ -116,7 +116,7 @@ void main() {
116116

117117
// #docregion downcast-check
118118
void assumeStrings(dynamic objects) {
119-
// ignore_for_file: invalid_assignment
119+
// ignore_for_file: stable, beta, dev, invalid_assignment
120120
List<String> strings = objects; // Runtime downcast check
121121
String string = strings[0]; // Expect a String value
122122
// #enddocregion downcast-check
File renamed without changes.
File renamed without changes.
File renamed without changes.

null_safety_examples/analysis/analyzer-results.txt

-7
This file was deleted.

null_safety_examples/misc/analyzer-results.txt

-5
This file was deleted.

0 commit comments

Comments
 (0)