x/tools/gopls: Rename: crash due to Info.Defs[id]=nil bug in checkStructField
Closed this issue · 8 comments
#!stacks
"runtime.sigpanic" && "checkStructField:+36"
Issue created by stacks.
named := r.pkg.TypesInfo().Defs[spec.Name].Type()This stack Zepg4g was reported by telemetry:
crash/crashruntime.gopanic:+69runtime.panicmem:=262runtime.sigpanic:+19golang.org/x/tools/gopls/internal/golang.(*renamer).checkStructField:+36golang.org/x/tools/gopls/internal/golang.(*renamer).check:+14golang.org/x/tools/gopls/internal/golang.(*renamer).checkInLexicalScope:+62golang.org/x/tools/gopls/internal/golang.(*renamer).checkInPackageBlock:+47golang.org/x/tools/gopls/internal/golang.(*renamer).check:+12golang.org/x/tools/gopls/internal/golang.renameObjects:+24golang.org/x/tools/gopls/internal/golang.renameExported:+56golang.org/x/tools/gopls/internal/golang.renameOrdinary:+157golang.org/x/tools/gopls/internal/golang.Rename:+24golang.org/x/tools/gopls/internal/server.(*server).Rename:+17golang.org/x/tools/gopls/internal/protocol.serverDispatch:+489golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2
golang.org/x/tools/gopls@v0.17.0 go1.23.3 darwin/arm64 other,vscode (1)
Dups: _A3zlQ
Related Issues
- x/tools/gopls: "edit does not belong to syntax of package %q" bug in golang.Rename #70049
- x/tools/gopls: rename crashes in objectpath #60789 (closed)
- x/tools/gopls: nil pointer on rename #32974 (closed)
- x/tools/gopls: crash when renaming in a package using builtins with type parameters #52940 (closed)
- x/tools/gopls: rename crashes on builtin types #32992 (closed)
- x/tools/gopls: crash in Hover (telemetry) #69362
- x/tools/gopls: Hover: panic in lookup{ObjectByName,DocLinkSymbol} #69616
- x/tools/gopls: rename fails on struct method that references bad struct field #32882 (closed)
- x/tools/gopls: gopls fails to rename all uses of instantiated struct field #61640 (closed)
- x/tools/gopls: rename crashes on single segment import path #33768 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Thanks. Let's put this in v0.18.0 for now.
Since it is in rename (and likely in the context of a broken build), I think it is not too disruptive to leave it until the v0.18.0 release. Can re-evaluate if we see this frequently.
Of course, we still have no idea how this scenario arises...
This stack _A3zlQ was reported by telemetry:
crash/crashruntime.gopanic:+69runtime.panicmem:=262runtime.sigpanic:+19golang.org/x/tools/gopls/internal/golang.(*renamer).checkStructField:+36golang.org/x/tools/gopls/internal/golang.(*renamer).check:+14golang.org/x/tools/gopls/internal/golang.renameObjects:+24golang.org/x/tools/gopls/internal/golang.renameOrdinary:+99golang.org/x/tools/gopls/internal/golang.Rename:+24golang.org/x/tools/gopls/internal/server.(*server).Rename:+17golang.org/x/tools/gopls/internal/protocol.serverDispatch:+489golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.17.1 go1.23.4 darwin/amd64 other,vscode (1)
golang.org/x/tools/gopls@v0.17.1 go1.23.3 darwin/arm64 vscode (1)
Yay, repro:
type T int
type T struct { f int } // rename f to g[stderr] goroutine 37661 gp=0x1400809b6c0 m=19 mp=0x14018440008 [running]:
[stderr] panic({0x102f88fc0?, 0x103817890?})
[stderr] /Users/adonovan/w/goroot/src/runtime/panic.go:806 +0x154 fp=0x14000040fe0 sp=0x14000040f30 pc=0x10220e0e4
[stderr] runtime.panicmem(...)
[stderr] /Users/adonovan/w/goroot/src/runtime/panic.go:262
[stderr] runtime.sigpanic()
[stderr] /Users/adonovan/w/goroot/src/runtime/signal_unix.go:925 +0x300 fp=0x14000041040 sp=0x14000040fe0 pc=0x1022107c0
[stderr] golang.org/x/tools/gopls/internal/golang.(*renamer).checkStructField(0x1400fb295e0, 0x14014261bc0)
[stderr] /Users/adonovan/w/xtools/gopls/internal/golang/rename_check.go:475 +0x2c4 fp=0x14000041120 sp=0x14000041050 pc=0x102a922b4
[stderr] golang.org/x/tools/gopls/internal/golang.(*renamer).check(0x1400fb295e0, {0x103102378, 0x14014261bc0})
[stderr] golang.org/x/tools/gopls/internal/golang.(*renamer).check(0x1400fb295e0, {0x103102378, 0x14014261bc0})
[stderr] /Users/adonovan/w/xtools/gopls/internal/golang/rename_check.go:106 +0x10c fp=0x140000411d0 sp=0x14000041120 pc=0x102a902fc
[stderr] golang.org/x/tools/gopls/internal/golang.renameObjects({0x102e7e478, 0x1}, 0x14011332f60, {0x140154ffe40, 0x1, 0x1?})
[stderr] /Users/adonovan/w/xtools/gopls/internal/golang/rename.go:1173 +0x23c fp=0x14000041300 sp=0x140000411d0 pc=0x102a8d7ac
[stderr] golang.org/x/tools/gopls/internal/golang.renameOrdinary({0x1030f3e38, 0x1400fce2450}, 0x1400ca89560, {0x1030f6c20, 0x1401463f4a0}, {0x298a868?, 0x1?}, {0x102e7e478, 0x1})
[stderr] /Users/adonovan/w/xtools/gopls/internal/golang/rename.go:574 +0x908 fp=0x14000041500 sp=0x14000041300 pc=0x102a8ac38
[stderr] golang.org/x/tools/gopls/internal/golang.Rename({0x1030f3e38?, 0x1400fce22a0?}, 0x1400ca89560, {0x1030f6c20, 0x1401463f4a0}, {0x230d80c?, 0x1?}, {0x102e7e478, 0x1})
[stderr] /Users/adonovan/w/xtools/gopls/internal/golang/rename.go:419 +0x138 fp=0x140000416b0 sp=0x14000041500 pc=0x102a89d58
[stderr] golang.org/x/tools/gopls/internal/server.(*server).Rename(0x14000032d80, {0x1030f3e38, 0x14006ad0f60}, 0x1401538e140)
We really need to write down all the invariants of go/ast and go/types, including:
Defs[id]may be absent, even for an id on the LHS of a declaration, if that identifier is an illegal redeclaration.
Change https://go.dev/cl/663895 mentions this issue: go/types: document that Defs[id] may be nil in ill-typed code
Change https://go.dev/cl/663915 mentions this issue: gopls/internal/golang: Rename: fix crash in ill-typed redeclaration