Skip to content

Commit 44806b2

Browse files
scheglovCommit Bot
authored and
Commit Bot
committed
Don't report VALUES_DECLARATION_IN_ENUM for static setter.
See dart-lang/co19#1312 Change-Id: Ie535a826a2997c45344486febbb8cc35a748496c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236300 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 1d9b850 commit 44806b2

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

pkg/analyzer/lib/error/listener.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ class ErrorReporter {
7070
/// is used to compute the location of the error.
7171
void reportErrorForElement(ErrorCode errorCode, Element element,
7272
[List<Object>? arguments]) {
73-
reportErrorForOffset(errorCode, element.nonSynthetic.nameOffset,
74-
element.nameLength, arguments);
73+
var nonSynthetic = element.nonSynthetic;
74+
reportErrorForOffset(
75+
errorCode, nonSynthetic.nameOffset, nonSynthetic.nameLength, arguments);
7576
}
7677

7778
/// Report a diagnostic with the given [code] and [arguments]. The

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ class DuplicateDefinitionVerifier {
9393
member.name,
9494
setterScope: member.isStatic ? staticSetters : instanceSetters,
9595
);
96-
_checkValuesDeclarationInEnum(member.name);
96+
if (!(member.isStatic && member.isSetter)) {
97+
_checkValuesDeclarationInEnum(member.name);
98+
}
9799
}
98100
}
99101

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,17 @@ enum E {
326326
]);
327327
}
328328

329+
test_enum_static_generatedGetter_thisSetter_index() async {
330+
await assertErrorsInCode('''
331+
enum E {
332+
v;
333+
static set values(int _) {}
334+
}
335+
''', [
336+
error(CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES, 5, 1),
337+
]);
338+
}
339+
329340
test_extension_instance() async {
330341
await assertErrorsInCode('''
331342
extension E on Object {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,11 @@ enum E {
115115
}
116116

117117
test_setter_static() async {
118-
await assertErrorsInCode(r'''
118+
await assertNoErrorsInCode(r'''
119119
enum E {
120120
v;
121121
static set values(_) {}
122122
}
123-
''', [
124-
error(CompileTimeErrorCode.VALUES_DECLARATION_IN_ENUM, 27, 6),
125-
]);
123+
''');
126124
}
127125
}

0 commit comments

Comments
 (0)