Skip to content

Commit eeabaae

Browse files
committed
[AST/Sema] Allow @execution(...) attribute to be used on initializers and accessors
1 parent 9826e27 commit eeabaae

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ DECL_ATTR(abi, ABI,
862862
DECL_ATTR_FEATURE_REQUIREMENT(ABI, ABIAttribute)
863863

864864
DECL_ATTR(execution, Execution,
865-
OnFunc,
865+
OnAbstractFunction,
866866
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
867867
166)
868868
DECL_ATTR_FEATURE_REQUIREMENT(Execution, ExecutionAttribute)

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
257257

258258
public:
259259
void visitExecutionAttr(ExecutionAttr *attr) {
260-
auto *F = dyn_cast<FuncDecl>(D);
260+
auto *F = dyn_cast<AbstractFunctionDecl>(D);
261261
if (!F)
262262
return;
263263

test/IDE/complete_decl_attribute_feature_requirement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct _S {
6363
@#^ON_INIT^# init()
6464
// ON_INIT: Begin completions
6565
// ON_INIT_ENABLED-DAG: Keyword/None: abi[#Constructor Attribute#]; name=abi
66-
// ON_INIT_ENABLED-NOT: Keyword/None: execution[#{{.*}} Attribute#]; name=execution
66+
// ON_INIT_ENABLED-DAG: Keyword/None: execution[#{{.*}} Attribute#]; name=execution
6767
// ON_INIT_DISABLED-NOT: Keyword/None: abi[#{{.*}} Attribute#]; name=abi
6868
// ON_INIT_DISABLED-NOT: Keyword/None: execution[#{{.*}} Attribute#]; name=execution
6969
// ON_INIT: End completions

test/attr/attr_execution.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@
1818

1919
struct Test {
2020
@execution(concurrent) init() {}
21-
// expected-error@-1 {{@execution(concurrent) may only be used on 'func' declarations}}
21+
// expected-error@-1 {{cannot use '@execution' on non-async initializer 'init()'}}
2222

2323
@execution(concurrent) func member() {}
2424
// expected-error@-1 {{cannot use '@execution' on non-async instance method 'member()'}}
2525

2626
@execution(concurrent) func member() async {} // Ok
2727

28-
// expected-error@+1 {{@execution(caller) may only be used on 'func' declarations}}
28+
// expected-error@+1 {{'@execution(caller)' attribute cannot be applied to this declaration}}
2929
@execution(caller) subscript(a: Int) -> Bool {
3030
get { false }
3131
@execution(concurrent) set { }
32-
// expected-error@-1 {{@execution(concurrent) may only be used on 'func' declarations}}
32+
// expected-error@-1 {{cannot use '@execution' on non-async setter for subscript 'subscript(_:)'}}
3333
}
3434

3535
@execution(caller) var x: Int
36-
// expected-error@-1 {{@execution(caller) may only be used on 'func' declarations}}
36+
// expected-error@-1 {{'@execution(caller)' attribute cannot be applied to this declaration}}
3737
}
3838

3939
do {
@@ -93,3 +93,21 @@ _ = { @execution(concurrent) () -> Int in
9393
_ = { @execution(caller) (x: isolated (any Actor)?) in
9494
// expected-error@-1 {{cannot use '@execution' together with an isolated parameter}}
9595
}
96+
97+
struct TestDifferentPositions {
98+
@execution(caller)
99+
init() async {
100+
}
101+
102+
var x: Int {
103+
@execution(concurrent)
104+
get async {
105+
}
106+
}
107+
108+
subscript(x: Int) -> Bool {
109+
@execution(concurrent)
110+
get async {
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)