@@ -1777,6 +1777,33 @@ static TypeRepr *unwrapAttributedRepr(TypeRepr *repr) {
1777
1777
return repr;
1778
1778
}
1779
1779
1780
+ static void collectProtocolsFromInheritedEntry (
1781
+ const InheritedEntry &entry,
1782
+ Type inheritedTy,
1783
+ llvm::SmallPtrSetImpl<ProtocolDecl *> &protocolsWithRetroactiveAttr,
1784
+ SmallVectorImpl<ProtocolDecl *> &protos) {
1785
+
1786
+ if (auto *protoTy = inheritedTy->getAs <ProtocolType>()) {
1787
+ auto *proto = protoTy->getDecl ();
1788
+
1789
+ // As a fallback, to support previous language versions, also allow
1790
+ // this through if the protocol has been explicitly module-qualified.
1791
+ TypeRepr *repr = unwrapAttributedRepr (entry.getTypeRepr ());
1792
+ if (isModuleQualified (repr, proto->getParentModule ())) {
1793
+ protocolsWithRetroactiveAttr.insert (proto);
1794
+ }
1795
+
1796
+ protos.push_back (proto);
1797
+ } else if (auto *pct = inheritedTy->getAs <ProtocolCompositionType>()) {
1798
+ for (auto member : pct->getMembers ()) {
1799
+ collectProtocolsFromInheritedEntry (entry, member,
1800
+ protocolsWithRetroactiveAttr, protos);
1801
+ }
1802
+ } else if (auto *ppt = inheritedTy->getAs <ParameterizedProtocolType>()) {
1803
+ protos.push_back (ppt->getProtocol ());
1804
+ }
1805
+ }
1806
+
1780
1807
// / Determines if this extension declares a conformance of a type declared
1781
1808
// / outside this module to a protocol declared outside this module (but only
1782
1809
// / in library evolution mode)
@@ -1813,7 +1840,7 @@ static void diagnoseRetroactiveConformances(
1813
1840
// At this point, we know we're extending a type declared outside this module.
1814
1841
// We better only be conforming it to protocols declared within this module.
1815
1842
llvm::SmallMapVector<ProtocolDecl *, bool , 8 > protocols;
1816
- llvm::SmallSet <ProtocolDecl *, 8 > protocolsWithRetroactiveAttr;
1843
+ llvm::SmallPtrSet <ProtocolDecl *, 2 > protocolsWithRetroactiveAttr;
1817
1844
1818
1845
for (auto *conformance : ext->getLocalConformances ()) {
1819
1846
auto *proto = conformance->getProtocol ();
@@ -1841,27 +1868,8 @@ static void diagnoseRetroactiveConformances(
1841
1868
}
1842
1869
1843
1870
SmallVector<ProtocolDecl *, 2 > protos;
1844
- if (auto *protoTy = inheritedTy->getAs <ProtocolType>()) {
1845
- auto *proto = protoTy->getDecl ();
1846
-
1847
- // As a fallback, to support previous language versions, also allow
1848
- // this through if the protocol has been explicitly module-qualified.
1849
- TypeRepr *repr = unwrapAttributedRepr (entry.getTypeRepr ());
1850
- if (isModuleQualified (repr, proto->getParentModule ())) {
1851
- protocolsWithRetroactiveAttr.insert (proto);
1852
- continue ;
1853
- }
1854
-
1855
- protos.push_back (proto);
1856
- } else if (auto *compositionTy = inheritedTy->getAs <ProtocolCompositionType>()) {
1857
- for (auto memberTy : compositionTy->getMembers ()) {
1858
- if (auto *protoTy = memberTy->getAs <ProtocolType>()) {
1859
- protos.push_back (protoTy->getDecl ());
1860
- }
1861
- }
1862
- } else {
1863
- continue ;
1864
- }
1871
+ collectProtocolsFromInheritedEntry (entry, inheritedTy,
1872
+ protocolsWithRetroactiveAttr, protos);
1865
1873
1866
1874
for (auto *proto : protos) {
1867
1875
proto->walkInheritedProtocols ([&](ProtocolDecl *decl) {
0 commit comments