Skip to content

Commit 2d83c52

Browse files
committed
[NoncopyableGenerics] more regression testing
1 parent bbb14ad commit 2d83c52

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NoncopyableGenerics
2+
3+
// REQUIRES: asserts
4+
5+
public struct Cond<T: ~Copyable>: ~Copyable {}
6+
extension Cond: Copyable where T: Copyable {} // expected-note {{requirement from conditional conformance}}
7+
8+
public typealias AlwaysCopyable<T> = Cond<T>
9+
public typealias CondAlias<T> = Cond<T> where T: ~Copyable
10+
11+
func checkCopyable<T>(_ t: T) {}
12+
13+
func test<C, NC: ~Copyable>(_ a: Cond<C>, _ b: borrowing Cond<NC>) {
14+
checkCopyable(a)
15+
checkCopyable(b) // expected-error {{global function 'checkCopyable' requires that 'NC' conform to 'Copyable'}}
16+
}
17+
18+
// FIXME: we should expect a warning/error that NC actually did require Copyable
19+
// despite the annotation due to the implied requirement!
20+
func checkAliases<C, NC: ~Copyable>(_ a: AlwaysCopyable<C>, _ b: AlwaysCopyable<NC>) {
21+
checkCopyable(a)
22+
checkCopyable(b)
23+
}
24+
25+
protocol Removed: ~Copyable {
26+
func requiresCopyableSelf(_ t: AlwaysCopyable<Self>)
27+
// expected-error@-1 {{type 'Self' does not conform to protocol 'Copyable'}}
28+
}
29+
protocol Plain {
30+
func requiresCopyableSelf(_ t: AlwaysCopyable<Self>)
31+
}

test/Generics/inverse_copyable_requirement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,15 @@ struct GenerousGuy: Gives { // expected-error {{type 'GenerousGuy' does not conf
279279
func give() -> Ty {}
280280
}
281281

282-
func doBadMetatypeStuff<T>(_ t: T) { // expected-note@:25 {{generic parameter 'T' has an implicit Copyable requirement}}
282+
func doBadMetatypeStuff<T>(_ t: T) {
283283
let y = t as! Any.Type
284284
if let MO_MetaType = y as? MO.Type { // expected-warning {{cast from 'any Any.Type' to unrelated type 'MO.Type' always fails}}
285285
let x = MO_MetaType.init()
286286
let _ = x
287287
}
288288
}
289289
func tryToDoBadMetatypeStuff() {
290-
doBadMetatypeStuff(MO.self) // expected-error {{metatype 'MO.Type' of noncopyable type 'MO' cannot be substituted for copyable generic parameter 'T' in 'doBadMetatypeStuff'}}
290+
doBadMetatypeStuff(MO.self)
291291
}
292292

293293
func packingHeat<each T>(_ t: repeat each T) {} // expected-note {{generic parameter 'each T' has an implicit Copyable requirement}}

test/Generics/inverse_signatures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -enable-experimental-feature NoncopyableGenerics -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -enable-experimental-feature NoncopyableGenerics -verify -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s --implicit-check-not "error:"
22

33
// REQUIRES: asserts
44

@@ -8,7 +8,7 @@ func genericFn<T>(_ t: T) {}
88

99
// CHECK-LABEL: .withInverse@
1010
// CHECK: Generic signature: <T>
11-
func withInverse<T: ~Copyable>(_ t: T) {}
11+
func withInverse<T: ~Copyable>(_ t: borrowing T) {}
1212

1313
// CHECK-LABEL: .S1@
1414
// CHECK: Generic signature: <T where T : Copyable>

0 commit comments

Comments
 (0)