Skip to content

Commit a4ca3de

Browse files
srawlinsCommit Queue
authored andcommitted
[analyzer] Move two more Hints to be Warnings, EQUAL_*
Bug: #50796 Change-Id: Id07ac5940eafed58b1473804248381dd933cb311 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279229 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 4871e74 commit a4ca3de

File tree

10 files changed

+130
-130
lines changed

10 files changed

+130
-130
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,14 +1370,6 @@ HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE:
13701370
status: hasFix
13711371
HintCode.DIVISION_OPTIMIZATION:
13721372
status: hasFix
1373-
HintCode.EQUAL_ELEMENTS_IN_SET:
1374-
status: noFix
1375-
notes: |-
1376-
Fix depends on user's intent, which can't be known.
1377-
HintCode.EQUAL_KEYS_IN_MAP:
1378-
status: noFix
1379-
notes: |-
1380-
Fix depends on user's intent, which can't be known.
13811373
HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE:
13821374
status: noFix
13831375
notes: |-
@@ -2761,6 +2753,14 @@ WarningCode.DUPLICATE_IMPORT:
27612753
status: hasFix
27622754
WarningCode.DUPLICATE_SHOWN_NAME:
27632755
status: hasFix
2756+
WarningCode.EQUAL_ELEMENTS_IN_SET:
2757+
status: noFix
2758+
notes: |-
2759+
Fix depends on user's intent, which can't be known.
2760+
WarningCode.EQUAL_KEYS_IN_MAP:
2761+
status: noFix
2762+
notes: |-
2763+
Fix depends on user's intent, which can't be known.
27642764
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
27652765
status: hasFix
27662766
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT:
@@ -2787,4 +2787,4 @@ WarningCode.SDK_VERSION_UI_AS_CODE:
27872787
status: hasFix
27882788
WarningCode.SDK_VERSION_UI_AS_CODE_IN_CONST_CONTEXT:
27892789
status: noFix
2790-
notes: Deprecated
2790+
notes: Deprecated

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,6 @@ class HintCode extends AnalyzerErrorCode {
173173
hasPublishedDocs: true,
174174
);
175175

176-
/// No parameters.
177-
static const HintCode EQUAL_ELEMENTS_IN_SET = HintCode(
178-
'EQUAL_ELEMENTS_IN_SET',
179-
"Two elements in a set literal shouldn't be equal.",
180-
correctionMessage: "Change or remove the duplicate element.",
181-
hasPublishedDocs: true,
182-
);
183-
184-
/// No parameters.
185-
static const HintCode EQUAL_KEYS_IN_MAP = HintCode(
186-
'EQUAL_KEYS_IN_MAP',
187-
"Two keys in a map literal shouldn't be equal.",
188-
correctionMessage: "Change or remove the duplicate key.",
189-
hasPublishedDocs: true,
190-
);
191-
192176
/// It is a bad practice for a source file in a package "lib" directory
193177
/// hierarchy to traverse outside that directory hierarchy. For example, a
194178
/// source file in the "lib" directory should not contain a directive such as

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
990990
var value = constEvaluation.value;
991991
if (value != null && !alreadySeen.add(value)) {
992992
var errorCode = node.isSet
993-
? HintCode.EQUAL_ELEMENTS_IN_SET
994-
: HintCode.EQUAL_KEYS_IN_MAP;
993+
? WarningCode.EQUAL_ELEMENTS_IN_SET
994+
: WarningCode.EQUAL_KEYS_IN_MAP;
995995
_errorReporter.reportErrorForNode(errorCode, expression);
996996
}
997997
}

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,6 +5693,22 @@ class WarningCode extends AnalyzerErrorCode {
56935693
hasPublishedDocs: true,
56945694
);
56955695

5696+
/// No parameters.
5697+
static const WarningCode EQUAL_ELEMENTS_IN_SET = WarningCode(
5698+
'EQUAL_ELEMENTS_IN_SET',
5699+
"Two elements in a set literal shouldn't be equal.",
5700+
correctionMessage: "Change or remove the duplicate element.",
5701+
hasPublishedDocs: true,
5702+
);
5703+
5704+
/// No parameters.
5705+
static const WarningCode EQUAL_KEYS_IN_MAP = WarningCode(
5706+
'EQUAL_KEYS_IN_MAP',
5707+
"Two keys in a map literal shouldn't be equal.",
5708+
correctionMessage: "Change or remove the duplicate key.",
5709+
hasPublishedDocs: true,
5710+
);
5711+
56965712
/// Parameters:
56975713
/// 0: the name of the class
56985714
static const WarningCode SDK_VERSION_ASYNC_EXPORTED_FROM_CORE = WarningCode(

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,6 @@ const List<ErrorCode> errorCodeValues = [
579579
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE,
580580
HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE,
581581
HintCode.DIVISION_OPTIMIZATION,
582-
HintCode.EQUAL_ELEMENTS_IN_SET,
583-
HintCode.EQUAL_KEYS_IN_MAP,
584582
HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
585583
HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE,
586584
HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION,
@@ -972,6 +970,8 @@ const List<ErrorCode> errorCodeValues = [
972970
WarningCode.DUPLICATE_IGNORE,
973971
WarningCode.DUPLICATE_IMPORT,
974972
WarningCode.DUPLICATE_SHOWN_NAME,
973+
WarningCode.EQUAL_ELEMENTS_IN_SET,
974+
WarningCode.EQUAL_KEYS_IN_MAP,
975975
WarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
976976
WarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
977977
WarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,

pkg/analyzer/messages.yaml

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -18116,97 +18116,6 @@ HintCode:
1811618116
```dart
1811718117
int divide(num x, num y) => x ~/ y;
1811818118
```
18119-
EQUAL_ELEMENTS_IN_SET:
18120-
problemMessage: "Two elements in a set literal shouldn't be equal."
18121-
correctionMessage: Change or remove the duplicate element.
18122-
hasPublishedDocs: true
18123-
comment: No parameters.
18124-
documentation: |-
18125-
#### Description
18126-
18127-
The analyzer produces this diagnostic when an element in a non-constant set
18128-
is the same as a previous element in the same set. If two elements are the
18129-
same, then the second value is ignored, which makes having both elements
18130-
pointless and likely signals a bug.
18131-
18132-
#### Example
18133-
18134-
The following code produces this diagnostic because the element `1` appears
18135-
twice:
18136-
18137-
```dart
18138-
const a = 1;
18139-
const b = 1;
18140-
var s = <int>{a, [!b!]};
18141-
```
18142-
18143-
#### Common fixes
18144-
18145-
If both elements should be included in the set, then change one of the
18146-
elements:
18147-
18148-
```dart
18149-
const a = 1;
18150-
const b = 2;
18151-
var s = <int>{a, b};
18152-
```
18153-
18154-
If only one of the elements is needed, then remove the one that isn't
18155-
needed:
18156-
18157-
```dart
18158-
const a = 1;
18159-
var s = <int>{a};
18160-
```
18161-
18162-
Note that literal sets preserve the order of their elements, so the choice
18163-
of which element to remove might affect the order in which elements are
18164-
returned by an iterator.
18165-
EQUAL_KEYS_IN_MAP:
18166-
problemMessage: "Two keys in a map literal shouldn't be equal."
18167-
correctionMessage: Change or remove the duplicate key.
18168-
hasPublishedDocs: true
18169-
comment: No parameters.
18170-
documentation: |-
18171-
#### Description
18172-
18173-
The analyzer produces this diagnostic when a key in a non-constant map is
18174-
the same as a previous key in the same map. If two keys are the same, then
18175-
the second value overwrites the first value, which makes having both pairs
18176-
pointless and likely signals a bug.
18177-
18178-
#### Example
18179-
18180-
The following code produces this diagnostic because the keys `a` and `b`
18181-
have the same value:
18182-
18183-
```dart
18184-
const a = 1;
18185-
const b = 1;
18186-
var m = <int, String>{a: 'a', [!b!]: 'b'};
18187-
```
18188-
18189-
#### Common fixes
18190-
18191-
If both entries should be included in the map, then change one of the keys:
18192-
18193-
```dart
18194-
const a = 1;
18195-
const b = 2;
18196-
var m = <int, String>{a: 'a', b: 'b'};
18197-
```
18198-
18199-
If only one of the entries is needed, then remove the one that isn't
18200-
needed:
18201-
18202-
```dart
18203-
const a = 1;
18204-
var m = <int, String>{a: 'a'};
18205-
```
18206-
18207-
Note that literal maps preserve the order of their entries, so the choice
18208-
of which entry to remove might affect the order in which the keys and
18209-
values are returned by an iterator.
1821018119
FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE:
1821118120
problemMessage: "A file in the 'lib' directory shouldn't import a file outside the 'lib' directory."
1821218121
correctionMessage: "Try removing the import, or moving the imported file inside the 'lib' directory."
@@ -22838,6 +22747,97 @@ WarningCode:
2283822747

2283922748
var x = min(2, min(0, 1));
2284022749
```
22750+
EQUAL_ELEMENTS_IN_SET:
22751+
problemMessage: "Two elements in a set literal shouldn't be equal."
22752+
correctionMessage: Change or remove the duplicate element.
22753+
hasPublishedDocs: true
22754+
comment: No parameters.
22755+
documentation: |-
22756+
#### Description
22757+
22758+
The analyzer produces this diagnostic when an element in a non-constant set
22759+
is the same as a previous element in the same set. If two elements are the
22760+
same, then the second value is ignored, which makes having both elements
22761+
pointless and likely signals a bug.
22762+
22763+
#### Example
22764+
22765+
The following code produces this diagnostic because the element `1` appears
22766+
twice:
22767+
22768+
```dart
22769+
const a = 1;
22770+
const b = 1;
22771+
var s = <int>{a, [!b!]};
22772+
```
22773+
22774+
#### Common fixes
22775+
22776+
If both elements should be included in the set, then change one of the
22777+
elements:
22778+
22779+
```dart
22780+
const a = 1;
22781+
const b = 2;
22782+
var s = <int>{a, b};
22783+
```
22784+
22785+
If only one of the elements is needed, then remove the one that isn't
22786+
needed:
22787+
22788+
```dart
22789+
const a = 1;
22790+
var s = <int>{a};
22791+
```
22792+
22793+
Note that literal sets preserve the order of their elements, so the choice
22794+
of which element to remove might affect the order in which elements are
22795+
returned by an iterator.
22796+
EQUAL_KEYS_IN_MAP:
22797+
problemMessage: "Two keys in a map literal shouldn't be equal."
22798+
correctionMessage: Change or remove the duplicate key.
22799+
hasPublishedDocs: true
22800+
comment: No parameters.
22801+
documentation: |-
22802+
#### Description
22803+
22804+
The analyzer produces this diagnostic when a key in a non-constant map is
22805+
the same as a previous key in the same map. If two keys are the same, then
22806+
the second value overwrites the first value, which makes having both pairs
22807+
pointless and likely signals a bug.
22808+
22809+
#### Example
22810+
22811+
The following code produces this diagnostic because the keys `a` and `b`
22812+
have the same value:
22813+
22814+
```dart
22815+
const a = 1;
22816+
const b = 1;
22817+
var m = <int, String>{a: 'a', [!b!]: 'b'};
22818+
```
22819+
22820+
#### Common fixes
22821+
22822+
If both entries should be included in the map, then change one of the keys:
22823+
22824+
```dart
22825+
const a = 1;
22826+
const b = 2;
22827+
var m = <int, String>{a: 'a', b: 'b'};
22828+
```
22829+
22830+
If only one of the entries is needed, then remove the one that isn't
22831+
needed:
22832+
22833+
```dart
22834+
const a = 1;
22835+
var m = <int, String>{a: 'a'};
22836+
```
22837+
22838+
Note that literal maps preserve the order of their entries, so the choice
22839+
of which entry to remove might affect the order in which the keys and
22840+
values are returned by an iterator.
2284122841
SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
2284222842
problemMessage: "The class '{0}' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions."
2284322843
correctionMessage: "Try either importing 'dart:async' or updating the SDK constraints."

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var c = const {1, ...{1}};
143143
await assertErrorsInCode('''
144144
var c = {1, 2, 1};
145145
''', [
146-
error(HintCode.EQUAL_ELEMENTS_IN_SET, 15, 1),
146+
error(WarningCode.EQUAL_ELEMENTS_IN_SET, 15, 1),
147147
]);
148148
}
149149
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/src/dart/error/hint_codes.dart';
5+
import 'package:analyzer/src/error/codes.dart';
66
import 'package:test_reflective_loader/test_reflective_loader.dart';
77

88
import '../dart/resolution/context_collection_resolution.dart';
@@ -21,7 +21,7 @@ const a = 1;
2121
const b = 1;
2222
var s = {a, b};
2323
''', [
24-
error(HintCode.EQUAL_ELEMENTS_IN_SET, 38, 1),
24+
error(WarningCode.EQUAL_ELEMENTS_IN_SET, 38, 1),
2525
]);
2626
}
2727

@@ -30,15 +30,15 @@ var s = {a, b};
3030
const one = 1;
3131
var s = {1, one};
3232
''', [
33-
error(HintCode.EQUAL_ELEMENTS_IN_SET, 27, 3),
33+
error(WarningCode.EQUAL_ELEMENTS_IN_SET, 27, 3),
3434
]);
3535
}
3636

3737
test_literal_literal() async {
3838
await assertErrorsInCode('''
3939
var s = {1, 1};
4040
''', [
41-
error(HintCode.EQUAL_ELEMENTS_IN_SET, 12, 1),
41+
error(WarningCode.EQUAL_ELEMENTS_IN_SET, 12, 1),
4242
]);
4343
}
4444
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var c = const {1: null, ...{1: null}};
143143
await assertErrorsInCode('''
144144
var c = {1: null, 2: null, 1: null};
145145
''', [
146-
error(HintCode.EQUAL_KEYS_IN_MAP, 27, 1),
146+
error(WarningCode.EQUAL_KEYS_IN_MAP, 27, 1),
147147
]);
148148
}
149149
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/src/dart/error/hint_codes.dart';
5+
import 'package:analyzer/src/error/codes.dart';
66
import 'package:test_reflective_loader/test_reflective_loader.dart';
77

88
import '../dart/resolution/context_collection_resolution.dart';
@@ -21,7 +21,7 @@ const a = 1;
2121
const b = 1;
2222
var s = {a: 2, b: 3};
2323
''', [
24-
error(HintCode.EQUAL_KEYS_IN_MAP, 41, 1),
24+
error(WarningCode.EQUAL_KEYS_IN_MAP, 41, 1),
2525
]);
2626
}
2727

@@ -30,15 +30,15 @@ var s = {a: 2, b: 3};
3030
const one = 1;
3131
var s = {1: 2, one: 3};
3232
''', [
33-
error(HintCode.EQUAL_KEYS_IN_MAP, 30, 3),
33+
error(WarningCode.EQUAL_KEYS_IN_MAP, 30, 3),
3434
]);
3535
}
3636

3737
test_literal_literal() async {
3838
await assertErrorsInCode('''
3939
var s = {1: 2, 1: 3};
4040
''', [
41-
error(HintCode.EQUAL_KEYS_IN_MAP, 15, 1),
41+
error(WarningCode.EQUAL_KEYS_IN_MAP, 15, 1),
4242
]);
4343
}
4444
}

0 commit comments

Comments
 (0)