@@ -148,7 +148,7 @@ Error: $e
148148 RecordedUsesSyntax syntax,
149149 DefinitionDeserializationContext definitionContext,
150150 ) {
151- final constants = < Constant > [];
151+ final constants = < MaybeConstant > [];
152152 // Create a context that includes an empty list for the constants. This
153153 // list will be populated by [_deserializeConstants], providing the
154154 // self-referential access needed to resolve recursive constants (e.g.
@@ -158,7 +158,10 @@ Error: $e
158158 constants,
159159 );
160160 for (final constantSyntax in syntax.constants ?? < ConstantSyntax > []) {
161- final constant = ConstantProtected .fromSyntax (constantSyntax, context);
161+ final constant = MaybeConstantProtected .fromSyntax (
162+ constantSyntax,
163+ context,
164+ );
162165 if (! constants.contains (constant)) {
163166 constants.add (constant);
164167 }
@@ -237,44 +240,36 @@ Error: $e
237240 );
238241 }
239242
240- Iterable <Constant > _collectConstants () => {
241- ...calls.values
242- .expand ((calls) => calls)
243- .whereType <CallWithArguments >()
244- .expand (
245- (call) => [
246- ...call.positionalArguments,
247- ...call.namedArguments.values,
248- ],
249- )
250- .expand (
251- (argument) => switch (argument) {
252- final Constant c => [c],
253- NonConstant () => < Constant > [],
254- },
255- ),
256- ...instances.values
257- .expand ((instances) => instances)
258- .expand (
259- (instance) => switch (instance) {
260- InstanceConstantReference (: final instanceConstant) => {
261- ...instanceConstant.fields.values,
262- instanceConstant,
243+ Iterable <MaybeConstant > _collectConstants () {
244+ final values = < MaybeConstant > {
245+ ...calls.values
246+ .expand ((calls) => calls)
247+ .whereType <CallWithArguments >()
248+ .expand (
249+ (call) => [
250+ ...call.positionalArguments,
251+ ...call.namedArguments.values,
252+ ],
253+ ),
254+ ...instances.values
255+ .expand ((instances) => instances)
256+ .expand (
257+ (instance) => switch (instance) {
258+ InstanceConstantReference (: final instanceConstant) => {
259+ ...instanceConstant.fields.values,
260+ instanceConstant,
261+ },
262+ InstanceCreationReference (
263+ : final positionalArguments,
264+ : final namedArguments,
265+ ) =>
266+ [...positionalArguments, ...namedArguments.values],
267+ ConstructorTearoffReference () => < MaybeConstant > [],
263268 },
264- InstanceCreationReference (
265- : final positionalArguments,
266- : final namedArguments,
267- ) =>
268- [...positionalArguments, ...namedArguments.values].expand (
269- (argument) => switch (argument) {
270- final Constant c => [c],
271- NonConstant () => < Constant > [],
272- },
273- ),
274- ConstructorTearoffReference () => < Constant > [],
275- },
276- ),
277- }.flatten ();
269+ ),
270+ };
271+ return values.flatten ();
272+ }
278273
279274 Iterable <LoadingUnit > _collectLoadingUnits () => {
280275 ...calls.values
@@ -292,7 +287,7 @@ Error: $e
292287 );
293288
294289 DefinitionSerializationContext _serializeDefinitions (
295- Iterable <Constant > allConstants,
290+ Iterable <MaybeConstant > allConstants,
296291 LoadingUnitSerializationContext loadingUnitContext,
297292 ) {
298293 final allDefinitions = {
@@ -307,7 +302,7 @@ Error: $e
307302 }
308303
309304 (SerializationContext , List <ConstantSyntax >) _serializeConstants (
310- Iterable <Constant > allConstants,
305+ Iterable <MaybeConstant > allConstants,
311306 DefinitionSerializationContext definitionContext,
312307 ) {
313308 final constantsMap = allConstants.asMapToIndices;
@@ -563,23 +558,24 @@ Error: $e
563558 }
564559}
565560
566- extension FlattenConstantsExtension on Iterable <Constant > {
567- Set <Constant > flatten () {
568- final constants = < Constant > {};
561+ extension FlattenConstantsExtension on Iterable <MaybeConstant > {
562+ Set <MaybeConstant > flatten () {
563+ final constants = < MaybeConstant > {};
569564 for (final constant in this ) {
570565 depthFirstSearch (constant, constants);
571566 }
572567 return constants;
573568 }
574569
575- void depthFirstSearch (Constant constant, Set <Constant > collected) {
576- final children = switch (constant) {
570+ void depthFirstSearch (MaybeConstant constant, Set <MaybeConstant > collected) {
571+ // ignore: omit_local_variable_types
572+ final Iterable <MaybeConstant > children = switch (constant) {
577573 ListConstant () => constant.value,
578574 MapConstant () => constant.entries.expand (
579575 (e) => [e.key, e.value],
580576 ),
581577 InstanceConstant () => constant.fields.values,
582- _ => < Constant > [],
578+ _ => < MaybeConstant > [],
583579 };
584580 for (final child in children) {
585581 if (! collected.contains (child)) {
0 commit comments