golang/go

x/tools/gopls: Rename: crash due to Info.Defs[id]=nil bug in checkStructField

Closed this issue · 8 comments

This has essentially the same root cause as #69362.

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...

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