22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- library fasta.source_type_alias_builder;
6-
75import 'package:kernel/ast.dart' ;
86import 'package:kernel/class_hierarchy.dart' ;
97
@@ -21,6 +19,7 @@ import '../builder/record_type_builder.dart';
2119import '../builder/type_builder.dart' ;
2220import '../codes/cfe_codes.dart'
2321 show templateCyclicTypedef, templateTypeArgumentMismatch;
22+ import '../fragment/fragment.dart' ;
2423import '../kernel/body_builder_context.dart' ;
2524import '../kernel/constructor_tearoff_lowering.dart' ;
2625import '../kernel/expression_generator_helper.dart' ;
@@ -29,47 +28,55 @@ import 'source_library_builder.dart' show SourceLibraryBuilder;
2928import 'source_loader.dart' ;
3029
3130class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
32- final List <MetadataBuilder >? metadata;
33-
34- @override
35- TypeBuilder type;
31+ late TypeBuilder _type;
3632
37- final List < NominalVariableBuilder > ? _typeVariables ;
33+ final Reference _reference ;
3834
39- /// The [Typedef] built by this builder.
40- @override
41- final Typedef typedef ;
35+ Typedef ? _typedef;
4236
4337 @override
4438 DartType ? thisType;
4539
4640 @override
4741 Map <Name , Procedure >? tearOffs;
4842
43+ TypedefFragment _introductory;
44+
4945 SourceTypeAliasBuilder (
50- {required this .metadata,
51- required String name,
52- required List <NominalVariableBuilder >? typeVariables,
53- required this .type,
46+ {required String name,
5447 required SourceLibraryBuilder enclosingLibraryBuilder,
5548 required Uri fileUri,
5649 required int fileOffset,
50+ required TypedefFragment fragment,
5751 required Reference ? reference})
58- : typedef = new Typedef (name, null ,
59- typeParameters: NominalVariableBuilder .typeParametersFromBuilders (
60- typeVariables),
61- fileUri: fileUri,
62- reference: reference)
63- ..fileOffset = fileOffset,
64- _typeVariables = typeVariables,
65- super (name, enclosingLibraryBuilder, fileUri, fileOffset);
52+ : _reference = reference ?? new Reference (),
53+ _introductory = fragment,
54+ _type = fragment.type,
55+ super (name, enclosingLibraryBuilder, fileUri, fileOffset) {
56+ _introductory.builder = this ;
57+ }
58+
59+ @override
60+ TypeBuilder get type => _type;
61+
62+ /// The [Typedef] built by this builder.
63+ @override
64+ Typedef get typedef {
65+ assert (
66+ _typedef != null , "Typedef node has not been created yet for $this ." );
67+ return _typedef! ;
68+ }
69+
70+ @override
71+ Reference get reference => _reference;
6672
6773 @override
6874 SourceLibraryBuilder get libraryBuilder =>
6975 super .libraryBuilder as SourceLibraryBuilder ;
7076
7177 @override
72- List <NominalVariableBuilder >? get typeVariables => _typeVariables;
78+ List <NominalVariableBuilder >? get typeVariables =>
79+ _introductory.typeVariables;
7380
7481 @override
7582 bool get fromDill => false ;
@@ -81,9 +88,15 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
8188
8289 void _breakCyclicDependency () {
8390 if (_hasCheckedForCyclicDependency) return ;
91+ _typedef = new Typedef (name, null ,
92+ typeParameters:
93+ NominalVariableBuilder .typeParametersFromBuilders (typeVariables),
94+ fileUri: fileUri,
95+ reference: _reference)
96+ ..fileOffset = charOffset;
8497 if (_checkCyclicTypedefDependency (type, this , {this })) {
8598 typedef .type = new InvalidType ();
86- type = new InvalidTypeBuilderImpl (fileUri, charOffset);
99+ _type = new InvalidTypeBuilderImpl (fileUri, charOffset);
87100 }
88101 if (typeVariables != null ) {
89102 for (TypeVariableBuilder typeVariable in typeVariables! ) {
@@ -97,15 +110,14 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
97110 // The typedef itself can't be used without proper bounds of its type
98111 // variables, so we set it to mean [InvalidType] too.
99112 typedef .type = new InvalidType ();
100- type = new InvalidTypeBuilderImpl (fileUri, charOffset);
113+ _type = new InvalidTypeBuilderImpl (fileUri, charOffset);
101114 }
102115 }
103116 }
104117 _hasCheckedForCyclicDependency = true ;
105118 }
106119
107120 Typedef build () {
108- _breakCyclicDependency ();
109121 buildThisType ();
110122 return typedef ;
111123 }
@@ -257,8 +269,10 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
257269
258270 @override
259271 DartType buildThisType () {
272+ _breakCyclicDependency ();
260273 if (thisType != null ) {
261274 if (identical (thisType, pendingTypeAliasMarker)) {
275+ // Coverage-ignore-block(suite): Not run.
262276 thisType = cyclicTypeAliasMarker;
263277 assert (libraryBuilder.loader.assertProblemReportedElsewhere (
264278 "SourceTypeAliasBuilder.buildThisType" ,
@@ -346,7 +360,7 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
346360 List <DelayedDefaultValueCloner > delayedDefaultValueCloners) {
347361 MetadataBuilder .buildAnnotations (
348362 typedef ,
349- metadata,
363+ _introductory. metadata,
350364 createBodyBuilderContext (
351365 inOutlineBuildingPhase: true ,
352366 inMetadata: true ,
0 commit comments