Skip to content

Commit f74b3fb

Browse files
committed
[Sema] Only emit warnings for implicit self use in getters
This fixes a pre-existing bug where implicit DeclRefExprs involving *any* expression of the same type within a getter were flagged with warnings, even if they were references to something other than "self".
1 parent de93a8d commit f74b3fb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,13 @@ static void diagRecursivePropertyAccess(TypeChecker &TC, const Expr *E,
14691469
const FuncDecl *Accessor)
14701470
: TC(TC), Var(var), Accessor(Accessor) {}
14711471

1472+
/// Return true if this is an implicit reference to self.
1473+
static bool isImplicitSelfUse(Expr *E) {
1474+
auto *DRE = dyn_cast<DeclRefExpr>(E);
1475+
return DRE && DRE->isImplicit() && isa<VarDecl>(DRE->getDecl()) &&
1476+
cast<VarDecl>(DRE->getDecl())->isSelfParameter();
1477+
}
1478+
14721479
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
14731480
Expr *subExpr;
14741481
bool isStore = false;
@@ -1529,7 +1536,7 @@ static void diagRecursivePropertyAccess(TypeChecker &TC, const Expr *E,
15291536
// Find MemberRefExprs that have an implicit "self" base.
15301537
if (MRE->getMember().getDecl() == Var &&
15311538
isa<DeclRefExpr>(MRE->getBase()) &&
1532-
MRE->getBase()->isImplicit()) {
1539+
isImplicitSelfUse(MRE->getBase())) {
15331540

15341541
if (MRE->getAccessSemantics() != AccessSemantics::DirectToStorage) {
15351542
bool shouldDiagnose = false;

0 commit comments

Comments
 (0)