mirror of
https://github.com/golang/go
synced 2024-11-19 04:14:45 -07:00
e5f21acdc3
Calculate expected type in the following cases: - switch case statements - index expressions (e.g. []int{}[<>] or map[string]int{}[<>]) - slice expressions (e.g. []int{}[1:<>]) - channel send statements - channel receive expression We now also prefer type names in type switch clauses and type asserts. Change-Id: Iff8c317a9116868b36701d931c802d9147f962d8 GitHub-Last-Rev: e039a45aebe1c6aa9b2011cad67ddaa5e4ed4d77 GitHub-Pull-Request: golang/tools#97 Reviewed-on: https://go-review.googlesource.com/c/tools/+/176941 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package func_rank
|
|
|
|
var stringAVar = "var" //@item(stringAVar, "stringAVar", "string", "var")
|
|
func stringBFunc() string { return "str" } //@item(stringBFunc, "stringBFunc()", "string", "func")
|
|
type stringer struct{} //@item(stringer, "stringer", "struct{...}", "struct")
|
|
|
|
func _() stringer //@complete("tr", stringer, stringAVar, stringBFunc)
|
|
|
|
func _(val stringer) {} //@complete("tr", stringer, stringAVar, stringBFunc)
|
|
|
|
func (stringer) _() {} //@complete("tr", stringer, stringAVar, stringBFunc)
|
|
|
|
func _() {
|
|
var s struct {
|
|
AA int //@item(rankAA, "AA", "int", "field")
|
|
AB string //@item(rankAB, "AB", "string", "field")
|
|
AC int //@item(rankAC, "AC", "int", "field")
|
|
}
|
|
fnStr := func(string) {}
|
|
fnStr(s.A) //@complete(")", rankAB, rankAA, rankAC)
|
|
fnStr("" + s.A) //@complete(")", rankAB, rankAA, rankAC)
|
|
|
|
fnInt := func(int) {}
|
|
fnInt(-s.A) //@complete(")", rankAA, rankAC, rankAB)
|
|
|
|
// no expected type
|
|
fnInt(func() int { s.A }) //@complete(" }", rankAA, rankAB, rankAC)
|
|
fnInt(s.A()) //@complete("()", rankAA, rankAB, rankAC)
|
|
fnInt([]int{}[s.A]) //@complete("])", rankAA, rankAC, rankAB)
|
|
fnInt([]int{}[:s.A]) //@complete("])", rankAA, rankAC, rankAB)
|
|
|
|
fnInt(s.A.(int)) //@complete(".(", rankAA, rankAB, rankAC)
|
|
|
|
fnPtr := func(*string) {}
|
|
fnPtr(&s.A) //@complete(")", rankAB, rankAA, rankAC)
|
|
|
|
var aaPtr *string //@item(rankAAPtr, "aaPtr", "*string", "var")
|
|
var abPtr *int //@item(rankABPtr, "abPtr", "*int", "var")
|
|
fnInt(*a) //@complete(")", rankABPtr, rankAAPtr)
|
|
|
|
_ = func() string {
|
|
return s.A //@complete(" //", rankAB, rankAA, rankAC)
|
|
}
|
|
}
|