mirror of
https://github.com/golang/go
synced 2024-11-18 20:24:41 -07:00
go.tools/go/types: result of make and new builtins are not addressable
LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/89390045
This commit is contained in:
parent
379e0e7704
commit
998b73a2e9
@ -397,7 +397,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
||||
check.invalidArg(call.Args[1].Pos(), "length and capacity swapped")
|
||||
// safe to continue
|
||||
}
|
||||
x.mode = variable
|
||||
x.mode = value
|
||||
x.typ = T
|
||||
if check.Types != nil {
|
||||
params := [...]Type{T, Typ[Int], Typ[Int]}
|
||||
@ -412,7 +412,7 @@ func (check *checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
|
||||
return
|
||||
}
|
||||
|
||||
x.mode = variable
|
||||
x.mode = value
|
||||
x.typ = &Pointer{base: T}
|
||||
if check.Types != nil {
|
||||
check.recordBuiltinType(call.Fun, makeSig(x.typ, T))
|
||||
|
4
go/types/testdata/builtins.src
vendored
4
go/types/testdata/builtins.src
vendored
@ -436,6 +436,7 @@ func make1() {
|
||||
_ = make([]int, 10 /* ERROR length and capacity swapped */ , 9)
|
||||
_ = make([]int, 1 /* ERROR overflows */ <<100, 12345)
|
||||
_ = make([]int, m /* ERROR must be integer */ )
|
||||
_ = &make /* ERROR cannot take address */ ([]int, 0)
|
||||
|
||||
// maps
|
||||
_ = make /* ERROR arguments */ (map[int]string, 10, 20)
|
||||
@ -446,6 +447,7 @@ func make1() {
|
||||
_ = make(map[int]float32, int64(n))
|
||||
_ = make(map[string]bool, 10.0)
|
||||
_ = make(map[string]bool, 10.0<<s)
|
||||
_ = &make /* ERROR cannot take address */ (map[string]bool)
|
||||
|
||||
// channels
|
||||
_ = make /* ERROR arguments */ (chan int, 10, 20)
|
||||
@ -456,6 +458,7 @@ func make1() {
|
||||
_ = make(chan string, int64(n))
|
||||
_ = make(chan bool, 10.0)
|
||||
_ = make(chan bool, 10.0<<s)
|
||||
_ = &make /* ERROR cannot take address */ (chan bool)
|
||||
|
||||
make /* ERROR not used */ ([]int, 10)
|
||||
|
||||
@ -479,6 +482,7 @@ func new1() {
|
||||
q := new(*float64)
|
||||
_ = *p == **q
|
||||
new /* ERROR not used */ (int)
|
||||
_ = &new /* ERROR cannot take address */ (int)
|
||||
|
||||
_ = new(int... /* ERROR invalid use of \.\.\. */ )
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user