#!stacks
"sigpanic" && "inlineVariableOne-range1"
Issue created by stacks.
id := curIdent.Node().(*ast.Ident)
obj1 := info.Uses[id]
_, obj2 := scope.LookupParent(id.Name, pos)
if obj1 != obj2 {
return nil, nil, fmt.Errorf("cannot inline variable: its initializer expression refers to %q, which is shadowed by the declaration at line %d", id.Name, safetoken.Position(pgf.Tok, obj2.Pos()).Line) // <----------- obj2 is nil
}
This stack tdbvkw was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x14fruntime.panicmem:=262,+0x2e7runtime.sigpanic:+19,+0x2b8golang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+8,+0x124golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xbbgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+13,+0x28fgolang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x33golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x6dbgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x67golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x6fgolang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x407golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x11bgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0x907golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x167golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xa5bgolang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x6fgolang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x637
golang.org/x/tools/gopls@v0.19.1 go1.25rc1 darwin/arm64 other,vscode (3)
Dups: BPia1w srVy-g ZsJ7Vw PPnIfw dPhsZQ 46y2Vg
Comment From: adonovan
The faulting instruction is the retrieval of obj2.Pos from the types.Object itable, meaning that obj2 is nil or invalid. (Yay for PC values!) If obj2 is nil, this means obj1 is non-nil, so we must have an input of the form:
func f(y int) {
var x = y // y is a valid reference (to obj1)
{
y := 2
println(x) <-- invoke inline-variable on x
_ = y
}
}
but somehow the LookupParent("y") operation at println(x) fails to find any object. I don't see how this can happen, because the environment at that point must define a superset of the names defined at var x = y. So this cannot happen.
Therefore, this must be caused by memory corruption of obj2. Ugh, I hate this.
Comment From: adonovan
Having just written "this cannot happen", like a bull to a red flag I sought to disprove myself, and did so easily: what if the set of free names that we loop over is too large, and includes names that are not free? This seems easily possible. Example:
func f() {
var x = func(notfree int) { _ = notfree }
println(x) <-- invoke inline-variable on x
}
Lo and behold gopls crashes. Not memory corruption, just bad code. Yay.
Comment From: gopherbot
Change https://go.dev/cl/683535 mentions this issue: gopls/internal/golang: fix crash in refactor.inline.variable
Comment From: gabyhelp
Related Issues
- x/tools/gopls: ChangeSignature: OOB panic in inlineCall (FuncType.Params inconsistent with Signature) #73912
- x/tools/internal/refactor/inline: panic in needsParens #71486 (closed)
- x/tools/gopls: ChangeSignature: crash in in inliner (likely due to ill-formed variadic call) #73187
- x/tools/gopls: ChangeSignature: OOB panic in inline.updateCalleeParams (mismatched syntactic/semantic params) #73913
- x/tools/gopls: Implementation (by signatures): nil panic in dynamicFuncCallType #74305 (closed)
- x/tools/gopls: nil deref in x/telemetry/internal/counter.(*Counter).add #73890
- x/tools/gopls: "inline: corrupted reference %v" bug in golang.RemoveUnusedParameter #69896 (closed)
- x/tools/gopls: Hover: invalid nil entry in types.Defs map #69362 (closed)
- x/tools/gopls: nil deref in 'go vendor' Snapshot.GoCommandInvocation #73891
- x/tools/gopls: ChangeSignature: "cannot inline: corrupted reference" bug #73779
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
Comment From: adonovan
This stack BPia1w was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x358runtime.sigpanic:+19,+0x328golang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+8,+0x177golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xabgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+13,+0x37agolang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x23golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x702golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x85golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x86golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x582golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x19cgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xac1golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x1b8golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xcf9golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908
golang.org/x/tools/gopls@v0.19.1 go1.24.4 linux/amd64 other (1)
Comment From: adonovan
This stack srVy-g was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x197runtime.sigpanic:+9,+0x167golang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+8,+0x177golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xabgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+13,+0x37agolang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x23golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x702golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x85golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x86golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x582golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x19cgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xac1golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x1b8golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xcf9golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908
golang.org/x/tools/gopls@v0.19.1 go1.24.4 windows/amd64 vscode (2)
Comment From: adonovan
This stack ZsJ7Vw was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x153runtime.panicmem:=262,+0x2ffruntime.sigpanic:+19,+0x2ccgolang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+8,+0x144golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xbfgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+13,+0x2dfgolang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x33golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x72bgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x77golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x7fgolang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x46bgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x14bgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xa07golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x17fgolang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xb03golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68f
golang.org/x/tools/gopls@v0.19.1 go1.24.4 darwin/arm64 other,vscode (2)
Comment From: adonovan
This stack PPnIfw was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x153runtime.panicmem:=262,+0x2ffruntime.sigpanic:+19,+0x2ccgolang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+14,+0x1b8golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xbfgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+14,+0x307golang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x33golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x72bgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x77golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x7fgolang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x46bgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x14bgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xa07golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x17fgolang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xb03golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.handshaker.func5:+52,+0x68f
golang.org/x/tools/gopls@v0.20.0-pre.1 go1.24.4 darwin/arm64 vscode (1)
Comment From: adonovan
Latest stack implicates obj2.Pos() where obj2 is nil, in inlineVariableOne.
Comment From: adonovan
This stack dPhsZQ was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x358runtime.sigpanic:+19,+0x328golang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+14,+0x203golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xabgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+14,+0x3a5golang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x23golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x702golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x85golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x86golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x582golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x19cgolang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xac1golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x1b8golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xcf9golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.handshaker.func5:+52,+0x908
golang.org/x/tools/gopls@v0.20.0 go1.24.5 linux/amd64 vscode (2)
Comment From: adonovan
This stack 46y2Vg was reported by telemetry:
crash/crashruntime.gopanic:+69,+0x167runtime.panicmem:=262,+0x358runtime.sigpanic:+19,+0x328golang.org/x/tools/gopls/internal/golang.inlineVariableOne-range1:+14,+0x203golang.org/x/tools/go/ast/inspector.Cursor.Preorder.func1:+6,+0xabgolang.org/x/tools/gopls/internal/golang.inlineVariableOne:+14,+0x385golang.org/x/tools/gopls/internal/golang.ApplyFix.singleFile.func6:+1,+0x23golang.org/x/tools/gopls/internal/golang.ApplyFix:+43,+0x6fbgolang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix.func1:+1,+0x85golang.org/x/tools/gopls/internal/server.(*commandHandler).run.func2:+3,+0x86golang.org/x/tools/gopls/internal/server.(*commandHandler).run:+81,+0x582golang.org/x/tools/gopls/internal/server.(*commandHandler).ApplyFix:+2,+0x1a4golang.org/x/tools/gopls/internal/protocol/command.Dispatch:+31,+0xaa1golang.org/x/tools/gopls/internal/server.(*server).ResolveCodeAction:+21,+0x1b8golang.org/x/tools/gopls/internal/protocol.serverDispatch:+46,+0xcd9golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*StreamServer).ServeStream.handshaker.func5:+52,+0x908
golang.org/x/tools/gopls@v0.20.0 go1.25.0 linux/amd64 vscode (1)