2019-12-22 10:58:14 -07:00
|
|
|
package address
|
|
|
|
|
|
|
|
func wantsPtr(*int) {}
|
|
|
|
|
|
|
|
type foo struct{ c int } //@item(addrFieldC, "c", "int", "field")
|
|
|
|
|
|
|
|
func _() {
|
|
|
|
var (
|
|
|
|
a string //@item(addrA, "a", "string", "var")
|
|
|
|
b int //@item(addrB, "b", "int", "var")
|
|
|
|
)
|
|
|
|
|
2019-12-23 21:06:34 -07:00
|
|
|
&b //@item(addrBRef, "&b", "int", "var")
|
|
|
|
|
|
|
|
wantsPtr() //@rank(")", addrBRef, addrA),snippet(")", addrBRef, "&b", "&b")
|
2019-12-22 10:58:14 -07:00
|
|
|
wantsPtr(&b) //@snippet(")", addrB, "b", "b")
|
|
|
|
|
|
|
|
var s foo
|
|
|
|
s.c //@item(addrDeepC, "s.c", "int", "field")
|
2019-12-23 21:06:34 -07:00
|
|
|
&s.c //@item(addrDeepCRef, "&s.c", "int", "field")
|
|
|
|
wantsPtr() //@snippet(")", addrDeepCRef, "&s.c", "&s.c")
|
|
|
|
wantsPtr(s) //@snippet(")", addrDeepCRef, "&s.c", "&s.c")
|
2019-12-22 10:58:14 -07:00
|
|
|
wantsPtr(&s) //@snippet(")", addrDeepC, "s.c", "s.c")
|
|
|
|
|
|
|
|
// don't add "&" in item (it gets added as an additional edit)
|
|
|
|
wantsPtr(&s.c) //@snippet(")", addrFieldC, "c", "c")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f foo) ptr() *foo { return &f }
|
|
|
|
|
|
|
|
func _() {
|
|
|
|
getFoo := func() foo { return foo{} }
|
|
|
|
|
|
|
|
// not addressable
|
|
|
|
getFoo().c //@item(addrGetFooC, "getFoo().c", "int", "field")
|
|
|
|
|
|
|
|
// addressable
|
2019-12-23 21:06:34 -07:00
|
|
|
getFoo().ptr().c //@item(addrGetFooPtrC, "getFoo().ptr().c", "int", "field")
|
|
|
|
&getFoo().ptr().c //@item(addrGetFooPtrCRef, "&getFoo().ptr().c", "int", "field")
|
2019-12-22 10:58:14 -07:00
|
|
|
|
2019-12-23 21:06:34 -07:00
|
|
|
wantsPtr() //@rank(addrGetFooPtrCRef, addrGetFooC),snippet(")", addrGetFooPtrCRef, "&getFoo().ptr().c", "&getFoo().ptr().c")
|
2019-12-22 10:58:14 -07:00
|
|
|
wantsPtr(&g) //@rank(addrGetFooPtrC, addrGetFooC),snippet(")", addrGetFooPtrC, "getFoo().ptr().c", "getFoo().ptr().c")
|
|
|
|
}
|
|
|
|
|
|
|
|
type nested struct {
|
|
|
|
f foo
|
|
|
|
}
|
|
|
|
|
|
|
|
func _() {
|
|
|
|
getNested := func() nested { return nested{} }
|
|
|
|
|
2019-12-23 21:06:34 -07:00
|
|
|
getNested().f.c //@item(addrNestedC, "getNested().f.c", "int", "field")
|
|
|
|
&getNested().f.ptr().c //@item(addrNestedPtrC, "&getNested().f.ptr().c", "int", "field")
|
2019-12-22 10:58:14 -07:00
|
|
|
|
|
|
|
// addrNestedC is not addressable, so rank lower
|
|
|
|
wantsPtr(getNestedfc) //@fuzzy(")", addrNestedPtrC, addrNestedC)
|
|
|
|
}
|