@@ -167,18 +167,20 @@ func (r *renamer) checkInPackageBlock(from types.Object) {
167
167
}
168
168
}
169
169
170
- // Check for conflicts between package block and all file blocks.
171
- for _ , f := range r .pkg .Syntax () {
172
- fileScope := r .pkg .TypesInfo ().Scopes [f ]
173
- b , prev := fileScope .LookupParent (r .to , token .NoPos )
174
- if b == fileScope {
175
- r .errorf (from .Pos (), "renaming this %s %q to %q would conflict" , objectKind (from ), from .Name (), r .to )
176
- var prevPos token.Pos
177
- if prev != nil {
178
- prevPos = prev .Pos ()
170
+ // In the declaring package, check for conflicts between the
171
+ // package block and all file blocks.
172
+ if from .Pkg () == r .pkg .Types () {
173
+ for _ , f := range r .pkg .Syntax () {
174
+ fileScope := r .pkg .TypesInfo ().Scopes [f ]
175
+ if fileScope == nil {
176
+ continue // type error? (golang/go#40835)
177
+ }
178
+ b , prev := fileScope .LookupParent (r .to , token .NoPos )
179
+ if b == fileScope {
180
+ r .errorf (from .Pos (), "renaming this %s %q to %q would conflict" , objectKind (from ), from .Name (), r .to )
181
+ r .errorf (prev .Pos (), "\t with this %s" , objectKind (prev ))
182
+ return // since checkInPackageBlock would report redundant errors
179
183
}
180
- r .errorf (prevPos , "\t with this %s" , objectKind (prev ))
181
- return // since checkInPackageBlock would report redundant errors
182
184
}
183
185
}
184
186
@@ -436,7 +438,6 @@ func (r *renamer) checkLabel(label *types.Label) {
436
438
// checkStructField checks that the field renaming will not cause
437
439
// conflicts at its declaration, or ambiguity or changes to any selection.
438
440
func (r * renamer ) checkStructField (from * types.Var ) {
439
-
440
441
// If this is the declaring package, check that the struct
441
442
// declaration is free of field conflicts, and field/method
442
443
// conflicts.
0 commit comments