Skip to content

Commit

Permalink
internal/refactor/inline: improve a confusing error message
Browse files Browse the repository at this point in the history
Change-Id: I31e587105ffd16dbe32436ce5a090180f5186200
Reviewed-on: https://go-review.googlesource.com/c/tools/+/554061
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Jan 5, 2024
1 parent ba8672b commit c9c95f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions internal/refactor/inline/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
// check not shadowed at caller.
found := caller.lookup(obj.Name) // always finds something
if found.Pos().IsValid() {
return nil, fmt.Errorf("cannot inline because built-in %q is shadowed in caller by a %s (line %d)",
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)",
obj.Name, objectKind(found),
caller.Fset.PositionFor(found.Pos(), false).Line)
}
Expand All @@ -505,8 +505,9 @@ func inline(logf func(string, ...any), caller *Caller, callee *gobCallee) (*resu
// around the refactored signature.
found := caller.lookup(obj.Name)
if found != nil && !isPkgLevel(found) {
return nil, fmt.Errorf("cannot inline because %q is shadowed in caller by a %s (line %d)",
obj.Name, objectKind(found),
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)",
obj.Kind, obj.Name,
objectKind(found),
caller.Fset.PositionFor(found.Pos(), false).Line)
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions internal/refactor/inline/testdata/err-shadow-builtin.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package a

func _() {
const nil = 1
_ = f() //@ inline(re"f", re"nil.*shadowed.*by.*const .line 4")
_ = f() //@ inline(re"f", re"nil.*shadowed.*by.*const.*line 4")
}

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

func _() {
type append int
g(nil) //@ inline(re"g", re"append.*shadowed.*by.*typename .line 4")
g(nil) //@ inline(re"g", re"append.*shadowed.*by.*typename.*line 4")
}

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

func _() {
type int uint8
_ = h(0) //@ inline(re"h", re"int.*shadowed.*by.*typename .line 4")
_ = h(0) //@ inline(re"h", re"int.*shadowed.*by.*typename.*line 4")
}

func h(x int) int { return x + 1 }
4 changes: 2 additions & 2 deletions internal/refactor/inline/testdata/err-shadow-pkg.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package a
func _() {
f() //@ inline(re"f", result)
const v = 1
f() //@ inline(re"f", re"v.*shadowed.*by.*const .line 5")
f() //@ inline(re"f", re"v.*shadowed.*by.*const.*line 5")
}

func f() int { return v }
Expand All @@ -28,7 +28,7 @@ package a
func _() {
_ = v //@ inline(re"f", result)
const v = 1
f() //@ inline(re"f", re"v.*shadowed.*by.*const .line 5")
f() //@ inline(re"f", re"v.*shadowed.*by.*const.*line 5")
}

func f() int { return v }
Expand Down

0 comments on commit c9c95f9

Please sign in to comment.