Skip to content

Commit 8fcf1eb

Browse files
authored
Merge pull request #23959 from jrose-apple/i-specialize-in-a-very-specific-type-of-security
[test] Add additional implementation-only conformance test cases
2 parents def1af6 + bcde0f8 commit 8fcf1eb

File tree

2 files changed

+25
-110
lines changed

2 files changed

+25
-110
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: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -162,102 +162,9 @@ public func testDefaultArgument(_: Int = NormalProtoAssoc<NormalStruct>()) {} //
162162

163163
public class SubclassOfNormalClass: NormalClass {}
164164

165-
public func testInheritedConformance(_: NormalProtoAssocHolder<SubclassOfNormalClass>) {} // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
166-
public func testSpecializedConformance(_: NormalProtoAssocHolder<GenericStruct<Int>>) {} // expected-error {{cannot use conformance of 'GenericStruct<T>' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
167-
168-
extension Array where Element == NormalProtoAssocHolder<NormalStruct> { // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
169-
public func testConstrainedExtensionUsingBadConformance() {}
170-
}
171-
172-
public struct ConditionalGenericStruct<T> {}
173-
extension ConditionalGenericStruct: NormalProto where T: NormalProto {
174-
public typealias Assoc = Int
175-
}
176-
public func testConditionalGeneric(_: NormalProtoAssocHolder<ConditionalGenericStruct<NormalStruct>>) {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
177-
178-
public protocol PublicInferredAssociatedType {
179-
associatedtype Assoc: NormalProto
180-
func takesAssoc(_: Assoc)
181-
}
182-
@usableFromInline protocol UFIInferredAssociatedType {
183-
associatedtype Assoc: NormalProto
184-
func takesAssoc(_: Assoc)
185-
}
186-
protocol InternalInferredAssociatedType {
187-
associatedtype Assoc: NormalProto
188-
func takesAssoc(_: Assoc)
189-
}
190-
191-
public struct PublicInferredAssociatedTypeImpl {
192-
public func takesAssoc(_: NormalStruct) {}
193-
}
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
197-
198-
@usableFromInline struct UFIInferredAssociatedTypeImpl {
199-
public func takesAssoc(_: NormalStruct) {}
200-
}
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
204-
205-
struct InternalInferredAssociatedTypeImpl {
206-
public func takesAssoc(_: NormalStruct) {}
207-
}
208-
extension InternalInferredAssociatedTypeImpl: PublicInferredAssociatedType {} // okay
209-
extension InternalInferredAssociatedTypeImpl: UFIInferredAssociatedType {} // okay
210-
extension InternalInferredAssociatedTypeImpl: InternalInferredAssociatedType {} // okay
211-
212-
213-
public protocol BaseProtoWithNoRequirement {
214-
associatedtype Assoc
215-
func takesAssoc(_: Assoc)
216-
}
217-
public protocol RefinedProto: BaseProtoWithNoRequirement where Assoc: NormalProto {
218-
}
219-
220-
public struct RefinedProtoImpl: RefinedProto { // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
221-
public func takesAssoc(_: NormalStruct) {}
222-
}
223-
224-
public protocol RefinedSelfProto where Self: NormalProto {}
225-
extension NormalStruct: RefinedSelfProto {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
226-
227-
public protocol RefinedSelfProtoInheritance: NormalProto {}
228-
extension NormalStruct: RefinedSelfProtoInheritance {} // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' here; 'BADLibrary' has been imported as '@_implementationOnly'}}
229-
230-
231-
public protocol SlightlyMoreComplicatedRequirement {
232-
associatedtype Assoc: Collection where Assoc.Element: NormalProto
233-
func takesAssoc(_: Assoc)
234-
}
235-
public struct SlightlyMoreComplicatedRequirementImpl: SlightlyMoreComplicatedRequirement { // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc.Element' (inferred as 'NormalStruct'); 'BADLibrary' has been imported as '@_implementationOnly'}}
236-
public func takesAssoc(_: [NormalStruct]) {}
237-
}
238-
public struct RequirementsHandleSubclassesToo: SlightlyMoreComplicatedRequirement { // expected-error {{cannot use conformance of 'NormalClass' to 'NormalProto' in associated type 'Self.Assoc.Element' (inferred as 'SubclassOfNormalClass'); 'BADLibrary' has been imported as '@_implementationOnly'}}
239-
public func takesAssoc(_: [SubclassOfNormalClass]) {}
240-
}
241-
242-
public struct RequirementsHandleSpecializationsToo: SlightlyMoreComplicatedRequirement { // expected-error {{cannot use conformance of 'NormalStruct' to 'NormalProto' in associated type 'Self.Assoc.Element' (inferred as 'ConditionalGenericStruct<NormalStruct>'); 'BADLibrary' has been imported as '@_implementationOnly'}}
243-
public func takesAssoc(_: [ConditionalGenericStruct<NormalStruct>]) {}
244-
}
245-
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'}}
247-
public func takesAssoc(_: T) {}
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'}}
248167
}
249-
250-
251-
public protocol RecursiveRequirements {
252-
associatedtype Other: RecursiveRequirements
253-
}
254-
extension GenericStruct: RecursiveRequirements {
255-
public typealias Other = GenericStruct<T>
256-
}
257-
public struct RecursiveRequirementsHolder<T: RecursiveRequirements> {}
258-
public func makeSureRecursiveRequirementsDontBreakEverything(_: RecursiveRequirementsHolder<GenericStruct<Int>>) {}
259-
260-
261-
@inlinable func testFunctionBody() {
262-
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'}}
263170
}

0 commit comments

Comments
 (0)