Skip to content

Commit

Permalink
Sema: Don't trigger ImplInfoRequest from TypeChecker::buildRefExpr()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slavapestov committed Sep 25, 2020
1 parent ddc0cbd commit 6a82f24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/Sema/CSApply.cpp
Expand Up @@ -482,8 +482,7 @@ namespace {
public:
/// Build a reference to the given declaration.
Expr *buildDeclRef(SelectedOverload overload, DeclNameLoc loc,
ConstraintLocatorBuilder locator, bool implicit,
AccessSemantics semantics) {
ConstraintLocatorBuilder locator, bool implicit) {
auto choice = overload.choice;
assert(choice.getKind() != OverloadChoiceKind::DeclViaDynamic);
auto *decl = choice.getDecl();
Expand All @@ -492,6 +491,9 @@ namespace {
// Determine the declaration selected for this overloaded reference.
auto &ctx = cs.getASTContext();

auto semantics = decl->getAccessSemanticsFromContext(cs.DC,
/*isAccessOnSelf*/false);

// If this is a member of a nominal type, build a reference to the
// member with an implied base type.
if (decl->getDeclContext()->isTypeContext() && isa<FuncDecl>(decl)) {
Expand Down Expand Up @@ -2686,7 +2688,7 @@ namespace {
// Find the overload choice used for this declaration reference.
auto selected = solution.getOverloadChoice(locator);
return buildDeclRef(selected, expr->getNameLoc(), locator,
expr->isImplicit(), expr->getAccessSemantics());
expr->isImplicit());
}

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

return buildDeclRef(selected, expr->getNameLoc(), locator,
expr->isImplicit(), AccessSemantics::Ordinary);
expr->isImplicit());
}

Expr *visitUnresolvedDeclRefExpr(UnresolvedDeclRefExpr *expr) {
Expand Down Expand Up @@ -3036,8 +3038,7 @@ namespace {
diagnoseDeprecatedConditionalConformanceOuterAccess(
UDE, selected.choice.getDecl());

return buildDeclRef(selected, nameLoc, memberLocator, implicit,
AccessSemantics::Ordinary);
return buildDeclRef(selected, nameLoc, memberLocator, implicit);
}

switch (selected.choice.getKind()) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Sema/TypeCheckExpr.cpp
Expand Up @@ -601,10 +601,10 @@ Expr *TypeChecker::buildRefExpr(ArrayRef<ValueDecl *> Decls,
assert(!Decls.empty() && "Must have at least one declaration");

auto &Context = UseDC->getASTContext();
if (Decls.size() == 1 && !isa<ProtocolDecl>(Decls[0]->getDeclContext())) {
auto semantics = Decls[0]->getAccessSemanticsFromContext(UseDC,
/*isAccessOnSelf*/false);
return new (Context) DeclRefExpr(Decls[0], NameLoc, Implicit, semantics);

if (Decls.size() == 1) {
return new (Context) DeclRefExpr(Decls[0], NameLoc, Implicit,
AccessSemantics::Ordinary);
}

Decls = Context.AllocateCopy(Decls);
Expand Down

0 comments on commit 6a82f24

Please sign in to comment.