Skip to content

Commit ee43e61

Browse files
committed
Typecheck ABI-only VarDecls
The decl checker was effectively not being run on these because we weren’t typechecking the PBD and typechecking the VarDecl itself is basically a no-op.
1 parent c62122c commit ee43e61

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,13 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
23172317
if (!ObjCMethodLookup && !createObjCMethodLookup())
23182318
return;
23192319

2320+
// Only record API decls.
2321+
Decl *abiRoleDecl = method;
2322+
if (auto accessor = dyn_cast<AccessorDecl>(method))
2323+
abiRoleDecl = accessor->getStorage();
2324+
if (!ABIRoleInfo(abiRoleDecl).providesAPI())
2325+
return;
2326+
23202327
// Record the method.
23212328
bool isInstanceMethod = method->isObjCInstanceMethod();
23222329
auto &vec = (*ObjCMethodLookup)[{selector, isInstanceMethod}].Methods;

lib/Sema/TypeCheckAttrABI.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ void checkABIAttrPBD(PatternBindingDecl *APBD, VarDecl *VD) {
11521152
}
11531153

11541154
// Check that each pattern has the same number of variables.
1155+
bool didDiagnose = false;
11551156
for (auto i : range(PBD->getNumPatternEntries())) {
11561157
SmallVector<VarDecl *, 8> VDs;
11571158
SmallVector<VarDecl *, 8> AVDs;
@@ -1161,18 +1162,24 @@ void checkABIAttrPBD(PatternBindingDecl *APBD, VarDecl *VD) {
11611162

11621163
if (VDs.size() < AVDs.size()) {
11631164
for (auto AVD : drop_begin(AVDs, VDs.size())) {
1164-
AVD->diagnose(diag::attr_abi_mismatched_var,
1165-
AVD, /*isABI=*/true);
1165+
AVD->diagnose(diag::attr_abi_mismatched_var, AVD, /*isABI=*/true);
1166+
didDiagnose = true;
11661167
}
11671168
}
11681169
else if (VDs.size() > AVDs.size()) {
11691170
for (auto VD : drop_begin(VDs, AVDs.size())) {
1170-
VD->diagnose(diag::attr_abi_mismatched_var,
1171-
VD, /*isABI=*/false);
1171+
VD->diagnose(diag::attr_abi_mismatched_var, VD, /*isABI=*/false);
1172+
didDiagnose = true;
11721173
}
11731174
}
11741175
}
1176+
if (didDiagnose)
1177+
return;
1178+
1179+
// Check the ABI PBD--this is what checks the underlying vars.
1180+
TypeChecker::typeCheckDecl(APBD);
11751181
}
1182+
11761183
} // end anonymous namespace
11771184

11781185
void TypeChecker::checkDeclABIAttribute(Decl *D, ABIAttr *attr) {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,6 +3845,10 @@ void HasStorageRequest::cacheResult(bool hasStorage) const {
38453845
StorageImplInfo
38463846
StorageImplInfoRequest::evaluate(Evaluator &evaluator,
38473847
AbstractStorageDecl *storage) const {
3848+
auto abiRole = ABIRoleInfo(storage);
3849+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
3850+
return abiRole.getCounterpart()->getImplInfo();
3851+
38483852
if (auto *param = dyn_cast<ParamDecl>(storage)) {
38493853
return StorageImplInfo::getSimpleStored(
38503854
param->isImmutableInFunctionBody()

0 commit comments

Comments
 (0)