@@ -199,29 +199,33 @@ namespace {
199199 // / Used to gather lookup results
200200class ASTScopeDeclConsumerForUnqualifiedLookup
201201 : public AbstractASTScopeDeclConsumer {
202+ private:
202203 UnqualifiedLookupFactory &factory;
203204
204205 // / The 'self' parameter from the innermost scope containing the lookup
205206 // / location to be used when an instance member of a type is accessed,
206- // / or nullptr if instance members should not be 'self' qualified.
207- DeclContext *candidateSelfDC;
207+ // / or \c nullptr if instance members should not be 'self' qualified.
208+ // /
209+ // FIXME: This field is currently reset to \c nullptr by `lookInMembers` as
210+ // part of the lookup traversal of scopes. If, instead, consumers were
211+ // created at each point in the traversal, this field would no longer need
212+ // to be marked \c mutable.
213+ mutable const DeclContext *candidateSelfDC;
214+
215+ void maybeUpdateSelfDC (VarDecl *var);
208216
209217public:
210218 ASTScopeDeclConsumerForUnqualifiedLookup (UnqualifiedLookupFactory &factory)
211219 : factory(factory), candidateSelfDC(nullptr ) {}
212220
213221 virtual ~ASTScopeDeclConsumerForUnqualifiedLookup () = default ;
214222
215- void maybeUpdateSelfDC (VarDecl *var);
216-
217223 bool consume (ArrayRef<ValueDecl *> values,
218224 NullablePtr<DeclContext> baseDC = nullptr ) override ;
219225
220226 bool consumePossiblyNotInScope (ArrayRef<VarDecl *> vars) override ;
221227
222- // / returns true if finished
223- bool lookInMembers (DeclContext *const scopeDC,
224- NominalTypeDecl *const nominal) override ;
228+ bool lookInMembers (const DeclContext *) const override ;
225229
226230#ifndef NDEBUG
227231 void startingNextLookupStep () override {
@@ -539,8 +543,7 @@ void UnqualifiedLookupFactory::lookInASTScopes() {
539543 ASTScope::unqualifiedLookup (DC->getParentSourceFile (), Loc, consumer);
540544}
541545
542- void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC (
543- VarDecl *var) {
546+ void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC (VarDecl *var) {
544547 // We have a binding named 'self'.
545548 //
546549 // There are three possibilities:
@@ -649,8 +652,7 @@ bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,
649652
650653// TODO: in future, migrate this functionality into ASTScopes
651654bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers (
652- DeclContext *const scopeDC,
653- NominalTypeDecl *const nominal) {
655+ const DeclContext *scopeDC) const {
654656 if (candidateSelfDC) {
655657 if (auto *afd = dyn_cast<AbstractFunctionDecl>(candidateSelfDC)) {
656658 assert (factory.isInsideBodyOfFunction (afd) && " Should be inside" );
@@ -672,7 +674,7 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
672674 // We're done looking inside a nominal type declaration. It is possible
673675 // that this nominal type is nested inside of another type, in which case
674676 // we will visit the outer type next. Make sure to clear out the known
675- // 'self' parameeter context, since any members of the outer type are
677+ // 'self' parameter context, since any members of the outer type are
676678 // not accessed via the innermost 'self' parameter.
677679 candidateSelfDC = nullptr ;
678680
@@ -820,8 +822,7 @@ class ASTScopeDeclConsumerForLocalLookup
820822 return (!stopAfterInnermostBraceStmt && !results.empty ());
821823 }
822824
823- bool lookInMembers (DeclContext *const ,
824- NominalTypeDecl *const ) override {
825+ bool lookInMembers (const DeclContext *) const override {
825826 return true ;
826827 }
827828
0 commit comments