Skip to content

Commit e796ec7

Browse files
authored
Merge pull request #60179 from tshortli/cross-module-typealias-tests
NFC: Test printing swiftinterfaces containing declarations originally written using typealiases from another module
2 parents 83d9781 + 1a7b23c commit e796ec7

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-emit-module-interface(%t/Original.swiftinterface) %t/Original.swift
5+
// RUN: %target-swift-typecheck-module-from-interface(%t/Original.swiftinterface)
6+
7+
// RUN: %target-swift-emit-module-interface(%t/Aliases.swiftinterface) %t/Aliases.swift -I %t
8+
// RUN: %target-swift-typecheck-module-from-interface(%t/Aliases.swiftinterface) -I %t
9+
10+
// RUN: %target-swift-emit-module-interface(%t/UsesAliases.swiftinterface) %t/UsesAliases.swift -I %t -disable-availability-checking
11+
// TODO: enable verification of UsesAliases.swiftinterface (rdar://91447971)
12+
// RUN/: %target-swift-typecheck-module-from-interface(%t/UsesAliases.swiftinterface) -I %t
13+
14+
// RUN: %FileCheck %s < %t/UsesAliases.swiftinterface
15+
16+
17+
//--- Original.swift
18+
19+
open class Clazz {}
20+
21+
public protocol Proto {
22+
func requirement()
23+
}
24+
25+
public struct Struct {
26+
public init() {}
27+
}
28+
29+
@propertyWrapper
30+
public struct Wrapper<T> {
31+
public var wrappedValue: T
32+
public init(wrappedValue: T) {
33+
self.wrappedValue = wrappedValue
34+
}
35+
}
36+
37+
38+
//--- Aliases.swift
39+
40+
import Original
41+
42+
public typealias ClazzAlias = Clazz
43+
public typealias ProtoAlias = Proto
44+
public typealias StructAlias = Struct
45+
public typealias WrapperAlias = Wrapper
46+
47+
48+
//--- UsesAliases.swift
49+
50+
import Aliases
51+
52+
// CHECK: public class InheritsFromClazzAlias : Aliases.ClazzAlias
53+
public class InheritsFromClazzAlias: ClazzAlias {}
54+
55+
// CHECK: public protocol HasAssociatedTypeWithStructAliasDefault
56+
public protocol HasAssociatedTypeWithStructAliasDefault {
57+
// CHECK: associatedtype Assoc = Aliases.StructAlias
58+
associatedtype Assoc = StructAlias
59+
}
60+
61+
// CHECK: public func usesStructAlias(_ x: Aliases.StructAlias) -> Aliases.StructAlias
62+
public func usesStructAlias(_ x: StructAlias) -> StructAlias {
63+
return x
64+
}
65+
66+
// CHECK: public func usesGenericTypesConstrainedToProtoAlias<T>(_ x: T) -> T where T : Original.Proto
67+
public func usesGenericTypesConstrainedToProtoAlias<T: ProtoAlias>(_ x: T) -> T {
68+
return x
69+
}
70+
71+
// CHECK: public func usesGenericTypesConstrainedToProtoAliasWithWhereClause<T>(_ x: T) -> T where T : Original.Proto
72+
public func usesGenericTypesConstrainedToProtoAliasWithWhereClause<T>(_ x: T) -> T where T: ProtoAlias {
73+
return x
74+
}
75+
76+
// TODO: opaque parameters should probably print fully qualified
77+
// CHECK: public func usesOpaqueProtoAliasTypes(_ x: some ProtoAlias) -> some Original.Proto
78+
public func usesOpaqueProtoAliasTypes(_ x: some ProtoAlias) -> some ProtoAlias {
79+
return x
80+
}
81+
82+
// CHECK: public func usesExistentialProtoAliasTypes(_ x: any Original.Proto) -> any Original.Proto
83+
public func usesExistentialProtoAliasTypes(_ x: any ProtoAlias) -> any ProtoAlias {
84+
return x
85+
}
86+
87+
// CHECK: public struct ConformsToProtoAlias : Aliases.ProtoAlias
88+
public struct ConformsToProtoAlias: ProtoAlias {
89+
// CHECK: @_implements(Aliases.ProtoAlias, requirement) public func requirement()
90+
@_implements(ProtoAlias, requirement) public func requirement() {}
91+
}
92+
93+
// CHECK: public struct HasProtoAliasGenericConstraint<T> where T : Original.Proto
94+
public struct HasProtoAliasGenericConstraint<T: ProtoAlias> {}
95+
96+
// CHECK: public struct HasMembers
97+
public struct HasMembers {
98+
// CHECK: public var foo: Aliases.StructAlias
99+
public var foo: StructAlias
100+
101+
// CHECK: public var fooInferred: Aliases.StructAlias
102+
public var fooInferred = StructAlias()
103+
104+
// CHECK: public var closure: (Aliases.StructAlias) -> Aliases.StructAlias
105+
public var closure: (StructAlias) -> StructAlias
106+
107+
// CHECK: public var closureInferred: (_ x: Aliases.StructAlias) -> Aliases.StructAlias
108+
public var closureInferred = { (x: StructAlias) -> StructAlias in
109+
return x
110+
}
111+
112+
// TODO: referencing StructAlias here results in a spurious warning:
113+
// warning: cannot use struct 'Struct' here; 'Original' was not imported by this file
114+
// CHECK: public var tuple: (Aliases.StructAlias)
115+
public var tuple: (StructAlias)
116+
117+
// CHECK: public subscript(i: Aliases.StructAlias) -> Aliases.StructAlias
118+
public subscript(i: StructAlias) -> StructAlias {
119+
return i
120+
}
121+
122+
// CHECK: @Original.Wrapper public var wrapped: Swift.Int
123+
@WrapperAlias public var wrapped: Int
124+
}
125+
126+
// CHECK: public enum HasCasePayloads
127+
public enum HasCasePayloads {
128+
// CHECK: case hasStructAlias(Aliases.StructAlias)
129+
case hasStructAlias(StructAlias)
130+
131+
// CHECK: case hasExistentialProtoAlias(any Original.Proto)
132+
case hasExistentialProtoAlias(any ProtoAlias)
133+
}
134+
135+
// CHECK: extension Original.Struct
136+
extension StructAlias {
137+
// CHECK-NEXT: public func publicMember()
138+
public func publicMember() {}
139+
}
140+
141+
// CHECK: public typealias ProtoAliasAlias = Aliases.ProtoAlias
142+
public typealias ProtoAliasAlias = ProtoAlias
143+
144+
// TODO: @_typeEraser should probably print fully qualified
145+
// CHECK: @_typeEraser(StructAlias) public protocol StructAliasTypeEraser
146+
@_typeEraser(StructAlias) public protocol StructAliasTypeEraser {}
147+
148+
// CHECK: extension Original.Struct : UsesAliases.StructAliasTypeEraser
149+
extension StructAlias: StructAliasTypeEraser {
150+
// CHECK: public init<T>(erasing: T) where T : UsesAliases.StructAliasTypeEraser
151+
public init<T: StructAliasTypeEraser>(erasing: T) {}
152+
}

0 commit comments

Comments
 (0)