golang / go

The Go programming language

Home Page:https://go.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cmd/compile: failure to diagnose invalid conversion to complex64

dvyukov opened this issue · comments

gc successfully compiles the following program:

package a
var a = complex64(6)/774516156475830989403545856475830078125

while both gccgo and go/types reject it with:

error: complex real part overflow
774516156475830989403545856475830078125 (untyped int constant) overflows complex64

go version devel +40a1516 Fri Jul 3 03:08:40 2015 +0000 linux/amd64

I don't believe this is a gc bug. First of all, the conversion is not illegal - an untyped int constant can be converted into a complex value. The complaints are about overflow. But the value 774516156475830989403545856475830078125 is converted into a float64 w/o problem:

package a
var x float64 = 774516156475830989403545856475830078125

Making this a go/types bug.

Never mind - my bad! It's complex64 - not complex128! (I hate these names).

Indeed, "var _ float32 = 774516156475830989403545856475830078125" is not valid because the number is too large for any float32, and thus too large for any complex64 component.

gc should not accept this. Changing back to gc bug. Sorry.

CL forthcoming.

CL https://golang.org/cl/16920 mentions this issue.