Skip to content

Commit f0d2d35

Browse files
authored
Merge pull request #3229 from ahoppen/SR-1827-change-syntax
Make #selector a primary expression
2 parents 67874ad + 884af9c commit f0d2d35

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
480480
/// expr-postfix(Mode)
481481
/// operator-prefix expr-unary(Mode)
482482
/// '&' expr-unary(Mode)
483-
/// expr-selector
484483
///
485484
ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
486485
UnresolvedDeclRefExpr *Operator;
@@ -504,9 +503,6 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
504503
case tok::pound_keyPath:
505504
return parseExprKeyPath();
506505

507-
case tok::pound_selector:
508-
return parseExprSelector();
509-
510506
case tok::oper_postfix:
511507
// Postfix operators cannot start a subexpression, but can happen
512508
// syntactically because the operator may just follow whatever precedes this
@@ -1030,6 +1026,7 @@ getMagicIdentifierLiteralKind(tok Kind) {
10301026
/// expr-paren
10311027
/// expr-super
10321028
/// expr-discard
1029+
/// expr-selector
10331030
///
10341031
/// expr-delayed-identifier:
10351032
/// '.' identifier
@@ -1191,6 +1188,10 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
11911188
new (Context) DiscardAssignmentExpr(consumeToken(), /*Implicit=*/false));
11921189
break;
11931190

1191+
case tok::pound_selector: // expr-selector
1192+
Result = parseExprSelector();
1193+
break;
1194+
11941195
case tok::l_brace: // expr-closure
11951196
Result = parseExprClosure();
11961197
break;

test/Inputs/clang-importer-sdk/swift-modules/ObjectiveC.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public struct Selector : StringLiteralConvertible {
6363
}
6464
}
6565

66+
extension Selector : Equatable {}
67+
68+
public func ==(lhs: Selector, rhs: Selector) -> Bool {
69+
return sel_isEqual(lhs, rhs)
70+
}
71+
6672
public struct NSZone {
6773
public var pointer : OpaquePointer
6874
}

test/Inputs/clang-importer-sdk/usr/include/objc/objc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef __typeof__(__objc_yes) BOOL;
1616

1717
typedef struct objc_selector *SEL;
1818
SEL sel_registerName(const char *str);
19+
BOOL sel_isEqual(SEL sel1, SEL sel2);
1920

2021
void NSDeallocateObject(id object) NS_AUTOMATED_REFCOUNT_UNAVAILABLE;
2122

test/expr/unary/selector/selector.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ func testParseErrors4() {
111111
// Subscripts
112112
_ = #selector(C1.subscript) // expected-error{{type 'C1.Type' has no subscript members}}
113113
}
114+
115+
// SR-1827
116+
117+
let optionalSel: Selector? = nil
118+
119+
switch optionalSel {
120+
case #selector(C1.method1)?:
121+
break
122+
}

0 commit comments

Comments
 (0)