cmd/guru: implements: if selected expr is a value, use its type
...as the basis of the query, instead of reporting an error.
+ test
Change-Id: Ie5defa98cd8dfc8e200e296c2aa02c88893cf9ac
Reviewed-on: https://go-review.googlesource.com/22117
Reviewed-by: Michael Matloob <matloob@golang.org>
diff --git a/cmd/guru/implements.go b/cmd/guru/implements.go
index e852441..b7c2962 100644
--- a/cmd/guru/implements.go
+++ b/cmd/guru/implements.go
@@ -88,11 +88,17 @@
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 22457d9..fea9006 100644
--- a/cmd/guru/testdata/src/implements/main.go
+++ b/cmd/guru/testdata/src/implements/main.go
@@ -37,3 +37,8 @@
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 ee00f3d..1077c98 100644
--- a/cmd/guru/testdata/src/implements/main.golden
+++ b/cmd/guru/testdata/src/implements/main.golden
@@ -42,3 +42,9 @@
interface type I
is implemented by basic type lib.Type
+-------- @implements var_d --------
+struct type D
+ implements F
+pointer type *D
+ implements FG
+