Skip to content

Commit a3917df

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Change RecordType to stop implementing SharedRecordTypeStructure.
When I introduced the `SharedRecordType` class in https://dart-review.googlesource.com/c/sdk/+/362481 (now called `SharedRecordTypeStructure`), I failed to realize that a side effect of this change was to expose the shared getter `positionalTypes` through the analyzer's public API. Later, when the getter `sortedNamedTypes` was added to this class, that also was inadvertently exposed through the analyzer's public API. To correct that mistake, I've moved the reference to `SharedRecordTypeStructure` from the `implements` clause of `RecordType` to the `implements` clause of `RecordTypeImpl`. To avoid this change causing a breakage for clients, I've also added deprecated declarations of the getters `positionalTypes` and `sortedNamedTypes` to the `RecordType` class. This ensures that if any analyzer clients have already started depending on them, their code will continue to work, but they'll be alerted to the fact that the members will be removed in the future. In the process, I improved the types of `positionalTypes` and `sortedNamedTypes` so that they no longer refer to shared types; this should reduce further API exposure. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See #59763. Change-Id: If56b8689180d2214eccd7ec8ec4f4f10b31358f6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402620 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 6b21d8b commit a3917df

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

pkg/analyzer/lib/dart/element/type.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ abstract class ParameterizedType implements DartType {
574574
/// The type of a record literal or a record type annotation.
575575
///
576576
/// Clients may not extend, implement or mix-in this class.
577-
abstract class RecordType
578-
implements DartType, SharedRecordTypeStructure<DartType> {
577+
abstract class RecordType implements DartType {
579578
/// Creates a record type from of [positional] and [named] fields.
580579
factory RecordType({
581580
required List<DartType> positional,
@@ -591,6 +590,24 @@ abstract class RecordType
591590

592591
/// The positional fields (might be empty).
593592
List<RecordTypePositionalField> get positionalFields;
593+
594+
/// The types of the positional fields (might be empty).
595+
///
596+
/// Deprecated: this getter is a part of the analyzer's private
597+
/// implementation, and was exposed by accident (see
598+
/// https://github.com/dart-lang/sdk/issues/59763). Please use
599+
/// [positionalFields] instead.
600+
@Deprecated('Use positionalFields instead')
601+
List<DartType> get positionalTypes;
602+
603+
/// All the named fields, sorted by name (might be empty).
604+
///
605+
/// Deprecated: this getter is a part of the analyzer's private
606+
/// implementation, and was exposed by accident (see
607+
/// https://github.com/dart-lang/sdk/issues/59763). Please use [namedFields]
608+
/// instead.
609+
@Deprecated('Use namedFields instead')
610+
List<RecordTypeNamedField> get sortedNamedTypes;
594611
}
595612

596613
/// A field in a [RecordType].

pkg/analyzer/lib/src/dart/element/type.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,8 @@ abstract class RecordTypeFieldImpl implements RecordTypeField {
13381338
});
13391339
}
13401340

1341-
class RecordTypeImpl extends TypeImpl implements RecordType {
1341+
class RecordTypeImpl extends TypeImpl
1342+
implements RecordType, SharedRecordTypeStructure<DartType> {
13421343
@override
13431344
final List<RecordTypePositionalFieldImpl> positionalFields;
13441345

@@ -1395,10 +1396,10 @@ class RecordTypeImpl extends TypeImpl implements RecordType {
13951396
@override
13961397
String? get name => null;
13971398

1398-
List<SharedNamedTypeStructure<DartType>> get namedTypes => namedFields;
1399+
List<RecordTypeNamedFieldImpl> get namedTypes => namedFields;
13991400

14001401
@override
1401-
List<SharedNamedTypeStructure<DartType>> get sortedNamedTypes => namedTypes;
1402+
List<RecordTypeNamedFieldImpl> get sortedNamedTypes => namedTypes;
14021403

14031404
@override
14041405
bool operator ==(Object other) {

0 commit comments

Comments
 (0)