// 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
}
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 != "" {
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
+// 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.
// 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
"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") },
"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