@@ -4481,6 +4481,9 @@ static Type formExtensionInterfaceType(TypeChecker &tc, ExtensionDecl *ext,
4481
4481
Type type,
4482
4482
GenericParamList *genericParams,
4483
4483
bool &mustInferRequirements) {
4484
+ if (type->is <ErrorType>())
4485
+ return type;
4486
+
4484
4487
// Find the nominal type declaration and its parent type.
4485
4488
Type parentType;
4486
4489
GenericTypeDecl *genericDecl;
@@ -4602,30 +4605,22 @@ checkExtensionGenericParams(TypeChecker &tc, ExtensionDecl *ext, Type type,
4602
4605
return { env, extInterfaceType };
4603
4606
}
4604
4607
4605
- void TypeChecker::validateExtension (ExtensionDecl *ext) {
4606
- // If we're currently validating, or have already validated this extension,
4607
- // there's nothing more to do now.
4608
- if (ext->hasValidationStarted ())
4609
- return ;
4610
-
4611
- DeclValidationRAII IBV (ext);
4612
-
4613
- auto dc = ext->getDeclContext ();
4614
-
4608
+ static void validateExtendedType (ExtensionDecl *ext, TypeChecker &tc) {
4615
4609
// If we didn't parse a type, fill in an error type and bail out.
4616
4610
if (!ext->getExtendedTypeLoc ().getTypeRepr ()) {
4617
4611
ext->setInvalid ();
4618
- ext->getExtendedTypeLoc ().setInvalidType (Context);
4612
+ ext->getExtendedTypeLoc ().setInvalidType (tc. Context );
4619
4613
return ;
4620
4614
}
4621
4615
4622
4616
// Validate the extended type.
4623
4617
TypeResolutionOptions options (TypeResolverContext::ExtensionBinding);
4624
4618
options |= TypeResolutionFlags::AllowUnboundGenerics;
4625
- if (validateType (ext->getExtendedTypeLoc (),
4626
- TypeResolution::forInterface (dc), options)) {
4619
+ if (tc.validateType (ext->getExtendedTypeLoc (),
4620
+ TypeResolution::forInterface (ext->getDeclContext ()),
4621
+ options)) {
4627
4622
ext->setInvalid ();
4628
- ext->getExtendedTypeLoc ().setInvalidType (Context);
4623
+ ext->getExtendedTypeLoc ().setInvalidType (tc. Context );
4629
4624
return ;
4630
4625
}
4631
4626
@@ -4646,38 +4641,47 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
4646
4641
4647
4642
// Cannot extend a metatype.
4648
4643
if (extendedType->is <AnyMetatypeType>()) {
4649
- diagnose (ext->getLoc (), diag::extension_metatype, extendedType)
4644
+ tc. diagnose (ext->getLoc (), diag::extension_metatype, extendedType)
4650
4645
.highlight (ext->getExtendedTypeLoc ().getSourceRange ());
4651
4646
ext->setInvalid ();
4652
- ext->getExtendedTypeLoc ().setInvalidType (Context);
4647
+ ext->getExtendedTypeLoc ().setInvalidType (tc. Context );
4653
4648
return ;
4654
4649
}
4655
4650
4656
4651
// Cannot extend a bound generic type.
4657
4652
if (extendedType->isSpecialized ()) {
4658
- diagnose (ext->getLoc (), diag::extension_specialization,
4653
+ tc. diagnose (ext->getLoc (), diag::extension_specialization,
4659
4654
extendedType->getAnyNominal ()->getName ())
4660
4655
.highlight (ext->getExtendedTypeLoc ().getSourceRange ());
4661
4656
ext->setInvalid ();
4662
- ext->getExtendedTypeLoc ().setInvalidType (Context);
4657
+ ext->getExtendedTypeLoc ().setInvalidType (tc. Context );
4663
4658
return ;
4664
4659
}
4665
4660
4666
- auto *nominal = extendedType->getAnyNominal ();
4667
-
4668
4661
// Cannot extend function types, tuple types, etc.
4669
- if (nominal == nullptr ) {
4670
- diagnose (ext->getLoc (), diag::non_nominal_extension, extendedType)
4662
+ if (!extendedType-> getAnyNominal () ) {
4663
+ tc. diagnose (ext->getLoc (), diag::non_nominal_extension, extendedType)
4671
4664
.highlight (ext->getExtendedTypeLoc ().getSourceRange ());
4672
4665
ext->setInvalid ();
4673
- ext->getExtendedTypeLoc ().setInvalidType (Context);
4666
+ ext->getExtendedTypeLoc ().setInvalidType (tc. Context );
4674
4667
return ;
4675
4668
}
4669
+ }
4670
+
4671
+ void TypeChecker::validateExtension (ExtensionDecl *ext) {
4672
+ // If we're currently validating, or have already validated this extension,
4673
+ // there's nothing more to do now.
4674
+ if (ext->hasValidationStarted ())
4675
+ return ;
4676
+
4677
+ DeclValidationRAII IBV (ext);
4678
+
4679
+ validateExtendedType (ext, *this );
4676
4680
4677
4681
// Extensions nested inside other declarations are invalid and we
4678
4682
// do not bind them.
4679
- if (!isa<SourceFile>(dc ))
4680
- return ;
4683
+ if (!isa<SourceFile>(ext-> getDeclContext () ))
4684
+ return ;
4681
4685
4682
4686
// If this is not bound to any decls at this point, this extension is in
4683
4687
// inactive coditional compilation block. It's not safe to typecheck this
@@ -4686,26 +4690,25 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
4686
4690
if (!ext->alreadyBoundToNominal ())
4687
4691
return ;
4688
4692
4689
- // Validate the nominal type declaration being extended.
4690
- validateDecl (nominal);
4693
+ if (auto *nominal = ext->getExtendedNominal ()) {
4694
+ // Validate the nominal type declaration being extended.
4695
+ validateDecl (nominal);
4691
4696
4692
- if (nominal->getGenericParamsOfContext ()) {
4693
- auto genericParams = ext->getGenericParams ();
4694
- assert (genericParams && " bindExtensionDecl didn't set generic params?" );
4697
+ if (nominal->getGenericParamsOfContext ()) {
4698
+ auto genericParams = ext->getGenericParams ();
4699
+ assert (genericParams && " bindExtensionDecl didn't set generic params?" );
4695
4700
4696
- // Check generic parameters.
4697
- GenericEnvironment *env;
4698
- std::tie (env, extendedType) = checkExtensionGenericParams (
4699
- *this , ext, ext->getExtendedType (),
4700
- genericParams);
4701
+ // Check generic parameters.
4702
+ GenericEnvironment *env;
4703
+ Type extendedType = ext->getExtendedType ();
4704
+ std::tie (env, extendedType) = checkExtensionGenericParams (
4705
+ *this , ext, extendedType,
4706
+ genericParams);
4701
4707
4702
- ext->getExtendedTypeLoc ().setType (extendedType);
4703
- ext->setGenericEnvironment (env);
4704
- return ;
4708
+ ext->getExtendedTypeLoc ().setType (extendedType);
4709
+ ext->setGenericEnvironment (env);
4710
+ }
4705
4711
}
4706
-
4707
- assert (extendedType->is <NominalType>());
4708
- assert (!nominal->isGenericContext ());
4709
4712
}
4710
4713
4711
4714
// / Build a default initializer string for the given pattern.
0 commit comments