Skip to content

Commit fd72dbb

Browse files
author
Dart CI
committed
Version 2.12.0-247.0.dev
Merge commit '54402fb7e0633e6608ecefa73d04014fed61340a' into 'dev'
2 parents 970d74c + 54402fb commit fd72dbb

File tree

90 files changed

+4831
-3419
lines changed

Some content is hidden

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

90 files changed

+4831
-3419
lines changed

CHANGELOG.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22

33
### Language
44

5-
**Breaking Change** [Null
6-
Safety](https://dart.dev/null-safety/understanding-null-safety) is now enabled
7-
by default in all packages with a lower sdk constraint of 2.12.0 or greater.
8-
Files that are not subject to language versioning (whether because they are not
9-
contained in a pub package, or because the package that they are contained in
10-
has no lower sdk constraint) are treated as opted into to null safety by default
11-
and may report new errors. Pub packages may be opted out of null safety by
12-
setting a min sdk constraint in pubspec.yaml of 2.9.0 or less. Files may be
13-
opted out of null safety by adding `// @dart=2.9` to the beginning of the file.
5+
* **Breaking Change** [Null
6+
Safety](https://dart.dev/null-safety/understanding-null-safety) is now
7+
enabled by default in all packages with a lower sdk constraint of 2.12.0 or
8+
greater. Files that are not subject to language versioning (whether because
9+
they are not contained in a pub package, or because the package that they
10+
are contained in has no lower sdk constraint) are treated as opted into to
11+
null safety by default and may report new errors. Pub packages may be opted
12+
out of null safety by setting a min sdk constraint in pubspec.yaml of 2.9.0
13+
or less. Files may be opted out of null safety by adding `// @dart=2.9` to
14+
the beginning of the file.
15+
16+
* **Breaking Change** [#44660][]: Fixed an implementation bug where `this`
17+
would sometimes undergo type promotion in extensions.
18+
19+
[#44660]: https://github.com/dart-lang/sdk/issues/44660
1420

1521
### Core libraries
1622

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ const List<ErrorCode> errorCodeValues = [
240240
CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME,
241241
CompileTimeErrorCode.INVALID_EXTENSION_ARGUMENT_COUNT,
242242
CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS,
243+
CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE,
243244
CompileTimeErrorCode.INVALID_INLINE_FUNCTION_TYPE,
244245
CompileTimeErrorCode.INVALID_MODIFIER_ON_CONSTRUCTOR,
245246
CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER,

pkg/analyzer/lib/src/error/codes.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,6 +5890,23 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
58905890
"the immediately enclosing class.",
58915891
hasPublishedDocs: true);
58925892

5893+
/**
5894+
* Parameters:
5895+
* 0: the name of the declared member that is not a valid override.
5896+
* 1: the name of the interface that declares the member.
5897+
* 2: the type of the declared member in the interface.
5898+
* 3. the name of the interface with the overridden member.
5899+
* 4. the type of the overridden member.
5900+
*
5901+
* These parameters must be kept in sync with those of
5902+
* [CompileTimeErrorCode.INVALID_OVERRIDE].
5903+
*/
5904+
static const CompileTimeErrorCode INVALID_IMPLEMENTATION_OVERRIDE =
5905+
CompileTimeErrorCode(
5906+
'INVALID_IMPLEMENTATION_OVERRIDE',
5907+
"'{1}.{0}' ('{2}') isn't a valid concrete implementation of "
5908+
"'{3}.{0}' ('{4}').");
5909+
58935910
/**
58945911
* No parameters.
58955912
*/

pkg/analyzer/lib/src/error/correct_override.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/element/element.dart';
77
import 'package:analyzer/dart/element/nullability_suffix.dart';
88
import 'package:analyzer/dart/element/type.dart';
9+
import 'package:analyzer/error/error.dart';
910
import 'package:analyzer/error/listener.dart';
1011
import 'package:analyzer/src/dart/analysis/session.dart';
1112
import 'package:analyzer/src/dart/element/element.dart';
@@ -48,11 +49,12 @@ class CorrectOverrideHelper {
4849
@required ExecutableElement superMember,
4950
@required ErrorReporter errorReporter,
5051
@required AstNode errorNode,
52+
ErrorCode errorCode,
5153
}) {
5254
var isCorrect = isCorrectOverrideOf(superMember: superMember);
5355
if (!isCorrect) {
5456
errorReporter.reportErrorForNode(
55-
CompileTimeErrorCode.INVALID_OVERRIDE,
57+
errorCode ?? CompileTimeErrorCode.INVALID_OVERRIDE,
5658
errorNode,
5759
[
5860
_thisMember.name,

pkg/analyzer/lib/src/error/inheritance_override.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class _ClassVerifier {
237237
superMember: interfaceElement,
238238
errorReporter: reporter,
239239
errorNode: classNameNode,
240+
errorCode: CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE,
240241
);
241242
}
242243

pkg/analyzer/test/generated/static_warning_code_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ abstract class D {
8282
foo(x, [y]);
8383
}
8484
class E extends C implements D {}''', [
85-
error(CompileTimeErrorCode.INVALID_OVERRIDE, 73, 1),
85+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 73, 1),
8686
]);
8787
}
8888

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/context_collection_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(InvalidImplementationOverrideTest);
13+
defineReflectiveTests(InvalidImplementationOverrideWithNullSafetyTest);
14+
});
15+
}
16+
17+
@reflectiveTest
18+
class InvalidImplementationOverrideTest extends PubPackageResolutionTest {
19+
test_getter_abstractOverridesConcrete() async {
20+
await assertErrorsInCode('''
21+
class A {
22+
num get g => 7;
23+
}
24+
class B extends A {
25+
int get g;
26+
}
27+
''', [
28+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 36, 1),
29+
]);
30+
}
31+
32+
test_method_abstractOverridesConcrete() async {
33+
await assertErrorsInCode('''
34+
class A {
35+
int add(int a, int b) => a + b;
36+
}
37+
class B extends A {
38+
int add();
39+
}
40+
''', [
41+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 52, 1),
42+
error(CompileTimeErrorCode.INVALID_OVERRIDE, 72, 3),
43+
]);
44+
}
45+
46+
test_method_abstractOverridesConcrete_expandedParameterType() async {
47+
await assertErrorsInCode('''
48+
class A {
49+
int add(int a) => a;
50+
}
51+
class B extends A {
52+
int add(num a);
53+
}
54+
''', [
55+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 41, 1),
56+
]);
57+
}
58+
59+
test_method_abstractOverridesConcrete_expandedParameterType_covariant() async {
60+
await assertNoErrorsInCode('''
61+
class A {
62+
int add(covariant int a) => a;
63+
}
64+
class B extends A {
65+
int add(num a);
66+
}
67+
''');
68+
}
69+
70+
test_method_abstractOverridesConcrete_withOptional() async {
71+
await assertErrorsInCode('''
72+
class A {
73+
int add() => 7;
74+
}
75+
class B extends A {
76+
int add([int a = 0, int b = 0]);
77+
}
78+
''', [
79+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 36, 1),
80+
]);
81+
}
82+
83+
test_method_abstractOverridesConcreteInMixin() async {
84+
await assertErrorsInCode('''
85+
mixin M {
86+
int add(int a, int b) => a + b;
87+
}
88+
class A with M {
89+
int add();
90+
}
91+
''', [
92+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 52, 1),
93+
error(CompileTimeErrorCode.INVALID_OVERRIDE, 69, 3),
94+
]);
95+
}
96+
97+
test_method_abstractOverridesConcreteViaMixin() async {
98+
await assertErrorsInCode('''
99+
class A {
100+
int add(int a, int b) => a + b;
101+
}
102+
mixin M {
103+
int add();
104+
}
105+
class B extends A with M {}
106+
''', [
107+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 77, 1),
108+
error(CompileTimeErrorCode.INVALID_OVERRIDE, 94, 1),
109+
]);
110+
}
111+
}
112+
113+
@reflectiveTest
114+
class InvalidImplementationOverrideWithNullSafetyTest
115+
extends PubPackageResolutionTest with WithNullSafetyMixin {}

pkg/analyzer/test/src/diagnostics/invalid_override_test.dart

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,40 @@ class B extends A {
8787
int add();
8888
}
8989
''', [
90-
error(CompileTimeErrorCode.INVALID_OVERRIDE, 52, 1),
90+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 52, 1),
9191
error(CompileTimeErrorCode.INVALID_OVERRIDE, 72, 3),
9292
]);
9393
}
9494

95+
test_method_abstractOverridesConcreteInMixin() async {
96+
await assertErrorsInCode('''
97+
mixin M {
98+
int add(int a, int b) => a + b;
99+
}
100+
class A with M {
101+
int add();
102+
}
103+
''', [
104+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 52, 1),
105+
error(CompileTimeErrorCode.INVALID_OVERRIDE, 69, 3),
106+
]);
107+
}
108+
109+
test_method_abstractOverridesConcreteViaMixin() async {
110+
await assertErrorsInCode('''
111+
class A {
112+
int add(int a, int b) => a + b;
113+
}
114+
mixin M {
115+
int add();
116+
}
117+
class B extends A with M {}
118+
''', [
119+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 77, 1),
120+
error(CompileTimeErrorCode.INVALID_OVERRIDE, 94, 1),
121+
]);
122+
}
123+
95124
test_method_covariant_1() async {
96125
await assertNoErrorsInCode(r'''
97126
abstract class A<T> {

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ import 'invalid_factory_name_not_a_class_test.dart'
290290
as invalid_factory_name_not_a_class;
291291
import 'invalid_field_type_in_struct_test.dart' as invalid_field_type_in_struct;
292292
import 'invalid_immutable_annotation_test.dart' as invalid_immutable_annotation;
293+
import 'invalid_implementation_override_test.dart'
294+
as invalid_implementation_override;
293295
import 'invalid_internal_annotation_test.dart' as invalid_internal_annotation;
294296
import 'invalid_language_override_greater_test.dart'
295297
as invalid_language_override_greater;
@@ -850,6 +852,7 @@ main() {
850852
invalid_factory_name_not_a_class.main();
851853
invalid_field_type_in_struct.main();
852854
invalid_immutable_annotation.main();
855+
invalid_implementation_override.main();
853856
invalid_internal_annotation.main();
854857
invalid_language_override_greater.main();
855858
invalid_language_override.main();

pkg/analyzer/test/src/task/strong/checker_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,7 +3809,7 @@ class C = Object with B;
38093809
38103810
class D extends Object with C implements A {}
38113811
''', [
3812-
error(CompileTimeErrorCode.INVALID_OVERRIDE, 100, 1),
3812+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 100, 1),
38133813
]);
38143814
}
38153815

@@ -4180,8 +4180,8 @@ class D extends B with X { }
41804180
class E extends B implements A { }
41814181
''', [
41824182
error(CompileTimeErrorCode.INVALID_OVERRIDE, 78, 4),
4183-
error(CompileTimeErrorCode.INVALID_OVERRIDE, 159, 1),
4184-
error(CompileTimeErrorCode.INVALID_OVERRIDE, 189, 1),
4183+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 159, 1),
4184+
error(CompileTimeErrorCode.INVALID_IMPLEMENTATION_OVERRIDE, 189, 1),
41854185
]);
41864186
}
41874187

0 commit comments

Comments
 (0)