Skip to content

Commit f42bca8

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent 229f848 commit f42bca8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This test exercises the panic reported in golang/go#61813.
2+
3+
-- p.go --
4+
package p
5+
6+
type P struct{}
7+
8+
func (P) M() {} //@rename("M", N, MToN)
9+
10+
var x = []*P{{}}
11+
-- @MToN/p.go --
12+
package p
13+
14+
type P struct{}
15+
16+
func (P) N() {} //@rename("M", N, MToN)
17+
18+
var x = []*P{{}}

refactor/satisfy/find.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (f *Finder) expr(e ast.Expr) types.Type {
355355
f.sig = saved
356356

357357
case *ast.CompositeLit:
358-
switch T := coreType(tv.Type).(type) {
358+
switch T := coreType(deref(tv.Type)).(type) {
359359
case *types.Struct:
360360
for i, elem := range e.Elts {
361361
if kv, ok := elem.(*ast.KeyValueExpr); ok {
@@ -386,7 +386,7 @@ func (f *Finder) expr(e ast.Expr) types.Type {
386386
}
387387

388388
default:
389-
panic("unexpected composite literal type: " + tv.Type.String())
389+
panic(fmt.Sprintf("unexpected composite literal type %T: %v", tv.Type, tv.Type.String()))
390390
}
391391

392392
case *ast.ParenExpr:

0 commit comments

Comments
 (0)