Skip to content

Commit fb5516f

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

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

test/Interpreter/Inputs/type_wrapper_defs.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,14 @@ public struct PersonWithUnmanagedTest {
136136

137137
@PropWrapper public var favoredColor: String = "red"
138138
}
139+
140+
@Wrapper
141+
@available(macOS 10.15, *)
142+
public actor Actor {
143+
public var name: String
144+
@PropWrapper public var age: Int? = nil
145+
146+
public func setAge(_ newAge: Int) async {
147+
age = newAge
148+
}
149+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
let a = Actor(name: "Arhtur Dent")
20+
await print(a.name)
21+
// CHECK: in getter
22+
// CHECK-NEXT: Arhtur Dent
23+
await print(a.age)
24+
// CHECK: in getter
25+
// CHECK-NEXT: nil
26+
27+
await a.setAge(30)
28+
// CHECK: in getter
29+
// CHECK-NEXT: in setter => PropWrapper<Optional<Int>>(value: Optional(30))
30+
31+
await print(a.age)
32+
// CHECK: in getter
33+
// 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)