Skip to content

Commit c9c95f9

Browse files
adonovangopherbot
authored andcommitted
internal/refactor/inline: improve a confusing error message
Change-Id: I31e587105ffd16dbe32436ce5a090180f5186200 Reviewed-on: https://go-review.googlesource.com/c/tools/+/554061 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent ba8672b commit c9c95f9

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

internal/refactor/inline/inline.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
485485
// check not shadowed at caller.
486486
found := caller.lookup(obj.Name) // always finds something
487487
if found.Pos().IsValid() {
488-
return nil, fmt.Errorf("cannot inline because built-in %q is shadowed in caller by a %s (line %d)",
488+
return nil, fmt.Errorf("cannot inline, because the callee refers to built-in %q, which in the caller is shadowed by a %s (declared at line %d)",
489489
obj.Name, objectKind(found),
490490
caller.Fset.PositionFor(found.Pos(), false).Line)
491491
}
@@ -505,8 +505,9 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
505505
// around the refactored signature.
506506
found := caller.lookup(obj.Name)
507507
if found != nil && !isPkgLevel(found) {
508-
return nil, fmt.Errorf("cannot inline because %q is shadowed in caller by a %s (line %d)",
509-
obj.Name, objectKind(found),
508+
return nil, fmt.Errorf("cannot inline, because the callee refers to %s %q, which in the caller is shadowed by a %s (declared at line %d)",
509+
obj.Kind, obj.Name,
510+
objectKind(found),
510511
caller.Fset.PositionFor(found.Pos(), false).Line)
511512
}
512513
} else {

internal/refactor/inline/testdata/err-shadow-builtin.txtar

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ package a
1010

1111
func _() {
1212
const nil = 1
13-
_ = f() //@ inline(re"f", re"nil.*shadowed.*by.*const .line 4")
13+
_ = f() //@ inline(re"f", re"nil.*shadowed.*by.*const.*line 4")
1414
}
1515

1616
func f() *int { return nil }
@@ -20,7 +20,7 @@ package a
2020

2121
func _() {
2222
type append int
23-
g(nil) //@ inline(re"g", re"append.*shadowed.*by.*typename .line 4")
23+
g(nil) //@ inline(re"g", re"append.*shadowed.*by.*typename.*line 4")
2424
}
2525

2626
func g(x []int) { _ = append(x, x...) }
@@ -30,7 +30,7 @@ package a
3030

3131
func _() {
3232
type int uint8
33-
_ = h(0) //@ inline(re"h", re"int.*shadowed.*by.*typename .line 4")
33+
_ = h(0) //@ inline(re"h", re"int.*shadowed.*by.*typename.*line 4")
3434
}
3535

3636
func h(x int) int { return x + 1 }

internal/refactor/inline/testdata/err-shadow-pkg.txtar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package a
1515
func _() {
1616
f() //@ inline(re"f", result)
1717
const v = 1
18-
f() //@ inline(re"f", re"v.*shadowed.*by.*const .line 5")
18+
f() //@ inline(re"f", re"v.*shadowed.*by.*const.*line 5")
1919
}
2020

2121
func f() int { return v }
@@ -28,7 +28,7 @@ package a
2828
func _() {
2929
_ = v //@ inline(re"f", result)
3030
const v = 1
31-
f() //@ inline(re"f", re"v.*shadowed.*by.*const .line 5")
31+
f() //@ inline(re"f", re"v.*shadowed.*by.*const.*line 5")
3232
}
3333

3434
func f() int { return v }

0 commit comments

Comments
 (0)