@@ -199,29 +199,33 @@ namespace {
199
199
// / Used to gather lookup results
200
200
class ASTScopeDeclConsumerForUnqualifiedLookup
201
201
: public AbstractASTScopeDeclConsumer {
202
+ private:
202
203
UnqualifiedLookupFactory &factory;
203
204
204
205
// / The 'self' parameter from the innermost scope containing the lookup
205
206
// / 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);
208
216
209
217
public:
210
218
ASTScopeDeclConsumerForUnqualifiedLookup (UnqualifiedLookupFactory &factory)
211
219
: factory(factory), candidateSelfDC(nullptr ) {}
212
220
213
221
virtual ~ASTScopeDeclConsumerForUnqualifiedLookup () = default ;
214
222
215
- void maybeUpdateSelfDC (VarDecl *var);
216
-
217
223
bool consume (ArrayRef<ValueDecl *> values,
218
224
NullablePtr<DeclContext> baseDC = nullptr ) override ;
219
225
220
226
bool consumePossiblyNotInScope (ArrayRef<VarDecl *> vars) override ;
221
227
222
- // / returns true if finished
223
- bool lookInMembers (DeclContext *const scopeDC,
224
- NominalTypeDecl *const nominal) override ;
228
+ bool lookInMembers (const DeclContext *) const override ;
225
229
226
230
#ifndef NDEBUG
227
231
void startingNextLookupStep () override {
@@ -539,8 +543,7 @@ void UnqualifiedLookupFactory::lookInASTScopes() {
539
543
ASTScope::unqualifiedLookup (DC->getParentSourceFile (), Loc, consumer);
540
544
}
541
545
542
- void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC (
543
- VarDecl *var) {
546
+ void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC (VarDecl *var) {
544
547
// We have a binding named 'self'.
545
548
//
546
549
// There are three possibilities:
@@ -649,8 +652,7 @@ bool ASTScopeDeclGatherer::consume(ArrayRef<ValueDecl *> valuesArg,
649
652
650
653
// TODO: in future, migrate this functionality into ASTScopes
651
654
bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers (
652
- DeclContext *const scopeDC,
653
- NominalTypeDecl *const nominal) {
655
+ const DeclContext *scopeDC) const {
654
656
if (candidateSelfDC) {
655
657
if (auto *afd = dyn_cast<AbstractFunctionDecl>(candidateSelfDC)) {
656
658
assert (factory.isInsideBodyOfFunction (afd) && " Should be inside" );
@@ -672,7 +674,7 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::lookInMembers(
672
674
// We're done looking inside a nominal type declaration. It is possible
673
675
// that this nominal type is nested inside of another type, in which case
674
676
// 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
676
678
// not accessed via the innermost 'self' parameter.
677
679
candidateSelfDC = nullptr ;
678
680
@@ -820,8 +822,7 @@ class ASTScopeDeclConsumerForLocalLookup
820
822
return (!stopAfterInnermostBraceStmt && !results.empty ());
821
823
}
822
824
823
- bool lookInMembers (DeclContext *const ,
824
- NominalTypeDecl *const ) override {
825
+ bool lookInMembers (const DeclContext *) const override {
825
826
return true ;
826
827
}
827
828
0 commit comments