@@ -716,7 +716,6 @@ class ConstantInitializerImpl implements ConstantInitializer {
716716class ConstructorElementImpl extends ExecutableElementImpl
717717 with
718718 FragmentedExecutableElementMixin <ConstructorFragmentImpl >,
719- FragmentedFunctionTypedElementMixin <ConstructorFragmentImpl >,
720719 FragmentedTypeParameterizedElementMixin <ConstructorFragmentImpl >,
721720 FragmentedAnnotatableElementMixin <ConstructorFragmentImpl >,
722721 FragmentedElementMixin <ConstructorFragmentImpl >,
@@ -856,7 +855,12 @@ class ConstructorElementImpl extends ExecutableElementImpl
856855
857856 @override
858857 InterfaceTypeImpl get returnType {
859- return firstFragment.returnType;
858+ var result = _returnType;
859+ if (result != null ) {
860+ return result as InterfaceTypeImpl ;
861+ }
862+
863+ return _returnType = enclosingElement.thisType;
860864 }
861865
862866 @override
@@ -1073,33 +1077,6 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl
10731077 firstTokenOffset ??
10741078 enclosingElement.offset;
10751079
1076- @override
1077- InterfaceTypeImpl get returnType {
1078- var result = _returnType;
1079- if (result != null ) {
1080- return result as InterfaceTypeImpl ;
1081- }
1082-
1083- result = enclosingElement.element.thisType;
1084- return _returnType = result as InterfaceTypeImpl ;
1085- }
1086-
1087- @override
1088- FunctionTypeImpl get type {
1089- // TODO(scheglov): Remove "element" in the breaking changes branch.
1090- return _type ?? = FunctionTypeImpl (
1091- typeParameters: typeParameters.map ((f) => f.asElement2).toList (),
1092- parameters: parameters.map ((f) => f.asElement2).toList (),
1093- returnType: returnType,
1094- nullabilitySuffix: NullabilitySuffix .none,
1095- );
1096- }
1097-
1098- @override
1099- set type (FunctionType type) {
1100- assert (false );
1101- }
1102-
11031080 @override
11041081 void appendTo (ElementDisplayStringBuilder builder) {
11051082 builder.writeConstructorFragment (this );
@@ -2121,6 +2098,7 @@ abstract class ExecutableElementImpl extends FunctionTypedElementImpl
21212098 with DeferredResolutionReadingMixin
21222099 implements ExecutableElement2OrMember , AnnotatableElementImpl {
21232100 TypeImpl ? _returnType;
2101+ FunctionTypeImpl ? _type;
21242102
21252103 @override
21262104 ExecutableElementImpl get baseElement => this ;
@@ -2136,24 +2114,27 @@ abstract class ExecutableElementImpl extends FunctionTypedElementImpl
21362114 @override
21372115 List <Element > get children2 => children;
21382116
2117+ @override
2118+ ExecutableFragmentImpl get firstFragment;
2119+
21392120 /// Whether the type of this element references a type parameter of the
21402121 /// enclosing element. This includes not only explicitly specified type
21412122 /// annotations, but also inferred types.
21422123 ///
21432124 /// Top-level declarations don't have enclosing element type parameters,
21442125 /// so for them this flag is always `false` .
21452126 bool get hasEnclosingTypeParameterReference {
2146- var firstFragment = this .firstFragment as ExecutableFragmentImpl ;
2127+ var firstFragment = this .firstFragment;
21472128 return firstFragment.hasEnclosingTypeParameterReference;
21482129 }
21492130
21502131 bool get invokesSuperSelf {
2151- var firstFragment = this .firstFragment as ExecutableFragmentImpl ;
2132+ var firstFragment = this .firstFragment;
21522133 return firstFragment.hasModifier (Modifier .INVOKES_SUPER_SELF );
21532134 }
21542135
21552136 ExecutableFragmentImpl get lastFragment {
2156- var result = firstFragment as ExecutableFragmentImpl ;
2137+ var result = firstFragment;
21572138 while (true ) {
21582139 if (result.nextFragment case ExecutableFragmentImpl nextFragment) {
21592140 result = nextFragment;
@@ -2165,7 +2146,7 @@ abstract class ExecutableElementImpl extends FunctionTypedElementImpl
21652146
21662147 @override
21672148 LibraryElementImpl get library {
2168- var firstFragment = this .firstFragment as ExecutableFragmentImpl ;
2149+ var firstFragment = this .firstFragment;
21692150 return firstFragment.library;
21702151 }
21712152
@@ -2181,6 +2162,8 @@ abstract class ExecutableElementImpl extends FunctionTypedElementImpl
21812162 if (_returnType == null && isSynthetic) {
21822163 if (this case GetterElementImpl thisGetter) {
21832164 thisGetter.variable! .type;
2165+ } else if (this case SetterElementImpl thisSetter) {
2166+ thisSetter.variable! .type;
21842167 }
21852168 }
21862169
@@ -2189,6 +2172,24 @@ abstract class ExecutableElementImpl extends FunctionTypedElementImpl
21892172
21902173 set returnType (TypeImpl value) {
21912174 _returnType = value;
2175+ // We do this because of return type inference. At the moment when we
2176+ // create a local function element we don't know yet its return type,
2177+ // because we have not done static type analysis yet.
2178+ // It somewhere it between we access the type of this element, so it gets
2179+ // cached in the element. When we are done static type analysis, we then
2180+ // should clear this cached type to make it right.
2181+ // TODO(scheglov): Remove when type analysis is done in the single pass.
2182+ _type = null ;
2183+ }
2184+
2185+ @override
2186+ FunctionTypeImpl get type {
2187+ return _type ?? = FunctionTypeImpl (
2188+ typeParameters: typeParameters.cast (),
2189+ parameters: formalParameters,
2190+ returnType: returnType,
2191+ nullabilitySuffix: NullabilitySuffix .none,
2192+ );
21922193 }
21932194}
21942195
@@ -2199,12 +2200,6 @@ abstract class ExecutableFragmentImpl extends _ExistingFragmentImpl
21992200 /// element.
22002201 List <FormalParameterFragmentImpl > _parameters = const [];
22012202
2202- /// The inferred return type of this executable element.
2203- TypeImpl ? _returnType;
2204-
2205- /// The type of function defined by this executable element.
2206- FunctionTypeImpl ? _type;
2207-
22082203 /// Initialize a newly created executable element to have the given [name] and
22092204 /// [offset] .
22102205 ExecutableFragmentImpl ({required super .firstTokenOffset});
@@ -2359,52 +2354,6 @@ abstract class ExecutableFragmentImpl extends _ExistingFragmentImpl
23592354 return _parameters;
23602355 }
23612356
2362- /// The return type specified by this fragment.
2363- TypeImpl get returnType {
2364- _ensureReadResolution ();
2365-
2366- // If a synthetic getter, we might need to infer the type.
2367- if (_returnType == null && isSynthetic) {
2368- if (this case GetterFragmentImpl thisGetter) {
2369- thisGetter.element.variable! .type;
2370- } else if (this case SetterFragmentImpl thisSetter) {
2371- thisSetter.element.variable! .type;
2372- }
2373- }
2374-
2375- return _returnType! ;
2376- }
2377-
2378- set returnType (DartType returnType) {
2379- // TODO(paulberry): eliminate this cast by changing the setter parameter
2380- // type to `TypeImpl`.
2381- _returnType = returnType as TypeImpl ;
2382- // We do this because of return type inference. At the moment when we
2383- // create a local function element we don't know yet its return type,
2384- // because we have not done static type analysis yet.
2385- // It somewhere it between we access the type of this element, so it gets
2386- // cached in the element. When we are done static type analysis, we then
2387- // should clear this cached type to make it right.
2388- // TODO(scheglov): Remove when type analysis is done in the single pass.
2389- _type = null ;
2390- }
2391-
2392- /// The type defined by this element.
2393- FunctionTypeImpl get type {
2394- if (_type != null ) return _type! ;
2395-
2396- return _type = FunctionTypeImpl (
2397- typeParameters: typeParameters.map ((f) => f.asElement2).toList (),
2398- parameters: parameters.map ((f) => f.asElement2).toList (),
2399- returnType: returnType,
2400- nullabilitySuffix: NullabilitySuffix .none,
2401- );
2402- }
2403-
2404- set type (FunctionTypeImpl type) {
2405- _type = type;
2406- }
2407-
24082357 @override
24092358 void appendTo (ElementDisplayStringBuilder builder) {
24102359 builder.writeExecutableFragment (this , displayName);
@@ -3559,38 +3508,6 @@ mixin FragmentedExecutableElementMixin<E extends ExecutableFragmentImpl>
35593508 bool get isStatic => (firstFragment as ExecutableFragmentImpl ).isStatic;
35603509}
35613510
3562- mixin FragmentedFunctionTypedElementMixin <E extends ExecutableFragment >
3563- implements FragmentedElementMixin <E > {
3564- // TODO(augmentations): This might be wrong. The parameters need to be a
3565- // merge of the parameters of all of the fragments, but this probably doesn't
3566- // account for missing data (such as the parameter types).
3567- List <FormalParameterElementMixin > get formalParameters {
3568- var fragment = firstFragment;
3569- return switch (fragment) {
3570- FunctionTypedFragmentImpl (: var parameters) =>
3571- parameters.map ((fragment) => fragment.asElement2).toList (),
3572- ExecutableFragmentImpl (: var parameters) =>
3573- parameters.map ((fragment) => fragment.asElement2).toList (),
3574- _ =>
3575- throw UnsupportedError (
3576- 'Cannot get formal parameters for ${fragment .runtimeType }' ,
3577- ),
3578- };
3579- }
3580-
3581- // TODO(augmentations): This is wrong. The function type needs to be a merge
3582- // of the function types of all of the fragments, but I don't know how to
3583- // perform that merge.
3584- FunctionTypeImpl get type {
3585- if (firstFragment is ExecutableFragmentImpl ) {
3586- return (firstFragment as ExecutableFragmentImpl ).type;
3587- } else if (firstFragment is FunctionTypedFragmentImpl ) {
3588- return (firstFragment as FunctionTypedFragmentImpl ).type;
3589- }
3590- throw UnimplementedError ();
3591- }
3592- }
3593-
35943511mixin FragmentedTypeParameterizedElementMixin <
35953512 E extends TypeParameterizedFragment
35963513>
@@ -3941,11 +3858,6 @@ abstract class FunctionTypedFragmentImpl implements _ExistingFragmentImpl {
39413858 /// The parameters defined by this executable element.
39423859 List <FormalParameterFragmentImpl > get parameters;
39433860
3944- set returnType (DartType returnType);
3945-
3946- /// The type defined by this element.
3947- FunctionTypeImpl get type;
3948-
39493861 /// The type parameters declared by this element directly.
39503862 ///
39513863 /// This does not include type parameters that are declared by any enclosing
@@ -4130,14 +4042,12 @@ class GenericFunctionTypeFragmentImpl extends _ExistingFragmentImpl
41304042
41314043 /// Set the return type defined by this function type element to the given
41324044 /// [returnType] .
4133- @override
41344045 set returnType (DartType returnType) {
41354046 // TODO(paulberry): eliminate this cast by changing the setter parameter
41364047 // type to `TypeImpl`.
41374048 _returnType = returnType as TypeImpl ;
41384049 }
41394050
4140- @override
41414051 FunctionTypeImpl get type {
41424052 if (_type != null ) return _type! ;
41434053
@@ -4173,7 +4083,6 @@ abstract class GetterElement2OrMember
41734083class GetterElementImpl extends PropertyAccessorElementImpl
41744084 with
41754085 FragmentedExecutableElementMixin <GetterFragmentImpl >,
4176- FragmentedFunctionTypedElementMixin <GetterFragmentImpl >,
41774086 FragmentedTypeParameterizedElementMixin <GetterFragmentImpl >,
41784087 FragmentedAnnotatableElementMixin <GetterFragmentImpl >,
41794088 FragmentedElementMixin <GetterFragmentImpl >,
@@ -6971,7 +6880,6 @@ final class LoadLibraryFunctionProvider {
69716880 );
69726881 fragment.isSynthetic = true ;
69736882 fragment.isStatic = true ;
6974- fragment.returnType = library.typeProvider.futureDynamicType;
69756883 fragment.enclosingElement = library.definingCompilationUnit;
69766884
69776885 return TopLevelFunctionElementImpl (elementReference, fragment)
@@ -7055,12 +6963,6 @@ class LocalFunctionElementImpl extends ExecutableElementImpl
70556963 @override
70566964 String ? get name3 => name;
70576965
7058- @override
7059- TypeImpl get returnType => _wrappedFragment.returnType;
7060-
7061- @override
7062- FunctionTypeImpl get type => _wrappedFragment.type;
7063-
70646966 @override
70656967 List <TypeParameterElement > get typeParameters =>
70666968 _wrappedFragment.typeParameters
@@ -7697,7 +7599,6 @@ abstract class MethodElement2OrMember
76977599class MethodElementImpl extends ExecutableElementImpl
76987600 with
76997601 FragmentedExecutableElementMixin <MethodFragmentImpl >,
7700- FragmentedFunctionTypedElementMixin <MethodFragmentImpl >,
77017602 FragmentedTypeParameterizedElementMixin <MethodFragmentImpl >,
77027603 FragmentedAnnotatableElementMixin <MethodFragmentImpl >,
77037604 FragmentedElementMixin <MethodFragmentImpl >,
@@ -9038,12 +8939,10 @@ abstract class PropertyInducingElementImpl extends VariableElementImpl
90388939 var element = this ;
90398940 if (element.getter case var getterElement? ) {
90408941 getterElement.returnType = type;
9041- getterElement.firstFragment.returnType = type;
90428942 }
90438943 if (element.setter case var setterElement? ) {
90448944 if (setterElement.isSynthetic) {
90458945 setterElement.returnType = VoidTypeImpl .instance;
9046- setterElement.firstFragment.returnType = VoidTypeImpl .instance;
90478946 (setterElement.formalParameters.single as FormalParameterElementImpl )
90488947 .type = type;
90498948 }
@@ -9147,7 +9046,6 @@ abstract class SetterElement2OrMember
91479046class SetterElementImpl extends PropertyAccessorElementImpl
91489047 with
91499048 FragmentedExecutableElementMixin <SetterFragmentImpl >,
9150- FragmentedFunctionTypedElementMixin <SetterFragmentImpl >,
91519049 FragmentedTypeParameterizedElementMixin <SetterFragmentImpl >,
91529050 FragmentedAnnotatableElementMixin <SetterFragmentImpl >,
91539051 FragmentedElementMixin <SetterFragmentImpl >,
@@ -9487,7 +9385,6 @@ class SuperFormalParameterFragmentImpl extends FormalParameterFragmentImpl
94879385class TopLevelFunctionElementImpl extends ExecutableElementImpl
94889386 with
94899387 FragmentedExecutableElementMixin <FunctionFragmentImpl >,
9490- FragmentedFunctionTypedElementMixin <FunctionFragmentImpl >,
94919388 FragmentedTypeParameterizedElementMixin <FunctionFragmentImpl >,
94929389 FragmentedAnnotatableElementMixin <FunctionFragmentImpl >,
94939390 FragmentedElementMixin <FunctionFragmentImpl >,
0 commit comments