Skip to content

Commit

Permalink
[analyzer] Change RecordType to stop implementing SharedRecordTypeStr…
Browse files Browse the repository at this point in the history
…ucture.

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 <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
stereotype441 authored and Commit Queue committed Jan 6, 2025
1 parent 6b21d8b commit a3917df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 19 additions & 2 deletions pkg/analyzer/lib/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ abstract class ParameterizedType implements DartType {
/// The type of a record literal or a record type annotation.
///
/// Clients may not extend, implement or mix-in this class.
abstract class RecordType
implements DartType, SharedRecordTypeStructure<DartType> {
abstract class RecordType implements DartType {
/// Creates a record type from of [positional] and [named] fields.
factory RecordType({
required List<DartType> positional,
Expand All @@ -591,6 +590,24 @@ abstract class RecordType

/// The positional fields (might be empty).
List<RecordTypePositionalField> get positionalFields;

/// The types of the positional fields (might be empty).
///
/// Deprecated: this getter is a part of the analyzer's private
/// implementation, and was exposed by accident (see
/// https://github.com/dart-lang/sdk/issues/59763). Please use
/// [positionalFields] instead.
@Deprecated('Use positionalFields instead')
List<DartType> get positionalTypes;

/// All the named fields, sorted by name (might be empty).
///
/// Deprecated: this getter is a part of the analyzer's private
/// implementation, and was exposed by accident (see
/// https://github.com/dart-lang/sdk/issues/59763). Please use [namedFields]
/// instead.
@Deprecated('Use namedFields instead')
List<RecordTypeNamedField> get sortedNamedTypes;
}

/// A field in a [RecordType].
Expand Down
7 changes: 4 additions & 3 deletions pkg/analyzer/lib/src/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,8 @@ abstract class RecordTypeFieldImpl implements RecordTypeField {
});
}

class RecordTypeImpl extends TypeImpl implements RecordType {
class RecordTypeImpl extends TypeImpl
implements RecordType, SharedRecordTypeStructure<DartType> {
@override
final List<RecordTypePositionalFieldImpl> positionalFields;

Expand Down Expand Up @@ -1395,10 +1396,10 @@ class RecordTypeImpl extends TypeImpl implements RecordType {
@override
String? get name => null;

List<SharedNamedTypeStructure<DartType>> get namedTypes => namedFields;
List<RecordTypeNamedFieldImpl> get namedTypes => namedFields;

@override
List<SharedNamedTypeStructure<DartType>> get sortedNamedTypes => namedTypes;
List<RecordTypeNamedFieldImpl> get sortedNamedTypes => namedTypes;

@override
bool operator ==(Object other) {
Expand Down

0 comments on commit a3917df

Please sign in to comment.