@@ -1757,6 +1757,17 @@ namespace {
1757
1757
};
1758
1758
}
1759
1759
1760
+ // / Given an extension declaration, return the extended nominal type if the
1761
+ // / extension was produced by expanding an extension or conformance macro from
1762
+ // / the nominal declaration itself.
1763
+ static NominalTypeDecl *nominalForExpandedExtensionDecl (ExtensionDecl *ext) {
1764
+ if (!ext->isInMacroExpansionInContext ())
1765
+ return nullptr ;
1766
+
1767
+
1768
+ return ext->getSelfNominalTypeDecl ();
1769
+ }
1770
+
1760
1771
PotentialMacroExpansions PotentialMacroExpansionsInContextRequest::evaluate (
1761
1772
Evaluator &evaluator, TypeOrExtensionDecl container) const {
1762
1773
// / The implementation here needs to be kept in sync with
@@ -1767,6 +1778,15 @@ PotentialMacroExpansions PotentialMacroExpansionsInContextRequest::evaluate(
1767
1778
auto containerDecl = container.getAsDecl ();
1768
1779
forEachPotentialAttachedMacro (containerDecl, MacroRole::Member, nameTracker);
1769
1780
1781
+ // If the container is an extension that was created from an extension macro,
1782
+ // look at the nominal declaration to find any extension macros.
1783
+ if (auto ext = dyn_cast<ExtensionDecl>(containerDecl)) {
1784
+ if (auto nominal = nominalForExpandedExtensionDecl (ext)) {
1785
+ forEachPotentialAttachedMacro (
1786
+ nominal, MacroRole::Extension, nameTracker);
1787
+ }
1788
+ }
1789
+
1770
1790
// Peer and freestanding declaration macros.
1771
1791
auto dc = container.getAsDeclContext ();
1772
1792
auto idc = container.getAsIterableDeclContext ();
@@ -1825,13 +1845,15 @@ populateLookupTableEntryFromMacroExpansions(ASTContext &ctx,
1825
1845
// names match.
1826
1846
{
1827
1847
MacroIntroducedNameTracker nameTracker;
1828
- if (auto nominal = dyn_cast<NominalTypeDecl>(container.getAsDecl ())) {
1829
- forEachPotentialAttachedMacro (nominal, MacroRole::Extension, nameTracker);
1830
- if (nameTracker.shouldExpandForName (name)) {
1831
- (void )evaluateOrDefault (
1832
- ctx.evaluator ,
1833
- ExpandExtensionMacros{nominal},
1834
- false );
1848
+ if (auto ext = dyn_cast<ExtensionDecl>(container.getAsDecl ())) {
1849
+ if (auto nominal = nominalForExpandedExtensionDecl (ext)) {
1850
+ forEachPotentialAttachedMacro (nominal, MacroRole::Extension, nameTracker);
1851
+ if (nameTracker.shouldExpandForName (name)) {
1852
+ (void )evaluateOrDefault (
1853
+ ctx.evaluator ,
1854
+ ExpandExtensionMacros{nominal},
1855
+ false );
1856
+ }
1835
1857
}
1836
1858
}
1837
1859
}
0 commit comments