Skip to content

Commit eefad8c

Browse files
scheglovCommit Queue
authored andcommitted
Issue 58580. Support for getter_setter_error feature.
Bug: #58580 Change-Id: I1926ffb0157ef1b5c294487b183f93cbcb0ea177 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422180 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent a389d82 commit eefad8c

File tree

9 files changed

+302
-149
lines changed

9 files changed

+302
-149
lines changed

pkg/analyzer/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ package:analyzer/dart/analysis/features.dart:
100100
enhanced_parts (static getter: ExperimentalFeature)
101101
extension_methods (static getter: ExperimentalFeature)
102102
generic_metadata (static getter: ExperimentalFeature)
103+
getter_setter_error (static getter: ExperimentalFeature)
103104
inference_update_1 (static getter: ExperimentalFeature)
104105
inference_update_2 (static getter: ExperimentalFeature)
105106
inference_update_3 (static getter: ExperimentalFeature)

pkg/analyzer/lib/dart/analysis/features.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ abstract class Feature {
4646
/// Feature information for generic metadata.
4747
static final generic_metadata = ExperimentalFeatures.generic_metadata;
4848

49+
/// Feature information for getter-setter-error.
50+
static final getter_setter_error = ExperimentalFeatures.getter_setter_error;
51+
4952
/// Feature information for inference using bounds.
5053
static final inference_using_bounds =
5154
ExperimentalFeatures.inference_using_bounds;

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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/dart/analysis/features.dart';
56
import 'package:analyzer/dart/element/element2.dart';
67
import 'package:analyzer/error/listener.dart';
78
import 'package:analyzer/src/dart/element/element.dart';
@@ -14,28 +15,45 @@ import 'package:analyzer/src/error/codes.dart';
1415
/// of the corresponding setter. Where "match" means "subtype" in non-nullable,
1516
/// and "assignable" in legacy.
1617
class GetterSetterTypesVerifier {
18+
final LibraryElementImpl library;
1719
final TypeSystemImpl _typeSystem;
1820
final ErrorReporter _errorReporter;
1921

2022
GetterSetterTypesVerifier({
21-
required TypeSystemImpl typeSystem,
23+
required this.library,
2224
required ErrorReporter errorReporter,
23-
}) : _typeSystem = typeSystem,
25+
}) : _typeSystem = library.typeSystem,
2426
_errorReporter = errorReporter;
2527

28+
bool get _skipGetterSetterTypesCheck {
29+
return library.featureSet.isEnabled(Feature.getter_setter_error);
30+
}
31+
2632
void checkExtension(ExtensionElementImpl2 element) {
33+
if (_skipGetterSetterTypesCheck) {
34+
return;
35+
}
36+
2737
for (var getter in element.getters2) {
2838
_checkLocalGetter(getter);
2939
}
3040
}
3141

3242
void checkExtensionType(
3343
ExtensionTypeElementImpl2 element, Interface interface) {
44+
if (_skipGetterSetterTypesCheck) {
45+
return;
46+
}
47+
3448
checkInterface(element, interface);
3549
checkStaticGetters(element.getters2);
3650
}
3751

3852
void checkInterface(InterfaceElementImpl2 element, Interface interface) {
53+
if (_skipGetterSetterTypesCheck) {
54+
return;
55+
}
56+
3957
var libraryUri = element.library2.uri;
4058

4159
var interfaceMap = interface.map2;
@@ -88,6 +106,10 @@ class GetterSetterTypesVerifier {
88106
}
89107

90108
void checkStaticGetters(List<GetterElement2OrMember> getters) {
109+
if (_skipGetterSetterTypesCheck) {
110+
return;
111+
}
112+
91113
for (var getter in getters) {
92114
if (getter.isStatic) {
93115
_checkLocalGetter(getter);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class _ClassVerifier {
282282
_checkIllegalEnumValuesInheritance();
283283

284284
GetterSetterTypesVerifier(
285-
typeSystem: typeSystem,
285+
library: library,
286286
errorReporter: reporter,
287287
).checkInterface(element, interface);
288288

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
484484
_checkForMixinClassErrorCodes(node, members, superclass, withClause);
485485

486486
GetterSetterTypesVerifier(
487-
typeSystem: typeSystem,
487+
library: _currentLibrary,
488488
errorReporter: errorReporter,
489489
).checkStaticGetters(augmented.getters2);
490490

@@ -541,7 +541,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
541541
_checkForIllegalLanguageOverride(node);
542542

543543
GetterSetterTypesVerifier(
544-
typeSystem: typeSystem,
544+
library: _currentLibrary,
545545
errorReporter: errorReporter,
546546
).checkStaticGetters(fragment.element.getters);
547547

@@ -665,7 +665,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
665665
_checkForEnumInstantiatedToBoundsIsNotWellBounded(node, declaredFragment);
666666

667667
GetterSetterTypesVerifier(
668-
typeSystem: typeSystem,
668+
library: _currentLibrary,
669669
errorReporter: errorReporter,
670670
).checkStaticGetters(declaredElement.getters2);
671671

@@ -709,7 +709,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
709709
_checkForFinalNotInitializedInClass(declaredFragment, node.members);
710710

711711
GetterSetterTypesVerifier(
712-
typeSystem: typeSystem,
712+
library: _currentLibrary,
713713
errorReporter: errorReporter,
714714
).checkExtension(declaredElement);
715715

@@ -763,7 +763,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
763763

764764
var interface = _inheritanceManager.getInterface(firstFragment);
765765
GetterSetterTypesVerifier(
766-
typeSystem: typeSystem,
766+
library: _currentLibrary,
767767
errorReporter: errorReporter,
768768
).checkExtensionType(declaredElement, interface);
769769

pkg/analyzer/test/generated/non_error_resolver_test.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -738,17 +738,6 @@ set x(_) {}
738738
''');
739739
}
740740

741-
test_conflictingStaticGetterAndInstanceSetter_thisClass() async {
742-
await assertErrorsInCode(r'''
743-
class A {
744-
static get x => 0;
745-
static set x(int p) {}
746-
}
747-
''', [
748-
error(CompileTimeErrorCode.GETTER_NOT_SUBTYPE_SETTER_TYPES, 23, 1),
749-
]);
750-
}
751-
752741
test_const_constructor_with_named_generic_parameter() async {
753742
await assertNoErrorsInCode('''
754743
class C<T> {

0 commit comments

Comments
 (0)