Skip to content

Commit

Permalink
Legacy. Remove expectedErrorsByNullability()
Browse files Browse the repository at this point in the history
Change-Id: I23cf2c905134e009d6e371e46920242f23502b91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346680
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 16, 2024
1 parent a4bfeb1 commit b03a417
Show file tree
Hide file tree
Showing 25 changed files with 202 additions and 382 deletions.
15 changes: 5 additions & 10 deletions pkg/analyzer/test/generated/strong_mode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4107,23 +4107,18 @@ MethodInvocation
}

test_genericMethod_nestedCaptureBounds() async {
await assertErrorsInCode(
r'''
await assertErrorsInCode(r'''
class C<T> {
T f<S extends T>(S x) {
new C<S>().f<int>(3);
new C<S>().f; // tear-off
return null;
}
}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 3),
error(
CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 106, 4),
], legacy: [
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 3),
]));
''', [
error(CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 56, 3),
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_METHOD, 106, 4),
]);

final node1 = findNode.methodInvocation('f<int>(3);');
assertResolvedNodeText(node1, r'''
Expand Down
20 changes: 8 additions & 12 deletions pkg/analyzer/test/src/dart/resolution/binary_expression_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1563,17 +1563,15 @@ BinaryExpression
}

test_plus_num_context_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
T f<T>() => throw Error();
g(num a) {
h(a + f());
}
h(int x) {}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 42, 7),
], legacy: []));
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 42, 7),
]);

final node = findNode.methodInvocation('f()');
assertResolvedNodeText(node, r'''
Expand All @@ -1594,8 +1592,7 @@ MethodInvocation
}

test_plus_other_context_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
abstract class A {
num operator+(String x);
}
Expand All @@ -1604,10 +1601,9 @@ g(A a) {
h(a + f());
}
h(int x) {}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 88, 7),
], legacy: []));
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 88, 7),
]);

final node = findNode.methodInvocation('f()');
assertResolvedNodeText(node, r'''
Expand Down
77 changes: 28 additions & 49 deletions pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,15 @@ MethodInvocation
}

test_clamp_double_context_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
T f<T>() => throw Error();
g(double a) {
h(a.clamp(f(), f()));
}
h(int x) {}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 45, 17),
], legacy: []));
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 45, 17),
]);

var node = findNode.methodInvocation('h(a');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -482,17 +480,15 @@ MethodInvocation
}

test_clamp_int_context_double() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
T f<T>() => throw Error();
g(int a) {
h(a.clamp(f(), f()));
}
h(double x) {}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 42, 17),
], legacy: []));
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 42, 17),
]);

var node = findNode.methodInvocation('h(a');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -981,15 +977,11 @@ MethodInvocation
}

test_clamp_int_int_int_from_cascade() async {
await assertErrorsInCode(
'''
await assertNoErrorsInCode('''
f(int a, int b, int c) {
a..clamp(b, c).isEven;
}
''',
expectedErrorsByNullability(nullable: [], legacy: [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 42, 6),
]));
''');

var node = findNode.methodInvocation('clamp');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -1108,15 +1100,13 @@ MethodInvocation
}

test_clamp_int_never_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
f(int a, Never b, int c) {
a.clamp(b, c);
}
''',
expectedErrorsByNullability(nullable: [
error(WarningCode.DEAD_CODE, 40, 3),
], legacy: []));
''', [
error(WarningCode.DEAD_CODE, 40, 3),
]);

var node = findNode.methodInvocation('clamp');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -1150,18 +1140,14 @@ MethodInvocation
}

test_clamp_never_int_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
f(Never a, int b, int c) {
a.clamp(b, c);
}
''',
expectedErrorsByNullability(nullable: [
error(WarningCode.RECEIVER_OF_TYPE_NEVER, 29, 1),
error(WarningCode.DEAD_CODE, 36, 7),
], legacy: [
error(CompileTimeErrorCode.UNDEFINED_METHOD, 31, 5),
]));
''', [
error(WarningCode.RECEIVER_OF_TYPE_NEVER, 29, 1),
error(WarningCode.DEAD_CODE, 36, 7),
]);

var node = findNode.methodInvocation('clamp');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -1195,8 +1181,7 @@ MethodInvocation
}

