Skip to content

Commit 357f8b7

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Extract and augment DUPLICATE_DEFINITION tests.
[email protected] Change-Id: Idbf6db69ea51ec784b3a8bf94586ea4d535252d5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112681 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 261fd62 commit 357f8b7

File tree

7 files changed

+998
-568
lines changed

7 files changed

+998
-568
lines changed

pkg/analyzer/test/generated/compile_time_error_code.dart

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,186 +1097,6 @@ main() {
10971097
]);
10981098
}
10991099

1100-
test_duplicateDefinition_acrossLibraries() async {
1101-
var libFile = newFile('/test/lib/lib.dart', content: '''
1102-
library lib;
1103-
1104-
part 'a.dart';
1105-
part 'test.dart';
1106-
''');
1107-
newFile('/test/lib/a.dart', content: '''
1108-
part of lib;
1109-
1110-
class A {}
1111-
''');
1112-
String partContent = '''
1113-
part of lib;
1114-
1115-
class A {}
1116-
''';
1117-
newFile('/test/lib/test.dart', content: partContent);
1118-
await resolveFile(libFile.path);
1119-
await assertErrorsInCode(partContent, [
1120-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 20, 1),
1121-
]);
1122-
}
1123-
1124-
test_duplicateDefinition_catch() async {
1125-
await assertErrorsInCode(r'''
1126-
main() {
1127-
try {} catch (e, e) {}
1128-
}''', [
1129-
error(HintCode.UNUSED_CATCH_STACK, 28, 1),
1130-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 28, 1),
1131-
]);
1132-
}
1133-
1134-
test_duplicateDefinition_inPart() async {
1135-
var libFile = newFile('/test/lib/lib1.dart', content: '''
1136-
library test;
1137-
part 'test.dart';
1138-
class A {}
1139-
''');
1140-
String partContent = '''
1141-
part of test;
1142-
class A {}
1143-
''';
1144-
newFile('/test/lib/test.dart', content: partContent);
1145-
await resolveFile(libFile.path);
1146-
await assertErrorsInCode(partContent, [
1147-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 20, 1),
1148-
]);
1149-
}
1150-
1151-
test_duplicateDefinition_locals_inCase() async {
1152-
await assertErrorsInCode(r'''
1153-
main() {
1154-
switch(1) {
1155-
case 1:
1156-
var a;
1157-
var a;
1158-
}
1159-
}
1160-
''', [
1161-
error(HintCode.UNUSED_LOCAL_VARIABLE, 45, 1),
1162-
error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
1163-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 58, 1),
1164-
]);
1165-
}
1166-
1167-
test_duplicateDefinition_locals_inFunctionBlock() async {
1168-
await assertErrorsInCode(r'''
1169-
main() {
1170-
int m = 0;
1171-
m(a) {}
1172-
}
1173-
''', [
1174-
error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
1175-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
1176-
error(HintCode.UNUSED_ELEMENT, 24, 1),
1177-
]);
1178-
}
1179-
1180-
test_duplicateDefinition_locals_inIf() async {
1181-
await assertErrorsInCode(r'''
1182-
main(int p) {
1183-
if (p != 0) {
1184-
var a;
1185-
var a;
1186-
}
1187-
}
1188-
''', [
1189-
error(HintCode.UNUSED_LOCAL_VARIABLE, 38, 1),
1190-
error(HintCode.UNUSED_LOCAL_VARIABLE, 49, 1),
1191-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 49, 1),
1192-
]);
1193-
}
1194-
1195-
test_duplicateDefinition_locals_inMethodBlock() async {
1196-
await assertErrorsInCode(r'''
1197-
class A {
1198-
m() {
1199-
int a;
1200-
int a;
1201-
}
1202-
}
1203-
''', [
1204-
error(HintCode.UNUSED_LOCAL_VARIABLE, 26, 1),
1205-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 37, 1),
1206-
error(HintCode.UNUSED_LOCAL_VARIABLE, 37, 1),
1207-
]);
1208-
}
1209-
1210-
test_duplicateDefinition_notInDefiningUnit() async {
1211-
newFile('/test/lib/a.dart', content: '''
1212-
part of test;
1213-
class A {}
1214-
''');
1215-
await assertNoErrorsInCode('''
1216-
library test;
1217-
part 'a.dart';
1218-
class A {}
1219-
''');
1220-
}
1221-
1222-
test_duplicateDefinition_parameters_inConstructor() async {
1223-
await assertErrorsInCode(r'''
1224-
class A {
1225-
int a;
1226-
A(int a, this.a);
1227-
}
1228-
''', [
1229-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 35, 1),
1230-
]);
1231-
}
1232-
1233-
test_duplicateDefinition_parameters_inFunctionTypeAlias() async {
1234-
await assertErrorsInCode(r'''
1235-
typedef F(int a, double a);
1236-
''', [
1237-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
1238-
]);
1239-
}
1240-
1241-
test_duplicateDefinition_parameters_inLocalFunction() async {
1242-
await assertErrorsInCode(r'''
1243-
main() {
1244-
f(int a, double a) {
1245-
};
1246-
}
1247-
''', [
1248-
error(HintCode.UNUSED_ELEMENT, 11, 1),
1249-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 27, 1),
1250-
]);
1251-
}
1252-
1253-
test_duplicateDefinition_parameters_inMethod() async {
1254-
await assertErrorsInCode(r'''
1255-
class A {
1256-
m(int a, double a) {
1257-
}
1258-
}
1259-
''', [
1260-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 28, 1),
1261-
]);
1262-
}
1263-
1264-
test_duplicateDefinition_parameters_inTopLevelFunction() async {
1265-
await assertErrorsInCode(r'''
1266-
f(int a, double a) {}
1267-
''', [
1268-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 16, 1),
1269-
]);
1270-
}
1271-
1272-
test_duplicateDefinition_typeParameters() async {
1273-
await assertErrorsInCode(r'''
1274-
class A<T, T> {}
1275-
''', [
1276-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 11, 1),
1277-
]);
1278-
}
1279-
12801100
test_duplicateNamedArgument() async {
12811101
await assertErrorsInCode(r'''
12821102
f({a, b}) {}

pkg/analyzer/test/generated/compile_time_error_code_test.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,6 @@ f() async {
138138
]);
139139
}
140140

141-
test_duplicateDefinition_for_initializers() async {
142-
await assertErrorsInCode(r'''
143-
f() {
144-
for (int i = 0, i = 0; i < 5;) {}
145-
}
146-
''', [
147-
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
148-
error(HintCode.UNUSED_LOCAL_VARIABLE, 24, 1),
149-
]);
150-
}
151-
152141
test_expectedOneListTypeArgument() async {
153142
await assertErrorsInCode(r'''
154143
main() {

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

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -948,160 +948,6 @@ class C {
948948
]);
949949
}
950950

951-
test_error_duplicateDefinition_field_field() async {
952-
addTestFile(r'''
953-
class C {
954-
int foo;
955-
int foo;
956-
}
957-
''');
958-
await resolveTestFile();
959-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
960-
}
961-
962-
test_error_duplicateDefinition_field_field_static() async {
963-
addTestFile(r'''
964-
class C {
965-
static int foo;
966-
static int foo;
967-
}
968-
''');
969-
await resolveTestFile();
970-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
971-
}
972-
973-
test_error_duplicateDefinition_field_getter() async {
974-
addTestFile(r'''
975-
class C {
976-
int foo;
977-
int get foo => 0;
978-
}
979-
''');
980-
await resolveTestFile();
981-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
982-
}
983-
984-
test_error_duplicateDefinition_field_method() async {
985-
addTestFile(r'''
986-
class C {
987-
int foo;
988-
void foo() {}
989-
}
990-
''');
991-
await resolveTestFile();
992-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
993-
}
994-
995-
test_error_duplicateDefinition_getter_getter() async {
996-
addTestFile(r'''
997-
class C {
998-
int get foo => 0;
999-
int get foo => 0;
1000-
}
1001-
''');
1002-
await resolveTestFile();
1003-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1004-
}
1005-
1006-
test_error_duplicateDefinition_getter_method() async {
1007-
addTestFile(r'''
1008-
class C {
1009-
int get foo => 0;
1010-
void foo() {}
1011-
}
1012-
''');
1013-
await resolveTestFile();
1014-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1015-
}
1016-
1017-
test_error_duplicateDefinition_method_getter() async {
1018-
addTestFile(r'''
1019-
class C {
1020-
void foo() {}
1021-
int get foo => 0;
1022-
}
1023-
''');
1024-
await resolveTestFile();
1025-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1026-
}
1027-
1028-
test_error_duplicateDefinition_method_method() async {
1029-
addTestFile(r'''
1030-
class C {
1031-
void foo() {}
1032-
void foo() {}
1033-
}
1034-
''');
1035-
await resolveTestFile();
1036-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1037-
}
1038-
1039-
test_error_duplicateDefinition_method_setter() async {
1040-
addTestFile(r'''
1041-
class C {
1042-
void foo() {}
1043-
set foo(_) {}
1044-
}
1045-
''');
1046-
await resolveTestFile();
1047-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1048-
}
1049-
1050-
test_error_duplicateDefinition_OK_fieldFinal_setter() async {
1051-
addTestFile(r'''
1052-
class C {
1053-
final int foo = 0;
1054-
set foo(int x) {}
1055-
}
1056-
''');
1057-
await resolveTestFile();
1058-
assertNoTestErrors();
1059-
}
1060-
1061-
test_error_duplicateDefinition_OK_getter_setter() async {
1062-
addTestFile(r'''
1063-
class C {
1064-
int get foo => 0;
1065-
set foo(_) {}
1066-
}
1067-
''');
1068-
await resolveTestFile();
1069-
assertNoTestErrors();
1070-
}
1071-
1072-
test_error_duplicateDefinition_OK_setter_getter() async {
1073-
addTestFile(r'''
1074-
class C {
1075-
set foo(_) {}
1076-
int get foo => 0;
1077-
}
1078-
''');
1079-
await resolveTestFile();
1080-
assertNoTestErrors();
1081-
}
1082-
1083-
test_error_duplicateDefinition_setter_method() async {
1084-
addTestFile(r'''
1085-
class C {
1086-
set foo(_) {}
1087-
void foo() {}
1088-
}
1089-
''');
1090-
await resolveTestFile();
1091-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1092-
}
1093-
1094-
test_error_duplicateDefinition_setter_setter() async {
1095-
addTestFile(r'''
1096-
class C {
1097-
void set foo(_) {}
1098-
void set foo(_) {}
1099-
}
1100-
''');
1101-
await resolveTestFile();
1102-
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1103-
}
1104-
1105951
test_error_extendsNonClass_dynamic() async {
1106952
addTestFile(r'''
1107953
class A extends dynamic {}

0 commit comments

Comments
 (0)