Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 64202f2

Browse files
author
Dart CI
committed
Version 2.13.0-161.0.dev
Merge commit '86c5085565f90fe661290d5b2feebba9c1a7df8f' into 'dev'
2 parents 3d878d7 + 86c5085 commit 64202f2

File tree

8 files changed

+200
-108
lines changed

8 files changed

+200
-108
lines changed

pkg/analysis_server/lib/src/services/correction/dart/make_return_type_nullable.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ class MakeReturnTypeNullable extends CorrectionProducer {
2222
return;
2323
}
2424
var body = node.thisOrAncestorOfType<FunctionBody>();
25-
TypeAnnotation returnType;
26-
var function = body.parent;
27-
if (function is FunctionExpression) {
28-
function = function.parent;
29-
}
30-
if (function is MethodDeclaration) {
31-
returnType = function.returnType;
32-
} else if (function is FunctionDeclaration) {
33-
returnType = function.returnType;
34-
} else {
25+
26+
var returnType = _getReturnTypeNode(body);
27+
if (returnType == null) {
3528
return;
3629
}
30+
3731
if (body.isAsynchronous || body.isGenerator) {
3832
if (returnType is! NamedType) {
3933
return null;
@@ -60,4 +54,17 @@ class MakeReturnTypeNullable extends CorrectionProducer {
6054

6155
/// Return an instance of this class. Used as a tear-off in `FixProcessor`.
6256
static MakeReturnTypeNullable newInstance() => MakeReturnTypeNullable();
57+
58+
static TypeAnnotation _getReturnTypeNode(FunctionBody body) {
59+
var function = body.parent;
60+
if (function is FunctionExpression) {
61+
function = function.parent;
62+
}
63+
if (function is MethodDeclaration) {
64+
return function.returnType;
65+
} else if (function is FunctionDeclaration) {
66+
return function.returnType;
67+
}
68+
return null;
69+
}
6370
}

pkg/analysis_server/test/src/services/correction/fix/make_return_type_nullable_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ class C {
133133
''');
134134
}
135135

136+
Future<void> test_method_sync_inherited() async {
137+
await resolveTestCode('''
138+
abstract class A {
139+
String m(String? s);
140+
}
141+
142+
class B extends A {
143+
m(String? s) {
144+
return s;
145+
}
146+
}
147+
''');
148+
await assertNoFix();
149+
}
150+
136151
Future<void> test_returnTypeHasTypeArguments() async {
137152
await resolveTestCode('''
138153
List<String> f() {

pkg/analyzer/lib/src/dart/resolver/property_element_resolver.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'package:analyzer/dart/element/type.dart';
88
import 'package:analyzer/error/error.dart';
99
import 'package:analyzer/error/listener.dart';
1010
import 'package:analyzer/src/dart/ast/extensions.dart';
11-
import 'package:analyzer/src/dart/element/element.dart';
1211
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1312
import 'package:analyzer/src/dart/element/type.dart';
1413
import 'package:analyzer/src/dart/element/type_system.dart';
@@ -677,15 +676,11 @@ class PropertyElementResolver {
677676
inherited: true,
678677
);
679678
if (writeElement != null) {
680-
var receiverSuperClass =
681-
targetType.element.supertype!.element as ClassElementImpl;
682-
if (!receiverSuperClass.hasNoSuchMethod) {
683-
_errorReporter.reportErrorForNode(
684-
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
685-
propertyName,
686-
[writeElement.kind.displayName, propertyName.name],
687-
);
688-
}
679+
_errorReporter.reportErrorForNode(
680+
CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE,
681+
propertyName,
682+
[writeElement.kind.displayName, propertyName.name],
683+
);
689684
} else {
690685
_errorReporter.reportErrorForNode(
691686
CompileTimeErrorCode.UNDEFINED_SUPER_SETTER,

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,34 @@ abstract class B extends A {
378378
}
379379
}
380380

381+
test_propertyAccess_setter_mixin_implements() async {
382+
await assertErrorsInCode(r'''
383+
class A {
384+
set foo(int _) {}
385+
}
386+
387+
mixin M implements A {
388+
void bar() {
389+
super.foo = 0;
390+
}
391+
}
392+
''', [
393+
error(CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE, 81, 3),
394+
]);
395+
396+
assertSuperExpression(findNode.super_('super.foo'));
397+
398+
assertAssignment(
399+
findNode.assignment('foo ='),
400+
readElement: null,
401+
readType: null,
402+
writeElement: findElement.setter('foo'),
403+
writeType: 'int',
404+
operatorElement: null,
405+
type: 'int',
406+
);
407+
}
408+
381409
test_propertyAccess_setter_mixinHasNoSuchMethod() async {
382410
await assertErrorsInCode('''
383411
class A {

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

Lines changed: 104 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,103 @@ import '../dart/resolution/context_collection_resolution.dart';
1111
main() {
1212
defineReflectiveSuite(() {
1313
defineReflectiveTests(ArgumentTypeNotAssignableTest);
14-
defineReflectiveTests(ArgumentTypeNotAssignableWithNullSafetyTest);
14+
defineReflectiveTests(ArgumentTypeNotAssignableWithoutNullSafetyTest);
1515
});
1616
}
1717

1818
@reflectiveTest
1919
class ArgumentTypeNotAssignableTest extends PubPackageResolutionTest
20-
with WithoutNullSafetyMixin {
20+
with ArgumentTypeNotAssignableTestCases {
21+
test_annotation_namedConstructor_generic() async {
22+
await assertErrorsInCode('''
23+
class A<T> {
24+
const A.fromInt(T p);
25+
}
26+
@A<int>.fromInt('0')
27+
main() {
28+
}''', [
29+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 55, 3),
30+
]);
31+
}
32+
33+
test_binary_eqEq_covariantParameterType() async {
34+
await assertErrorsInCode(r'''
35+
class A {
36+
bool operator==(covariant A other) => false;
37+
}
38+
39+
void f(A a, A? aq) {
40+
a == 0;
41+
aq == 1;
42+
aq == aq;
43+
aq == null;
44+
}
45+
''', [
46+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 88, 1),
47+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 99, 1),
48+
]);
49+
}
50+
51+
test_downcast() async {
52+
await assertErrorsInCode(r'''
53+
m() {
54+
num y = 1;
55+
n(y);
56+
}
57+
n(int x) {}
58+
''', [
59+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 23, 1),
60+
]);
61+
}
62+
63+
test_downcast_nullableNonNullable() async {
64+
await assertErrorsInCode(r'''
65+
m() {
66+
int? y;
67+
n(y);
68+
}
69+
n(int x) {}
70+
''', [
71+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 20, 1),
72+
]);
73+
}
74+
75+
test_dynamicCast() async {
76+
await assertNoErrorsInCode(r'''
77+
m() {
78+
dynamic i;
79+
n(i);
80+
}
81+
n(int i) {}
82+
''');
83+
}
84+
85+
test_invocation_functionTypes_optional() async {
86+
await assertErrorsInCode('''
87+
void acceptFunOptBool(void funNumOptBool([bool b])) {}
88+
void funBool(bool b) {}
89+
main() {
90+
acceptFunOptBool(funBool);
91+
}''', [
92+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 107, 7),
93+
]);
94+
}
95+
96+
test_invocation_functionTypes_optional_method() async {
97+
await assertErrorsInCode('''
98+
void acceptFunOptBool(void funOptBool([bool b])) {}
99+
class C {
100+
static void funBool(bool b) {}
101+
}
102+
main() {
103+
acceptFunOptBool(C.funBool);
104+
}''', [
105+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 125, 9),
106+
]);
107+
}
108+
}
109+
110+
mixin ArgumentTypeNotAssignableTestCases on PubPackageResolutionTest {
21111
test_ambiguousClassName() async {
22112
// See dartbug.com/19624
23113
newFile('$testPackageLibPath/lib2.dart', content: '''
@@ -290,30 +380,6 @@ class A<K, V> {
290380
]);
291381
}
292382

293-
test_invocation_functionTypes_optional() async {
294-
await assertErrorsInCode('''
295-
void acceptFunOptBool(void funNumOptBool([bool b])) {}
296-
void funBool(bool b) {}
297-
main() {
298-
acceptFunOptBool(funBool);
299-
}''', [
300-
error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 107, 7),
301-
]);
302-
}
303-
304-
test_invocation_functionTypes_optional_method() async {
305-
await assertErrorsInCode('''
306-
void acceptFunOptBool(void funOptBool([bool b])) {}
307-
class C {
308-
static void funBool(bool b) {}
309-
}
310-
main() {
311-
acceptFunOptBool(C.funBool);
312-
}''', [
313-
error(CompileTimeErrorCode.INVALID_CAST_METHOD, 125, 9),
314-
]);
315-
}
316-
317383
test_invocation_generic() async {
318384
await assertErrorsInCode('''
319385
class A<T> {
@@ -441,69 +507,20 @@ g(C c) {
441507
}
442508

443509
@reflectiveTest
444-
class ArgumentTypeNotAssignableWithNullSafetyTest
445-
extends ArgumentTypeNotAssignableTest with WithNullSafetyMixin {
446-
test_binary_eqEq_covariantParameterType() async {
447-
await assertErrorsInCode(r'''
448-
class A {
449-
bool operator==(covariant A other) => false;
450-
}
451-
452-
void f(A a, A? aq) {
453-
a == 0;
454-
aq == 1;
455-
aq == aq;
456-
aq == null;
457-
}
458-
''', [
459-
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 88, 1),
460-
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 99, 1),
461-
]);
462-
}
463-
464-
test_downcast() async {
465-
await assertErrorsInCode(r'''
466-
m() {
467-
num y = 1;
468-
n(y);
469-
}
470-
n(int x) {}
471-
''', [
472-
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 23, 1),
473-
]);
474-
}
475-
476-
@failingTest
477-
test_downcast_nullableNonNullable() async {
478-
await assertErrorsInCode(r'''
479-
m() {
480-
int? y;
481-
n(y);
482-
}
483-
n(int x) {}
484-
''', [
485-
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 24, 1),
486-
]);
487-
}
488-
489-
test_dynamicCast() async {
490-
await assertNoErrorsInCode(r'''
491-
m() {
492-
dynamic i;
493-
n(i);
494-
}
495-
n(int i) {}
496-
''');
497-
}
498-
499-
@failingTest
500-
@override
510+
class ArgumentTypeNotAssignableWithoutNullSafetyTest
511+
extends PubPackageResolutionTest
512+
with WithoutNullSafetyMixin, ArgumentTypeNotAssignableTestCases {
501513
test_invocation_functionTypes_optional() async {
502-
// The test is currently generating an error where none is expected.
503-
await super.test_invocation_functionTypes_optional();
514+
await assertErrorsInCode('''
515+
void acceptFunOptBool(void funNumOptBool([bool b])) {}
516+
void funBool(bool b) {}
517+
main() {
518+
acceptFunOptBool(funBool);
519+
}''', [
520+
error(CompileTimeErrorCode.INVALID_CAST_FUNCTION, 107, 7),
521+
]);
504522
}
505523

506-
@override
507524
test_invocation_functionTypes_optional_method() async {
508525
await assertErrorsInCode('''
509526
void acceptFunOptBool(void funOptBool([bool b])) {}
@@ -513,7 +530,7 @@ class C {
513530
main() {
514531
acceptFunOptBool(C.funBool);
515532
}''', [
516-
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 125, 9),
533+
error(CompileTimeErrorCode.INVALID_CAST_METHOD, 125, 9),
517534
]);
518535
}
519536
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ import 'lib1.dart' deferred as a;
3131
]);
3232
}
3333

34+
@FailingTest(reason: 'https://github.com/dart-lang/sdk/issues/45418')
35+
test_constructor_argument() async {
36+
newFile('$testPackageLibPath/lib1.dart', content: '''
37+
const x = 0;
38+
''');
39+
await assertErrorsInCode('''
40+
library root;
41+
import 'lib1.dart' deferred as a;
42+
class C { const C(int i); }
43+
@C(a.x) main () {}
44+
''', [
45+
error(
46+
CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY, 49, 3),
47+
]);
48+
}
49+
3450
test_from_deferred_library() async {
3551
newFile('$testPackageLibPath/lib1.dart', content: '''
3652
library lib1;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ main() {
1515

1616
@reflectiveTest
1717
class TypeAnnotationDeferredClassTest extends PubPackageResolutionTest {
18+
test_annotation_typeArgument() async {
19+
newFile('$testPackageLibPath/lib1.dart', content: '''
20+
class D {}
21+
''');
22+
await assertErrorsInCode('''
23+
library root;
24+
import 'lib1.dart' deferred as a;
25+
class C<T> { const C(); }
26+
@C<a.D>() main () {}
27+
''', [
28+
error(CompileTimeErrorCode.TYPE_ANNOTATION_DEFERRED_CLASS, 77, 3),
29+
]);
30+
}
31+
1832
test_asExpression() async {
1933
newFile('$testPackageLibPath/lib1.dart', content: '''
2034
library lib1;

0 commit comments

Comments
 (0)