Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: conversion from int/float typed constant to complex variable changed in 1.14 #38117
What version of Go are you using (
|const int (explicit type)||y||n|
|variable int (explicit type)||n||n|
|const float (explicit type)||y||n|
|variable float (explicit type)||n||n|
The results for go version 1.14.1 are the same for v1.14
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.
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.
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.
…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 <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Robert Griesemer <firstname.lastname@example.org> (cherry picked from commit 3431428) Reviewed-on: https://go-review.googlesource.com/c/go/+/232719 Run-TryBot: Dmitri Shuralyov <email@example.com> Reviewed-by: Matthew Dempsky <firstname.lastname@example.org>