Skip to content

Commit bcde0f8

Browse files
committed
[test] Add additional implementation-only conformance test cases
...suggested by Brent and Slava. Thanks, both!
1 parent 59974a5 commit bcde0f8

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

test/Sema/implementation-only-import-in-decls.swift

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,39 +175,47 @@ extension ConditionalGenericStruct: NormalProto where T: NormalProto {
175175
}
176176
public func testConditionalGeneric(_: NormalProtoAssocHolder<ConditionalGenericStruct<NormalStruct>>) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
177177

178-
public protocol PublicInferredAssociatedType {
178+
public protocol PublicAssociatedTypeProto {
179179
associatedtype Assoc: NormalProto
180180
func takesAssoc(_: Assoc)
181181
}
182-
@usableFromInline protocol UFIInferredAssociatedType {
182+
@usableFromInline protocol UFIAssociatedTypeProto {
183183
associatedtype Assoc: NormalProto
184184
func takesAssoc(_: Assoc)
185185
}
186-
protocol InternalInferredAssociatedType {
186+
protocol InternalAssociatedTypeProto {
187187
associatedtype Assoc: NormalProto
188188
func takesAssoc(_: Assoc)
189189
}
190190

191191
public struct PublicInferredAssociatedTypeImpl {
192192
public func takesAssoc(_: NormalStruct) {}
193193
}
194-
extension PublicInferredAssociatedTypeImpl: PublicInferredAssociatedType {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
195-
extension PublicInferredAssociatedTypeImpl: UFIInferredAssociatedType {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
196-
extension PublicInferredAssociatedTypeImpl: InternalInferredAssociatedType {} // okay
194+
extension PublicInferredAssociatedTypeImpl: PublicAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
195+
extension PublicInferredAssociatedTypeImpl: UFIAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
196+
extension PublicInferredAssociatedTypeImpl: InternalAssociatedTypeProto {} // okay
197197

198198
@usableFromInline struct UFIInferredAssociatedTypeImpl {
199199
public func takesAssoc(_: NormalStruct) {}
200200
}
201-
extension UFIInferredAssociatedTypeImpl: PublicInferredAssociatedType {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
202-
extension UFIInferredAssociatedTypeImpl: UFIInferredAssociatedType {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
203-
extension UFIInferredAssociatedTypeImpl: InternalInferredAssociatedType {} // okay
201+
extension UFIInferredAssociatedTypeImpl: PublicAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
202+
extension UFIInferredAssociatedTypeImpl: UFIAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
203+
extension UFIInferredAssociatedTypeImpl: InternalAssociatedTypeProto {} // okay
204204

205205
struct InternalInferredAssociatedTypeImpl {
206206
public func takesAssoc(_: NormalStruct) {}
207207
}
208-
extension InternalInferredAssociatedTypeImpl: PublicInferredAssociatedType {} // okay
209-
extension InternalInferredAssociatedTypeImpl: UFIInferredAssociatedType {} // okay
210-
extension InternalInferredAssociatedTypeImpl: InternalInferredAssociatedType {} // okay
208+
extension InternalInferredAssociatedTypeImpl: PublicAssociatedTypeProto {} // okay
209+
extension InternalInferredAssociatedTypeImpl: UFIAssociatedTypeProto {} // okay
210+
extension InternalInferredAssociatedTypeImpl: InternalAssociatedTypeProto {} // okay
211+
212+
public struct PublicExplicitAssociatedTypeImpl {
213+
public typealias Assoc = NormalStruct
214+
public func takesAssoc(_: NormalStruct) {}
215+
}
216+
extension PublicExplicitAssociatedTypeImpl: PublicAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
217+
extension PublicExplicitAssociatedTypeImpl: UFIAssociatedTypeProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
218+
extension PublicExplicitAssociatedTypeImpl: InternalAssociatedTypeProto {} // okay
211219

212220

213221
public protocol BaseProtoWithNoRequirement {
@@ -243,7 +251,7 @@ public struct RequirementsHandleSpecializationsToo: SlightlyMoreComplicatedRequi
243251
public func takesAssoc(_: [ConditionalGenericStruct<NormalStruct>]) {}
244252
}
245253

246-
public struct ClassConstrainedGenericArg<T: NormalClass>: PublicInferredAssociatedType { // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'T'); 'BADLibrary' has been imported as '@_implementationOnly'}}
254+
public struct ClassConstrainedGenericArg<T: NormalClass>: PublicAssociatedTypeProto { // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'T'); 'BADLibrary' has been imported as '@_implementationOnly'}}
247255
public func takesAssoc(_: T) {}
248256
}
249257

test/Sema/implementation-only-import-inlinable-conformances.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,13 @@ extension NormalProtoAssocHolder {
158158
@inlinable public func signatureOfInlinable(_: NormalProtoAssocHolder<NormalStruct>) {} // expected-error{{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
159159

160160
public func testDefaultArgument(_: Int = NormalProtoAssoc<NormalStruct>()) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
161+
162+
163+
public class SubclassOfNormalClass: NormalClass {}
164+
165+
@inlinable public func testInheritedConformance() {
166+
_ = NormalProtoAssocHolder<SubclassOfNormalClass>.self // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
167+
}
168+
@inlinable public func testSpecializedConformance() {
169+
_ = NormalProtoAssocHolder<GenericStruct<Int>>.self // expected-error {{cannot use conformance of 'GenericStruct<T>' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
170+
}

0 commit comments

Comments
 (0)