]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: fix constant conversion involving complex types
authorMatthew Dempsky <mdempsky@google.com>
Fri, 27 Mar 2020 21:33:54 +0000 (14:33 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 31 Mar 2020 20:59:14 +0000 (20:59 +0000)
commit34314280e46da1558bc7f9cd7e8a9ed610cf417b
tree0eef8fc2694a4a1daa28889860baa20656466609
parentfaa53e17d1c91d97aa2b780ac41190d151aa6b0e
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 #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>
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue38117.go [new file with mode: 0644]