@@ -35,91 +35,148 @@ void f(List<int> list) {
35
35
]);
36
36
}
37
37
38
- test_initializerInDeclaration_namedOptional () async {
39
- // TODO(srawlins): Any test which just assigns a function literal to a
40
- // variable should be converted to something like an argument, or let
41
- // downwards inference work in some other way.
42
- // See https://github.com/dart-lang/linter/issues/1099.
38
+ test_assignedToFunctionTypedTarget () async {
39
+ await assertDiagnostics (r'''
40
+ void f(C c) {
41
+ c.onFoo = (int p) {};
42
+ }
43
+ class C {
44
+ void Function(int p)? onFoo;
45
+ }
46
+ ''' , [
47
+ lint (27 , 3 ),
48
+ ]);
49
+ }
50
+
51
+ test_assignedToNonFunctionTypedTarget () async {
52
+ await assertNoDiagnostics (r'''
53
+ var onFoo = (int p) {};
54
+ ''' );
55
+ }
56
+
57
+ test_closureIsArgument_dartCoreFunctionType () async {
58
+ await assertNoDiagnostics (r'''
59
+ void f(Future<void> future) {
60
+ future.then((_) {}, onError: (e, st) {});
61
+ }
62
+ ''' );
63
+ }
64
+
65
+ test_closureIsArgument_namedOptional () async {
43
66
await assertNoDiagnostics (r'''
44
- var f = ({e}) => e.isEven;
67
+ void f(C c) {
68
+ c.map(({e}) => e?.isEven);
69
+ }
70
+ class C {
71
+ void map(void Function({int? e})) {}
72
+ }
45
73
''' );
46
74
}
47
75
48
- test_initializerInDeclaration_optionalNullable () async {
49
- // TODO(srawlins): Any test which just assigns a function literal to a
50
- // variable should be converted to something like an argument, or let
51
- // downwards inference work in some other way.
52
- // See https://github.com/dart-lang/linter/issues/1099.
76
+ test_closureIsArgument_optionalNullable () async {
53
77
await assertNoDiagnostics (r'''
54
- var f = ([e]) => e.name;
78
+ void f(C c) {
79
+ c.map(([e]) => e?.isEven);
80
+ }
81
+ class C {
82
+ void map(void Function([int? e])) {}
83
+ }
55
84
''' );
56
85
}
57
86
58
- test_initializerInDeclaration_optionalWithDefault () async {
59
- // TODO(srawlins): Any test which just assigns a function literal to a
60
- // variable should be converted to something like an argument, or let
61
- // downwards inference work in some other way.
62
- // See https://github.com/dart-lang/linter/issues/1099.
87
+ test_closureIsArgument_optionalWithDefault () async {
63
88
await assertNoDiagnostics (r'''
64
- var f = ({e = ''}) => e;
89
+ void f(C c) {
90
+ c.map(({e = 7}) => e?.isEven);
91
+ }
92
+ class C {
93
+ void map(void Function({int? e})) {}
94
+ }
65
95
''' );
66
96
}
67
97
68
- test_initializerInDeclaration_parameterIsTyped_dynamic () async {
69
- // TODO(srawlins): Any test which just assigns a function literal to a
70
- // variable should be converted to something like an argument, or let
71
- // downwards inference work in some other way.
72
- // See https://github.com/dart-lang/linter/issues/1099.
98
+ test_closureIsArgument_parameterIsTyped_dynamic () async {
73
99
await assertNoDiagnostics (r'''
74
- var goodName5 = (dynamic person) => person.name;
100
+ void f(C c) {
101
+ c.map((dynamic p) => p);
102
+ }
103
+ class C {
104
+ void map(int Function(dynamic p)) {}
105
+ }
75
106
''' );
76
107
}
77
108
78
- test_initializerInDeclaration_parameterIsTyped_functionType () async {
79
- // TODO(srawlins): Any test which just assigns a function literal to a
80
- // variable should be converted to something like an argument, or let
81
- // downwards inference work in some other way.
82
- // See https://github.com/dart-lang/linter/issues/1099.
109
+ test_closureIsArgument_parameterIsTyped_functionType () async {
83
110
await assertDiagnostics (r'''
84
- var functionWithFunction = (int f(int x)) => f(0);
111
+ void f(List<int Function(int)> list) {
112
+ list.map((int p(int x)) => p(0));
113
+ }
85
114
''' , [
86
- lint (28 , 12 ),
115
+ lint (51 , 12 ),
87
116
]);
88
117
}
89
118
90
- test_initializerInDeclaration_parameterIsTyped_namedRequired () async {
91
- // TODO(srawlins): Any test which just assigns a function literal to a
92
- // variable should be converted to something like an argument, or let
93
- // downwards inference work in some other way.
94
- // See https://github.com/dart-lang/linter/issues/1099.
119
+ test_closureIsArgument_parameterIsTyped_namedRequired () async {
95
120
await assertDiagnostics (r'''
96
- var f = ({required int e}) => e.isEven;
121
+ void f(C c) {
122
+ c.map(({required int p}) => p);
123
+ }
124
+ class C {
125
+ void map(int Function({required int p})) {}
126
+ }
97
127
''' , [
98
- lint (19 , 3 ),
128
+ lint (33 , 3 ),
99
129
]);
100
130
}
101
131
102
- test_initializerInDeclaration_parameterIsTyped_optionalNullable () async {
103
- // TODO(srawlins): Any test which just assigns a function literal to a
104
- // variable should be converted to something like an argument, or let
105
- // downwards inference work in some other way.
106
- // See https://github.com/dart-lang/linter/issues/1099.
132
+ test_closureIsArgument_parameterIsTyped_optionalNullable () async {
107
133
await assertDiagnostics (r'''
108
- var f = ([int? e]) => e?.isEven;
134
+ void f(C c) {
135
+ c.map(([int? p]) => p);
136
+ }
137
+ class C {
138
+ void map(int? Function([int? p])) {}
139
+ }
109
140
''' , [
110
- lint (10 , 4 ),
141
+ lint (24 , 4 ),
111
142
]);
112
143
}
113
144
114
- test_initializerInDeclaration_parameterIsTyped_optionalWithDefault () async {
115
- // TODO(srawlins): Any test which just assigns a function literal to a
116
- // variable should be converted to something like an argument, or let
117
- // downwards inference work in some other way.
118
- // See https://github.com/dart-lang/linter/issues/1099.
145
+ test_closureIsArgument_parameterIsTyped_optionalWithDefault () async {
119
146
await assertDiagnostics (r'''
120
- var f = ([String e = '']) => e;
147
+ void f(C c) {
148
+ c.map(([int p = 0]) => p);
149
+ }
150
+ class C {
151
+ void map(int? Function([int p])) {}
152
+ }
121
153
''' , [
122
- lint (10 , 6 ),
154
+ lint (24 , 3 ),
123
155
]);
124
156
}
157
+
158
+ test_parameterIsNotInClosure_inFunction () async {
159
+ await assertNoDiagnostics (r'''
160
+ void f(int p) {}
161
+ ''' );
162
+ }
163
+
164
+ test_parameterIsNotInClosure_inLocalFunction () async {
165
+ await assertNoDiagnostics (r'''
166
+ void f(List<int> list) {
167
+ list.map((e) {
168
+ void g(int p) {}
169
+ return g(e);
170
+ });
171
+ }
172
+ ''' );
173
+ }
174
+
175
+ test_parameterIsNotInClosure_inMethod () async {
176
+ await assertNoDiagnostics (r'''
177
+ class C {
178
+ void f(int p) {}
179
+ }
180
+ ''' );
181
+ }
125
182
}
0 commit comments