Skip to content

Commit 6cf6e7f

Browse files
authored
Merge pull request swiftlang#24064 from rjmccall/param-attr-checking
[NFC] Late-check parameter attributes
2 parents a6e9f11 + 5589089 commit 6cf6e7f

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,12 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) {
24712471
attr->setInvalid();
24722472
}
24732473

2474+
void TypeChecker::checkParameterAttributes(ParameterList *params) {
2475+
for (auto param: *params) {
2476+
checkDeclAttributes(param);
2477+
}
2478+
}
2479+
24742480
void TypeChecker::checkDeclAttributes(Decl *D) {
24752481
AttributeChecker Checker(*this, D);
24762482

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24192419
TC.checkDynamicReplacementAttribute(SD);
24202420
}
24212421

2422+
TC.checkParameterAttributes(SD->getIndices());
24222423
TC.checkDefaultArguments(SD->getIndices(), SD);
24232424
}
24242425

@@ -2931,6 +2932,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29312932
if (FD->getAttrs().hasAttribute<DynamicReplacementAttr>()) {
29322933
TC.checkDynamicReplacementAttribute(FD);
29332934
}
2935+
2936+
TC.checkParameterAttributes(FD->getParameters());
29342937
}
29352938

29362939
void visitModuleDecl(ModuleDecl *) { }
@@ -2945,8 +2948,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29452948
TC.validateDecl(EED);
29462949
TC.checkDeclAttributes(EED);
29472950

2948-
if (auto *PL = EED->getParameterList())
2951+
if (auto *PL = EED->getParameterList()) {
2952+
TC.checkParameterAttributes(PL);
29492953
TC.checkDefaultArguments(PL, EED);
2954+
}
29502955

29512956
checkAccessControl(TC, EED);
29522957
}
@@ -3130,6 +3135,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
31303135
}
31313136

31323137
TC.checkDeclAttributes(CD);
3138+
TC.checkParameterAttributes(CD->getParameters());
31333139

31343140
checkAccessControl(TC, CD);
31353141

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,8 @@ bool TypeChecker::typeCheckDestructorBodyUntil(DestructorDecl *DD,
20612061
}
20622062

20632063
bool TypeChecker::typeCheckClosureBody(ClosureExpr *closure) {
2064+
checkParameterAttributes(closure->getParameters());
2065+
20642066
BraceStmt *body = closure->getBody();
20652067

20662068
Optional<FunctionBodyTimer> timer;

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ class TypeChecker final : public LazyResolver {
10461046
void checkDeclAttributesEarly(Decl *D);
10471047
static void addImplicitDynamicAttribute(Decl *D);
10481048
void checkDeclAttributes(Decl *D);
1049+
void checkParameterAttributes(ParameterList *params);
10491050
void checkDynamicReplacementAttribute(ValueDecl *D);
10501051
static ValueDecl *findReplacedDynamicFunction(const ValueDecl *d);
10511052
void checkTypeModifyingDeclAttributes(VarDecl *var);

0 commit comments

Comments
 (0)