Skip to content

Commit cd83896

Browse files
committed
Index objcdynamic
1 parent 4841731 commit cd83896

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

include/swift/AST/ASTWalker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum class SemaReferenceKind : uint8_t {
3737
TypeRef,
3838
EnumElementRef,
3939
SubscriptRef,
40+
DynamicMemberRef,
4041
};
4142

4243
struct ReferenceMetaData {

lib/IDE/SourceEntityWalker.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
511511

512512
return doSkipChildren();
513513
}
514+
} else if (auto DMRE = dyn_cast<DynamicMemberRefExpr>(E)) {
515+
if (!passReference(DMRE->getMember().getDecl(), DMRE->getType(),
516+
DMRE->getNameLoc(),
517+
ReferenceMetaData(SemaReferenceKind::DynamicMemberRef,
518+
OpAccess)))
519+
return stopTraversal;
514520
}
515521

516522
return { true, E };
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %target-swift-ide-test -print-indexed-symbols -source-filename %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc protocol AProtocol {
7+
@objc optional func dynamicMethod()
8+
// CHECK: [[@LINE-1]]:25 | instance-method/Swift | dynamicMethod() | [[DynamicMethod_USR:.*]] | Def
9+
@objc optional var property: String { get }
10+
// CHECK: [[@LINE-1]]:24 | instance-property/Swift | property | [[DynamicProperty_USR:.*]] | Def
11+
}
12+
13+
class AClass {
14+
15+
weak var objcDelegate: AProtocol?
16+
// CHECK: [[@LINE-1]]:14 | instance-property/Swift | objcDelegate | [[Delegate_USR:.*]] | Def
17+
18+
func doSomething() {
19+
objcDelegate?.dynamicMethod?()
20+
// CHECK: [[@LINE-1]]:23 | instance-method/Swift | dynamicMethod() | [[DynamicMethod_USR]] | Ref
21+
// CHECK: [[@LINE-2]]:9 | instance-property/Swift | objcDelegate | [[Delegate_USR]] | Ref
22+
_ = objcDelegate?.property
23+
// CHECK: [[@LINE-1]]:27 | instance-property/Swift | property | [[DynamicProperty_USR]] | Ref
24+
// CHECK: [[@LINE-2]]:13 | instance-property/Swift | objcDelegate | [[Delegate_USR]] | Ref
25+
}
26+
}

0 commit comments

Comments
 (0)