Skip to content

Commit 7655b48

Browse files
committed
NFC: Test printing swiftinterfaces that include declarations that were written using typealiases from another module.
This test establishes a baseline for the behavior of swiftinterface emission when public declarations of all kinds reference typealiases from another module. It seems that for many types of declarations, the printer is looking through the typealias definition and printing the original type instead of a fully qualified reference to the typealias. This behavior can cause swiftinterfaces to be unparsable since the original type may not be declared in the module declaring the typealias. Every CHECK line in this test that includes a reference to fully qualified type from the `Original` module represents an instance of this bug. Once this behavior is corrected, it should be possible to succesfully parse `UsesAliases.swiftinterface` and the `RUN:` line for doing so should be uncommented.
1 parent 33335f9 commit 7655b48

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
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)