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