Skip to content

Commit 6da8d2e

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/golang: Rename imports: be defensive
This CL makes the map lookup/type assertion defensive. I have no hypothesis for why it fails (it should be sound given the postcondition of the "pass 1" loop), but this will at least stop the tool from crashing. Fixes golang/go#71656 Change-Id: I32576689e4a2e2fcf7f2640f877a8580107cc387 Reviewed-on: https://go-review.googlesource.com/c/tools/+/667195 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 015c0fc commit 6da8d2e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gopls/internal/golang/rename.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,12 @@ func renameImports(ctx context.Context, snapshot *cache.Snapshot, mp *metadata.P
11521152
continue // not the import we're looking for
11531153
}
11541154

1155-
pkgname := pkg.TypesInfo().Implicits[imp].(*types.PkgName)
1155+
pkgname, ok := pkg.TypesInfo().Implicits[imp].(*types.PkgName)
1156+
if !ok {
1157+
// "can't happen", but be defensive (#71656)
1158+
return fmt.Errorf("internal error: missing type information for %s import at %s",
1159+
imp.Path.Value, safetoken.StartPosition(pkg.FileSet(), imp.Pos()))
1160+
}
11561161

11571162
pkgScope := pkg.Types().Scope()
11581163
fileScope := pkg.TypesInfo().Scopes[f.File]

0 commit comments

Comments
 (0)