mirror of
https://github.com/golang/go
synced 2024-11-26 01:07:57 -07:00
go/types: generate conversions.go from types2 source
This CL reduces the amount of code that needs to be maintained manually by about 300 LOC. Change-Id: I749e47668e90e77e99109005fbe19045d4a5ad29 Reviewed-on: https://go-review.googlesource.com/c/go/+/565437 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
3374dad1d9
commit
cc276a768f
@ -98,17 +98,18 @@ func (check *Checker) conversion(x *operand, T Type) {
|
||||
// given a type explicitly by a constant declaration or conversion,...".
|
||||
if isUntyped(x.typ) {
|
||||
final := T
|
||||
// - For conversions to interfaces, except for untyped nil arguments,
|
||||
// use the argument's default type.
|
||||
// - For conversions to interfaces, except for untyped nil arguments
|
||||
// and isTypes2, use the argument's default type.
|
||||
// - For conversions of untyped constants to non-constant types, also
|
||||
// use the default type (e.g., []byte("foo") should report string
|
||||
// not []byte as type for the constant "foo").
|
||||
// - If !isTypes2, keep untyped nil for untyped nil arguments.
|
||||
// - For constant integer to string conversions, keep the argument type.
|
||||
// (See also the TODO below.)
|
||||
if x.typ == Typ[UntypedNil] {
|
||||
if isTypes2 && x.typ == Typ[UntypedNil] {
|
||||
// ok
|
||||
} else if isNonTypeParamInterface(T) || constArg && !isConstType(T) {
|
||||
final = Default(x.typ)
|
||||
} else if isNonTypeParamInterface(T) || constArg && !isConstType(T) || !isTypes2 && x.isNil() {
|
||||
final = Default(x.typ) // default type of untyped nil is untyped nil
|
||||
} else if x.mode == constant_ && isInteger(x.typ) && allString(T) {
|
||||
final = x.typ
|
||||
}
|
||||
@ -227,7 +228,7 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
errorf := func(format string, args ...interface{}) {
|
||||
errorf := func(format string, args ...any) {
|
||||
if check != nil && cause != nil {
|
||||
msg := check.sprintf(format, args...)
|
||||
if *cause != "" {
|
||||
|
@ -11,6 +11,8 @@ package types2
|
||||
|
||||
import "cmd/compile/internal/syntax"
|
||||
|
||||
const isTypes2 = true
|
||||
|
||||
// cmpPos compares the positions p and q and returns a result r as follows:
|
||||
//
|
||||
// r < 0: p is before q
|
||||
|
@ -1,3 +1,5 @@
|
||||
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
|
||||
|
||||
// Copyright 2012 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.
|
||||
@ -98,14 +100,17 @@ func (check *Checker) conversion(x *operand, T Type) {
|
||||
// given a type explicitly by a constant declaration or conversion,...".
|
||||
if isUntyped(x.typ) {
|
||||
final := T
|
||||
// - For conversions to interfaces, use the argument's default type.
|
||||
// - For conversions to interfaces, except for untyped nil arguments
|
||||
// and isTypes2, use the argument's default type.
|
||||
// - For conversions of untyped constants to non-constant types, also
|
||||
// use the default type (e.g., []byte("foo") should report string
|
||||
// not []byte as type for the constant "foo").
|
||||
// - Keep untyped nil for untyped nil arguments.
|
||||
// - If !isTypes2, keep untyped nil for untyped nil arguments.
|
||||
// - For constant integer to string conversions, keep the argument type.
|
||||
// (See also the TODO below.)
|
||||
if isNonTypeParamInterface(T) || constArg && !isConstType(T) || x.isNil() {
|
||||
if isTypes2 && x.typ == Typ[UntypedNil] {
|
||||
// ok
|
||||
} else if isNonTypeParamInterface(T) || constArg && !isConstType(T) || !isTypes2 && x.isNil() {
|
||||
final = Default(x.typ) // default type of untyped nil is untyped nil
|
||||
} else if x.mode == constant_ && isInteger(x.typ) && allString(T) {
|
||||
final = x.typ
|
||||
|
@ -115,6 +115,7 @@ var filemap = map[string]action{
|
||||
"const.go": func(f *ast.File) { fixTokenPos(f) },
|
||||
"context.go": nil,
|
||||
"context_test.go": nil,
|
||||
"conversions.go": nil,
|
||||
"errsupport.go": nil,
|
||||
"gccgosizes.go": nil,
|
||||
"gcsizes.go": func(f *ast.File) { renameIdents(f, "IsSyncAtomicAlign64->_IsSyncAtomicAlign64") },
|
||||
|
@ -14,6 +14,8 @@ import (
|
||||
"go/token"
|
||||
)
|
||||
|
||||
const isTypes2 = false
|
||||
|
||||
// cmpPos compares the positions p and q and returns a result r as follows:
|
||||
//
|
||||
// r < 0: p is before q
|
||||
|
Loading…
Reference in New Issue
Block a user