Commit 9c850958 authored by Alan Donovan's avatar Alan Donovan

go/types: expose Default function, which converts untyped T to T

Change-Id: Ibcf5e0ba694b280744a00c2c6fda300f0a653455
Reviewed-on: https://go-review.googlesource.com/30715Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 41a005d4
......@@ -41,7 +41,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
x.mode = invalid
return
}
target = defaultType(x.typ)
target = Default(x.typ)
}
check.convertUntyped(x, target)
if x.mode == invalid {
......@@ -116,7 +116,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
lhs.typ = Typ[Invalid]
return nil
}
typ = defaultType(typ)
typ = Default(typ)
}
lhs.typ = typ
}
......
......@@ -632,7 +632,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
func makeSig(res Type, args ...Type) *Signature {
list := make([]*Var, len(args))
for i, param := range args {
list[i] = NewVar(token.NoPos, nil, "", defaultType(param))
list[i] = NewVar(token.NoPos, nil, "", Default(param))
}
params := NewTuple(list...)
var result *Tuple
......
......@@ -55,7 +55,7 @@ func (check *Checker) conversion(x *operand, T Type) {
// not []byte as type for the constant "foo").
// - Keep untyped nil for untyped nil arguments.
if IsInterface(T) || constArg && !isConstType(T) {
final = defaultType(x.typ)
final = Default(x.typ)
}
check.updateExprType(x.expr, final, true)
}
......
......@@ -541,7 +541,7 @@ func (check *Checker) convertUntyped(x *operand, target Type) {
if !t.Empty() {
goto Error
}
target = defaultType(x.typ)
target = Default(x.typ)
}
case *Pointer, *Signature, *Slice, *Map, *Chan:
if !x.isNil() {
......@@ -605,8 +605,8 @@ func (check *Checker) comparison(x, y *operand, op token.Token) {
// time will be materialized. Update the expression trees.
// If the current types are untyped, the materialized type
// is the respective default type.
check.updateExprType(x.expr, defaultType(x.typ), true)
check.updateExprType(y.expr, defaultType(y.typ), true)
check.updateExprType(x.expr, Default(x.typ), true)
check.updateExprType(y.expr, Default(y.typ), true)
}
// spec: "Comparison operators compare two operands and yield
......
......@@ -291,11 +291,11 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool {
return false
}
// defaultType returns the default "typed" type for an "untyped" type;
// Default returns the default "typed" type for an "untyped" type;
// it returns the incoming type for all other types. The default type
// for untyped nil is untyped nil.
//
func defaultType(typ Type) Type {
func Default(typ Type) Type {
if t, ok := typ.(*Basic); ok {
switch t.kind {
case UntypedBool:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment