Skip to content

Commit

Permalink
[analyzer] Stop implementing SharedFunctionTypeStructure in analyzer …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
stereotype441 authored and Commit Queue committed Dec 25, 2024
1 parent d2f3470 commit 61f1d69
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
37 changes: 30 additions & 7 deletions pkg/analyzer/lib/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,7 @@ abstract class DynamicType implements DartType {}
/// T<sub>xk</sub> xk}) &rarr; T</i>.
///
/// Clients may not extend, implement or mix-in this class.
abstract class FunctionType
implements
DartType,
SharedFunctionTypeStructure<DartType, TypeParameterElement,
ParameterElement> {
abstract class FunctionType implements DartType {
@override
Null get element;

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

/// All the positional parameter types, starting with the required ones, and
/// followed by the optional ones.
///
/// 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
/// [normalParameterTypes] and [optionalParameterTypes] instead.
@Deprecated('Please use normalParameterTypes and optionalParameterTypes')
List<DartType> get positionalParameterTypes;

/// The number of elements of [positionalParameterTypes] that are required
/// parameters.
///
/// 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
/// [normalParameterTypes].length instead.
@Deprecated('Please use normalParameterTypes.length')
int get requiredPositionalParameterCount;

/// The type of object returned by this type of function.
@override
DartType get returnType;

/// All the named parameters, sorted by name.
///
/// 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 [parameters]
/// instead.
@Deprecated('Please use parameters')
List<ParameterElement> get sortedNamedParameters;

/// The formal type parameters of this generic function; for example,
/// `<T> T -> T`.
//
// TODO(scheglov): Remove the mention for "typeParameters".
// These are distinct from the `typeParameters` list, which contains type
// parameters from surrounding contexts, and thus are free type variables
// from the perspective of this function type.
@override
List<TypeParameterElement> get typeFormals;

/// The type parameters.
Expand Down
6 changes: 5 additions & 1 deletion pkg/analyzer/lib/src/dart/element/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ class DynamicTypeImpl extends TypeImpl
}

/// The type of a function, method, constructor, getter, or setter.
class FunctionTypeImpl extends TypeImpl implements FunctionType {
class FunctionTypeImpl extends TypeImpl
implements
FunctionType,
SharedFunctionTypeStructure<DartType, TypeParameterElement,
ParameterElement> {
@override
late int hashCode = _computeHashCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_schema.dart';
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
Expand Down Expand Up @@ -226,7 +227,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
@override
(DartType, DartType, {List<TypeParameterElement> typeParametersToEliminate})
instantiateFunctionTypesAndProvideFreshTypeParameters(
covariant FunctionType P, covariant FunctionType Q,
covariant FunctionTypeImpl P, covariant FunctionTypeImpl Q,
{required bool leftSchema}) {
// And `Z0...Zn` are fresh variables with bounds `B20, ..., B2n`.
// Where `B2i` is `B0i[Z0/T0, ..., Zn/Tn]` if `P` is a type schema.
Expand Down

0 comments on commit 61f1d69

Please sign in to comment.