@@ -1195,20 +1195,31 @@ static void configureImplicitSelf(TypeChecker &tc,
1195
1195
selfDecl->setSpecifier (specifier);
1196
1196
1197
1197
selfDecl->setInterfaceType (selfParam.getPlainType ());
1198
+
1199
+ if (selfParam.getPlainType ()->is <ErrorType>())
1200
+ selfDecl->setInvalid ();
1198
1201
}
1199
1202
1200
- // / Record the context type of 'self' after the generic environment of
1201
- // / the function has been determined.
1202
- static void recordSelfContextType (AbstractFunctionDecl *func) {
1203
- auto selfDecl = func->getImplicitSelfDecl ();
1204
- auto selfParam = computeSelfParam (func, /* isInitializingCtor*/ true ,
1205
- /* wantDynamicSelf*/ true );
1203
+ static void recordParamContextTypes (AbstractFunctionDecl *func) {
1204
+ auto *env = func->getGenericEnvironment ();
1205
+ for (auto paramList : func->getParameterLists ()) {
1206
+ for (auto param : *paramList) {
1207
+ if (!env)
1208
+ param->setType (param->getInterfaceType ());
1209
+ else
1210
+ param->setType (env->mapTypeIntoContext (param->getInterfaceType ()));
1211
+ }
1212
+ }
1213
+ }
1206
1214
1207
- auto selfTy = func->mapTypeIntoContext (selfParam.getType ());
1208
- if (selfParam.getParameterFlags ().isInOut ()) {
1209
- selfDecl->setSpecifier (VarDecl::Specifier::InOut);
1215
+ static void recordIndexContextTypes (SubscriptDecl *subscript) {
1216
+ auto *env = subscript->getGenericEnvironment ();
1217
+ for (auto param : *subscript->getIndices ()) {
1218
+ if (!env)
1219
+ param->setType (param->getInterfaceType ());
1220
+ else
1221
+ param->setType (env->mapTypeIntoContext (param->getInterfaceType ()));
1210
1222
}
1211
- selfDecl->setType (selfTy->getInOutObjectType ());
1212
1223
}
1213
1224
1214
1225
// / If we need to infer 'dynamic', do so now.
@@ -4105,7 +4116,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4105
4116
auto accessorParam = valueParams->get (valueParams->size () - e + i);
4106
4117
accessorParam->setType (paramTy);
4107
4118
accessorParam->setInterfaceType (paramIfaceTy);
4108
- accessorParam->getTypeLoc ().setType (paramTy );
4119
+ accessorParam->getTypeLoc ().setType (paramIfaceTy );
4109
4120
}
4110
4121
}
4111
4122
@@ -4155,64 +4166,21 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4155
4166
configureImplicitSelf (*this , FD);
4156
4167
4157
4168
// If we have generic parameters, check the generic signature now.
4158
- if (auto gp = FD->getGenericParams ()) {
4159
- gp->setOuterParameters (FD->getDeclContext ()->getGenericParamsOfContext ());
4160
-
4161
- auto *sig = validateGenericFuncSignature (FD);
4169
+ if (FD->getGenericParams () || !isa<AccessorDecl>(FD)) {
4170
+ validateGenericFuncSignature (FD);
4171
+ recordParamContextTypes (FD);
4172
+ } else {
4173
+ // We've inherited all of the type information already.
4174
+ configureInterfaceType (FD,
4175
+ FD->getDeclContext ()->getGenericSignatureOfContext ());
4162
4176
4163
- GenericEnvironment *env;
4164
- if (auto AD = dyn_cast<AccessorDecl>(FD)) {
4165
- env = cast<SubscriptDecl>(AD->getStorage ())->getGenericEnvironment ();
4166
- assert (env && " accessor has generics but subscript is not generic" );
4167
- } else {
4168
- env = sig->createGenericEnvironment ();
4169
- }
4170
- FD->setGenericEnvironment (env);
4171
-
4172
- // Revert the types within the signature so it can be type-checked with
4173
- // archetypes below.
4174
- revertGenericFuncSignature (FD);
4175
- } else if (auto genericSig =
4176
- FD->getDeclContext ()->getGenericSignatureOfContext ()) {
4177
- if (!isa<AccessorDecl>(FD)) {
4178
- (void )validateGenericFuncSignature (FD);
4179
-
4180
- // Revert all of the types within the signature of the function.
4181
- revertGenericFuncSignature (FD);
4182
- } else {
4183
- // We've inherited all of the type information already.
4184
- configureInterfaceType (FD, genericSig);
4177
+ if (FD->getInterfaceType ()->hasError ()) {
4178
+ FD->setInterfaceType (ErrorType::get (Context));
4179
+ FD->setInvalid ();
4185
4180
}
4186
4181
4187
4182
FD->setGenericEnvironment (
4188
- FD->getDeclContext ()->getGenericEnvironmentOfContext ());
4189
- }
4190
-
4191
- // Set the context type of 'self'.
4192
- if (FD->getDeclContext ()->isTypeContext ())
4193
- recordSelfContextType (FD);
4194
-
4195
- // Type check the parameters and return type again, now with archetypes.
4196
- GenericTypeToArchetypeResolver resolver (FD);
4197
-
4198
- bool badType = false ;
4199
- if (!FD->getBodyResultTypeLoc ().isNull ()) {
4200
- TypeResolutionOptions options = TypeResolutionFlags::AllowIUO;
4201
- if (FD->hasDynamicSelf ())
4202
- options |= TypeResolutionFlags::DynamicSelfResult;
4203
-
4204
- if (validateType (FD->getBodyResultTypeLoc (), FD, options,
4205
- &resolver)) {
4206
- badType = true ;
4207
- }
4208
- }
4209
-
4210
- badType |= typeCheckParameterLists (FD, resolver);
4211
-
4212
- if (badType) {
4213
- FD->setInterfaceType (ErrorType::get (Context));
4214
- FD->setInvalid ();
4215
- break ;
4183
+ FD->getDeclContext ()->getGenericEnvironmentOfContext ());
4216
4184
}
4217
4185
4218
4186
if (!isa<AccessorDecl>(FD) || cast<AccessorDecl>(FD)->isGetter ()) {
@@ -4224,9 +4192,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4224
4192
}
4225
4193
}
4226
4194
4227
- if (!FD->getGenericSignatureOfContext ())
4228
- configureInterfaceType (FD, FD->getGenericSignature ());
4229
-
4230
4195
// We want the function to be available for name lookup as soon
4231
4196
// as it has a valid interface type.
4232
4197
FD->setSignatureIsValidated ();
@@ -4258,9 +4223,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4258
4223
// had an @objc or @iboutlet property.
4259
4224
4260
4225
AbstractStorageDecl *storage = accessor->getStorage ();
4261
- // Validate the subscript or property because it might not be type
4262
- // checked yet.
4263
- validateDecl (storage);
4264
4226
4265
4227
if (storage->getAttrs ().hasAttribute <NonObjCAttr>())
4266
4228
isObjC = None;
@@ -4383,40 +4345,8 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4383
4345
if (CD->getDeclContext ()->isTypeContext ())
4384
4346
configureImplicitSelf (*this , CD);
4385
4347
4386
- if (auto gp = CD->getGenericParams ()) {
4387
- // Write up generic parameters and check the generic parameter list.
4388
- gp->setOuterParameters (CD->getDeclContext ()->getGenericParamsOfContext ());
4389
-
4390
- auto *sig = validateGenericFuncSignature (CD);
4391
- auto *env = sig->createGenericEnvironment ();
4392
- CD->setGenericEnvironment (env);
4393
-
4394
- // Revert the types within the signature so it can be type-checked with
4395
- // archetypes below.
4396
- revertGenericFuncSignature (CD);
4397
- } else if (CD->getDeclContext ()->getGenericSignatureOfContext ()) {
4398
- (void )validateGenericFuncSignature (CD);
4399
-
4400
- // Revert all of the types within the signature of the constructor.
4401
- revertGenericFuncSignature (CD);
4402
-
4403
- CD->setGenericEnvironment (
4404
- CD->getDeclContext ()->getGenericEnvironmentOfContext ());
4405
- }
4406
-
4407
- // Set the context type of 'self'.
4408
- if (CD->getDeclContext ()->isTypeContext ())
4409
- recordSelfContextType (CD);
4410
-
4411
- // Type check the constructor parameters.
4412
- GenericTypeToArchetypeResolver resolver (CD);
4413
- if (typeCheckParameterLists (CD, resolver) || CD->isInvalid ()) {
4414
- CD->setInterfaceType (ErrorType::get (Context));
4415
- CD->setInvalid ();
4416
- } else {
4417
- if (!CD->getGenericSignatureOfContext ())
4418
- configureInterfaceType (CD, CD->getGenericSignature ());
4419
- }
4348
+ validateGenericFuncSignature (CD);
4349
+ recordParamContextTypes (CD);
4420
4350
4421
4351
// We want the constructor to be available for name lookup as soon
4422
4352
// as it has a valid interface type.
@@ -4470,23 +4400,8 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4470
4400
4471
4401
configureImplicitSelf (*this , DD);
4472
4402
4473
- if (DD->getDeclContext ()->getGenericSignatureOfContext ()) {
4474
- (void )validateGenericFuncSignature (DD);
4475
- DD->setGenericEnvironment (
4476
- DD->getDeclContext ()->getGenericEnvironmentOfContext ());
4477
- }
4478
-
4479
- // Set the context type of 'self'.
4480
- recordSelfContextType (DD);
4481
-
4482
- GenericTypeToArchetypeResolver resolver (DD);
4483
- if (typeCheckParameterLists (DD, resolver)) {
4484
- DD->setInterfaceType (ErrorType::get (Context));
4485
- DD->setInvalid ();
4486
- }
4487
-
4488
- if (!DD->getGenericSignatureOfContext ())
4489
- configureInterfaceType (DD, DD->getGenericSignature ());
4403
+ validateGenericFuncSignature (DD);
4404
+ recordParamContextTypes (DD);
4490
4405
4491
4406
DD->setSignatureIsValidated ();
4492
4407
@@ -4508,49 +4423,8 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4508
4423
4509
4424
DeclValidationRAII IBV (SD);
4510
4425
4511
- auto dc = SD->getDeclContext ();
4512
-
4513
- if (auto gp = SD->getGenericParams ()) {
4514
- // Write up generic parameters and check the generic parameter list.
4515
- gp->setOuterParameters (dc->getGenericParamsOfContext ());
4516
-
4517
- auto *sig = validateGenericSubscriptSignature (SD);
4518
- auto *env = sig->createGenericEnvironment ();
4519
- SD->setGenericEnvironment (env);
4520
-
4521
- // Revert the types within the signature so it can be type-checked with
4522
- // archetypes below.
4523
- revertGenericSubscriptSignature (SD);
4524
- } else if (dc->getGenericSignatureOfContext ()) {
4525
- (void )validateGenericSubscriptSignature (SD);
4526
-
4527
- // Revert all of the types within the signature of the subscript.
4528
- revertGenericSubscriptSignature (SD);
4529
-
4530
- SD->setGenericEnvironment (
4531
- SD->getDeclContext ()->getGenericEnvironmentOfContext ());
4532
- }
4533
-
4534
- // Type check the subscript parameters.
4535
- GenericTypeToArchetypeResolver resolver (SD);
4536
-
4537
- bool isInvalid = validateType (SD->getElementTypeLoc (), SD,
4538
- TypeResolutionFlags::AllowIUO,
4539
- &resolver);
4540
- TypeResolutionOptions options;
4541
- options |= TypeResolutionFlags::SubscriptParameters;
4542
-
4543
- isInvalid |= typeCheckParameterList (SD->getIndices (), SD,
4544
- options,
4545
- resolver);
4546
-
4547
- if (isInvalid || SD->isInvalid ()) {
4548
- SD->setInterfaceType (ErrorType::get (Context));
4549
- SD->setInvalid ();
4550
- } else {
4551
- if (!SD->getGenericSignatureOfContext ())
4552
- configureInterfaceType (SD, SD->getGenericSignature ());
4553
- }
4426
+ validateGenericSubscriptSignature (SD);
4427
+ recordIndexContextTypes (SD);
4554
4428
4555
4429
SD->setSignatureIsValidated ();
4556
4430
@@ -4566,7 +4440,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4566
4440
}
4567
4441
4568
4442
// Member subscripts need some special validation logic.
4569
- if (dc ->isTypeContext ()) {
4443
+ if (SD-> getDeclContext () ->isTypeContext ()) {
4570
4444
// If this is a class member, mark it final if the class is final.
4571
4445
inferFinalAndDiagnoseIfNeeded (*this , SD, StaticSpellingKind::None);
4572
4446
@@ -4590,14 +4464,15 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4590
4464
4591
4465
case DeclKind::EnumElement: {
4592
4466
auto *EED = cast<EnumElementDecl>(D);
4467
+ EnumDecl *ED = EED->getParentEnum ();
4593
4468
4594
4469
checkDeclAttributesEarly (EED);
4595
4470
validateAttributes (*this , EED);
4596
4471
4597
4472
DeclValidationRAII IBV (EED);
4598
4473
4599
4474
if (auto *PL = EED->getParameterList ()) {
4600
- GenericTypeToArchetypeResolver resolver (EED-> getParentEnum ());
4475
+ CompleteGenericTypeResolver resolver (* this , ED-> getGenericSignature ());
4601
4476
4602
4477
bool isInvalid
4603
4478
= typeCheckParameterList (PL, EED->getParentEnum (),
@@ -4613,7 +4488,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4613
4488
4614
4489
// If we have a raw value, make sure there's a raw type as well.
4615
4490
if (auto *rawValue = EED->getRawValueExpr ()) {
4616
- EnumDecl *ED = EED->getParentEnum ();
4617
4491
if (!ED->hasRawType ()) {
4618
4492
diagnose (rawValue->getLoc (),diag::enum_raw_value_without_raw_type);
4619
4493
// Recover by setting the raw type as this element's type.
@@ -4630,8 +4504,8 @@ void TypeChecker::validateDecl(ValueDecl *D) {
4630
4504
4631
4505
// Now that we have an argument type we can set the element's declared
4632
4506
// type.
4633
- if (!EED->hasInterfaceType () && !EED-> computeType ())
4634
- break ;
4507
+ if (!EED->isInvalid ())
4508
+ EED-> computeType () ;
4635
4509
4636
4510
EED->setSignatureIsValidated ();
4637
4511
0 commit comments