@@ -4747,17 +4747,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4747
4747
// PatternBindingDecl.
4748
4748
}
4749
4749
4750
- bool semaFuncParamPatterns (AbstractFunctionDecl *fd,
4751
- GenericTypeResolver &resolver) {
4752
- bool hadError = false ;
4753
- for (auto paramList : fd->getParameterLists ()) {
4754
- hadError |= TC.typeCheckParameterList (paramList, fd,
4755
- TypeResolutionOptions (), resolver);
4756
- }
4757
-
4758
- return hadError;
4759
- }
4760
-
4761
4750
static TypeLoc getTypeLocForFunctionResult (FuncDecl *FD) {
4762
4751
auto accessor = dyn_cast<AccessorDecl>(FD);
4763
4752
if (!accessor) {
@@ -4789,7 +4778,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4789
4778
}
4790
4779
}
4791
4780
4792
- badType |= semaFuncParamPatterns (FD, resolver);
4781
+ badType |= TC. typeCheckParameterLists (FD, resolver);
4793
4782
4794
4783
if (badType) {
4795
4784
FD->setInterfaceType (ErrorType::get (TC.Context ));
@@ -7027,7 +7016,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
7027
7016
7028
7017
// Type check the constructor parameters.
7029
7018
GenericTypeToArchetypeResolver resolver (CD);
7030
- if (semaFuncParamPatterns (CD, resolver) || CD->isInvalid ()) {
7019
+ if (TC. typeCheckParameterLists (CD, resolver) || CD->isInvalid ()) {
7031
7020
CD->setInterfaceType (ErrorType::get (TC.Context ));
7032
7021
CD->setInvalid ();
7033
7022
} else {
@@ -7160,62 +7149,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
7160
7149
}
7161
7150
7162
7151
void visitDestructorDecl (DestructorDecl *DD) {
7163
- auto enclosingClass = dyn_cast<ClassDecl>(DD->getDeclContext ());
7164
- if (DD->isInvalid () ||
7165
- enclosingClass == nullptr ) {
7166
- DD->setInterfaceType (ErrorType::get (TC.Context ));
7167
- DD->setInvalid ();
7168
- return ;
7169
- }
7170
-
7171
7152
if (!IsFirstPass) {
7172
7153
if (DD->getBody ())
7173
7154
TC.definedFunctions .push_back (DD);
7174
- }
7175
7155
7176
- if (!IsFirstPass ||
7177
- DD->hasInterfaceType () ||
7178
- DD->isBeingValidated ()) {
7179
7156
return ;
7180
7157
}
7181
7158
7182
- DD->setIsBeingValidated ();
7183
-
7184
- assert (DD->getDeclContext ()->isTypeContext ()
7185
- && " Decl parsing must prevent destructors outside of types!" );
7186
-
7187
- TC.checkDeclAttributesEarly (DD);
7188
- DD->copyFormalAccessAndVersionedAttrFrom (enclosingClass);
7189
-
7190
- configureImplicitSelf (TC, DD);
7191
-
7192
- if (DD->getDeclContext ()->getGenericSignatureOfContext ()) {
7193
- (void )TC.validateGenericFuncSignature (DD);
7194
- DD->setGenericEnvironment (
7195
- DD->getDeclContext ()->getGenericEnvironmentOfContext ());
7196
- }
7197
-
7198
- // Set the context type of 'self'.
7199
- recordSelfContextType (DD);
7200
-
7201
- GenericTypeToArchetypeResolver resolver (DD);
7202
- if (semaFuncParamPatterns (DD, resolver)) {
7203
- DD->setInterfaceType (ErrorType::get (TC.Context ));
7204
- DD->setInvalid ();
7205
- }
7206
-
7207
- if (!DD->getGenericSignatureOfContext ())
7208
- TC.configureInterfaceType (DD, DD->getGenericSignature ());
7209
-
7210
- DD->setIsBeingValidated (false );
7211
-
7212
- // Do this before markAsObjC() to diagnose @nonobjc better
7213
- validateAttributes (TC, DD);
7214
-
7215
- // Destructors are always @objc, because their Objective-C entry point is
7216
- // -dealloc.
7217
- markAsObjC (TC, DD, ObjCReason::ImplicitlyObjC);
7218
-
7159
+ TC.validateDecl (DD);
7219
7160
TC.checkDeclAttributes (DD);
7220
7161
}
7221
7162
};
@@ -7725,12 +7666,62 @@ void TypeChecker::validateDecl(ValueDecl *D) {
7725
7666
7726
7667
case DeclKind::Func:
7727
7668
case DeclKind::Accessor:
7728
- case DeclKind::Constructor:
7729
- case DeclKind::Destructor: {
7669
+ case DeclKind::Constructor: {
7730
7670
typeCheckDecl (D, true );
7731
7671
break ;
7732
7672
}
7733
7673
7674
+ case DeclKind::Destructor: {
7675
+ auto *DD = cast<DestructorDecl>(D);
7676
+
7677
+ auto enclosingClass = dyn_cast<ClassDecl>(DD->getDeclContext ());
7678
+ if (DD->isInvalid () ||
7679
+ enclosingClass == nullptr ) {
7680
+ DD->setInterfaceType (ErrorType::get (Context));
7681
+ DD->setInvalid ();
7682
+ return ;
7683
+ }
7684
+
7685
+ DD->setIsBeingValidated ();
7686
+
7687
+ assert (DD->getDeclContext ()->isTypeContext ()
7688
+ && " Decl parsing must prevent destructors outside of types!" );
7689
+
7690
+ checkDeclAttributesEarly (DD);
7691
+ DD->copyFormalAccessAndVersionedAttrFrom (enclosingClass);
7692
+
7693
+ configureImplicitSelf (*this , DD);
7694
+
7695
+ if (DD->getDeclContext ()->getGenericSignatureOfContext ()) {
7696
+ (void )validateGenericFuncSignature (DD);
7697
+ DD->setGenericEnvironment (
7698
+ DD->getDeclContext ()->getGenericEnvironmentOfContext ());
7699
+ }
7700
+
7701
+ // Set the context type of 'self'.
7702
+ recordSelfContextType (DD);
7703
+
7704
+ GenericTypeToArchetypeResolver resolver (DD);
7705
+ if (typeCheckParameterLists (DD, resolver)) {
7706
+ DD->setInterfaceType (ErrorType::get (Context));
7707
+ DD->setInvalid ();
7708
+ }
7709
+
7710
+ if (!DD->getGenericSignatureOfContext ())
7711
+ configureInterfaceType (DD, DD->getGenericSignature ());
7712
+
7713
+ DD->setIsBeingValidated (false );
7714
+
7715
+ // Do this before markAsObjC() to diagnose @nonobjc better
7716
+ validateAttributes (*this , DD);
7717
+
7718
+ // Destructors are always @objc, because their Objective-C entry point is
7719
+ // -dealloc.
7720
+ markAsObjC (*this , DD, ObjCReason::ImplicitlyObjC);
7721
+
7722
+ break ;
7723
+ }
7724
+
7734
7725
case DeclKind::Subscript: {
7735
7726
auto *SD = cast<SubscriptDecl>(D);
7736
7727
0 commit comments