Skip to content

Commit

Permalink
Merge pull request swiftlang#26016 from cltnschlosser/SR-11077-inner-…
Browse files Browse the repository at this point in the history
…rename-nested-type

[refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
  • Loading branch information
Nathan Hawes authored Jul 12, 2019
2 parents 75a5496 + 07675a7 commit 3065843
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/IDE/Refactoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ bool RefactoringActionLocalRename::performChange() {
CursorInfoResolver Resolver(*TheFile);
ResolvedCursorInfo CursorInfo = Resolver.resolve(StartLoc);
if (CursorInfo.isValid() && CursorInfo.ValueD) {
ValueDecl *VD = CursorInfo.ValueD;
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
llvm::SmallVector<DeclContext *, 8> Scopes;
analyzeRenameScope(VD, DiagEngine, Scopes);
if (Scopes.empty())
Expand Down Expand Up @@ -3526,7 +3526,7 @@ int swift::ide::findLocalRenameRanges(
Diags.diagnose(StartLoc, diag::unresolved_location);
return true;
}
ValueDecl *VD = CursorInfo.ValueD;
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
llvm::SmallVector<DeclContext *, 8> Scopes;
analyzeRenameScope(VD, Diags, Scopes);
if (Scopes.empty())
Expand Down
8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/C1.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/E1.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/S1.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/SLocal.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

29 changes: 29 additions & 0 deletions test/refactoring/rename/Outputs/basic/SP1.swift.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
struct S1 {}
func foo1(a: S1) {}
class C1 {}
func foo2(c : C1) {}
enum E1 {}
func foo3(e : E1) {}
func foo4(a : S1, b : C1, c: E1) { foo4(a: a, b: b, c :c) }

func test() {
struct SLocal {
init(x: S1) {}
}
func local(a: SLocal) {}
local(a: SLocal(x: S1()))
}

guard let top = Optional.some("top") else {
fatalError()
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct new_SP1: P1 {}
return new_SP1()
}
}

8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/foo4.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

8 changes: 8 additions & 0 deletions test/refactoring/rename/Outputs/basic/local.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let bottom = Optional.some("top") else {
}
print(bottom)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

29 changes: 29 additions & 0 deletions test/refactoring/rename/Outputs/basic_ranges/SP1.swift.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
struct S1 {}
func foo1(a: S1) {}
class C1 {}
func foo2(c : C1) {}
enum E1 {}
func foo3(e : E1) {}
func foo4(a : S1, b : C1, c: E1) { foo4(a: a, b: b, c :c) }

func test() {
struct SLocal {
init(x: S1) {}
}
func local(a: SLocal) {}
local(a: SLocal(x: S1()))
}

guard let top = Optional.some("top") else {
fatalError()
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct <base>SP1</base>: P1 {}
return <base>SP1</base>()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ guard let <base>top</base> = Optional.some("top") else {
}
print(<base>top</base>)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

12 changes: 12 additions & 0 deletions test/refactoring/rename/basic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ guard let top = Optional.some("top") else {
}
print(top)

protocol P1 {}
struct Test {
var test: P1 {
struct SP1: P1 {}
return SP1()
}
}

// RUN: %empty-directory(%t.result)
// RUN: %refactor -rename -source-filename %s -pos=2:15 -new-name new_S1 >> %t.result/S1.swift
// RUN: diff -u %S/Outputs/basic/S1.swift.expected %t.result/S1.swift
Expand Down Expand Up @@ -46,6 +54,8 @@ print(top)
// RUN: diff -u %S/Outputs/basic/local.swift.expected %t.result/local.swift
// RUN: %refactor -rename -source-filename %s -pos=20:7 -new-name 'bottom' > %t.result/top_level.swift
// RUN: diff -u %S/Outputs/basic/top_level.swift.expected %t.result/top_level.swift
// RUN: %refactor -rename -source-filename %s -pos=26:12 -new-name new_SP1 > %t.result/SP1.swift
// RUN: diff -u %S/Outputs/basic/SP1.swift.expected %t.result/SP1.swift
// RUN: %empty-directory(%t.ranges)
// RUN: %refactor -find-local-rename-ranges -source-filename %s -pos=2:15 > %t.ranges/S1.swift
// RUN: diff -u %S/Outputs/basic_ranges/S1.swift.expected %t.ranges/S1.swift
Expand All @@ -71,3 +81,5 @@ print(top)
// RUN: diff -u %S/Outputs/basic_ranges/local.swift.expected %t.ranges/local.swift
// RUN: %refactor -find-local-rename-ranges -source-filename %s -pos=20:7 > %t.result/top_level.swift
// RUN: diff -u %S/Outputs/basic_ranges/top_level.swift.expected %t.result/top_level.swift
// RUN: %refactor -find-local-rename-ranges -source-filename %s -pos=26:12 > %t.result/SP1.swift
// RUN: diff -u %S/Outputs/basic_ranges/SP1.swift.expected %t.result/SP1.swift

0 comments on commit 3065843

Please sign in to comment.