Skip to content

Commit 61f1d69

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Stop implementing SharedFunctionTypeStructure in analyzer public API.
When I introduced the `SharedFunctionTypeStructure` class in https://dart-review.googlesource.com/c/sdk/+/386322, I failed to realize that a side effect of this change was to expose the shared methods `positionalParameterTypes`, `requiredPositionalParameterCount`, and `sortedNamedParameters` through the analyzer's public API. To correct that mistake, I've moved the reference to `SharedFunctionTypeStructure` from the `implements` clause of `FunctionType` to the `implements` clause of `FunctionTypeImpl`. To avoid this change causing a breakage for clients, I've also added deprecated declarations of these three getters to the `FunctionType` 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. 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. Bug: #59763 Change-Id: I442cbe29ed938ec2fed3a3fa65a95c9f0f47a38d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401921 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent d2f3470 commit 61f1d69

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ abstract class DynamicType implements DartType {}
227227
/// T<sub>xk</sub> xk}) &rarr; T</i>.
228228
///
229229
/// Clients may not extend, implement or mix-in this class.
230-
abstract class FunctionType
231-
implements
232-
DartType,
233-
SharedFunctionTypeStructure<DartType, TypeParameterElement,
234-
ParameterElement> {
230+
abstract class FunctionType implements DartType {
235231
@override
236232
Null get element;
237233

@@ -268,18 +264,45 @@ abstract class FunctionType
268264
/// in the declaration of the function.
269265
List<ParameterElement> get parameters;
270266

267+
/// All the positional parameter types, starting with the required ones, and
268+
/// followed by the optional ones.
269+
///
270+
/// Deprecated: this getter is a part of the analyzer's private
271+
/// implementation, and was exposed by accident (see
272+
/// https://github.com/dart-lang/sdk/issues/59763). Please use
273+
/// [normalParameterTypes] and [optionalParameterTypes] instead.
274+
@Deprecated('Please use normalParameterTypes and optionalParameterTypes')
275+
List<DartType> get positionalParameterTypes;
276+
277+
/// The number of elements of [positionalParameterTypes] that are required
278+
/// parameters.
279+
///
280+
/// Deprecated: this getter is a part of the analyzer's private
281+
/// implementation, and was exposed by accident (see
282+
/// https://github.com/dart-lang/sdk/issues/59763). Please use
283+
/// [normalParameterTypes].length instead.
284+
@Deprecated('Please use normalParameterTypes.length')
285+
int get requiredPositionalParameterCount;
286+
271287
/// The type of object returned by this type of function.
272-
@override
273288
DartType get returnType;
274289

290+
/// All the named parameters, sorted by name.
291+
///
292+
/// Deprecated: this getter is a part of the analyzer's private
293+
/// implementation, and was exposed by accident (see
294+
/// https://github.com/dart-lang/sdk/issues/59763). Please use [parameters]
295+
/// instead.
296+
@Deprecated('Please use parameters')
297+
List<ParameterElement> get sortedNamedParameters;
298+
275299
/// The formal type parameters of this generic function; for example,
276300
/// `<T> T -> T`.
277301
//
278302
// TODO(scheglov): Remove the mention for "typeParameters".
279303
// These are distinct from the `typeParameters` list, which contains type
280304
// parameters from surrounding contexts, and thus are free type variables
281305
// from the perspective of this function type.
282-
@override
283306
List<TypeParameterElement> get typeFormals;
284307

285308
/// The type parameters.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ class DynamicTypeImpl extends TypeImpl
8686
}
8787

8888
/// The type of a function, method, constructor, getter, or setter.
89-
class FunctionTypeImpl extends TypeImpl implements FunctionType {
89+
class FunctionTypeImpl extends TypeImpl
90+
implements
91+
FunctionType,
92+
SharedFunctionTypeStructure<DartType, TypeParameterElement,
93+
ParameterElement> {
9094
@override
9195
late int hashCode = _computeHashCode();
9296

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import 'package:analyzer/dart/element/element.dart';
2424
import 'package:analyzer/dart/element/type.dart';
2525
import 'package:analyzer/src/dart/ast/ast.dart';
2626
import 'package:analyzer/src/dart/element/element.dart';
27+
import 'package:analyzer/src/dart/element/type.dart';
2728
import 'package:analyzer/src/dart/element/type_algebra.dart';
2829
import 'package:analyzer/src/dart/element/type_schema.dart';
2930
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
@@ -226,7 +227,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
226227
@override
227228
(DartType, DartType, {List<TypeParameterElement> typeParametersToEliminate})
228229
instantiateFunctionTypesAndProvideFreshTypeParameters(
229-
covariant FunctionType P, covariant FunctionType Q,
230+
covariant FunctionTypeImpl P, covariant FunctionTypeImpl Q,
230231
{required bool leftSchema}) {
231232
// And `Z0...Zn` are fresh variables with bounds `B20, ..., B2n`.
232233
// Where `B2i` is `B0i[Z0/T0, ..., Zn/Tn]` if `P` is a type schema.

0 commit comments

Comments
 (0)