@@ -3054,22 +3054,26 @@ void TypeTranslator::BuildFunctionType(bool simple) {
3054
3054
3055
3055
// Suspend finalization of types inside this one. They will be finalized after
3056
3056
// the whole function type is constructed.
3057
- //
3058
- // TODO(31213): Test further when nested generic function types
3059
- // are supported by fasta.
3060
3057
bool finalize = finalize_;
3061
3058
finalize_ = false ;
3059
+ intptr_t type_parameter_count = 0 ;
3062
3060
3063
3061
if (!simple) {
3062
+ type_parameter_count = helper_->ReadListLength ();
3064
3063
LoadAndSetupTypeParameters (
3065
3064
active_class_, Object::null_function (), Object::null_class (), signature,
3066
- helper_-> ReadListLength () , active_class_->klass ->nnbd_mode ());
3065
+ type_parameter_count , active_class_->klass ->nnbd_mode ());
3067
3066
}
3068
3067
3069
3068
ActiveTypeParametersScope scope (
3070
3069
active_class_, &signature,
3071
3070
TypeArguments::Handle (Z, signature.type_parameters ()), Z);
3072
3071
3072
+ if (!simple) {
3073
+ LoadAndSetupBounds (active_class_, Object::null_function (),
3074
+ Object::null_class (), signature, type_parameter_count);
3075
+ }
3076
+
3073
3077
intptr_t required_count;
3074
3078
intptr_t all_count;
3075
3079
intptr_t positional_count;
@@ -3324,7 +3328,6 @@ void TypeTranslator::LoadAndSetupTypeParameters(
3324
3328
? Nullability::kNonNullable
3325
3329
: Nullability::kLegacy ;
3326
3330
3327
- // Step a)
3328
3331
// - Create array of [TypeParameter] objects (without bound).
3329
3332
// - Create array of [String] objects.
3330
3333
type_parameters = TypeArguments::New (type_parameter_count);
@@ -3354,20 +3357,35 @@ void TypeTranslator::LoadAndSetupTypeParameters(
3354
3357
} else {
3355
3358
name = H.DartIdentifier (lib, helper.name_index_ ).ptr ();
3356
3359
}
3360
+ // Bounds are filled later in LoadAndSetupBounds as bound types may
3361
+ // reference type parameters which are not created yet.
3357
3362
parameter = TypeParameter::New (
3358
3363
parameterized_class, offset, offset + i, name, null_bound,
3359
3364
helper.IsGenericCovariantImpl (), nullability);
3360
3365
type_parameters.SetTypeAt (i, parameter);
3361
3366
}
3362
3367
}
3368
+ }
3363
3369
3364
- const FunctionType* enclosing = NULL ;
3365
- if (!parameterized_signature.IsNull ()) {
3366
- enclosing = ¶meterized_signature;
3370
+ void TypeTranslator::LoadAndSetupBounds (
3371
+ ActiveClass* active_class,
3372
+ const Function& function,
3373
+ const Class& parameterized_class,
3374
+ const FunctionType& parameterized_signature,
3375
+ intptr_t type_parameter_count) {
3376
+ ASSERT (parameterized_class.IsNull () != parameterized_signature.IsNull ());
3377
+ ASSERT (type_parameter_count >= 0 );
3378
+ if (type_parameter_count == 0 ) {
3379
+ return ;
3367
3380
}
3368
- ActiveTypeParametersScope scope (active_class, enclosing, type_parameters, Z);
3369
3381
3370
- // Step b) Fill in the bounds and default arguments of all [TypeParameter]s.
3382
+ const TypeArguments& type_parameters =
3383
+ TypeArguments::Handle (Z, !parameterized_class.IsNull ()
3384
+ ? parameterized_class.type_parameters ()
3385
+ : parameterized_signature.type_parameters ());
3386
+ TypeParameter& parameter = TypeParameter::Handle (Z);
3387
+
3388
+ // Fill in the bounds and default arguments of all [TypeParameter]s.
3371
3389
for (intptr_t i = 0 ; i < type_parameter_count; i++) {
3372
3390
TypeParameterHelper helper (helper_);
3373
3391
helper.ReadUntilExcludingAndSetJustRead (TypeParameterHelper::kBound );
@@ -3389,6 +3407,9 @@ void TypeTranslator::LoadAndSetupTypeParameters(
3389
3407
3390
3408
// Fix bounds and default arguments in all derived type parameters (with
3391
3409
// different nullabilities).
3410
+ const intptr_t offset = !parameterized_signature.IsNull ()
3411
+ ? parameterized_signature.NumParentTypeArguments ()
3412
+ : 0 ;
3392
3413
if (active_class->derived_type_parameters != nullptr ) {
3393
3414
auto & derived = TypeParameter::Handle (Z);
3394
3415
auto & type = AbstractType::Handle (Z);
@@ -3535,15 +3556,22 @@ void TypeTranslator::SetupFunctionParameters(
3535
3556
3536
3557
const FunctionType& signature = FunctionType::Handle (Z, function.signature ());
3537
3558
ASSERT (!signature.IsNull ());
3559
+ intptr_t type_parameter_count = 0 ;
3538
3560
if (!is_factory) {
3561
+ type_parameter_count = helper_->ReadListLength ();
3539
3562
LoadAndSetupTypeParameters (active_class_, function, Class::Handle (Z),
3540
- signature, helper_-> ReadListLength () ,
3563
+ signature, type_parameter_count ,
3541
3564
function.nnbd_mode ());
3542
- function_node_helper->SetJustRead (FunctionNodeHelper::kTypeParameters );
3543
3565
}
3544
3566
3545
3567
ActiveTypeParametersScope scope (active_class_, function, &signature, Z);
3546
3568
3569
+ if (!is_factory) {
3570
+ LoadAndSetupBounds (active_class_, function, Class::Handle (Z), signature,
3571
+ type_parameter_count);
3572
+ function_node_helper->SetJustRead (FunctionNodeHelper::kTypeParameters );
3573
+ }
3574
+
3547
3575
function_node_helper->ReadUntilExcluding (
3548
3576
FunctionNodeHelper::kPositionalParameters );
3549
3577
0 commit comments