mirror of
https://github.com/golang/go
synced 2024-11-19 05:44:40 -07:00
d31a08c2ed
We now understand what "kind" of type is expected when using various builtins. For example, when completing "close(<>)" we prefer channels, and when completing "delete(<>)" we prefer maps. I also added some code to infer the expected type for the second argument to "delete()" and for the args to "copy()": delete(map[someType]int{}, <>) // expect "someType" copy([]int{}, <>) // expect "[]int" copy(<>, []int{}) // expect "[]int" And I marked "new()" as expected a type name, and it infers the type name properly: var _ *int = new(<>) // expected type at "<>" is "int" Fixes golang/go#36326. Change-Id: I4295c8753f8341d47010a0553fd2d0c2586f2efa Reviewed-on: https://go-review.googlesource.com/c/tools/+/212957 Run-TryBot: Muir Manders <muir@mnd.rs> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
38 lines
1.8 KiB
Go
38 lines
1.8 KiB
Go
package builtins
|
|
|
|
func _() {
|
|
var (
|
|
slice_ []int //@item(builtinSlice, "slice_", "[]int", "var")
|
|
map_ map[string]int //@item(builtinMap, "map_", "map[string]int", "var")
|
|
string_ string //@item(builtinString, "string_", "string", "var")
|
|
array_ [0]int //@item(builtinArray, "array_", "[0]int", "var")
|
|
arrayPtr_ *[0]int //@item(builtinArrayPtr, "arrayPtr_", "*[0]int", "var")
|
|
chan_ chan int //@item(builtinChan, "chan_", "chan int", "var")
|
|
ptr_ *int //@item(builtinPtr, "ptr_", "*int", "var")
|
|
int_ int //@item(builtinInt, "int_", "int", "var")
|
|
)
|
|
|
|
close() //@rank(")", builtinChan, builtinSlice)
|
|
|
|
append() //@rank(")", builtinSlice, builtinChan)
|
|
|
|
copy() //@rank(")", builtinSlice, builtinChan)
|
|
copy(slice_, s) //@rank(")", builtinSlice, builtinString)
|
|
copy(s, slice_) //@rank(",", builtinSlice, builtinString)
|
|
|
|
delete() //@rank(")", builtinMap, builtinChan)
|
|
delete(map_, s) //@rank(")", builtinString, builtinSlice)
|
|
|
|
len() //@rank(")", builtinSlice, builtinInt),rank(")", builtinMap, builtinInt),rank(")", builtinString, builtinInt),rank(")", builtinArray, builtinInt),rank(")", builtinArrayPtr, builtinPtr),rank(")", builtinChan, builtinInt)
|
|
|
|
cap() //@rank(")", builtinSlice, builtinMap),rank(")", builtinArray, builtinString),rank(")", builtinArrayPtr, builtinPtr),rank(")", builtinChan, builtinInt)
|
|
|
|
make() //@rank(")", builtinMap, builtinInt),rank(")", builtinChan, builtinInt),rank(")", builtinSlice, builtinInt)
|
|
|
|
var _ []int = make() //@rank(")", builtinSlice, builtinMap)
|
|
|
|
type myStruct struct{} //@item(builtinStructType, "myStruct", "struct{...}", "struct")
|
|
new() //@rank(")", builtinStructType, builtinInt)
|
|
var _ *myStruct = new() //@rank(")", builtinStructType, int)
|
|
}
|