open2b/scriggo

Invalid behaviour with complex variables

Closed this issue · 2 comments

The following program prints

x: (0+3i)
y: (0+3i)

instead of

x: (0+0i)
y: (0+3i)
package main

import "fmt"

var x complex128

func main() {
	x = 3i
	y := x
	x = 0
	fmt.Printf("x: %#v\n", x)
	fmt.Printf("y: %#v\n", y)
}

The problem also applies to variables declared into a function scope:

package main

func main() {
	x := 3i
	x = 0
	println(x)
}

should print:

(+0.000000e+000+0.000000e+000i)

but it prints:

(+0.000000e+000+3.000000e+000i)

See also:

package main

func main() {
	var x int
	x = 10 + 0i
	println(x)
}