]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] cmd/compile: fix constant conversion involving complex types
authorMatthew Dempsky <mdempsky@google.com>
Fri, 27 Mar 2020 21:33:54 +0000 (14:33 -0700)
committerDmitri Shuralyov <dmitshur@golang.org>
Fri, 8 May 2020 16:33:58 +0000 (16:33 +0000)
commitf4274e64aac99aaa9af05988f2f8c36c47554889
tree9d4c78eb3aab8d1f62a61e6500e4fb17c9626e70
parentb7eca1cf3e27ab0796dd8766bf8cc08b14b3cc0d
[release-branch.go1.14] cmd/compile: fix constant conversion involving 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 <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
(cherry picked from commit 34314280e46da1558bc7f9cd7e8a9ed610cf417b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/232719
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue38117.go [new file with mode: 0644]