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