Skip to content

Commit 5057f0b

Browse files
committed
[tests] add very basic test to ensure modules / interfaces for moveonly types work with library evolution
1 parent b113d4e commit 5057f0b

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
public enum SwiftCoin : ~Copyable {
2+
case penny
3+
case nickel
14

2-
public class Message { var s: String = "hello" }
3-
4-
public struct FileDescriptor : ~Copyable {
5-
public var x: Int = 0
6-
public var msg: Message = Message()
5+
init() { self = .penny }
76
}
87

9-
public class FileHandle {
10-
var file: FileDescriptor = FileDescriptor()
8+
// ensures old attribute still works.
9+
@_moveOnly public enum ObjCCoin {
10+
case penny
11+
case nickel
12+
13+
init() { self = .penny }
1114
}
1215

test/ModuleInterface/moveonly_interface.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -enable-library-evolution -module-name Hello -emit-module -o %t/Hello.swiftmodule -emit-module-interface-path %t/Hello.swiftinterface %S/Inputs/moveonly_simple.swift -swift-version 5
3+
// RUN: %FileCheck %s < %t/Hello.swiftinterface
4+
// RUN: %target-swift-frontend -emit-sil -verify -I %t %s -swift-version 5
5+
6+
import Hello
7+
8+
// CHECK: #if compiler(>=5.3) && $MoveOnly
9+
// CHECK-NEXT: public enum SwiftCoin : ~Swift.Copyable {
10+
11+
// CHECK: #if compiler(>=5.3) && $MoveOnly
12+
// CHECK-NEXT: @_moveOnly public enum ObjCCoin {
13+
14+
func eat(_ c: consuming SwiftCoin) {}
15+
func eat(_ c: consuming ObjCCoin) {}
16+
17+
public func ensureItIsNonCopyable(_ c: consuming SwiftCoin) { // expected-error {{'c' consumed more than once}}
18+
eat(c) // expected-note {{consuming use here}}
19+
eat(c) // expected-note {{consuming use here}}
20+
}
21+
22+
public func ensureItIsNonCopyable(_ c: consuming ObjCCoin) { // expected-error {{'c' consumed more than once}}
23+
eat(c) // expected-note {{consuming use here}}
24+
eat(c) // expected-note {{consuming use here}}
25+
}

0 commit comments

Comments
 (0)