-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/compile: conversion from int/float typed constant to complex variable changed in 1.14 #38117
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
Comments
This is a change in compiler behavior, so I'm marking it as a release blocker for 1.15. If we decide that the change was in error, then we need to backport the fix to the 1.14 release branch. My quick reading of the spec is that it is unclear in this area, but I may have missed something. CC @mdempsky because this may be due to https://golang.org/cl/187657. |
Minimized test case:
I think it should be accepted. Conversions says "A constant value x can be converted to type T if x is representable by a value of T." And Representability says "A constant x is representable by a value of type T if one of the following conditions applies: - x is in the set of values determined by T. [...]"
|
Yeah. When writing that CL I assumed that whether we can convert (x : T) to U was simply a function of T and U. But in the case of T being an integer or floating point type and U being a complex type (or vice versa), it also depends on whether x is a constant. |
Change https://golang.org/cl/226197 mentions this issue: |
Looks like we're going back to the 1.13 behavior. I'll let @griesemer review the CL, but: @gopherbot Please open a backport to 1.14. The compiler behavior changed the way it handles constant conversions. This can break existing programs with no workaround other than rewriting the program, which should not be needed. |
Backport issue(s) opened: #38122 (for 1.13), #38123 (for 1.14). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
I agree with the general assessment. Generally speaking, numeric constant conversions are valid if the converted constant can be represented by the new type. |
Change https://golang.org/cl/232719 mentions this issue: |
…g complex types In CL 187657, I refactored constant conversion logic without realizing that conversions between int/float and complex types are allowed for constants (assuming the constant values are representable by the destination type), but are never allowed for non-constant expressions. This CL expands convertop to take an extra srcConstant parameter to indicate whether the source expression is a constant; and if so, to allow any numeric-to-numeric conversion. (Conversions of values that cannot be represented in the destination type are rejected by evconst.) Fixes #38123. For #38117. Change-Id: Id7077d749a14c8fd910be38da170fa5254819f2b Reviewed-on: https://go-review.googlesource.com/c/go/+/226197 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> (cherry picked from commit 3431428) Reviewed-on: https://go-review.googlesource.com/c/go/+/232719 Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?and
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputGO111MODULE="auto" GOARCH="amd64" GOBIN="/home/user/Go/go/bin" GOCACHE="/home/user/.cache/go-build" GOENV="/home/user/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/user/Go/go" GOPRIVATE="" GOPROXY="direct" GOROOT="/home/user/Go/go-current" GOSUMDB="off" GOTMPDIR="" GOTOOLDIR="/home/user/Go/go-current/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build444610156=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Ran the following test program for both specified versions.
What did you expect to see?
The test results to be the same for go version 1.13.6 and 1.14.1
What did you see instead?
Whereas both versions fail (correctly) when converting variable int/float to complex, they behave differently when converting typed constants to complex.
The results for go version 1.14.1 are the same for v1.14
The text was updated successfully, but these errors were encountered: