File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -1809,18 +1809,25 @@ bool ExtensionDecl::isWrittenWithConstraints() const {
1809
1809
typeSig->getRequirementsWithInverses (typeReqs, typeInverseReqs);
1810
1810
1811
1811
// If the (non-inverse) requirements are different between the extension and
1812
- // the original type, it's written with constraints. Note that
1813
- // the extension can only add requirements, so we need only check the size
1814
- // (not the specific requirements).
1815
- if (extReqs.size () > typeReqs.size ()) {
1812
+ // the original type, it's written with constraints.
1813
+ if (extReqs.size () != typeReqs.size ()) {
1816
1814
return true ;
1817
1815
}
1818
1816
1819
- assert (extReqs.size () == typeReqs.size ());
1817
+ // In case of equal number of constraints, we have to check the specific
1818
+ // requirements. Extensions can end up with fewer requirements than the type
1819
+ // extended, due to a same-type requirement in the extension.
1820
+ //
1821
+ // This mirrors the 'same' check in `ASTMangler::gatherGenericSignatureParts`
1822
+ for (size_t i = 0 ; i < extReqs.size (); i++) {
1823
+ if (extReqs[i] != typeReqs[i])
1824
+ return true ;
1825
+ }
1820
1826
1821
1827
// If the type has no inverse requirements, there are no extra constraints
1822
1828
// to write.
1823
1829
if (typeInverseReqs.empty ()) {
1830
+ assert (extInverseReqs.empty () && " extension retroactively added inverse?" );
1824
1831
return false ;
1825
1832
}
1826
1833
Original file line number Diff line number Diff line change
1
+ // RUN: %target-swift-frontend -emit-ir -g %s > /dev/null
2
+
3
+ // https://github.com/apple/swift/issues/72719
4
+
5
+ protocol D { }
6
+ struct U : D , Equatable { }
7
+ class Q < T> { }
8
+ class R < V, E: D & Equatable > { }
9
+ extension R where E == U {
10
+ struct S < X> { }
11
+ static func a< T> ( _: T ) -> R {
12
+ let x = Q < S < T > > ( )
13
+ fatalError ( )
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments