Skip to content

Commit 756bf30

Browse files
committed
GenericEnvironment: Don't use the existential layout's protocols to build "nested" opened archetypes
1 parent f90120e commit 756bf30

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,27 @@ GenericEnvironment::getOrCreateArchetypeFromInterfaceType(Type depType) {
349349

350350
case Kind::OpenedExistential: {
351351
// FIXME: The existential layout's protocols might differ from the
352-
// canonicalized set of protocols determined by the generic signature,
353-
// so use the existential layout's version. We should align these at
352+
// canonicalized set of protocols determined by the generic signature.
353+
// Before NestedArchetypeType was removed, we used the former when
354+
// building a root OpenedArchetypeType, and the latter when building
355+
// nested archetypes.
356+
// For compatibility, continue using the existential layout's version when
357+
// the interface type is a generic parameter. We should align these at
354358
// some point.
355-
auto layout = getOpenedExistentialType()->getExistentialLayout();
356-
SmallVector<ProtocolDecl *, 4> protos;
357-
for (auto protoType : layout.getProtocols())
358-
protos.push_back(protoType->getDecl());
359-
result = OpenedArchetypeType::getNew(this, requirements.anchor,
360-
protos, superclass,
361-
requirements.layout);
359+
if (depType->is<GenericTypeParamType>()) {
360+
auto layout = getOpenedExistentialType()->getExistentialLayout();
361+
SmallVector<ProtocolDecl *, 2> protos;
362+
for (auto protoType : layout.getProtocols())
363+
protos.push_back(protoType->getDecl());
364+
365+
result = OpenedArchetypeType::getNew(this, requirements.anchor, protos,
366+
superclass, requirements.layout);
367+
} else {
368+
result = OpenedArchetypeType::getNew(this, requirements.anchor,
369+
requirements.protos, superclass,
370+
requirements.layout);
371+
}
372+
362373
break;
363374
}
364375

test/decl/protocol/protocols_with_self_or_assoc_reqs.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,17 @@ do {
523523
// expected-error@-3 {{cannot convert value of type 'Bool' to expected argument type 'C<UnfulfillableGenericRequirements>'}}
524524
}
525525

526+
protocol RequirementFailures {
527+
associatedtype A
528+
}
529+
extension RequirementFailures {
530+
func method() where A: RequirementFailures {} // expected-note {{where 'Self.A' = '(RequirementFailures).A'}}
531+
}
532+
do {
533+
let exist: any RequirementFailures
534+
exist.method() // expected-error {{instance method 'method()' requires that '(RequirementFailures).A' conform to 'RequirementFailures'}}
535+
}
536+
526537
// Settable storage members with a 'Self' result type may not be used with an
527538
// existential base.
528539
protocol P2 {

0 commit comments

Comments
 (0)