Skip to content

Commit 6a64154

Browse files
committed
internal/lsp/cache: fix NPE in fileWasSaved
Reading the docstring, it looks like the sense of the type assertion was accidentally inverted in this function. Fix it to what I believe was intended. Fixes golang/go#37687 Change-Id: Ief44a996f1a262527c2916d6b78b81dd35b2cf9e Reviewed-on: https://go-review.googlesource.com/c/tools/+/222217 Run-TryBot: Rohan Challa <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rohan Challa <[email protected]>
1 parent d7d4448 commit 6a64154

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

internal/lsp/cache/snapshot.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,20 +787,20 @@ outer:
787787
return result
788788
}
789789

790-
// fileWasSaved returns true if the FileHandle passed in has been saved.
791-
// It accomplishes this by checking to see if the original and current FileHandles
792-
// are both overlays, and if the current FileHandles is saved while the original FileHandle
793-
// was not saved.
790+
// fileWasSaved reports whether the FileHandle passed in has been saved. It
791+
// accomplishes this by checking to see if the original and current FileHandles
792+
// are both overlays, and if the current FileHandle is saved while the original
793+
// FileHandle was not saved.
794794
func fileWasSaved(originalFH, currentFH source.FileHandle) bool {
795795
c, ok := currentFH.(*overlay)
796-
if ok {
796+
if !ok || c == nil {
797797
return true
798798
}
799-
if originalFH == nil {
799+
o, ok := originalFH.(*overlay)
800+
if !ok || o == nil {
800801
return c.saved
801802
}
802-
o, ok := originalFH.(*overlay)
803-
return ok && !o.saved && c.saved
803+
return !o.saved && c.saved
804804
}
805805

806806
// shouldInvalidateMetadata reparses a file's package and import declarations to

0 commit comments

Comments
 (0)