Skip to content

Commit 6a82f24

Browse files
committed
Sema: Don't trigger ImplInfoRequest from TypeChecker::buildRefExpr()
It's too early to do that here, because we may be building a reference to a ParamDecl that is not yet known to be inout, because the constraint solver has not run yet. Instead, always compute the access semantics in CSApply.
1 parent ddc0cbd commit 6a82f24

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ namespace {
482482
public:
483483
/// Build a reference to the given declaration.
484484
Expr *buildDeclRef(SelectedOverload overload, DeclNameLoc loc,
485-
ConstraintLocatorBuilder locator, bool implicit,
486-
AccessSemantics semantics) {
485+
ConstraintLocatorBuilder locator, bool implicit) {
487486
auto choice = overload.choice;
488487
assert(choice.getKind() != OverloadChoiceKind::DeclViaDynamic);
489488
auto *decl = choice.getDecl();
@@ -492,6 +491,9 @@ namespace {
492491
// Determine the declaration selected for this overloaded reference.
493492
auto &ctx = cs.getASTContext();
494493

494+
auto semantics = decl->getAccessSemanticsFromContext(cs.DC,
495+
/*isAccessOnSelf*/false);
496+
495497
// If this is a member of a nominal type, build a reference to the
496498
// member with an implied base type.
497499
if (decl->getDeclContext()->isTypeContext() && isa<FuncDecl>(decl)) {
@@ -2686,7 +2688,7 @@ namespace {
26862688
// Find the overload choice used for this declaration reference.
26872689
auto selected = solution.getOverloadChoice(locator);
26882690
return buildDeclRef(selected, expr->getNameLoc(), locator,
2689-
expr->isImplicit(), expr->getAccessSemantics());
2691+
expr->isImplicit());
26902692
}
26912693

26922694
Expr *visitSuperRefExpr(SuperRefExpr *expr) {
@@ -2716,7 +2718,7 @@ namespace {
27162718
auto selected = solution.getOverloadChoice(locator);
27172719

27182720
return buildDeclRef(selected, expr->getNameLoc(), locator,
2719-
expr->isImplicit(), AccessSemantics::Ordinary);
2721+
expr->isImplicit());
27202722
}
27212723

27222724
Expr *visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *expr) {
@@ -3036,8 +3038,7 @@ namespace {
30363038
diagnoseDeprecatedConditionalConformanceOuterAccess(
30373039
UDE, selected.choice.getDecl());
30383040

3039-
return buildDeclRef(selected, nameLoc, memberLocator, implicit,
3040-
AccessSemantics::Ordinary);
3041+
return buildDeclRef(selected, nameLoc, memberLocator, implicit);
30413042
}
30423043

30433044
switch (selected.choice.getKind()) {

lib/Sema/TypeCheckExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,10 @@ Expr *TypeChecker::buildRefExpr(ArrayRef<ValueDecl *> Decls,
601601
assert(!Decls.empty() && "Must have at least one declaration");
602602

603603
auto &Context = UseDC->getASTContext();
604-
if (Decls.size() == 1 && !isa<ProtocolDecl>(Decls[0]->getDeclContext())) {
605-
auto semantics = Decls[0]->getAccessSemanticsFromContext(UseDC,
606-
/*isAccessOnSelf*/false);
607-
return new (Context) DeclRefExpr(Decls[0], NameLoc, Implicit, semantics);
604+
605+
if (Decls.size() == 1) {
606+
return new (Context) DeclRefExpr(Decls[0], NameLoc, Implicit,
607+
AccessSemantics::Ordinary);
608608
}
609609

610610
Decls = Context.AllocateCopy(Decls);

0 commit comments

Comments
 (0)