Skip to content

Commit 4517333

Browse files
authored
Merge pull request #74372 from kavon/rdar125659789
2 parents de9aefc + 2735492 commit 4517333

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

lib/AST/Decl.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,14 +1809,20 @@ bool ExtensionDecl::isWrittenWithConstraints() const {
18091809
typeSig->getRequirementsWithInverses(typeReqs, typeInverseReqs);
18101810

18111811
// 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()) {
18161814
return true;
18171815
}
18181816

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+
}
18201826

18211827
// If the type has no inverse requirements, there are no extra constraints
18221828
// to write.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -interpret %s
2+
// REQUIRES: executable_test
3+
4+
// This only reproduced if you provide the -interpret flag!
5+
// https://github.com/apple/swift/issues/72719
6+
7+
protocol D {}
8+
struct U: D, Equatable {}
9+
class Q<T> {}
10+
class R<V, E: D & Equatable> {}
11+
extension R where E == U {
12+
struct S<X> {}
13+
static func a<T>(_: T) -> R {
14+
let x = Q<S<T>>()
15+
fatalError()
16+
}
17+
}

0 commit comments

Comments
 (0)