Skip to content

Commit e36e316

Browse files
authored
Add diagnostic test for @Observable macro (#67250)
This adds a diagnostic test that validates errors for putting the `@Observable` macro on a struct, enum, or actor.
1 parent 1cf3b64 commit e36e316

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: swift_swift_parser
2+
3+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -parse-as-library -enable-experimental-feature InitAccessors -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -plugin-path %swift-host-lib-dir/plugins
4+
5+
// Asserts is required for '-enable-experimental-feature InitAccessors'.
6+
// REQUIRES: asserts
7+
8+
// REQUIRES: observation
9+
// REQUIRES: concurrency
10+
// REQUIRES: objc_interop
11+
// UNSUPPORTED: use_os_stdlib
12+
// UNSUPPORTED: back_deployment_runtime
13+
14+
import Observation
15+
16+
@Observable // expected-error {{'@Observable' cannot be applied to actor type 'MyActor'}}
17+
actor MyActor {}
18+
19+
@Observable // expected-error {{'@Observable' cannot be applied to enumeration type 'MyEnum'}}
20+
enum MyEnum {
21+
case myCase // required for macro invocation
22+
}
23+
24+
@Observable // expected-error {{'@Observable' cannot be applied to struct type 'MyStruct'}}
25+
struct MyStruct {}

0 commit comments

Comments
 (0)