@@ -1653,7 +1653,6 @@ namespace {
1653
1653
1654
1654
DeclContext *BaseDC = nullptr ;
1655
1655
DeclContext *MetaBaseDC = nullptr ;
1656
- GenericParamList *GenericParams = nullptr ;
1657
1656
LookupDecls lookupDecls;
1658
1657
breadcrumbs.push_back (results);
1659
1658
@@ -1662,7 +1661,6 @@ namespace {
1662
1661
BaseDC = results.BaseDC ;
1663
1662
MetaBaseDC = results.MetaBaseDC ;
1664
1663
isCascadingUse = results.isCascadingUse ;
1665
- GenericParams = results.GenericParams ;
1666
1664
switch (results.result ) {
1667
1665
case ScopeLookupResult::next:
1668
1666
break ;
@@ -1673,17 +1671,6 @@ namespace {
1673
1671
}
1674
1672
// UP TO HERE
1675
1673
1676
- // If we're inside a function context, we've already moved to
1677
- // the parent DC, so we have to check the function's generic
1678
- // parameters first.
1679
- if (GenericParams) {
1680
- namelookup::FindLocalVal localVal (SM, Loc, Consumer);
1681
- localVal.checkGenericParams (GenericParams);
1682
-
1683
- if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults ())
1684
- return std::make_pair (ScopeLookupResult::finished, DC);
1685
- }
1686
-
1687
1674
// Check the generic parameters of our context.
1688
1675
GenericParamList *dcGenericParams = nullptr ;
1689
1676
if (auto nominal = dyn_cast<NominalTypeDecl>(DC))
@@ -1784,25 +1771,29 @@ namespace {
1784
1771
Consumer.foundDecl (selfParam, DeclVisibilityKind::FunctionParameter);
1785
1772
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults ())
1786
1773
return PerScopeLookupState{
1787
- ScopeLookupResult::finished, PBI, LookupDecls{}, nullptr , nullptr ,
1774
+ ScopeLookupResult::finished,
1775
+ PBI,
1776
+ LookupDecls{},
1777
+ nullptr ,
1778
+ nullptr ,
1788
1779
// FACTOR THIS LINE
1789
1780
isCascadingUse.hasValue () ? isCascadingUse.getValue ()
1790
- : PBI->isCascadingContextForLookup (false ),
1791
- nullptr };
1792
-
1781
+ : PBI->isCascadingContextForLookup (false )
1782
+ };
1793
1783
DeclContext *const parent = PBI->getParent ();
1794
1784
1795
1785
LookupDecls lookupDecls;
1796
1786
populateLookupDeclsFromContext (parent, lookupDecls);
1797
- return PerScopeLookupState{ScopeLookupResult::next,
1787
+ return PerScopeLookupState{
1788
+ ScopeLookupResult::next,
1798
1789
parent,
1799
1790
std::move (lookupDecls),
1800
1791
PBI,
1801
1792
parent,
1802
1793
isCascadingUse.hasValue ()
1803
1794
? isCascadingUse.getValue ()
1804
- : DC->isCascadingContextForLookup (false ),
1805
- nullptr };
1795
+ : DC->isCascadingContextForLookup (false )
1796
+ };
1806
1797
}
1807
1798
// Initializers for stored properties of types perform static
1808
1799
// lookup into the surrounding context.
@@ -1816,22 +1807,23 @@ namespace {
1816
1807
std::move (lookupDecls),
1817
1808
surroundingContext,
1818
1809
surroundingContext,
1819
- surroundingContext->isCascadingContextForLookup (false ),
1820
- nullptr };
1810
+ surroundingContext->isCascadingContextForLookup (false )
1811
+ };
1821
1812
}
1822
1813
// Otherwise, we have an initializer for a global or local property.
1823
1814
// There's not much to find here, we'll keep going up to a parent
1824
1815
// context.
1825
1816
1826
- return PerScopeLookupState{ScopeLookupResult::next,
1817
+ return PerScopeLookupState{
1818
+ ScopeLookupResult::next,
1827
1819
PBI,
1828
1820
LookupDecls{},
1829
1821
nullptr ,
1830
1822
nullptr ,
1831
1823
isCascadingUse.hasValue ()
1832
1824
? isCascadingUse.getValue ()
1833
- : PBI->isCascadingContextForLookup (false ),
1834
- nullptr };
1825
+ : PBI->isCascadingContextForLookup (false )
1826
+ };
1835
1827
}
1836
1828
1837
1829
PerScopeLookupState lookupInFunctionDecl (AbstractFunctionDecl *AFD,
@@ -1846,12 +1838,16 @@ namespace {
1846
1838
localVal.visit (AFD->getBody ());
1847
1839
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults ())
1848
1840
return PerScopeLookupState{
1849
- ScopeLookupResult::finished, AFD, LookupDecls{}, nullptr , nullptr ,
1841
+ ScopeLookupResult::finished,
1842
+ AFD,
1843
+ LookupDecls{},
1844
+ nullptr ,
1845
+ nullptr ,
1850
1846
// FACTOR INTO A FN
1851
1847
isCascadingUse.hasValue ()
1852
1848
? isCascadingUse.getValue ()
1853
- : !SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc),
1854
- nullptr };
1849
+ : !SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc)
1850
+ };
1855
1851
1856
1852
if (auto *P = AFD->getImplicitSelfDecl ())
1857
1853
localVal.checkValueDecl (P, DeclVisibilityKind::FunctionParameter);
@@ -1865,8 +1861,8 @@ namespace {
1865
1861
nullptr ,
1866
1862
isCascadingUse.hasValue ()
1867
1863
? isCascadingUse.getValue ()
1868
- : !SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc),
1869
- nullptr };
1864
+ : !SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc)
1865
+ };
1870
1866
}
1871
1867
const bool returnValueForIsCascadingUse =
1872
1868
AFD->isCascadingContextForLookup (false ) &&
@@ -1880,8 +1876,13 @@ namespace {
1880
1876
populateLookupDeclsFromContext (AFD->getDeclContext (), lookupDecls);
1881
1877
DeclContext *const MetaBaseDC = AFD->getDeclContext ();
1882
1878
1879
+ addGenericParameters (AFD);
1883
1880
return PerScopeLookupState{
1884
- ScopeLookupResult::next, AFD->getParent (), std::move (lookupDecls),
1881
+ isFinishedWithLookupNowThatIsAboutToLookForOuterResults ()
1882
+ ? ScopeLookupResult::finished
1883
+ : ScopeLookupResult::next,
1884
+ AFD->getParent (),
1885
+ std::move (lookupDecls),
1885
1886
// If we're not in the body of the function (for example, we
1886
1887
// might be type checking a default argument expression and
1887
1888
// performing name lookup from there), the base declaration
@@ -1891,16 +1892,34 @@ namespace {
1891
1892
!SM.rangeContainsTokenLoc (AFD->getBodySourceRange (), Loc)
1892
1893
? MetaBaseDC
1893
1894
: AFD,
1894
- MetaBaseDC, returnValueForIsCascadingUse, AFD->getGenericParams ()};
1895
+ MetaBaseDC,
1896
+ returnValueForIsCascadingUse
1897
+ };
1895
1898
}
1896
1899
// Look in the generic parameters after checking our local declaration.
1897
- return PerScopeLookupState{ScopeLookupResult::next,
1900
+ addGenericParameters (AFD);
1901
+ return PerScopeLookupState{
1902
+ isFinishedWithLookupNowThatIsAboutToLookForOuterResults ()
1903
+ ? ScopeLookupResult::finished
1904
+ : ScopeLookupResult::next,
1898
1905
AFD,
1899
1906
LookupDecls{},
1900
1907
nullptr ,
1901
1908
nullptr ,
1902
- returnValueForIsCascadingUse,
1903
- AFD->getGenericParams ()};
1909
+ returnValueForIsCascadingUse
1910
+ };
1911
+ }
1912
+
1913
+ // / Consume generic parameters
1914
+ void addGenericParameters (AbstractFunctionDecl *AFD) {
1915
+ // If we're inside a function context, we've already moved to
1916
+ // the parent DC, so we have to check the function's generic
1917
+ // parameters first.
1918
+ GenericParamList *GenericParams = AFD->getGenericParams ();
1919
+ if (GenericParams) {
1920
+ namelookup::FindLocalVal localVal (SM, Loc, Consumer);
1921
+ localVal.checkGenericParams (GenericParams);
1922
+ }
1904
1923
}
1905
1924
1906
1925
PerScopeLookupState lookupInClosure (AbstractClosureExpr *ACE,
@@ -1913,97 +1932,104 @@ namespace {
1913
1932
if (auto body = CE->getBody ())
1914
1933
localVal.visit (body);
1915
1934
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults ()) {
1916
- return PerScopeLookupState{ScopeLookupResult::finished,
1935
+ return PerScopeLookupState{
1936
+ ScopeLookupResult::finished,
1917
1937
ACE,
1918
1938
LookupDecls{},
1919
1939
nullptr ,
1920
1940
nullptr ,
1921
- isCascadingUse,
1922
- nullptr };
1941
+ isCascadingUse
1942
+ };
1923
1943
}
1924
1944
if (auto params = CE->getParameters ())
1925
1945
localVal.checkParameterList (params);
1926
1946
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults ()) {
1927
- return PerScopeLookupState{ScopeLookupResult::finished,
1947
+ return PerScopeLookupState{
1948
+ ScopeLookupResult::finished,
1928
1949
ACE,
1929
1950
LookupDecls{},
1930
1951
nullptr ,
1931
1952
nullptr ,
1932
- isCascadingUse,
1933
- nullptr };
1953
+ isCascadingUse
1954
+ };
1934
1955
}
1935
1956
}
1936
1957
}
1937
- return PerScopeLookupState{ScopeLookupResult::next,
1958
+ return PerScopeLookupState{
1959
+ ScopeLookupResult::next,
1938
1960
DC,
1939
1961
LookupDecls{},
1940
1962
nullptr ,
1941
1963
nullptr ,
1942
1964
isCascadingUse.hasValue ()
1943
1965
? isCascadingUse.getValue ()
1944
- : ACE->isCascadingContextForLookup (false ),
1945
- nullptr };
1966
+ : ACE->isCascadingContextForLookup (false )
1967
+ };
1946
1968
}
1947
1969
1948
1970
PerScopeLookupState lookupInExtension (ExtensionDecl *ED,
1949
1971
Optional<bool > isCascadingUse) {
1950
1972
LookupDecls lookupDecls;
1951
1973
if (shouldLookupMembers (ED, Loc))
1952
1974
populateLookupDeclsFromContext (ED, lookupDecls);
1953
- return PerScopeLookupState{ScopeLookupResult::next,
1975
+ return PerScopeLookupState{
1976
+ ScopeLookupResult::next,
1954
1977
DC,
1955
1978
std::move (lookupDecls),
1956
1979
ED,
1957
1980
ED,
1958
1981
isCascadingUse.hasValue ()
1959
1982
? isCascadingUse.getValue ()
1960
- : ED->isCascadingContextForLookup (false ),
1961
- nullptr };
1983
+ : ED->isCascadingContextForLookup (false )
1984
+ };
1962
1985
}
1963
1986
1964
1987
PerScopeLookupState lookupInNominalType (NominalTypeDecl *ND,
1965
1988
Optional<bool > isCascadingUse) {
1966
1989
LookupDecls lookupDecls;
1967
1990
if (shouldLookupMembers (ND, Loc))
1968
1991
populateLookupDeclsFromContext (ND, lookupDecls);
1969
- return PerScopeLookupState{ScopeLookupResult::next,
1992
+ return PerScopeLookupState{
1993
+ ScopeLookupResult::next,
1970
1994
DC,
1971
1995
std::move (lookupDecls),
1972
1996
DC,
1973
1997
DC,
1974
1998
isCascadingUse.hasValue ()
1975
1999
? isCascadingUse.getValue ()
1976
- : ND->isCascadingContextForLookup (false ),
1977
- nullptr };
2000
+ : ND->isCascadingContextForLookup (false )
2001
+ };
1978
2002
}
1979
2003
1980
2004
PerScopeLookupState
1981
2005
lookupInDefaultArgumentInitializer (DefaultArgumentInitializer *I,
1982
2006
Optional<bool > isCascadingUse) {
1983
2007
// In a default argument, skip immediately out of both the
1984
2008
// initializer and the function.
1985
- return PerScopeLookupState{ScopeLookupResult::stop,
2009
+ return PerScopeLookupState{
2010
+ ScopeLookupResult::stop,
1986
2011
I->getParent ()->getParent (),
1987
2012
LookupDecls{},
1988
2013
nullptr ,
1989
2014
nullptr ,
1990
- false ,
1991
- nullptr };
2015
+ false
2016
+ };
1992
2017
}
1993
2018
1994
2019
PerScopeLookupState lookupInMiscContext (DeclContext *DC,
1995
2020
Optional<bool > isCascadingUse) {
1996
2021
assert (isa<TopLevelCodeDecl>(DC) || isa<Initializer>(DC) ||
1997
2022
isa<TypeAliasDecl>(DC) || isa<SubscriptDecl>(DC));
1998
- return PerScopeLookupState{ScopeLookupResult::next,
2023
+ return PerScopeLookupState{
2024
+ ScopeLookupResult::next,
1999
2025
DC,
2000
2026
LookupDecls{},
2001
2027
nullptr ,
2002
2028
nullptr ,
2003
2029
isCascadingUse.hasValue ()
2004
2030
? isCascadingUse.getValue ()
2005
- : DC->isCascadingContextForLookup (false ),
2006
- nullptr };
2031
+ : DC->isCascadingContextForLookup (false )
2032
+ };
2007
2033
}
2008
2034
2009
2035
bool addLocalVariableResults () {
@@ -2172,11 +2198,6 @@ void ExpUnqualifiedLookup::PerScopeLookupState::dump() const {
2172
2198
for (const auto *D : foundDecls)
2173
2199
D->dump ();
2174
2200
e << " \n " ;
2175
- if (GenericParams) {
2176
- e << " GenericParams: " ;
2177
- GenericParams->print (e);
2178
- e << " \n " ;
2179
- }
2180
2201
}
2181
2202
2182
2203
#pragma mark Member lookup table
0 commit comments