diff --git a/cmd/guru/implements.go b/cmd/guru/implements.go index e852441e..b7c29626 100644 --- a/cmd/guru/implements.go +++ b/cmd/guru/implements.go @@ -88,11 +88,17 @@ func implements(q *Query) error { T = recv.Type() } } + + // If not a method, use the expression's type. + if T == nil { + T = qpos.info.TypeOf(path[0].(ast.Expr)) + } + case actionType: T = qpos.info.TypeOf(path[0].(ast.Expr)) } if T == nil { - return fmt.Errorf("no type or method here") + return fmt.Errorf("not a type, method, or value") } // Find all named types, even local types (which can have diff --git a/cmd/guru/testdata/src/implements/main.go b/cmd/guru/testdata/src/implements/main.go index 22457d99..fea9006e 100644 --- a/cmd/guru/testdata/src/implements/main.go +++ b/cmd/guru/testdata/src/implements/main.go @@ -37,3 +37,8 @@ func (sorter) Swap(i, j int) {} type I interface { // @implements I "I" Method(*int) *int } + +func _() { + var d D + _ = d // @implements var_d "d" +} diff --git a/cmd/guru/testdata/src/implements/main.golden b/cmd/guru/testdata/src/implements/main.golden index ee00f3d9..1077c982 100644 --- a/cmd/guru/testdata/src/implements/main.golden +++ b/cmd/guru/testdata/src/implements/main.golden @@ -42,3 +42,9 @@ slice type sorter interface type I is implemented by basic type lib.Type +-------- @implements var_d -------- +struct type D + implements F +pointer type *D + implements FG +