Skip to content

Commit 888dc92

Browse files
committed
Sema: Don't remove @objc attribute when evaluating IsObjCRequest
This was preventing us from emitting diagnostics if IsObjCRequest was evaluated before AttributeChecker::visitObjCAttr().
1 parent 8e83dd9 commit 888dc92

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,21 @@ bool swift::isRepresentableInObjC(
528528
Reason != ObjCReason::WitnessToObjC &&
529529
Reason != ObjCReason::MemberOfObjCProtocol) {
530530
if (Diagnose) {
531-
auto error = accessor->isGetter()
532-
? (isa<VarDecl>(storage)
533-
? diag::objc_getter_for_nonobjc_property
534-
: diag::objc_getter_for_nonobjc_subscript)
535-
: (isa<VarDecl>(storage)
536-
? diag::objc_setter_for_nonobjc_property
537-
: diag::objc_setter_for_nonobjc_subscript);
538-
539-
accessor->diagnose(error);
540-
describeObjCReason(accessor, Reason);
531+
if (accessor->isGetter()) {
532+
auto error = isa<VarDecl>(storage)
533+
? diag::objc_getter_for_nonobjc_property
534+
: diag::objc_getter_for_nonobjc_subscript;
535+
536+
accessor->diagnose(error);
537+
describeObjCReason(accessor, Reason);
538+
} else if (accessor->isSetter()) {
539+
auto error = isa<VarDecl>(storage)
540+
? diag::objc_setter_for_nonobjc_property
541+
: diag::objc_setter_for_nonobjc_subscript;
542+
543+
accessor->diagnose(error);
544+
describeObjCReason(accessor, Reason);
545+
}
541546
}
542547
return false;
543548
}
@@ -1443,19 +1448,9 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
14431448
// Cannot be @objc.
14441449
}
14451450

1446-
// Perform some icky stateful hackery to mark this declaration as
1447-
// not being @objc.
1448-
auto makeNotObjC = [&] {
1449-
if (auto objcAttr = VD->getAttrs().getAttribute<ObjCAttr>()) {
1450-
objcAttr->setInvalid();
1451-
}
1452-
};
1453-
14541451
// If this declaration should not be exposed to Objective-C, we're done.
1455-
if (!isObjC) {
1456-
makeNotObjC();
1452+
if (!isObjC)
14571453
return false;
1458-
}
14591454

14601455
if (auto accessor = dyn_cast<AccessorDecl>(VD)) {
14611456
auto storage = accessor->getStorage();
@@ -1479,23 +1474,17 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
14791474
Optional<ForeignAsyncConvention> asyncConvention;
14801475
Optional<ForeignErrorConvention> errorConvention;
14811476
if (auto var = dyn_cast<VarDecl>(VD)) {
1482-
if (!isRepresentableInObjC(var, *isObjC)) {
1483-
makeNotObjC();
1477+
if (!isRepresentableInObjC(var, *isObjC))
14841478
return false;
1485-
}
14861479
} else if (auto subscript = dyn_cast<SubscriptDecl>(VD)) {
1487-
if (!isRepresentableInObjC(subscript, *isObjC)) {
1488-
makeNotObjC();
1480+
if (!isRepresentableInObjC(subscript, *isObjC))
14891481
return false;
1490-
}
14911482
} else if (isa<DestructorDecl>(VD)) {
14921483
// Destructors need no additional checking.
14931484
} else if (auto func = dyn_cast<AbstractFunctionDecl>(VD)) {
14941485
if (!isRepresentableInObjC(
1495-
func, *isObjC, asyncConvention, errorConvention)) {
1496-
makeNotObjC();
1486+
func, *isObjC, asyncConvention, errorConvention))
14971487
return false;
1498-
}
14991488
}
15001489

15011490
// Note that this declaration is exposed to Objective-C.

0 commit comments

Comments
 (0)