refactor/satisfy: (re)allow composite lits of pointer type

CL 513775 fixed a bug related to composite lits of type parameter type,
but inadvertently removed handling for lits of pointer type (the 'deref'
call was replaced, rather than wrapped).

This results in a panic for unnamed literals of pointer type (such as
in []*X{{}}).

Replace the defer.

Fixes golang/go#61813

Change-Id: I2a66f6bfebd6d6d11a5fb7bf4c1cf453bcf02d4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/516775
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Robert Findley 2023-08-07 15:10:26 -04:00
Родитель 229f8486be
Коммит f42bca8e35
2 изменённых файлов: 20 добавлений и 2 удалений

18
gopls/internal/regtest/marker/testdata/rename/issue61813.txt поставляемый Normal file
Просмотреть файл

@ -0,0 +1,18 @@
This test exercises the panic reported in golang/go#61813.
-- p.go --
package p
type P struct{}
func (P) M() {} //@rename("M", N, MToN)
var x = []*P{{}}
-- @MToN/p.go --
package p
type P struct{}
func (P) N() {} //@rename("M", N, MToN)
var x = []*P{{}}

Просмотреть файл

@ -355,7 +355,7 @@ func (f *Finder) expr(e ast.Expr) types.Type {
f.sig = saved
case *ast.CompositeLit:
switch T := coreType(tv.Type).(type) {
switch T := coreType(deref(tv.Type)).(type) {
case *types.Struct:
for i, elem := range e.Elts {
if kv, ok := elem.(*ast.KeyValueExpr); ok {
@ -386,7 +386,7 @@ func (f *Finder) expr(e ast.Expr) types.Type {
}
default:
panic("unexpected composite literal type: " + tv.Type.String())
panic(fmt.Sprintf("unexpected composite literal type %T: %v", tv.Type, tv.Type.String()))
}
case *ast.ParenExpr: