Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: untyped arguments to real and imag converted to default type #15892

Closed
momchil-velikov opened this issue May 30, 2016 · 2 comments
Closed

Comments

@momchil-velikov
Copy link
Contributor

On
go version devel +81a8f1a Mon May 30 05:24:16 2016 +0000 linux/amd64

the following program (https://play.golang.org/p/DbyUqeHamB), compiled with go run real.go

package main
const A = real(1.1)

exits with error message

/real.go:3: invalid argument 1.1 (type float64) for real

and behaves analogously with other kinds of untyped constants, passed as an argument
to real or imag.

The Go Language Specification seems to allow any kind of
untyped numeric constant to be passed as an argument to real or imag.

https://golang.org/ref/spec#Complex_numbers

For real and imag, the argument must be of complex type, and the return type is the corresponding
floating-point type: float32 for a complex64 argument, and float64 for a complex128 argument. If the
argument evaluates to an untyped constant, it must be a number
, and the return value
of the function is an untyped floating-point constant.

Both gotypes and gccgo accept the program without diagnostics.

@cznic
Copy link
Contributor

cznic commented May 30, 2016

1.1 is a float64 untyped constant, not a typed or untyped complex128 or (typed only) complex64 constant, thus it is an invalid argument of the built int real function because

For real and imag, the argument must be of complex type.

as you already quoted.

(Correct example)

@griesemer
Copy link
Contributor

Duplicate of #11946. Closing.

@golang golang locked and limited conversation to collaborators May 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants