1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:14:47 -07:00
go/test/fixedbugs/issue13559.go
Robert Griesemer 8f19394b62 cmd/compile/internal/types2: refactor untyped conversions
Based on https://golang.org/cl/284256 for go/types.
Brings this code more in line with go/types.

Adjusted various tests to match new error messages which
generally are now better: for assignment errors, instead
of a generic "cannot convert" we now say "cannot use"
followed by a clearer reason as to why not.

Major differences to go/types with respect to the changed
files:

- Some of the new code now returns error codes, but they
  are only used internally for now, and not reported with
  errors.

- go/types does not "convert" untyped nil values to target
  types, but here we do. This is unchanged from how types2
  handled this before this CL.

Change-Id: If45336d7ee679ece100f6d9d9f291a6ea55004d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/302757
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-23 05:11:09 +00:00

90 lines
5.9 KiB
Go

// errorcheck
// Copyright 2015 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.
// Verify that error messages print meaningful values
// for various extreme floating-point constants.
package p
// failure case in issue
const _ int64 = 1e-10000 // ERROR "1e\-10000 truncated|.* truncated to int64|truncated"
const (
_ int64 = 1e10000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1e1000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1e100000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1e10000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1e1000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1e100 // ERROR "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 overflows|truncated to int64|truncated"
_ int64 = 1e10
_ int64 = 1e1
_ int64 = 1e0
_ int64 = 1e-1 // ERROR "0\.1 truncated|.* truncated to int64|truncated"
_ int64 = 1e-10 // ERROR "1e\-10 truncated|.* truncated to int64|truncated"
_ int64 = 1e-100 // ERROR "1e\-100 truncated|.* truncated to int64|truncated"
_ int64 = 1e-1000 // ERROR "1e\-1000 truncated|.* truncated to int64|truncated"
_ int64 = 1e-10000 // ERROR "1e\-10000 truncated|.* truncated to int64|truncated"
_ int64 = 1e-100000 // ERROR "1e\-100000 truncated|.* truncated to int64|truncated"
_ int64 = 1e-1000000 // ERROR "1e\-1000000 truncated|.* truncated to int64|truncated"
)
const (
_ int64 = -1e10000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1e1000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1e100000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1e10000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1e1000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1e100 // ERROR "\-10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 overflows|truncated to int64|truncated"
_ int64 = -1e10
_ int64 = -1e1
_ int64 = -1e0
_ int64 = -1e-1 // ERROR "\-0\.1 truncated|.* truncated to int64|truncated"
_ int64 = -1e-10 // ERROR "\-1e\-10 truncated|.* truncated to int64|truncated"
_ int64 = -1e-100 // ERROR "\-1e\-100 truncated|.* truncated to int64|truncated"
_ int64 = -1e-1000 // ERROR "\-1e\-1000 truncated|.* truncated to int64|truncated"
_ int64 = -1e-10000 // ERROR "\-1e\-10000 truncated|.* truncated to int64|truncated"
_ int64 = -1e-100000 // ERROR "\-1e\-100000 truncated|.* truncated to int64|truncated"
_ int64 = -1e-1000000 // ERROR "\-1e\-1000000 truncated|.* truncated to int64|truncated"
)
const (
_ int64 = 1.23456789e10000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1.23456789e1000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1.23456789e100000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1.23456789e10000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1.23456789e1000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = 1.23456789e100 // ERROR "12345678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 overflows|truncated to int64|truncated"
_ int64 = 1.23456789e10
_ int64 = 1.23456789e1 // ERROR "12\.3457 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e0 // ERROR "1\.23457 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-1 // ERROR "0\.123457 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-10 // ERROR "1\.23457e\-10 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-100 // ERROR "1\.23457e\-100 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-1000 // ERROR "1\.23457e\-1000 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-10000 // ERROR "1\.23457e\-10000 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-100000 // ERROR "1\.23457e\-100000 truncated|.* truncated to int64|truncated"
_ int64 = 1.23456789e-1000000 // ERROR "1\.23457e\-1000000 truncated|.* truncated to int64|truncated"
)
const (
_ int64 = -1.23456789e10000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1.23456789e1000000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1.23456789e100000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1.23456789e10000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1.23456789e1000 // ERROR "integer too large|truncated to int64|truncated"
_ int64 = -1.23456789e100 // ERROR "\-12345678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 overflows|truncated to int64|truncated"
_ int64 = -1.23456789e10
_ int64 = -1.23456789e1 // ERROR "\-12\.3457 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e0 // ERROR "\-1\.23457 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-1 // ERROR "\-0\.123457 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-10 // ERROR "\-1\.23457e\-10 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-100 // ERROR "\-1\.23457e\-100 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-1000 // ERROR "\-1\.23457e\-1000 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-10000 // ERROR "\-1\.23457e\-10000 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-100000 // ERROR "\-1\.23457e\-100000 truncated|.* truncated to int64|truncated"
_ int64 = -1.23456789e-1000000 // ERROR "\-1\.23457e\-1000000 truncated|.* truncated to int64|truncated"
)