Skip to content

Commit 5c332be

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Stop using 'factory something() => null;' in most cases.
I did not change MockSdk, to avoid conflict with https://dart-review.googlesource.com/c/sdk/+/135241 [email protected] Bug: #40603 Change-Id: I9f0af20f5914b5ac1aefee02aa8052db269529b5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135532 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 3d1b8b2 commit 5c332be

28 files changed

+80
-70
lines changed

pkg/analysis_server/test/analysis/notification_highlights2_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ external main() {
140140
Future<void> test_BUILT_IN_factory() async {
141141
addTestFile('''
142142
class A {
143-
factory A() => null;
143+
A.named();
144+
factory A() => A.named();
144145
}
145146
main() {
146147
var factory = 42;

pkg/analysis_server/test/analysis/notification_highlights_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ external main() {
140140
Future<void> test_BUILT_IN_factory() async {
141141
addTestFile('''
142142
class A {
143-
factory A() => null;
143+
A.named();
144+
factory A() => A();
144145
}
145146
main() {
146147
var factory = 42;

pkg/analysis_server/test/completion_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ class FileMode {
562562
final int _mode;
563563
}
564564
class File {
565-
factory File(String path) => null;
566-
factory File.fromPath(Path path) => null;
565+
File(String path);
566+
File.fromPath(Path path);
567567
}
568568
f() => new Fil!1''', <String>[
569569
'1+File',

pkg/analysis_server/test/domain_completion_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class A {
5555

5656
Future<void> test_ArgumentList_factory_named_param_label() async {
5757
addTestFile('main() { new A(^);}'
58-
'class A { factory A({one, two}) => null; }');
58+
'class A { factory A({one, two}) => throw 0; }');
5959
await getSuggestions();
6060
assertHasResult(CompletionSuggestionKind.NAMED_ARGUMENT, 'one: ',
6161
relevance: DART_RELEVANCE_NAMED_PARAMETER);

pkg/analysis_server/test/services/completion/dart/arglist_contributor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ foo({String children}) {}
606606
Future<void> test_ArgumentList_imported_factory_named_param() async {
607607
// ArgumentList InstanceCreationExpression ExpressionStatement
608608
addSource('/home/test/lib/a.dart',
609-
'library libA; class A{factory A({int one}) => null;}');
609+
'library libA; class A{factory A({int one}) => throw 0;}');
610610
addTestSource('import "a.dart"; main() { new A(^);}');
611611
await computeSuggestions();
612612
assertSuggestArgumentsAndTypes(namedArgumentsWithTypes: {'one': 'int'});

pkg/analysis_server/test/services/completion/dart/imported_reference_contributor_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ main() {new ^ String x = "hello";}''');
26102610
abstract class A {
26112611
A();
26122612
A.generative();
2613-
factory A.factory() => null;
2613+
factory A.factory() => A();
26142614
}
26152615
''');
26162616
addTestSource('''
@@ -3623,7 +3623,7 @@ class B extends A {
36233623
var m;''');
36243624
addTestSource('''
36253625
part of libA;
3626-
class B { factory B.bar(int x) => null; }
3626+
class B { B.bar(int x); }
36273627
main() {new ^}''');
36283628

36293629
await computeSuggestions();

pkg/analysis_server/test/services/completion/dart/local_constructor_contributor_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ main() {new ^ String x = "hello";}''');
23872387
abstract class A {
23882388
A();
23892389
A.generative();
2390-
factory A.factory() => null;
2390+
factory A.factory() => A();
23912391
}
23922392
23932393
main() {
@@ -3285,7 +3285,7 @@ class A { }
32853285
var m;''');
32863286
addTestSource('''
32873287
part of libA;
3288-
class B { factory B.bar(int x) => null; }
3288+
class B { B.bar(int x); }
32893289
main() {new ^}''');
32903290
await computeSuggestions();
32913291

pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LocalLibraryContributorTest extends DartCompletionContributorTest {
3939
var m;''');
4040
addTestSource('''
4141
part of libA;
42-
class B { factory B.bar(int x) => null; }
42+
class B { B.bar(int x); }
4343
main() {new ^}''');
4444
await computeSuggestions();
4545
expect(replacementOffset, completionOffset);
@@ -212,7 +212,7 @@ class LocalLibraryContributorTest extends DartCompletionContributorTest {
212212
int af() {return 0;}''');
213213
addTestSource('''
214214
part of libA;
215-
class B { factory B.bar(int x) => null; }
215+
class B { B.bar(int x); }
216216
main() {^}''');
217217
await computeSuggestions();
218218
expect(replacementOffset, completionOffset);

pkg/analysis_server/test/services/completion/dart/local_reference_contributor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,7 @@ class A { }
41214121
var m;''');
41224122
addTestSource('''
41234123
part of libA;
4124-
class B { factory B.bar(int x) => null; }
4124+
class B { B.bar(int x); }
41254125
main() {new ^}''');
41264126
await computeSuggestions();
41274127

pkg/analysis_server/test/services/completion/dart/type_member_contributor_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3238,7 +3238,7 @@ void main() {C.^ print("something");}''');
32383238
var m;''');
32393239
addTestSource('''
32403240
part of libA;
3241-
class B { factory B.bar(int x) => null; }
3241+
class B { B.bar(int x); }
32423242
main() {new ^}''');
32433243
await computeSuggestions();
32443244
expect(replacementOffset, completionOffset);

pkg/analysis_server/test/services/correction/sort_members_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ class A {
248248
/// constructor generative unnamed
249249
A();
250250
/// constructor factory unnamed
251-
factory A() => null;
251+
factory A() => A();
252252
/// constructor generative public
253253
A.nnn();
254254
/// constructor factory public
255-
factory A.ooo() => null;
255+
factory A.ooo() => A();
256256
/// constructor generative private
257257
A._nnn();
258258
/// constructor factory private
259-
factory A._ooo() => null;
259+
factory A._ooo() => A();
260260
}
261261
''');
262262
// validate change
@@ -281,15 +281,15 @@ class A {
281281
/// constructor generative unnamed
282282
A();
283283
/// constructor factory unnamed
284-
factory A() => null;
284+
factory A() => A();
285285
/// constructor generative public
286286
A.nnn();
287287
/// constructor factory public
288-
factory A.ooo() => null;
288+
factory A.ooo() => A();
289289
/// constructor generative private
290290
A._nnn();
291291
/// constructor factory private
292-
factory A._ooo() => null;
292+
factory A._ooo() => A();
293293
/// instance getter public
294294
int get nnn => null;
295295
/// instance setter public

pkg/analysis_server/test/src/services/correction/assist/convert_into_block_body_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ main() {
7373
Future<void> test_constructor() async {
7474
await resolveTestUnit('''
7575
class A {
76-
factory A() => null;
76+
A.named();
77+
78+
factory A() => A.named();
7779
}
7880
''');
7981
await assertHasAssistAt('A()', '''
8082
class A {
83+
A.named();
84+
8185
factory A() {
82-
return null;
86+
return A.named();
8387
}
8488
}
8589
''');

pkg/analysis_server/test/src/services/correction/assist/convert_into_expression_body_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,18 @@ main() {
9393
Future<void> test_constructor() async {
9494
await resolveTestUnit('''
9595
class A {
96+
A.named();
97+
9698
factory A() {
97-
return null;
99+
return A.named();
98100
}
99101
}
100102
''');
101103
await assertHasAssistAt('A()', '''
102104
class A {
103-
factory A() => null;
105+
A.named();
106+
107+
factory A() => A.named();
104108
}
105109
''');
106110
}

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ class B extends A {
921921
await assertErrorsInCode(r'''
922922
class A {
923923
int x;
924-
factory A(this.x) => null;
924+
factory A(this.x) => throw 0;
925925
}
926926
''', [
927927
error(CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, 31, 6),

pkg/analyzer/test/generated/non_error_resolver_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ class B extends Object with A {}
24172417
test_mixinDeclaresConstructor_factory() async {
24182418
await assertNoErrorsInCode(r'''
24192419
class A {
2420-
factory A() => null;
2420+
factory A() => throw 0;
24212421
}
24222422
class B extends Object with A {}
24232423
''');

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ void Function<A>(core.List<core.int> x) m() => null;
14181418
}
14191419

14201420
void test_parseClassMember_redirectingFactory_expressionBody() {
1421-
createParser('factory C() => null;');
1421+
createParser('factory C() => throw 0;');
14221422
var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
14231423
assertNoErrors();
14241424
expect(constructor, isNotNull);
@@ -1494,7 +1494,7 @@ void Function<A>(core.List<core.int> x) m() => null;
14941494
}
14951495

14961496
void test_parseConstructor_factory_named() {
1497-
createParser('factory C.foo() => null;');
1497+
createParser('factory C.foo() => throw 0;');
14981498
var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
14991499
assertNoErrors();
15001500
expect(constructor, isNotNull);

pkg/analyzer/test/generated/simple_resolver_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ class C = Object with A;''', [
853853
test_isValidMixin_factoryConstructor() async {
854854
await assertNoErrorsInCode(r'''
855855
class A {
856-
factory A() => null;
856+
factory A() => throw 0;
857857
}
858858
class C = Object with A;''');
859859
verifyTestResolved();

pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,8 @@ main() {
20182018
test_instanceCreation_factory() async {
20192019
String content = r'''
20202020
class C {
2021-
factory C() => null;
2022-
factory C.named() => null;
2021+
factory C() => throw 0;
2022+
factory C.named() => throw 0;
20232023
}
20242024
var a = new C();
20252025
var b = new C.named();
@@ -3153,7 +3153,7 @@ main() {
31533153
test_invalid_instanceCreation_constOfNotConst_factory() async {
31543154
addTestFile(r'''
31553155
class C {
3156-
factory C(x) => null;
3156+
factory C(x) => throw 0;
31573157
}
31583158
31593159
var a = 0;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class InvalidFactoryNameNotAClassTest extends DriverResolutionTest {
1919
await assertErrorsInCode(r'''
2020
int B;
2121
class A {
22-
factory B() => null;
22+
factory B() => throw 0;
2323
}
2424
''', [
2525
error(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, 27, 1),
@@ -29,7 +29,7 @@ class A {
2929
test_notEnclosingClassName() async {
3030
await assertErrorsInCode(r'''
3131
class A {
32-
factory B() => null;
32+
factory B() => throw 0;
3333
}
3434
''', [
3535
error(CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS, 20, 1),
@@ -39,7 +39,7 @@ class A {
3939
test_valid() async {
4040
await assertNoErrorsInCode(r'''
4141
class A {
42-
factory A() => null;
42+
factory A() => throw 0;
4343
}
4444
''');
4545
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ class NonGenerativeConstructorTest extends DriverResolutionTest {
1818
test_explicit() async {
1919
await assertErrorsInCode(r'''
2020
class A {
21-
factory A.named() => null;
21+
factory A.named() => throw 0;
2222
}
2323
class B extends A {
2424
B() : super.named();
2525
}
2626
''', [
27-
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 69, 13),
27+
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 72, 13),
2828
]);
2929
}
3030

3131
test_generative() async {
3232
await assertNoErrorsInCode(r'''
3333
class A {
3434
A.named() {}
35-
factory A() => null;
35+
factory A() => throw 0;
3636
}
3737
class B extends A {
3838
B() : super.named();
@@ -43,25 +43,25 @@ class B extends A {
4343
test_implicit() async {
4444
await assertErrorsInCode(r'''
4545
class A {
46-
factory A() => null;
46+
factory A() => throw 0;
4747
}
4848
class B extends A {
4949
B();
5050
}
5151
''', [
52-
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 57, 1),
52+
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 60, 1),
5353
]);
5454
}
5555

5656
test_implicit2() async {
5757
await assertErrorsInCode(r'''
5858
class A {
59-
factory A() => null;
59+
factory A() => throw 0;
6060
}
6161
class B extends A {
6262
}
6363
''', [
64-
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 41, 1),
64+
error(CompileTimeErrorCode.NON_GENERATIVE_CONSTRUCTOR, 44, 1),
6565
]);
6666
}
6767
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class B implements A {
134134
factory B() = C;
135135
}
136136
class C implements B {
137-
factory C() => null;
137+
factory C() => throw 0;
138138
}
139139
''');
140140
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RedirectGenerativeToNonGenerativeConstructorTest
2020
await assertErrorsInCode(r'''
2121
class A {
2222
A() : this.x();
23-
factory A.x() => null;
23+
factory A.x() => throw 0;
2424
}
2525
''', [
2626
error(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void f(d) {
228228
test_factoryConstructor_notUsed_multiple() async {
229229
await assertErrorsInCode(r'''
230230
class A {
231-
factory A._factory() => null;
231+
factory A._factory() => A();
232232
A();
233233
}
234234
''', [
@@ -239,7 +239,7 @@ class A {
239239
test_factoryConstructor_notUsed_single() async {
240240
await assertNoErrorsInCode(r'''
241241
class A {
242-
factory A._factory() => null;
242+
factory A._factory() => throw 0;
243243
}
244244
''');
245245
}

pkg/analyzer/test/src/fasta/ast_builder_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AstBuilderTest extends FastaParserTestCase {
1919
void test_constructor_factory_misnamed() {
2020
CompilationUnit unit = parseCompilationUnit('''
2121
class A {
22-
factory B() => null;
22+
factory B() => throw 0;
2323
}
2424
''');
2525
expect(unit, isNotNull);

0 commit comments

Comments
 (0)