1
0
mirror of https://github.com/golang/go synced 2024-09-25 13:20:13 -06:00
go/test/fixedbugs/issue38117.go
Matthew Dempsky 34314280e4 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>
2020-03-31 20:59:14 +00:00

18 lines
418 B
Go

// errorcheck
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// cmd/compile erroneously rejected conversions of constant values
// between int/float and complex types.
package p
const (
_ = int(complex64(int(0)))
_ = float64(complex128(float64(0)))
_ = int8(complex128(1000)) // ERROR "overflow"
)