@@ -4762,7 +4762,6 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
4762
4762
InterfaceTypeImpl get thisType {
4763
4763
if (_thisType == null ) {
4764
4764
List <TypeImpl > typeArguments;
4765
- var typeParameters = firstFragment.typeParameters;
4766
4765
if (typeParameters.isNotEmpty) {
4767
4766
typeArguments =
4768
4767
typeParameters.map <TypeImpl >((t) {
@@ -9877,6 +9876,23 @@ class TypeParameterElementImpl extends ElementImpl
9877
9876
@override
9878
9877
final String ? name;
9879
9878
9879
+ /// The value representing the variance modifier keyword, or `null` if
9880
+ /// there is no explicit variance modifier, meaning legacy covariance.
9881
+ shared.Variance ? _variance;
9882
+
9883
+ /// The type representing the bound associated with this type parameter,
9884
+ /// or `null` if this type parameter does not have an explicit bound.
9885
+ ///
9886
+ /// Being able to distinguish between an implicit and explicit bound is
9887
+ /// needed by the instantiate to bounds algorithm.
9888
+ @override
9889
+ TypeImpl ? bound;
9890
+
9891
+ /// The default value of the type parameter. It is used to provide the
9892
+ /// corresponding missing type argument in type annotations and as the
9893
+ /// fall-back type value in type inference.
9894
+ TypeImpl ? defaultType;
9895
+
9880
9896
TypeParameterElementImpl ({required this .firstFragment})
9881
9897
: name = firstFragment.name {
9882
9898
firstFragment.element = this ;
@@ -9890,21 +9906,9 @@ class TypeParameterElementImpl extends ElementImpl
9890
9906
@override
9891
9907
TypeParameterElementImpl get baseElement => this ;
9892
9908
9893
- @override
9894
- TypeImpl ? get bound => firstFragment.bound;
9895
-
9896
- set bound (TypeImpl ? value) {
9897
- firstFragment.bound = value;
9898
- }
9899
-
9900
9909
@override
9901
9910
TypeImpl ? get boundShared => bound;
9902
9911
9903
- /// The default value of the type parameter. It is used to provide the
9904
- /// corresponding missing type argument in type annotations and as the
9905
- /// fall-back type value in type inference.
9906
- TypeImpl ? get defaultType => firstFragment.defaultType;
9907
-
9908
9912
@override
9909
9913
Element ? get enclosingElement {
9910
9914
return firstFragment.enclosingFragment? .element;
@@ -9926,7 +9930,9 @@ class TypeParameterElementImpl extends ElementImpl
9926
9930
];
9927
9931
}
9928
9932
9929
- bool get isLegacyCovariant => firstFragment.isLegacyCovariant;
9933
+ bool get isLegacyCovariant {
9934
+ return _variance == null ;
9935
+ }
9930
9936
9931
9937
@override
9932
9938
bool get isSynthetic {
@@ -9957,12 +9963,12 @@ class TypeParameterElementImpl extends ElementImpl
9957
9963
@override
9958
9964
String ? get name3 => name;
9959
9965
9960
- shared.Variance get variance => firstFragment.variance;
9961
-
9962
- set variance (shared.Variance ? value) {
9963
- firstFragment.variance = value;
9966
+ shared.Variance get variance {
9967
+ return _variance ?? shared.Variance .covariant ;
9964
9968
}
9965
9969
9970
+ set variance (shared.Variance ? newVariance) => _variance = newVariance;
9971
+
9966
9972
@override
9967
9973
T ? accept <T >(ElementVisitor2 <T > visitor) {
9968
9974
return visitor.visitTypeParameterElement (this );
@@ -9977,6 +9983,52 @@ class TypeParameterElementImpl extends ElementImpl
9977
9983
builder.writeTypeParameterElement (this );
9978
9984
}
9979
9985
9986
+ /// Computes the variance of the type parameters in the [type] .
9987
+ shared.Variance computeVarianceInType (DartType type) {
9988
+ if (type is TypeParameterTypeImpl ) {
9989
+ if (type.element == this ) {
9990
+ return shared.Variance .covariant ;
9991
+ } else {
9992
+ return shared.Variance .unrelated;
9993
+ }
9994
+ } else if (type is InterfaceTypeImpl ) {
9995
+ var result = shared.Variance .unrelated;
9996
+ for (int i = 0 ; i < type.typeArguments.length; ++ i) {
9997
+ var argument = type.typeArguments[i];
9998
+ var parameter = type.element.typeParameters[i];
9999
+
10000
+ var parameterVariance = parameter.variance;
10001
+ result = result.meet (
10002
+ parameterVariance.combine (computeVarianceInType (argument)),
10003
+ );
10004
+ }
10005
+ return result;
10006
+ } else if (type is FunctionType ) {
10007
+ var result = computeVarianceInType (type.returnType);
10008
+
10009
+ for (var parameter in type.typeParameters) {
10010
+ // If [parameter] is referenced in the bound at all, it makes the
10011
+ // variance of [parameter] in the entire type invariant. The invocation
10012
+ // of [computeVariance] below is made to simply figure out if [variable]
10013
+ // occurs in the bound.
10014
+ var bound = parameter.bound;
10015
+ if (bound != null && ! computeVarianceInType (bound).isUnrelated) {
10016
+ result = shared.Variance .invariant;
10017
+ }
10018
+ }
10019
+
10020
+ for (var formalParameter in type.formalParameters) {
10021
+ result = result.meet (
10022
+ shared.Variance .contravariant.combine (
10023
+ computeVarianceInType (formalParameter.type),
10024
+ ),
10025
+ );
10026
+ }
10027
+ return result;
10028
+ }
10029
+ return shared.Variance .unrelated;
10030
+ }
10031
+
9980
10032
@override
9981
10033
TypeParameterTypeImpl instantiate ({
9982
10034
required NullabilitySuffix nullabilitySuffix,
@@ -10003,19 +10055,6 @@ class TypeParameterFragmentImpl extends FragmentImpl
10003
10055
@override
10004
10056
int ? nameOffset;
10005
10057
10006
- /// The default value of the type parameter. It is used to provide the
10007
- /// corresponding missing type argument in type annotations and as the
10008
- /// fall-back type value in type inference.
10009
- TypeImpl ? defaultType;
10010
-
10011
- /// The type representing the bound associated with this parameter, or `null`
10012
- /// if this parameter does not have an explicit bound.
10013
- TypeImpl ? _bound;
10014
-
10015
- /// The value representing the variance modifier keyword, or `null` if
10016
- /// there is no explicit variance modifier, meaning legacy covariance.
10017
- shared.Variance ? _variance;
10018
-
10019
10058
/// The element corresponding to this fragment.
10020
10059
TypeParameterElementImpl ? _element;
10021
10060
@@ -10030,25 +10069,6 @@ class TypeParameterFragmentImpl extends FragmentImpl
10030
10069
isSynthetic = true ;
10031
10070
}
10032
10071
10033
- /// The type representing the bound associated with this parameter, or `null`
10034
- /// if this parameter does not have an explicit bound. Being able to
10035
- /// distinguish between an implicit and explicit bound is needed by the
10036
- /// instantiate to bounds algorithm.
10037
- TypeImpl ? get bound {
10038
- return _bound;
10039
- }
10040
-
10041
- set bound (DartType ? bound) {
10042
- // TODO(paulberry): Change the type of the parameter `bound` so that this
10043
- // cast isn't needed.
10044
- _bound = bound as TypeImpl ? ;
10045
- if (_element case var element? ) {
10046
- if (! identical (element.bound, bound)) {
10047
- element.bound = bound;
10048
- }
10049
- }
10050
- }
10051
-
10052
10072
@override
10053
10073
List <Fragment > get children => const [];
10054
10074
@@ -10082,10 +10102,6 @@ class TypeParameterFragmentImpl extends FragmentImpl
10082
10102
_element = element;
10083
10103
}
10084
10104
10085
- bool get isLegacyCovariant {
10086
- return _variance == null ;
10087
- }
10088
-
10089
10105
@override
10090
10106
LibraryFragment ? get libraryFragment {
10091
10107
return enclosingFragment? .libraryFragment;
@@ -10105,66 +10121,6 @@ class TypeParameterFragmentImpl extends FragmentImpl
10105
10121
@override
10106
10122
// TODO(augmentations): Support chaining between the fragments.
10107
10123
TypeParameterFragmentImpl ? get previousFragment => null ;
10108
-
10109
- shared.Variance get variance {
10110
- return _variance ?? shared.Variance .covariant ;
10111
- }
10112
-
10113
- set variance (shared.Variance ? newVariance) => _variance = newVariance;
10114
-
10115
- /// Computes the variance of the type parameters in the [type] .
10116
- shared.Variance computeVarianceInType (DartType type) {
10117
- if (type is TypeParameterTypeImpl ) {
10118
- if (type.element == element) {
10119
- return shared.Variance .covariant ;
10120
- } else {
10121
- return shared.Variance .unrelated;
10122
- }
10123
- } else if (type is InterfaceTypeImpl ) {
10124
- var result = shared.Variance .unrelated;
10125
- for (int i = 0 ; i < type.typeArguments.length; ++ i) {
10126
- var argument = type.typeArguments[i];
10127
- var parameter = type.element.typeParameters[i];
10128
-
10129
- var parameterVariance = parameter.variance;
10130
- result = result.meet (
10131
- parameterVariance.combine (computeVarianceInType (argument)),
10132
- );
10133
- }
10134
- return result;
10135
- } else if (type is FunctionType ) {
10136
- var result = computeVarianceInType (type.returnType);
10137
-
10138
- for (var parameter in type.typeParameters) {
10139
- // If [parameter] is referenced in the bound at all, it makes the
10140
- // variance of [parameter] in the entire type invariant. The invocation
10141
- // of [computeVariance] below is made to simply figure out if [variable]
10142
- // occurs in the bound.
10143
- var bound = parameter.bound;
10144
- if (bound != null && ! computeVarianceInType (bound).isUnrelated) {
10145
- result = shared.Variance .invariant;
10146
- }
10147
- }
10148
-
10149
- for (var formalParameter in type.formalParameters) {
10150
- result = result.meet (
10151
- shared.Variance .contravariant.combine (
10152
- computeVarianceInType (formalParameter.type),
10153
- ),
10154
- );
10155
- }
10156
- return result;
10157
- }
10158
- return shared.Variance .unrelated;
10159
- }
10160
-
10161
- /// Creates the [TypeParameterType] with the given [nullabilitySuffix] for
10162
- /// this type parameter.
10163
- TypeParameterTypeImpl instantiate ({
10164
- required NullabilitySuffix nullabilitySuffix,
10165
- }) {
10166
- return element.instantiate (nullabilitySuffix: nullabilitySuffix);
10167
- }
10168
10124
}
10169
10125
10170
10126
/// Mixin representing an element which can have type parameters.
0 commit comments