@@ -145,13 +145,12 @@ class UnqualifiedLookupFactory {
145
145
146
146
private:
147
147
struct PlacesToSearch {
148
- // TODO: constify members?
149
- // / The context in which the places where found.
150
- DeclContext *fromWhence;
148
+ // / The context in which the places were found.
149
+ DeclContext *const fromWhence;
151
150
// / Nontypes are formally members of the base type
152
- DeclContext *whereNonTypesAreMembers;
151
+ DeclContext *const whereNonTypesAreMembers;
153
152
// / Types are formally members of the metatype
154
- DeclContext *whereTypesAreMembers;
153
+ DeclContext *const whereTypesAreMembers;
155
154
// / Places to search for the lookup.
156
155
SmallVector<NominalTypeDecl *, 2 > places;
157
156
@@ -759,7 +758,7 @@ UnqualifiedLookupFactory::lookupInPatternBindingInitializer(
759
758
false ,
760
759
parent,
761
760
PlacesToSearch (parent, PBI, parent, parent),
762
- resolveIsCascadingUse (PBI,isCascadingUse,
761
+ resolveIsCascadingUse (PBI, isCascadingUse,
763
762
/* onlyCareAboutFunctionBody=*/ false )};
764
763
// clang-format no
765
764
}
@@ -802,6 +801,7 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
802
801
803
802
namelookup::FindLocalVal localVal (SM, Loc, Consumer);
804
803
localVal.visit (AFD->getBody ());
804
+
805
805
setIndexOfFirstOuterResultIfNotSetAlready ();
806
806
if (isLookupDoneWithoutIncludingOuterResults ())
807
807
return None;
@@ -813,48 +813,46 @@ UnqualifiedLookupFactory::lookupInFunctionDecl(AbstractFunctionDecl *AFD,
813
813
if (isLookupDoneWithoutIncludingOuterResults ())
814
814
return None;
815
815
}
816
+ // TODO: is isOutsideBodyOfFunction better than the disjunction below?
816
817
const bool returnValueForIsCascadingUse =
817
818
AFD->isCascadingContextForLookup (false ) &&
818
819
(isCascadingUse.hasValue ()
819
820
? isCascadingUse.getValue ()
820
821
: !Loc.isValid () || !AFD->getBody () ||
821
822
!SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc));
822
823
823
- if (AFD->getDeclContext ()->isTypeContext ()) {
824
- DeclContext *fnDeclContext = AFD->getDeclContext ();
825
- DeclContext *fnParent = AFD->getParent ();
826
- addGenericParametersForFunction (AFD);
827
- setIndexOfFirstOuterResultIfNotSetAlready ();
828
- if (isLookupDoneWithoutIncludingOuterResults ())
829
- return None;
830
- // clang-format off
831
- return PerDeclInfo{
832
- false ,
833
- fnParent,
834
- PlacesToSearch (
835
- fnParent,
836
- // If we're not in the body of the function (for example, we
837
- // might be type checking a default argument expression and
838
- // performing name lookup from there), the base declaration
839
- // is the nominal type, not 'self'.
840
- isOutsideBodyOfFunction (AFD) ? fnDeclContext : AFD,
841
- fnDeclContext,
842
- AFD->getDeclContext ()),
843
- returnValueForIsCascadingUse};
844
- // clang-format on
845
- }
846
824
// Look in the generic parameters after checking our local declaration.
847
825
addGenericParametersForFunction (AFD);
848
826
setIndexOfFirstOuterResultIfNotSetAlready ();
849
827
if (isLookupDoneWithoutIncludingOuterResults ())
850
828
return None;
829
+
830
+ if (!AFD->getDeclContext ()->isTypeContext ())
831
+ // clang-format off
832
+ return PerDeclInfo{
833
+ false ,
834
+ AFD,
835
+ None,
836
+ returnValueForIsCascadingUse};
837
+ // clang-format on
838
+
839
+ DeclContext *const fnDeclContext = AFD->getDeclContext ();
840
+ // If we're not in the body of the function (for example, we
841
+ // might be type checking a default argument expression and
842
+ // performing name lookup from there), the base declaration
843
+ // is the nominal type, not 'self'.
844
+ DeclContext *const BaseDC = isOutsideBodyOfFunction (AFD) ? fnDeclContext : AFD;
845
+ DeclContext *const fnParent = AFD->getParent ();
851
846
// clang-format off
852
847
return PerDeclInfo{
853
848
false ,
854
- AFD,
855
- None,
849
+ fnParent,
850
+ PlacesToSearch (fnParent,
851
+ BaseDC,
852
+ fnDeclContext,
853
+ fnDeclContext),
856
854
returnValueForIsCascadingUse};
857
- // clang-format on
855
+ // clang-format on
858
856
}
859
857
860
858
Optional<UnqualifiedLookupFactory::PerDeclInfo>
0 commit comments