test_clamp_other_context_int() async {
await assertErrorsInCode(
'''
await assertErrorsInCode('''
abstract class A {
num clamp(String x, String y);
}
Expand All @@ -1205,10 +1190,9 @@ g(A a) {
h(a.clamp(f(), f()));
}
h(int x) {}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 94, 17),
], legacy: []));
''', [
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 94, 17),
]);

var node = findNode.methodInvocation('h(a');
assertResolvedNodeText(node, r'''
Expand Down Expand Up @@ -2653,20 +2637,15 @@ main() {
}

test_error_undefinedMethod_typeLiteral_conditional() async {
await assertErrorsInCode(
r'''
await assertErrorsInCode(r'''
class A {}
main() {
A?.toString();
}
''',
expectedErrorsByNullability(nullable: [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 23, 2),
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
], legacy: [
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
]),
);
''', [
error(StaticWarningCode.INVALID_NULL_AWARE_OPERATOR, 23, 2),
error(CompileTimeErrorCode.UNDEFINED_METHOD, 25, 8),
]);
}

test_error_unqualifiedReferenceToNonLocalStaticMember_method() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,16 +851,13 @@ PrefixExpression
}

test_plusPlus_simpleIdentifier_parameter_typeParameter() async {
await assertErrorsInCode(
r'''
await assertErrorsInCode(r'''
void f<T extends num>(T x) {
++x;
}
''',
expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 31, 3),
], legacy: []),
);
''', [
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 31, 3),
]);

var node = findNode.prefix('++x');
assertResolvedNodeText(node, r'''
Expand Down
16 changes: 5 additions & 11 deletions pkg/analyzer/test/src/dart/resolution/property_access_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2283,22 +2283,16 @@ PropertyAccess
}

test_targetTypeParameter_noBound() async {
await resolveTestCode('''
await assertErrorsInCode('''
class C<T> {
void f(T t) {
(t).foo;
}
}
''');
assertErrorsInResult(expectedErrorsByNullability(
nullable: [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
37, 3),
],
legacy: [
error(CompileTimeErrorCode.UNDEFINED_GETTER, 37, 3),
],
));
''', [
error(CompileTimeErrorCode.UNCHECKED_PROPERTY_ACCESS_OF_NULLABLE_VALUE,
37, 3),
]);

final node = findNode.singlePropertyAccess;
assertResolvedNodeText(node, r'''
Expand Down
11 changes: 0 additions & 11 deletions pkg/analyzer/test/src/dart/resolution/resolution.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,6 @@ mixin ResolutionTest implements ResourceProviderMixin {
messageContains: messageContains,
expectedContextMessages: contextMessages);

List<ExpectedError> expectedErrorsByNullability({
required List<ExpectedError> nullable,
required List<ExpectedError> legacy,
}) {
if (isNullSafetyEnabled) {
return nullable;
} else {
return legacy;
}
}

String getMacroCode(String relativePath) {
final code = MacrosEnvironment.instance.packageAnalyzerFolder
.getChildAssumingFile('test/src/summary/macro/$relativePath')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,15 @@ void test(dynamic a) {
}

test_contextFunctionType_returnType_async_blockBody_futureOrVoid() async {
var expectedErrors = expectedErrorsByNullability(
nullable: [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 72, 1),
],
legacy: [],
);
await assertErrorsInCode('''
import 'dart:async';
FutureOr<void> Function() v = () async {
return 0;
};
''', expectedErrors);
''', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 72, 1),
]);
_assertReturnType(
'() async {',
typeStringByNullability(
Expand All @@ -99,17 +95,13 @@ FutureOr<void> Function() v = () async {
}

test_contextFunctionType_returnType_async_blockBody_futureVoid() async {
var expectedErrors = expectedErrorsByNullability(
nullable: [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 48, 1),
],
legacy: [],
);
await assertErrorsInCode('''
Future<void> Function() v = () async {
return 0;
};
''', expectedErrors);
''', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 48, 1),
]);
_assertReturnType(
'() async {',
typeStringByNullability(
Expand Down Expand Up @@ -391,14 +383,13 @@ FunctionExpression
}

test_contextFunctionType_returnType_sync_blockBody_void() async {
var expectedErrors = expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 34, 1),
], legacy: []);
await assertErrorsInCode('''
void Function() v = () {
return 0;
};
''', expectedErrors);
''', [
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_CLOSURE, 34, 1),
]);
_assertReturnType(
'() {',
typeStringByNullability(
Expand Down
Loading

0 comments on commit b03a417

Please sign in to comment.