Skip to content

[refactoring] Fix error when renaming nested type at constructor - init() has no declaration location #26016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -3352,7 +3352,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