File tree Expand file tree Collapse file tree 4 files changed +38
-18
lines changed
test/SourceKit/CursorInfo Expand file tree Collapse file tree 4 files changed +38
-18
lines changed Original file line number Diff line number Diff line change @@ -552,6 +552,10 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
552
552
// / \c nullptr.
553
553
ArgumentList *getArgs () const ;
554
554
555
+ // / If the expression has a DeclNameLoc, returns it. Otherwise, returns
556
+ // / an nullp DeclNameLoc.
557
+ DeclNameLoc getNameLoc () const ;
558
+
555
559
// / Produce a mapping from each subexpression to its parent
556
560
// / expression, with the provided expression serving as the root of
557
561
// / the parent map.
Original file line number Diff line number Diff line change @@ -874,6 +874,25 @@ ArgumentList *Expr::getArgs() const {
874
874
return nullptr ;
875
875
}
876
876
877
+ DeclNameLoc Expr::getNameLoc () const {
878
+ if (auto *DRE = dyn_cast<DeclRefExpr>(this ))
879
+ return DRE->getNameLoc ();
880
+ if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(this ))
881
+ return UDRE->getNameLoc ();
882
+ if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(this ))
883
+ return ODRE->getNameLoc ();
884
+ if (auto *UDE = dyn_cast<UnresolvedDotExpr>(this ))
885
+ return UDE->getNameLoc ();
886
+ if (auto *UME = dyn_cast<UnresolvedMemberExpr>(this ))
887
+ return UME->getNameLoc ();
888
+ if (auto *MRE = dyn_cast<MemberRefExpr>(this ))
889
+ return MRE->getNameLoc ();
890
+ if (auto *DRME = dyn_cast<DynamicMemberRefExpr>(this ))
891
+ return DRME->getNameLoc ();
892
+
893
+ return DeclNameLoc ();
894
+ }
895
+
877
896
llvm::DenseMap<Expr *, Expr *> Expr::getParentMap () {
878
897
class RecordingTraversal : public ASTWalker {
879
898
public:
Original file line number Diff line number Diff line change @@ -214,23 +214,6 @@ class NodeFinder : ASTWalker {
214
214
return Action::Continue ();
215
215
}
216
216
217
- // / Retrieve the name location for an expression that supports cursor info.
218
- DeclNameLoc getExprNameLoc (Expr *E) {
219
- if (auto *DRE = dyn_cast<DeclRefExpr>(E))
220
- return DRE->getNameLoc ();
221
-
222
- if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(E))
223
- return UDRE->getNameLoc ();
224
-
225
- if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(E))
226
- return ODRE->getNameLoc ();
227
-
228
- if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E))
229
- return UDE->getNameLoc ();
230
-
231
- return DeclNameLoc ();
232
- }
233
-
234
217
PreWalkResult<Expr *> walkToExprPre (Expr *E) override {
235
218
if (auto closure = dyn_cast<ClosureExpr>(E)) {
236
219
DeclContextStack.push_back (closure);
@@ -247,7 +230,7 @@ class NodeFinder : ASTWalker {
247
230
}
248
231
}
249
232
250
- if (getExprNameLoc (E ).getBaseNameLoc () != LocToResolve)
233
+ if (E-> getNameLoc ( ).getBaseNameLoc () != LocToResolve)
251
234
return Action::Continue (E);
252
235
253
236
assert (Result == nullptr );
Original file line number Diff line number Diff line change
1
+ struct S {
2
+ static func foo( _ x: Int ) -> S { }
3
+ static func foo( _ x: String ) -> S { }
4
+ }
5
+
6
+ // https://github.com/swiftlang/swift/issues/77981 - Make sure we can resolve
7
+ // solver-based cursor info for UnresolvedMemberExprs.
8
+ func bar( ) {
9
+ // RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):15 %s -- %s | %FileCheck %s
10
+ let _: S = . foo( )
11
+ }
12
+
13
+ // CHECK-DAG: source.lang.swift.ref.function.method.static (2:15-2:28)
14
+ // CHECK-DAG: source.lang.swift.ref.function.method.static (3:15-3:31)
You can’t perform that action at this time.
0 commit comments