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: real and imag don't produce untyped results for untyped constant arguments #11945

Closed
griesemer opened this issue Jul 30, 2015 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

package main
const _ int = real(10i)

=>

$ go build x.go
# command-line-arguments
./x.go:2: cannot use real(10i) (type float64) as type int in const initializer

(same for use of imag instead of real).

It appears that real and imag always produce a float32 or float64 constant respectively, for untyped constant arguments. The spec is not explicit about this, but this behavior violates the invariant

z == complex(real(z), imag(z))

for untyped constants z because real and imag won't work if the complex arguments have untyped constant components outside the float64 domain (see also #11540 ).

Both gc, and go/types accept this code. Both gc and go/types produce an untyped floating-point constant for untyped constant arguments.

@gopherbot
Copy link
Contributor

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

mk0x9 pushed a commit to mk0x9/go that referenced this issue Aug 5, 2015
…'imag'

For golang#11669, golang#11540, golang#11945, golang#11946, golang#11947.

Change-Id: Ifb0053c498cee9f3473c396f9338d82bd856c110
Reviewed-on: https://go-review.googlesource.com/12860
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
@rsc rsc modified the milestones: Unplanned, Go1.6 Dec 5, 2015
@griesemer griesemer modified the milestones: Go1.7, Unplanned Feb 20, 2016
@rsc rsc modified the milestones: Go1.8, Go1.7 May 17, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8 Oct 21, 2016
@gopherbot
Copy link
Contributor

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

gopherbot pushed a commit that referenced this issue Jun 7, 2017
Prep work for issues mentioned below. No semantic or functionality change.

For #11945.
For #17446.

Change-Id: Ia1bb2b87647a6daa47f7863c0eb42cf5e1d35a7c
Reviewed-on: https://go-review.googlesource.com/45076
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@gopherbot
Copy link
Contributor

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

@golang golang locked and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants