Skip to content

Commit ce63aa6

Browse files
authored
Merge pull request swiftlang#37516 from xedin/rdar-75753598
[Parse] Disallow use of `actor` as a declaration modifier
2 parents 814ede0 + aeddab4 commit ce63aa6

File tree

5 files changed

+16
-51
lines changed

5 files changed

+16
-51
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,41 +3588,25 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
35883588
// that scope, so we have to store enough state to emit the diagnostics
35893589
// outside of the scope.
35903590
bool isActorModifier = false;
3591-
bool isClassNext = false;
35923591
SourceLoc actorLoc = Tok.getLoc();
3593-
SourceLoc classLoc;
3592+
35943593
{
35953594
BacktrackingScope Scope(*this);
35963595

3597-
// Is this the class token before the identifier?
3598-
auto atClassDecl = [this]() -> bool {
3599-
return peekToken().is(tok::identifier) ||
3600-
Tok.is(tok::kw_class) ||
3601-
Tok.is(tok::kw_enum) ||
3602-
Tok.is(tok::kw_struct);
3603-
};
36043596
consumeToken(); // consume actor
36053597
isActorModifier = isStartOfSwiftDecl();
3606-
if (isActorModifier) {
3607-
isClassNext = atClassDecl();
3608-
while (!atClassDecl())
3609-
consumeToken();
3610-
classLoc = Tok.getLoc();
3611-
}
36123598
}
36133599

36143600
if (!isActorModifier)
36153601
break;
36163602

3617-
auto diag = diagnose(actorLoc,
3618-
diag::renamed_platform_condition_argument, "actor class", "actor");
3619-
if (isClassNext)
3620-
diag.fixItRemove(classLoc);
3621-
else
3622-
diag.fixItReplace(classLoc, "actor")
3623-
.fixItRemove(actorLoc);
3624-
Attributes.add(new (Context) ActorAttr({}, Tok.getLoc()));
3625-
consumeToken();
3603+
// Actor is a standalone keyword now, so it can't be used
3604+
// as a modifier. Let's diagnose and recover.
3605+
isError = true;
3606+
3607+
consumeToken(); // consume 'actor'
3608+
3609+
diagnose(actorLoc, diag::keyword_cant_be_identifier, Tok.getText());
36263610
continue;
36273611
}
36283612

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ bool IsActorRequest::evaluate(
111111
if (!classDecl)
112112
return false;
113113

114-
return classDecl->isExplicitActor() ||
115-
classDecl->getAttrs().getAttribute<ActorAttr>();
114+
return classDecl->isExplicitActor();
116115
}
117116

118117
bool IsDefaultActorRequest::evaluate(

test/SourceKit/CursorInfo/cursor_info_concurrency.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ func test(act: MyActor) async throws {
77
try await act.asyncFunc {}
88
}
99

10-
public actor class MyActorClass {
11-
public func asyncFunc(fn: () async -> Void) async throws {}
12-
}
13-
14-
func test(act: MyActorClass) async throws {
15-
try await act.asyncFunc {}
16-
}
17-
1810
// BEGIN App.swift
1911
import MyModule
2012

@@ -35,15 +27,9 @@ func test(act: MyActor) async throws {
3527
// RUN: %sourcekitd-test -req=cursor -pos=5:16 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=ACTOR %s
3628
// RUN: %sourcekitd-test -req=cursor -pos=6:19 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=FUNC %s
3729

38-
// RUN: %sourcekitd-test -req=cursor -pos=9:20 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=CLASSACTOR %s
39-
// RUN: %sourcekitd-test -req=cursor -pos=13:16 %t/MyModule.swift -- %t/MyModule.swift -target %target-triple -Xfrontend -enable-experimental-concurrency | %FileCheck -check-prefix=CLASSACTOR %s
40-
4130
// ACTOR: <Declaration>public actor MyActor</Declaration>
4231
// ACTOR: <decl.class><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>actor</syntaxtype.keyword> <decl.name>MyActor</decl.name></decl.class>
4332

44-
// CLASSACTOR: <Declaration>public actor class MyActorClass</Declaration>
45-
// CLASSACTOR: <decl.class><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>actor</syntaxtype.keyword> <syntaxtype.keyword>class</syntaxtype.keyword> <decl.name>MyActorClass</decl.name></decl.class>
46-
4733
// FUNC: <Declaration>public func asyncFunc(fn: () async -&gt; <Type usr="s:s4Voida">Void</Type>) async throws</Declaration>
4834
// FUNC: <decl.function.method.instance><syntaxtype.keyword>public</syntaxtype.keyword> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>asyncFunc</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>fn</decl.var.parameter.argument_label>: <decl.var.parameter.type>() <syntaxtype.keyword>async</syntaxtype.keyword> -&gt; <decl.function.returntype><ref.typealias usr="s:s4Voida">Void</ref.typealias></decl.function.returntype></decl.var.parameter.type></decl.var.parameter>) <syntaxtype.keyword>async</syntaxtype.keyword> <syntaxtype.keyword>throws</syntaxtype.keyword></decl.function.method.instance>
4935

test/attr/attr_objc_async.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ actor MyActor {
4747
@objc nonisolated func synchronousGood() { }
4848
}
4949

50-
// CHECK: actor class MyActor2
5150
actor class MyActor2 { }
52-
// expected-warning@-1{{'actor class' has been renamed to 'actor'}}{{7-13=}}
51+
// expected-error@-1 {{keyword 'class' cannot be used as an identifier here}}
5352

5453
// CHECK: @objc actor MyObjCActor
5554
@objc actor MyObjCActor: NSObject { }
5655

57-
// CHECK: @objc actor class MyObjCActor2
5856
@objc actor class MyObjCActor2: NSObject {}
59-
// expected-warning@-1{{'actor class' has been renamed to 'actor'}}{{13-19=}}
57+
// expected-error@-1 {{keyword 'class' cannot be used as an identifier here}}

test/decl/class/actor/basic.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ class MyActorSubclass1: MyActor { } // expected-error{{actor types do not suppor
99

1010
actor MyActorSubclass2: MyActor { } // expected-error{{actor types do not support inheritance}}
1111

12-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{7-13=}}
12+
// expected-error@+1{{keyword 'class' cannot be used as an identifier here}}
1313
actor class MyActorClass { }
1414

1515
class NonActor { }
1616

1717
actor NonActorSubclass : NonActor { } // expected-error{{actor types do not support inheritance}}
1818

19-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{14-20=}}
19+
// expected-error@+1{{keyword 'class' cannot be used as an identifier here}}
2020
public actor class BobHope {}
21-
// expected-warning@+1{{'actor class' has been renamed to 'actor'}}{{14-19=actor}}{{1-7=}}
21+
// expected-error@+1{{keyword 'public' cannot be used as an identifier here}}
2222
actor public class BarbraStreisand {}
23-
// expected-warning@+2{{'actor class' has been renamed to 'actor'}}{{14-21=}}
24-
// expected-error@+1{{'actor' may only be used on 'class' declarations}}
23+
// expected-error@+1{{keyword 'struct' cannot be used as an identifier here}}
2524
public actor struct JulieAndrews {}
26-
// expected-warning@+2{{'actor class' has been renamed to 'actor'}}{{14-18=actor}}{{1-7=}}
27-
// expected-error@+1{{'actor' may only be used on 'class' declarations}}
25+
// expected-error@+1{{keyword 'public' cannot be used as an identifier here}}
2826
actor public enum TomHanks {}

0 commit comments

Comments
 (0)