Skip to content

Commit 07675a7

Browse files
committed
[refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
Resolves SR-11077
1 parent 0a22ab7 commit 07675a7

21 files changed

+208
-2
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ bool RefactoringActionLocalRename::performChange() {
784784
CursorInfoResolver Resolver(*TheFile);
785785
ResolvedCursorInfo CursorInfo = Resolver.resolve(StartLoc);
786786
if (CursorInfo.isValid() && CursorInfo.ValueD) {
787-
ValueDecl *VD = CursorInfo.ValueD;
787+
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
788788
llvm::SmallVector<DeclContext *, 8> Scopes;
789789
analyzeRenameScope(VD, DiagEngine, Scopes);
790790
if (Scopes.empty())
@@ -3352,7 +3352,7 @@ int swift::ide::findLocalRenameRanges(
33523352
Diags.diagnose(StartLoc, diag::unresolved_location);
33533353
return true;
33543354
}
3355-
ValueDecl *VD = CursorInfo.ValueD;
3355+
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
33563356
llvm::SmallVector<DeclContext *, 8> Scopes;
33573357
analyzeRenameScope(VD, Diags, Scopes);
33583358
if (Scopes.empty())

test/refactoring/rename/Outputs/basic/C1.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/E1.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/S1.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/SLocal.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/SLocal_init.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
struct S1 {}
2+
func foo1(a: S1) {}
3+
class C1 {}
4+
func foo2(c : C1) {}
5+
enum E1 {}
6+
func foo3(e : E1) {}
7+
func foo4(a : S1, b : C1, c: E1) { foo4(a: a, b: b, c :c) }
8+
9+
func test() {
10+
struct SLocal {
11+
init(x: S1) {}
12+
}
13+
func local(a: SLocal) {}
14+
local(a: SLocal(x: S1()))
15+
}
16+
17+
guard let top = Optional.some("top") else {
18+
fatalError()
19+
}
20+
print(top)
21+
22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct new_SP1: P1 {}
26+
return new_SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/foo4.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/foo4_multi.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

test/refactoring/rename/Outputs/basic/local.swift.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
1919
}
2020
print(top)
2121

22+
protocol P1 {}
23+
struct Test {
24+
var test: P1 {
25+
struct SP1: P1 {}
26+
return SP1()
27+
}
28+
}
29+

0 commit comments

Comments
 (0)