Skip to content

Commit 84896ed

Browse files
committed
Use Ctx.Id_self and update comments
1 parent 9167a17 commit 84896ed

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,9 @@ bool MemberAccessOnOptionalBaseFailure::diagnoseAsError() {
13761376
if (auto dotExpr = getAsExpr<UnresolvedDotExpr>(locator->getAnchor())) {
13771377
if (auto base = dotExpr->getBase()) {
13781378
if (auto baseDeclRef = dyn_cast<DeclRefExpr>(base)) {
1379-
if (baseDeclRef->isImplicit() && baseDeclRef->getDecl()->getBaseIdentifier().is("self")) {
1379+
ASTContext &Ctx = baseDeclRef->getDecl()->getASTContext();
1380+
if (baseDeclRef->isImplicit()
1381+
&& baseDeclRef->getDecl()->getName().isSimpleName(Ctx.Id_self)) {
13801382
emitDiagnostic(diag::optional_self_not_unwrapped);
13811383

13821384
emitDiagnostic(diag::optional_self_chain)

lib/Sema/MiscDiagnostics.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,8 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
15911591

15921592
// If this decl isn't named "self", then it isn't an implicit self capture
15931593
// and we have no reason to reject it.
1594-
if (!DRE->getDecl()->getBaseName().getIdentifier().is("self")) {
1594+
ASTContext &Ctx = DRE->getDecl()->getASTContext();
1595+
if (!DRE->getDecl()->getName().isSimpleName(Ctx.Id_self)) {
15951596
return false;
15961597
}
15971598

@@ -1634,11 +1635,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
16341635
if (cond.getKind() == StmtConditionElement::CK_PatternBinding) {
16351636
if (auto optionalPattern = dyn_cast<OptionalSomePattern>(cond.getPattern())) {
16361637
// if the lhs of the optional binding is `self`...
1637-
if (optionalPattern->getSubPattern()->getBoundName().is("self")) {
1638+
if (optionalPattern->getSubPattern()->getBoundName() == Ctx.Id_self) {
16381639
if (auto loadExpr = dyn_cast<LoadExpr>(cond.getInitializer())) {
16391640
if (auto declRefExpr = dyn_cast<DeclRefExpr>(loadExpr->getSubExpr())) {
16401641
// and the rhs of the optional binding is `self`...
1641-
if (declRefExpr->getDecl()->getBaseIdentifier().is("self")) {
1642+
if (declRefExpr->getDecl()->getName().isSimpleName(Ctx.Id_self)) {
16421643
// then we can permit implicit self in this closure
16431644
hasCorrectSelfBindingCondition = true;
16441645
}

lib/Sema/PreCheckExpr.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,11 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
761761
UDRE->getNameLoc(), NTD, BaseDC,
762762
DC->mapTypeIntoContext(NTD->getInterfaceType()));
763763
} else {
764-
// If this is an implicit self reference, the `VarDecl` will
765-
// currently have a non-optional type. But at this point,
766-
// we don't actually know if this is correct (it could be a
767-
// weak self capture that hasn't been unwrapped yet).
768-
// - Since we don't know the correct type of self yet,
769-
// we leave this as an UnresolvedDeclRefExpr that is
770-
// populated with the actual type later.
764+
// If this is an implicit self reference, we replace the `DeclRefExpr`
765+
// with an `UnresolvedDeclRefExpr` to make the type checker take another
766+
// pass on the expr. This causes `getParentPatternStmt()` to be populated,
767+
// which is required later to validate conditions for permitting
768+
// implicit self for `[weak self]` captures.
771769
bool isClosureImplicitSelfParameter = false;
772770
if (DC->getContextKind() == DeclContextKind::AbstractClosureExpr)
773771
if (auto varDecl = dyn_cast<VarDecl>(Base))

0 commit comments

Comments
 (0)