]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: expose Default function, which converts untyped T to T
authorAlan Donovan <adonovan@google.com>
Fri, 7 Oct 2016 22:11:06 +0000 (18:11 -0400)
committerAlan Donovan <adonovan@google.com>
Wed, 12 Oct 2016 14:59:23 +0000 (14:59 +0000)
Change-Id: Ibcf5e0ba694b280744a00c2c6fda300f0a653455
Reviewed-on: https://go-review.googlesource.com/30715
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/assignments.go
src/go/types/builtins.go
src/go/types/conversions.go
src/go/types/expr.go
src/go/types/predicates.go

index 6ebf3b5eab0745ae80d4475c1b26db780b3b8b6d..18f893d478126478022767522d07c044b5ae7d35 100644 (file)
@@ -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
        }
index fc4db4513b8af2eabd2ecbeb0518cbe614c83c92..596a989a2dfa2cbe957b96e1f0010318c592dc79 100644 (file)
@@ -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
index 9b6869c66858cd5984d7cfd549e5bbeccddabe8d..2bf1e2d5e3825829864b337dce32bd8d4d6d1d14 100644 (file)
@@ -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)
        }
index 634c568e2c7440303be48036dfa750f9df2a51a1..e1d92ee5ef4f55c5602a300e03f79961135125d3 100644 (file)
@@ -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
index c7e7660bd191a5e7806b9e24f3973fc1d8992222..21fd81e3c26c01d7abe0e8bef03d4e1905c88b75 100644 (file)
@@ -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: