Skip to content

Commit 3687d07

Browse files
committed
Minor edits.
- Parse "call" as identifier in patterns and enum case names. Add tests. - Disallow `@warn_unqualified_access` on `call` declarations. - Update failing attribute tests.
1 parent efc864d commit 3687d07

File tree

8 files changed

+25
-8
lines changed

8 files changed

+25
-8
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(indirect, Indirect, DeclModifier |
309309
OnEnum | OnEnumElement,
310310
60)
311311
SIMPLE_DECL_ATTR(warn_unqualified_access, WarnUnqualifiedAccess,
312-
OnFunc | OnAccessor | OnCall | /*OnVar |*/
312+
OnFunc | OnAccessor | /*OnVar |*/
313313
LongAttribute,
314314
61)
315315
SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5930,7 +5930,7 @@ Parser::parseDeclEnumCase(ParseDeclOptions Flags,
59305930
return Status;
59315931
}
59325932

5933-
if (Tok.is(tok::identifier)) {
5933+
if (Tok.is(tok::identifier) || Tok.is(tok::kw_call)) {
59345934
Status |= parseIdentifierDeclName(*this, Name, NameLoc, "enum 'case'",
59355935
tok::l_paren, tok::kw_case, tok::colon,
59365936
tok::r_brace);

lib/Parse/ParsePattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ ParserResult<Pattern> Parser::parsePattern() {
921921
PatternCtx.setCreateSyntax(SyntaxKind::WildcardPattern);
922922
return makeParserResult(new (Context) AnyPattern(consumeToken(tok::kw__)));
923923

924-
case tok::identifier: {
924+
case tok::identifier:
925+
case tok::kw_call: {
925926
PatternCtx.setCreateSyntax(SyntaxKind::IdentifierPattern);
926927
Identifier name;
927928
SourceLoc loc = consumeIdentifier(&name);

lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ bool Parser::parseSpecificIdentifier(StringRef expected, SourceLoc &loc,
864864
/// its name in Result. Otherwise, emit an error and return true.
865865
bool Parser::parseAnyIdentifier(Identifier &Result, SourceLoc &Loc,
866866
const Diagnostic &D) {
867-
if (Tok.is(tok::identifier) || Tok.isAnyOperator()) {
867+
if (Tok.is(tok::identifier) || Tok.isAnyOperator() || Tok.is(tok::kw_call)) {
868868
Result = Context.getIdentifier(Tok.getText());
869869
Loc = Tok.getLoc();
870870
consumeToken();

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ void TypeChecker::checkDeclAttributesEarly(Decl *D) {
690690
StringRef OnlyKind;
691691
switch (PossibleDeclKinds) {
692692
case DeclAttribute::OnAccessor: OnlyKind = "accessor"; break;
693+
case DeclAttribute::OnCall: OnlyKind = "call"; break;
693694
case DeclAttribute::OnClass: OnlyKind = "class"; break;
694695
case DeclAttribute::OnConstructor: OnlyKind = "init"; break;
695696
case DeclAttribute::OnDestructor: OnlyKind = "deinit"; break;

test/Parse/call_decl.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ struct SimpleCallable {
66
}
77
}
88

9+
// Test source compatibility with existing usages of "call" as an identifier.
10+
11+
struct CallFuncMember {
12+
func call() {}
13+
}
14+
struct CallVarMember {
15+
var call: Int
16+
}
17+
enum CallCase {
18+
case call(call: Int)
19+
}
20+
protocol CallRequirement {
21+
func call()
22+
}
23+
924
struct NoRedefinitionErrors {
1025
call(_ x: Int) -> Int {
1126
return x

test/Sema/immutability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class FooClass {
5959
self = FooClass() // expected-error {{cannot assign to value: 'self' is immutable}}
6060
}
6161

62-
mutating init(a : Bool) {} // expected-error {{'mutating' may only be used on 'func' declarations}} {{3-12=}}
62+
mutating init(a : Bool) {} // expected-error {{'mutating' modifier cannot be applied to this declaration}} {{3-12=}}
6363

6464
mutating // expected-error {{'mutating' isn't valid on methods in classes or class-bound protocols}} {{3-12=}}
6565
func baz() {}

test/attr/attr_cdecl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func emptyName(x: Int) -> Int { return x }
88
@_cdecl("noBody")
99
func noBody(x: Int) -> Int // expected-error{{expected '{' in body of function}}
1010

11-
@_cdecl("property") // expected-error{{may only be used on 'func' declarations}}
11+
@_cdecl("property") // expected-error{{cannot be applied to this declaration}}
1212
var property: Int
1313

1414
var computed: Int {
@@ -40,10 +40,10 @@ class Foo {
4040
@_cdecl("Foo_foo_2") // expected-error{{can only be applied to global functions}}
4141
static func foo(x: Int) -> Int { return x }
4242

43-
@_cdecl("Foo_init") // expected-error{{may only be used on 'func'}}
43+
@_cdecl("Foo_init") // expected-error{{cannot be applied to this declaration}}
4444
init() {}
4545

46-
@_cdecl("Foo_deinit") // expected-error{{may only be used on 'func'}}
46+
@_cdecl("Foo_deinit") // expected-error{{cannot be applied to this declaration}}
4747
deinit {}
4848
}
4949

0 commit comments

Comments
 (0)