Skip to content

Commit 941ac0d

Browse files
committed
xxx
1 parent acc01dc commit 941ac0d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/Sema/PreCheckExpr.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,25 +1218,8 @@ namespace {
12181218
return finish(true, expr);
12191219
}
12201220

1221-
if (auto unresolved = dyn_cast<UnresolvedDeclRefExpr>(expr)) {
1222-
auto *refExpr = TypeChecker::resolveDeclRefExpr(unresolved, DC);
1223-
1224-
// Check whether this is standalone `self` in init accessor, which
1225-
// is invalid.
1226-
if (auto *accessor = DC->getInnermostPropertyAccessorContext()) {
1227-
if (accessor->isInitAccessor() && isa<DeclRefExpr>(refExpr)) {
1228-
auto *DRE = cast<DeclRefExpr>(refExpr);
1229-
if (accessor->getImplicitSelfDecl() == DRE->getDecl() &&
1230-
!isa_and_nonnull<UnresolvedDotExpr>(Parent.getAsExpr())) {
1231-
diags.diagnose(unresolved->getLoc(),
1232-
diag::invalid_use_of_self_in_init_accessor);
1233-
refExpr = new (Ctx) ErrorExpr(unresolved->getSourceRange());
1234-
}
1235-
}
1236-
}
1237-
1238-
return finish(true, refExpr);
1239-
}
1221+
if (auto *unresolved = dyn_cast<UnresolvedDeclRefExpr>(expr))
1222+
return finish(true, TypeChecker::resolveDeclRefExpr(unresolved, DC));
12401223

12411224
// Let's try to figure out if `InOutExpr` is out of place early
12421225
// otherwise there is a risk of producing solutions which can't
@@ -1325,7 +1308,22 @@ namespace {
13251308
if (auto *typeExpr = simplifyUnresolvedSpecializeExpr(us))
13261309
return Action::Continue(typeExpr);
13271310
}
1328-
1311+
1312+
// Check whether this is standalone `self` in init accessor, which
1313+
// is invalid.
1314+
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
1315+
if (auto *accessor = DC->getInnermostPropertyAccessorContext()) {
1316+
if (accessor->isInitAccessor()) {
1317+
if (accessor->getImplicitSelfDecl() == DRE->getDecl() &&
1318+
!isa_and_nonnull<UnresolvedDotExpr>(Parent.getAsExpr())) {
1319+
Ctx.Diags.diagnose(DRE->getLoc(),
1320+
diag::invalid_use_of_self_in_init_accessor);
1321+
return Action::Continue(new (Ctx) ErrorExpr(DRE->getSourceRange()));
1322+
}
1323+
}
1324+
}
1325+
}
1326+
13291327
// If we're about to step out of a ClosureExpr, restore the DeclContext.
13301328
if (auto *ce = dyn_cast<ClosureExpr>(expr)) {
13311329
assert(DC == ce && "DeclContext imbalance");

0 commit comments

Comments
 (0)