1
0
mirror of https://github.com/golang/go synced 2024-11-18 20:14:43 -07:00

go.tools/go/types: built-in calls returning constants don't count as function calls

Fixes golang/go#7457.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/69890052
This commit is contained in:
Robert Griesemer 2014-03-04 09:26:21 -08:00
parent 31c219bef7
commit ddcdb3637a
2 changed files with 8 additions and 5 deletions

View File

@ -45,9 +45,10 @@ func (check *checker) call(x *operand, e *ast.CallExpr) exprKind {
x.mode = invalid
}
x.expr = e
// TODO(gri) Depending on the pending decision on the issue 7387,
// hasCallOrRecv may only need to be set if the result is not constant.
check.hasCallOrRecv = true
// a non-constant result implies a function call
if x.mode != invalid && x.mode != constant {
check.hasCallOrRecv = true
}
return predeclaredFuncs[id].kind
default:

View File

@ -121,13 +121,14 @@ func cap3() {
_ = cap([4]int{x})
_ = cap /* ERROR not constant */ ([4]int{f()})
_ = cap /* ERROR not constant */ ([4]int{cap([]int{})})
_ = cap /* ERROR not constant */ ([4]int{cap([4]int{})})
_ = cap([4]int{cap([4]int{})})
)
var y float64
var z complex128
const (
_ = cap([4]float64{})
_ = cap([4]float64{y})
_ = cap([4]float64{real(2i)})
_ = cap /* ERROR not constant */ ([4]float64{real(z)})
)
var ch chan [10]int
@ -390,13 +391,14 @@ func len3() {
_ = len([4]int{x})
_ = len /* ERROR not constant */ ([4]int{f()})
_ = len /* ERROR not constant */ ([4]int{len([]int{})})
_ = len /* ERROR not constant */ ([4]int{len([4]int{})})
_ = len([4]int{len([4]int{})})
)
var y float64
var z complex128
const (
_ = len([4]float64{})
_ = len([4]float64{y})
_ = len([4]float64{real(2i)})
_ = len /* ERROR not constant */ ([4]float64{real(z)})
)
var ch chan [10]int