Skip to content

Commit 3ea3769

Browse files
authored
Merge pull request #38085 from fwcd/fix-wildcard-name-range
[IDE] Fix name range of wildcard declarations
2 parents d05e79d + 8a79268 commit 3ea3769

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

lib/IDE/SourceEntityWalker.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ bool SemaAnnotator::walkToDeclPre(Decl *D) {
125125
bool IsExtension = false;
126126

127127
if (auto *VD = dyn_cast<ValueDecl>(D)) {
128-
if (VD->hasName() && !VD->isImplicit()) {
128+
if (!VD->isImplicit()) {
129129
SourceManager &SM = VD->getASTContext().SourceMgr;
130-
NameLen = VD->getBaseName().userFacingName().size();
131-
if (Loc.isValid() && SM.extractText({Loc, 1}) == "`")
132-
NameLen += 2;
130+
if (VD->hasName()) {
131+
NameLen = VD->getBaseName().userFacingName().size();
132+
if (Loc.isValid() && SM.extractText({Loc, 1}) == "`")
133+
NameLen += 2;
134+
} else if (Loc.isValid() && SM.extractText({Loc, 1}) == "_") {
135+
NameLen = 1;
136+
}
133137
}
134138

135139
auto ReportParamList = [&](ParameterList *PL) {

test/SourceKit/VariableType/basic.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func foo() {
1919
var local = 5
2020
}
2121

22+
let `else` = 3
23+
2224
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
2325
// CHECK: (1:5, 1:6): Int (explicit type: 1)
2426
// CHECK: (2:5, 2:6): String (explicit type: 0)
@@ -30,3 +32,4 @@ func foo() {
3032
// CHECK: (14:7, 14:8): [Int : Int] (explicit type: 1)
3133
// CHECK: (15:7, 15:8): (Int) -> Int (explicit type: 1)
3234
// CHECK: (19:7, 19:12): Int (explicit type: 0)
35+
// CHECK: (22:5, 22:11): Int (explicit type: 0)

test/SourceKit/VariableType/params.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ let z = { (param: String) in
88
param.count
99
}
1010

11+
let w: (String, Int) -> Void = { (_, x) in }
12+
1113
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
1214
// CHECK: (1:10, 1:15): Int (explicit type: 1)
1315
// CHECK: (5:5, 5:6): (String) -> Void (explicit type: 1)
1416
// CHECK: (5:29, 5:34): String (explicit type: 0)
1517
// CHECK: (7:5, 7:6): (String) -> Int (explicit type: 0)
1618
// CHECK: (7:12, 7:17): String (explicit type: 1)
19+
// CHECK: (11:35, 11:36): String (explicit type: 0)
20+
// CHECK: (11:38, 11:39): Int (explicit type: 0)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let = 2
2+
let : Int = 4
3+
4+
let x: (String) -> Void = { (: String) in }
5+
6+
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
7+
// CHECK: <VariableTypes>
8+
// CHECK-NEXT: (4:5, 4:6): (String) -> Void (explicit type: 1)
9+
// CHECK-NEXT: </VariableTypes>
10+

0 commit comments

Comments
 (0)