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.mode = invalid
} }
x.expr = e x.expr = e
// TODO(gri) Depending on the pending decision on the issue 7387, // a non-constant result implies a function call
// hasCallOrRecv may only need to be set if the result is not constant. if x.mode != invalid && x.mode != constant {
check.hasCallOrRecv = true check.hasCallOrRecv = true
}
return predeclaredFuncs[id].kind return predeclaredFuncs[id].kind
default: default:

View File

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