Skip to content

Commit ad25221

Browse files
committed
[Tests] TypeWrappers: Add test-cases to cover applying type wrapper to an actor
1 parent f7b366c commit ad25221

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -enable-experimental-feature TypeWrappers -parse-as-library -emit-library -emit-module-path %t/type_wrapper_defs.swiftmodule -module-name type_wrapper_defs %S/Inputs/type_wrapper_defs.swift -o %t/%target-library-name(type_wrapper_defs)
3+
// RUN: %target-build-swift -target %target-cpu-apple-macosx10.15 -ltype_wrapper_defs -module-name main -I %t -L %t %s -o %t/main %target-rpath(%t)
4+
// RUN: %target-codesign %t/main
5+
// RUN: %target-run %t/main %t/%target-library-name(type_wrapper_defs) | %FileCheck %s
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: asserts
9+
// REQUIRES: concurrency
10+
11+
// rdar://76038845
12+
// REQUIRES: concurrency_runtime
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// REQUIRES: OS=macosx
16+
17+
import type_wrapper_defs
18+
19+
@Wrapper
20+
public actor Actor {
21+
public var name: String
22+
@PropWrapper public var age: Int? = nil
23+
24+
public func setAge(_ newAge: Int) async {
25+
age = newAge
26+
}
27+
}
28+
29+
let a = Actor(name: "Arhtur Dent")
30+
await print(a.name)
31+
// CHECK: in getter
32+
// CHECK-NEXT: Arhtur Dent
33+
await print(a.age)
34+
// CHECK: in getter
35+
// CHECK-NEXT: nil
36+
37+
await a.setAge(30)
38+
// CHECK: in getter
39+
// CHECK-NEXT: in setter => PropWrapper<Optional<Int>>(value: Optional(30))
40+
41+
await print(a.age)
42+
// CHECK: in getter
43+
// CHECK-NEXT: 30

test/type/type_wrapper.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature TypeWrappers
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature TypeWrappers
22

33
// REQUIRES: asserts
44

@@ -380,3 +380,21 @@ func testDeclarationsWithUnmanagedProperties() {
380380

381381
_ = OnlyLazyLetAndComputed(name: "Arthur Dent") // Ok
382382
}
383+
384+
func testActors() async {
385+
@NoopWrapper
386+
actor Person {
387+
var name: String
388+
// expected-note@-1 {{mutation of this property is only permitted within the actor}}
389+
var age: Int
390+
// expected-note@-1 {{mutation of this property is only permitted within the actor}}
391+
}
392+
393+
let person = Person(name: "Arthur Dent", age: 30)
394+
395+
_ = await person.name
396+
_ = await person.age
397+
398+
person.name = "NoName" // expected-error {{actor-isolated property 'name' can not be mutated from a non-isolated context}}
399+
person.age = 0 // expected-error {{actor-isolated property 'age' can not be mutated from a non-isolated context}}
400+
}

0 commit comments

Comments
 (0)