@@ -868,7 +868,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
868
868
var holder = _EnclosingContext (
869
869
instanceElementBuilder: null ,
870
870
fragment: fragment,
871
- constFieldsForFinalInstance: true ,
872
871
);
873
872
_withEnclosing (holder, () {
874
873
node.typeParameters? .accept (this );
@@ -1011,7 +1010,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
1011
1010
var holder = _EnclosingContext (
1012
1011
instanceElementBuilder: null ,
1013
1012
fragment: fragment,
1014
- constFieldsForFinalInstance: true ,
1015
1013
);
1016
1014
1017
1015
// Build fields for all enum constants.
@@ -1279,24 +1277,6 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
1279
1277
name2: _getFragmentName (nameToken),
1280
1278
nameOffset: nameOffset,
1281
1279
);
1282
- if (variable.initializer case var initializer? ) {
1283
- if (node.fields.isConst) {
1284
- fragment = FieldFragmentImpl (
1285
- name2: _getFragmentName (nameToken),
1286
- nameOffset: nameOffset,
1287
- )..constantInitializer = initializer;
1288
- } else if (_enclosingContext.constFieldsForFinalInstance) {
1289
- if (node.fields.isFinal && ! node.isStatic) {
1290
- var constElement = FieldFragmentImpl (
1291
- name2: _getFragmentName (nameToken),
1292
- nameOffset: nameOffset,
1293
- )..constantInitializer = initializer;
1294
- fragment = constElement;
1295
- _libraryBuilder.finalInstanceFields.add (constElement);
1296
- }
1297
- }
1298
- }
1299
-
1300
1280
fragment.nameOffset2 = _getFragmentNameOffset (nameToken);
1301
1281
fragment.hasInitializer = variable.initializer != null ;
1302
1282
fragment.isAbstract = node.abstractKeyword != null ;
@@ -1311,6 +1291,15 @@ class FragmentBuilder extends ThrowingAstVisitor<void> {
1311
1291
_setCodeRange (fragment, variable);
1312
1292
_setDocumentation (fragment, node);
1313
1293
1294
+ if (variable.initializer case var initializer? ) {
1295
+ if (node.fields.isConst) {
1296
+ fragment.constantInitializer = initializer;
1297
+ } else if (node.fields.isFinal && ! node.isStatic) {
1298
+ fragment.constantInitializer = initializer;
1299
+ _libraryBuilder.finalInstanceFields.add (fragment);
1300
+ }
1301
+ }
1302
+
1314
1303
if (node.fields.type == null ) {
1315
1304
fragment.hasImplicitType = true ;
1316
1305
}
@@ -2213,10 +2202,6 @@ class _EnclosingContext {
2213
2202
final List <TypeAliasFragmentImpl > _typeAliases = [];
2214
2203
final List <TypeParameterFragmentImpl > _typeParameters = [];
2215
2204
2216
- /// A class can have `const` constructors, and if it has we need values
2217
- /// of final instance fields.
2218
- final bool constFieldsForFinalInstance;
2219
-
2220
2205
/// Not all optional formal parameters can have default values.
2221
2206
/// For example, formal parameters of methods can, but formal parameters
2222
2207
/// of function types - not. This flag specifies if we should create
@@ -2226,7 +2211,6 @@ class _EnclosingContext {
2226
2211
_EnclosingContext ({
2227
2212
required this .instanceElementBuilder,
2228
2213
required this .fragment,
2229
- this .constFieldsForFinalInstance = false ,
2230
2214
this .hasDefaultFormalParameters = false ,
2231
2215
});
2232
2216
0 commit comments