mirror of
https://github.com/golang/go
synced 2024-11-05 14:46:11 -07:00
34314280e4
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>
18 lines
418 B
Go
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"
|
|
)
|