Skip to content

Commit 26bfbd4

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
analyzer tests: Remove the WithNullSafety mixin
Two remaining test files are modified to use the TestCases structure. In each case, the tests are unchanged, but the classes are renamed. Additionally, each file had a *WtihNonFunctionTypes variant. Each of these classes just specified more test cases that include some form of "typeAlias" in the name, and can be safely merged with the null safety test cases. Fixes #44666 Bug: #44666 Change-Id: Id7db1038e64f8bbc12764cb558670b23427a5a86 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209763 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 79181ab commit 26bfbd4

File tree

4 files changed

+489
-509
lines changed

4 files changed

+489
-509
lines changed

pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart

-10
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,6 @@ mixin WithNoImplicitCastsMixin on PubPackageResolutionTest {
414414
}
415415
}
416416

417-
mixin WithNullSafetyMixin on PubPackageResolutionTest {
418-
// TODO(https://github.com/dart-lang/sdk/issues/44666): This mixin is a no-op
419-
// on PubPackageResolutionTest; remove its usage and remove it.
420-
@override
421-
String? get testPackageLanguageVersion => '2.14';
422-
423-
@override
424-
bool get typeToStringWithNullability => true;
425-
}
426-
427417
mixin WithoutConstructorTearoffsMixin on PubPackageResolutionTest {
428418
@override
429419
String? get testPackageLanguageVersion => '2.13';

pkg/analyzer/test/src/dart/resolution/language_version_test.dart

-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ var z = pi;
101101

102102
@reflectiveTest
103103
class NullSafetyUsingAllowedExperimentsTest extends _FeaturesTest {
104-
@override
105-
bool get typeToStringWithNullability => true;
106-
107104
test_jsonConfig_disable_bin() async {
108105
_configureAllowedExperimentsTestNullSafety();
109106

pkg/analyzer/test/src/dart/resolution/prefixed_identifier_test.dart

+124-128
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,132 @@ import 'context_collection_resolution.dart';
1111
main() {
1212
defineReflectiveSuite(() {
1313
defineReflectiveTests(PrefixedIdentifierResolutionTest);
14-
defineReflectiveTests(PrefixedIdentifierResolutionWithNullSafetyTest);
15-
defineReflectiveTests(
16-
PrefixedIdentifierResolutionWithNonFunctionTypeAliasesTest,
17-
);
14+
defineReflectiveTests(PrefixedIdentifierResolutionWithoutNullSafetyTest);
1815
});
1916
}
2017

2118
@reflectiveTest
2219
class PrefixedIdentifierResolutionTest extends PubPackageResolutionTest
23-
with WithoutNullSafetyMixin {
20+
with PrefixedIdentifierResolutionTestCases {
21+
test_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
22+
newFile('$testPackageLibPath/a.dart', content: r'''
23+
class A {}
24+
''');
25+
26+
await assertErrorsInCode(r'''
27+
// @dart = 2.7
28+
import 'a.dart' deferred as a;
29+
30+
main() {
31+
a.loadLibrary;
32+
}
33+
''', [
34+
error(HintCode.UNUSED_IMPORT, 22, 8),
35+
]);
36+
37+
var import = findElement.importFind('package:test/a.dart');
38+
39+
assertPrefixedIdentifier(
40+
findNode.prefixed('a.loadLibrary'),
41+
element: elementMatcher(
42+
import.importedLibrary.loadLibraryFunction,
43+
isLegacy: true,
44+
),
45+
type: 'Future<dynamic>* Function()*',
46+
);
47+
}
48+
49+
test_hasReceiver_typeAlias_staticGetter() async {
50+
await assertNoErrorsInCode(r'''
51+
class A {
52+
static int get foo => 0;
53+
}
54+
55+
typedef B = A;
56+
57+
void f() {
58+
B.foo;
59+
}
60+
''');
61+
62+
assertPrefixedIdentifier(
63+
findNode.prefixed('B.foo'),
64+
element: findElement.getter('foo'),
65+
type: 'int',
66+
);
67+
68+
assertTypeAliasRef(
69+
findNode.simple('B.foo'),
70+
findElement.typeAlias('B'),
71+
);
72+
73+
assertSimpleIdentifier(
74+
findNode.simple('foo;'),
75+
element: findElement.getter('foo'),
76+
type: 'int',
77+
);
78+
}
79+
80+
test_implicitCall_tearOff_nullable() async {
81+
newFile('$testPackageLibPath/a.dart', content: r'''
82+
class A {
83+
int call() => 0;
84+
}
85+
86+
A? a;
87+
''');
88+
await assertErrorsInCode('''
89+
import 'a.dart';
90+
91+
int Function() foo() {
92+
return a;
93+
}
94+
''', [
95+
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 50, 1),
96+
]);
97+
98+
var identifier = findNode.simple('a;');
99+
assertElement(
100+
identifier,
101+
findElement.importFind('package:test/a.dart').topGet('a'),
102+
);
103+
assertType(identifier, 'A?');
104+
}
105+
106+
test_read_typedef_interfaceType() async {
107+
newFile('$testPackageLibPath/a.dart', content: r'''
108+
typedef A = List<int>;
109+
''');
110+
111+
await assertNoErrorsInCode('''
112+
import 'a.dart' as p;
113+
114+
void f() {
115+
p.A;
116+
}
117+
''');
118+
119+
var importFind = findElement.importFind('package:test/a.dart');
120+
var A = importFind.typeAlias('A');
121+
122+
var prefixed = findNode.prefixed('p.A');
123+
assertPrefixedIdentifier(
124+
prefixed,
125+
element: A,
126+
type: 'Type',
127+
);
128+
129+
assertImportPrefix(prefixed.prefix, importFind.prefix);
130+
131+
assertSimpleIdentifier(
132+
prefixed.identifier,
133+
element: A,
134+
type: 'Type',
135+
);
136+
}
137+
}
138+
139+
mixin PrefixedIdentifierResolutionTestCases on PubPackageResolutionTest {
24140
test_dynamic_explicitCore_withPrefix() async {
25141
await assertNoErrorsInCode(r'''
26142
import 'dart:core' as mycore;
@@ -289,126 +405,6 @@ void f(A a) {
289405
}
290406

291407
@reflectiveTest
292-
class PrefixedIdentifierResolutionWithNonFunctionTypeAliasesTest
293-
extends PubPackageResolutionTest {
294-
test_hasReceiver_typeAlias_staticGetter() async {
295-
await assertNoErrorsInCode(r'''
296-
class A {
297-
static int get foo => 0;
298-
}
299-
300-
typedef B = A;
301-
302-
void f() {
303-
B.foo;
304-
}
305-
''');
306-
307-
assertPrefixedIdentifier(
308-
findNode.prefixed('B.foo'),
309-
element: findElement.getter('foo'),
310-
type: 'int',
311-
);
312-
313-
assertTypeAliasRef(
314-
findNode.simple('B.foo'),
315-
findElement.typeAlias('B'),
316-
);
317-
318-
assertSimpleIdentifier(
319-
findNode.simple('foo;'),
320-
element: findElement.getter('foo'),
321-
type: 'int',
322-
);
323-
}
324-
325-
test_read_typedef_interfaceType() async {
326-
newFile('$testPackageLibPath/a.dart', content: r'''
327-
typedef A = List<int>;
328-
''');
329-
330-
await assertNoErrorsInCode('''
331-
import 'a.dart' as p;
332-
333-
void f() {
334-
p.A;
335-
}
336-
''');
337-
338-
var importFind = findElement.importFind('package:test/a.dart');
339-
var A = importFind.typeAlias('A');
340-
341-
var prefixed = findNode.prefixed('p.A');
342-
assertPrefixedIdentifier(
343-
prefixed,
344-
element: A,
345-
type: 'Type',
346-
);
347-
348-
assertImportPrefix(prefixed.prefix, importFind.prefix);
349-
350-
assertSimpleIdentifier(
351-
prefixed.identifier,
352-
element: A,
353-
type: 'Type',
354-
);
355-
}
356-
}
357-
358-
@reflectiveTest
359-
class PrefixedIdentifierResolutionWithNullSafetyTest
360-
extends PrefixedIdentifierResolutionTest with WithNullSafetyMixin {
361-
test_deferredImportPrefix_loadLibrary_optIn_fromOptOut() async {
362-
newFile('$testPackageLibPath/a.dart', content: r'''
363-
class A {}
364-
''');
365-
366-
await assertErrorsInCode(r'''
367-
// @dart = 2.7
368-
import 'a.dart' deferred as a;
369-
370-
main() {
371-
a.loadLibrary;
372-
}
373-
''', [
374-
error(HintCode.UNUSED_IMPORT, 22, 8),
375-
]);
376-
377-
var import = findElement.importFind('package:test/a.dart');
378-
379-
assertPrefixedIdentifier(
380-
findNode.prefixed('a.loadLibrary'),
381-
element: elementMatcher(
382-
import.importedLibrary.loadLibraryFunction,
383-
isLegacy: true,
384-
),
385-
type: 'Future<dynamic>* Function()*',
386-
);
387-
}
388-
389-
test_implicitCall_tearOff_nullable() async {
390-
newFile('$testPackageLibPath/a.dart', content: r'''
391-
class A {
392-
int call() => 0;
393-
}
394-
395-
A? a;
396-
''');
397-
await assertErrorsInCode('''
398-
import 'a.dart';
399-
400-
int Function() foo() {
401-
return a;
402-
}
403-
''', [
404-
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 50, 1),
405-
]);
406-
407-
var identifier = findNode.simple('a;');
408-
assertElement(
409-
identifier,
410-
findElement.importFind('package:test/a.dart').topGet('a'),
411-
);
412-
assertType(identifier, 'A?');
413-
}
414-
}
408+
class PrefixedIdentifierResolutionWithoutNullSafetyTest
409+
extends PubPackageResolutionTest
410+
with PrefixedIdentifierResolutionTestCases, WithoutNullSafetyMixin {}

0 commit comments

Comments
 (0)