Skip to content

Commit 5e2ef63

Browse files
committed
ModuleInterface: Print existential any in swiftinterfaces since any is required for protocols with associated types in 5.7.
Resolves rdar://92976269
1 parent 056dd5d commit 5e2ef63

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
144144
PrintOptions::FunctionRepresentationMode::Full;
145145
result.AlwaysTryPrintParameterLabels = true;
146146
result.PrintSPIs = printSPIs;
147+
result.PrintExplicitAny = true;
147148

148149
// We should print __consuming, __owned, etc for the module interface file.
149150
result.SkipUnderscoredKeywords = false;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %target-swift-frontend-typecheck -swift-version 5 -enable-library-evolution -emit-module-interface-path %t.swiftinterface %s -module-name main
2+
// RUN: %target-swift-frontend -typecheck-module-from-interface %t.swiftinterface -module-name main
3+
// RUN: %FileCheck %s < %t.swiftinterface
4+
5+
// CHECK: public protocol P
6+
public protocol P { }
7+
8+
// CHECK: public protocol Q
9+
public protocol Q {
10+
// CHECK: associatedtype A : main.P
11+
associatedtype A: P
12+
}
13+
14+
// CHECK: public func takesAndReturnsP(_ x: any main.P) -> any main.P
15+
public func takesAndReturnsP(_ x: P) -> P {
16+
return x
17+
}
18+
19+
// CHECK: public func takesAndReturnsOptionalP(_ x: (any main.P)?) -> (any main.P)?
20+
public func takesAndReturnsOptionalP(_ x: P?) -> P? {
21+
return x
22+
}
23+
24+
// CHECK: public func takesAndReturnsQ(_ x: any main.Q) -> any main.Q
25+
public func takesAndReturnsQ(_ x: any Q) -> any Q {
26+
return x
27+
}
28+
29+
// CHECK: public struct S
30+
public struct S {
31+
// CHECK: public var p: any main.P
32+
public var p: P
33+
// CHECK: public var maybeP: (any main.P)?
34+
public var maybeP: P?
35+
// CHECK: public var q: any main.Q
36+
public var q: any Q
37+
}

test/ModuleInterface/features.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class OldSchool2: MP {
8888
// CHECK: public struct UsesRP {
8989
public struct UsesRP {
9090
// CHECK: #if compiler(>=5.3) && $RethrowsProtocol
91-
// CHECK-NEXT: public var value: FeatureTest.RP? {
91+
// CHECK-NEXT: public var value: (any FeatureTest.RP)? {
9292
// CHECK-NOT: #if compiler(>=5.3) && $RethrowsProtocol
9393
// CHECK: get
9494
public var value: RP? {

test/ModuleInterface/top-level-Type-and-Protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public func usesType(_ x: Type) {}
1919
// CHECK: public func genericProtocol<T>(_ x: T) where T : MyModule.`Protocol`
2020
public func genericProtocol<T: Protocol>(_ x: T) {}
2121

22-
// CHECK: public func existentialProtocol(_ x: MyModule.`Protocol`)
22+
// CHECK: public func existentialProtocol(_ x: any MyModule.`Protocol`)
2323
public func existentialProtocol(_ x: Protocol) {}
2424

2525
// CHECK: public struct Parent {

0 commit comments

Comments
 (0)