In the following code:
func Foo() []float64 {
return 0
}
gc reports "cannot use 0 (type int) as type []float64 in return argument".
However, 0 is not an integer, 0 is a constant.
http://play.golang.org/p/hyUix7H8aX
The text was updated successfully, but these errors were encountered:
you can't actually return a untyped constant "type" from a function,
so 0 here must be treated as some type, as the context doesn't specify
which integer type to use, it defaults to int.
I agree one cannot return an untyped constant from a function, but one can "use" the
untyped constant 0 in many ways. For example, the following code is correct
func Foo() float64 {
return 0
}
Here, 0 is used as a float64, not as an int. Thus, it seems like the error message
should be
"cannot use 0 (untyped constant literal) as type []float64 in return argument"
One may never use an int as a float64, but one may use an untyped constant literal as a
float64
rsc
changed the title
cmd/gc: Wrong type reported for constant in type mismatch report
cmd/compile: Wrong type reported for constant in type mismatch report
Jun 8, 2015
The text was updated successfully, but these errors were encountered: