Skip to content

Commit 0152d41

Browse files
committed
AST: Print parameterized protocols in opaque return types
The primary change was the refactoring of ArchetypeType::getExistentialType(); this commit just fixes the type sugar. Fixes rdar://problem/100911362.
1 parent 4eb1652 commit 0152d41

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6466,6 +6466,13 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
64666466
if (auto existential = constraint->getAs<ExistentialType>())
64676467
constraint = existential->getConstraintType();
64686468

6469+
// Opaque archetype substitutions are always canonical, so re-sugar the
6470+
// constraint type using the owning declaration's generic parameter names.
6471+
auto genericSig = T->getDecl()->getNamingDecl()->getInnermostDeclContext()
6472+
->getGenericSignatureOfContext();
6473+
if (genericSig)
6474+
constraint = genericSig->getSugaredType(constraint);
6475+
64696476
visit(constraint);
64706477
return;
64716478
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/ParameterizedProtocols.swiftinterface) %s -module-name ParameterizedProtocols
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/ParameterizedProtocols.swiftinterface) -module-name ParameterizedProtocols
4+
// RUN: %FileCheck %s < %t/ParameterizedProtocols.swiftinterface
5+
6+
public protocol P<T> {
7+
associatedtype T
8+
}
9+
10+
struct S<T>: P {}
11+
12+
// CHECK-LABEL: public func returnsP() -> some ParameterizedProtocols.P
13+
public func returnsP() -> some P { return S<Int>() }
14+
15+
// CHECK-LABEL: public func returnsPInt() -> some ParameterizedProtocols.P<Swift.Int>
16+
public func returnsPInt() -> some P<Int> { return S<Int>() }
17+
18+
// CHECK-LABEL: public func returnsPT<T>(_: T) -> some ParameterizedProtocols.P<T>
19+
public func returnsPT<T>(_: T) -> some P<T> { return S<T>() }

0 commit comments

Comments
 (0)