@@ -1962,6 +1962,15 @@ class EnumElementImpl extends InterfaceElementImpl implements EnumElement {
19621962 @override
19631963 ElementKind get kind => ElementKind .ENUM ;
19641964
1965+ FieldElementImpl ? get valuesField {
1966+ for (var field in fields) {
1967+ if (field.name3 == 'values' && field.isSyntheticEnumField) {
1968+ return field;
1969+ }
1970+ }
1971+ return null ;
1972+ }
1973+
19651974 @override
19661975 T ? accept <T >(ElementVisitor2 <T > visitor) => visitor.visitEnumElement (this );
19671976
@@ -1994,15 +2003,6 @@ class EnumFragmentImpl extends InterfaceFragmentImpl implements EnumFragment {
19942003 EnumFragmentImpl ? get previousFragment =>
19952004 super .previousFragment as EnumFragmentImpl ? ;
19962005
1997- FieldFragmentImpl ? get valuesField {
1998- for (var field in fields) {
1999- if (field.name == 'values' && field.isSyntheticEnumField) {
2000- return field;
2001- }
2002- }
2003- return null ;
2004- }
2005-
20062006 void addFragment (EnumFragmentImpl fragment) {
20072007 fragment.element = element;
20082008 fragment.previousFragment = this ;
@@ -2589,17 +2589,14 @@ class FieldElementImpl extends PropertyInducingElementImpl
25892589 with
25902590 FragmentedAnnotatableElementMixin <FieldFragmentImpl >,
25912591 FragmentedElementMixin <FieldFragmentImpl >,
2592- _HasSinceSdkVersionMixin ,
2593- DeferredResolutionReadingMixin
2592+ _HasSinceSdkVersionMixin
25942593 implements FieldElement2OrMember {
25952594 @override
25962595 final Reference reference;
25972596
25982597 @override
25992598 final FieldFragmentImpl firstFragment;
26002599
2601- TypeImpl ? _type;
2602-
26032600 FieldElementImpl ({required this .reference, required this .firstFragment}) {
26042601 reference.element = this ;
26052602 firstFragment.element = this ;
@@ -2669,6 +2666,20 @@ class FieldElementImpl extends PropertyInducingElementImpl
26692666 @override
26702667 bool get isStatic => firstFragment.isStatic;
26712668
2669+ /// Return `true` if this element is a synthetic enum field.
2670+ ///
2671+ /// It is synthetic because it is not written explicitly in code, but it
2672+ /// is different from other synthetic fields, because its getter is also
2673+ /// synthetic.
2674+ ///
2675+ /// Such fields are `index` , `_name` , and `values` .
2676+ bool get isSyntheticEnumField {
2677+ return enclosingElement is EnumElementImpl &&
2678+ isSynthetic &&
2679+ getter2? .isSynthetic == true &&
2680+ setter2 == null ;
2681+ }
2682+
26722683 @override
26732684 ElementKind get kind => ElementKind .FIELD ;
26742685
@@ -2682,43 +2693,6 @@ class FieldElementImpl extends PropertyInducingElementImpl
26822693 @override
26832694 String ? get name3 => firstFragment.name;
26842695
2685- @override
2686- TypeImpl get type {
2687- _ensureReadResolution ();
2688- if (_type != null ) return _type! ;
2689-
2690- // We must be linking, and the type has not been set yet.
2691- var type = firstFragment.typeInference? .perform ();
2692- type ?? = InvalidTypeImpl .instance;
2693- _type = type;
2694- firstFragment._type = type;
2695- firstFragment.shouldUseTypeForInitializerInference = false ;
2696-
2697- // TODO(scheglov): We repeat this code.
2698- var element = this ;
2699- if (element.getter2 case var getterElement? ) {
2700- getterElement.returnType = type;
2701- getterElement.firstFragment.returnType = type;
2702- }
2703- if (element.setter2 case var setterElement? ) {
2704- if (setterElement.isSynthetic) {
2705- setterElement.returnType = VoidTypeImpl .instance;
2706- setterElement.firstFragment.returnType = VoidTypeImpl .instance;
2707- (setterElement.formalParameters.single as FormalParameterElementImpl )
2708- .type = type;
2709- (setterElement.formalParameters.single as FormalParameterElementImpl )
2710- .firstFragment
2711- .type = type;
2712- }
2713- }
2714-
2715- return _type! ;
2716- }
2717-
2718- set type (TypeImpl value) {
2719- _type = value;
2720- }
2721-
27222696 @override
27232697 T ? accept <T >(ElementVisitor2 <T > visitor) {
27242698 return visitor.visitFieldElement (this );
@@ -2878,21 +2852,6 @@ class FieldFragmentImpl extends PropertyInducingFragmentImpl
28782852 setModifier (Modifier .PROMOTABLE , value);
28792853 }
28802854
2881- /// Return `true` if this element is a synthetic enum field.
2882- ///
2883- /// It is synthetic because it is not written explicitly in code, but it
2884- /// is different from other synthetic fields, because its getter is also
2885- /// synthetic.
2886- ///
2887- /// Such fields are `index` , `_name` , and `values` .
2888- bool get isSyntheticEnumField {
2889- // TODO(scheglov): move to element
2890- return enclosingElement3 is EnumFragmentImpl &&
2891- isSynthetic &&
2892- element.getter2? .isSynthetic == true &&
2893- element.setter2 == null ;
2894- }
2895-
28962855 @override
28972856 MetadataImpl get metadata {
28982857 _ensureReadResolution ();
@@ -3066,6 +3025,7 @@ class FormalParameterElementImpl extends PromotableElementImpl
30663025 // TODO(augmentations): Implement the merge of formal parameters.
30673026 TypeImpl get type => wrappedElement.type;
30683027
3028+ @override
30693029 set type (TypeImpl value) {
30703030 wrappedElement.type = value;
30713031 }
@@ -8218,10 +8178,7 @@ class PatternVariableFragmentImpl extends LocalVariableFragmentImpl
82188178 /// the [GuardedPattern] that declares this variable.
82198179 bool isVisitingWhenClause = false ;
82208180
8221- PatternVariableFragmentImpl ({
8222- required super .name,
8223- required super .nameOffset,
8224- });
8181+ PatternVariableFragmentImpl ({required super .name, required super .nameOffset});
82258182
82268183 @override
82278184 PatternVariableElementImpl get element =>
@@ -8455,10 +8412,7 @@ sealed class PropertyAccessorFragmentImpl extends ExecutableFragmentImpl
84558412
84568413 /// Initialize a newly created property accessor element to have the given
84578414 /// [name] and [offset] .
8458- PropertyAccessorFragmentImpl ({
8459- required this .name,
8460- required super .nameOffset,
8461- });
8415+ PropertyAccessorFragmentImpl ({required this .name, required super .nameOffset});
84628416
84638417 /// Initialize a newly created synthetic property accessor element to be
84648418 /// associated with the given [variable] .
@@ -8527,13 +8481,20 @@ abstract class PropertyInducingElement2OrMember
85278481}
85288482
85298483abstract class PropertyInducingElementImpl extends VariableElementImpl
8484+ with DeferredResolutionReadingMixin
85308485 implements PropertyInducingElement2OrMember , AnnotatableElementImpl {
85318486 @override
85328487 GetterElementImpl ? getter2;
85338488
85348489 @override
85358490 SetterElementImpl ? setter2;
85368491
8492+ TypeImpl ? _type;
8493+
8494+ PropertyInducingElementImpl () {
8495+ shouldUseTypeForInitializerInference = true ;
8496+ }
8497+
85378498 @override
85388499 PropertyInducingFragmentImpl get firstFragment;
85398500
@@ -8573,7 +8534,49 @@ abstract class PropertyInducingElementImpl extends VariableElementImpl
85738534 Reference get reference;
85748535
85758536 bool get shouldUseTypeForInitializerInference {
8576- return firstFragment.shouldUseTypeForInitializerInference;
8537+ return hasModifier (Modifier .SHOULD_USE_TYPE_FOR_INITIALIZER_INFERENCE );
8538+ }
8539+
8540+ set shouldUseTypeForInitializerInference (bool value) {
8541+ setModifier (Modifier .SHOULD_USE_TYPE_FOR_INITIALIZER_INFERENCE , value);
8542+ }
8543+
8544+ @override
8545+ TypeImpl get type {
8546+ _ensureReadResolution ();
8547+ if (_type != null ) return _type! ;
8548+
8549+ // We must be linking, and the type has not been set yet.
8550+ var type = firstFragment.typeInference? .perform ();
8551+ type ?? = InvalidTypeImpl .instance;
8552+ _type = type;
8553+ firstFragment._type = type;
8554+ shouldUseTypeForInitializerInference = false ;
8555+
8556+ // TODO(scheglov): We repeat this code.
8557+ var element = this ;
8558+ if (element.getter2 case var getterElement? ) {
8559+ getterElement.returnType = type;
8560+ getterElement.firstFragment.returnType = type;
8561+ }
8562+ if (element.setter2 case var setterElement? ) {
8563+ if (setterElement.isSynthetic) {
8564+ setterElement.returnType = VoidTypeImpl .instance;
8565+ setterElement.firstFragment.returnType = VoidTypeImpl .instance;
8566+ (setterElement.formalParameters.single as FormalParameterElementImpl )
8567+ .type = type;
8568+ (setterElement.formalParameters.single as FormalParameterElementImpl )
8569+ .firstFragment
8570+ .type = type;
8571+ }
8572+ }
8573+
8574+ return _type! ;
8575+ }
8576+
8577+ @override
8578+ set type (TypeImpl value) {
8579+ _type = value;
85778580 }
85788581
85798582 List <PropertyInducingFragmentImpl > get _fragments;
@@ -8614,12 +8617,7 @@ abstract class PropertyInducingFragmentImpl
86148617
86158618 /// Initialize a newly created synthetic element to have the given [name] and
86168619 /// [offset] .
8617- PropertyInducingFragmentImpl ({
8618- required this .name,
8619- required super .nameOffset,
8620- }) {
8621- setModifier (Modifier .SHOULD_USE_TYPE_FOR_INITIALIZER_INFERENCE , true );
8622- }
8620+ PropertyInducingFragmentImpl ({required this .name, required super .nameOffset});
86238621
86248622 @override
86258623 List <Fragment > get children3 => const [];
@@ -8652,52 +8650,9 @@ abstract class PropertyInducingFragmentImpl
86528650 @override
86538651 MetadataImpl get metadata2 => metadata;
86548652
8655- bool get shouldUseTypeForInitializerInference {
8656- return hasModifier (Modifier .SHOULD_USE_TYPE_FOR_INITIALIZER_INFERENCE );
8657- }
8658-
8659- set shouldUseTypeForInitializerInference (bool value) {
8660- setModifier (Modifier .SHOULD_USE_TYPE_FOR_INITIALIZER_INFERENCE , value);
8661- }
8662-
86638653 @override
86648654 TypeImpl get type {
86658655 _ensureReadResolution ();
8666- if (_type != null ) return _type! ;
8667-
8668- if (isSynthetic) {
8669- if (element.getter2 case var getter? ) {
8670- return _type = getter.returnType;
8671- }
8672- if (element.setter2 case var setter? ) {
8673- if (setter.formalParameters case [var value, ...]) {
8674- return _type = value.type;
8675- }
8676- }
8677- return _type = DynamicTypeImpl .instance;
8678- }
8679-
8680- // We must be linking, and the type has not been set yet.
8681- var type = typeInference! .perform ();
8682- _type = type;
8683- // TODO(scheglov): We repeat this code.
8684- if (element.getter2 case var getterElement? ) {
8685- getterElement.returnType = type;
8686- getterElement.firstFragment.returnType = type;
8687- }
8688- if (element.setter2 case var setterElement? ) {
8689- if (setterElement.isSynthetic) {
8690- setterElement.returnType = VoidTypeImpl .instance;
8691- setterElement.firstFragment.returnType = VoidTypeImpl .instance;
8692- (setterElement.formalParameters.single as FormalParameterElementImpl )
8693- .type = type;
8694- (setterElement.formalParameters.single as FormalParameterElementImpl )
8695- .firstFragment
8696- .type = type;
8697- }
8698- }
8699-
8700- shouldUseTypeForInitializerInference = false ;
87018656 return _type! ;
87028657 }
87038658}
@@ -9156,17 +9111,14 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl
91569111 with
91579112 FragmentedAnnotatableElementMixin <TopLevelVariableFragmentImpl >,
91589113 FragmentedElementMixin <TopLevelVariableFragmentImpl >,
9159- _HasSinceSdkVersionMixin ,
9160- DeferredResolutionReadingMixin
9114+ _HasSinceSdkVersionMixin
91619115 implements TopLevelVariableElement {
91629116 @override
91639117 final Reference reference;
91649118
91659119 @override
91669120 final TopLevelVariableFragmentImpl firstFragment;
91679121
9168- TypeImpl ? _type;
9169-
91709122 TopLevelVariableElementImpl (this .reference, this .firstFragment) {
91719123 reference.element = this ;
91729124 firstFragment.element = this ;
@@ -9225,43 +9177,6 @@ class TopLevelVariableElementImpl extends PropertyInducingElementImpl
92259177 @override
92269178 String ? get name3 => firstFragment.name;
92279179
9228- @override
9229- TypeImpl get type {
9230- _ensureReadResolution ();
9231- if (_type != null ) return _type! ;
9232-
9233- // We must be linking, and the type has not been set yet.
9234- var type = firstFragment.typeInference? .perform ();
9235- type ?? = InvalidTypeImpl .instance;
9236- _type = type;
9237- firstFragment._type = type;
9238- firstFragment.shouldUseTypeForInitializerInference = false ;
9239-
9240- // TODO(scheglov): We repeat this code.
9241- var element = this ;
9242- if (element.getter2 case var getterElement? ) {
9243- getterElement.returnType = type;
9244- getterElement.firstFragment.returnType = type;
9245- }
9246- if (element.setter2 case var setterElement? ) {
9247- if (setterElement.isSynthetic) {
9248- setterElement.returnType = VoidTypeImpl .instance;
9249- setterElement.firstFragment.returnType = VoidTypeImpl .instance;
9250- (setterElement.formalParameters.single as FormalParameterElementImpl )
9251- .type = type;
9252- (setterElement.formalParameters.single as FormalParameterElementImpl )
9253- .firstFragment
9254- .type = type;
9255- }
9256- }
9257-
9258- return _type! ;
9259- }
9260-
9261- set type (TypeImpl value) {
9262- _type = value;
9263- }
9264-
92659180 @override
92669181 T ? accept <T >(ElementVisitor2 <T > visitor) {
92679182 return visitor.visitTopLevelVariableElement (this );
@@ -10046,6 +9961,10 @@ abstract class VariableElementImpl extends ElementImpl
100469961 LibraryFragmentImpl ? get libraryFragment =>
100479962 firstFragment.libraryFragment as LibraryFragmentImpl ? ;
100489963
9964+ set type (TypeImpl type) {
9965+ // TODO(scheglov): eventually move logic from PropertyInducingElementImpl
9966+ }
9967+
100499968 /// Return a representation of the value of this variable, forcing the value
100509969 /// to be computed if it had not previously been computed, or `null` if either
100519970 /// this variable was not declared with the 'const' modifier or if the value
0 commit comments