]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: remove report parameter from infer and inferB
authorRobert Griesemer <gri@golang.org>
Tue, 21 Sep 2021 03:28:01 +0000 (20:28 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 21 Sep 2021 20:28:32 +0000 (20:28 +0000)
This is a clean port of CL 350049 from go/types to types2.

Change-Id: Ifc8551a772535f7b8e943bfbd9febbb78333fa68
Reviewed-on: https://go-review.googlesource.com/c/go/+/351169
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/call.go
src/cmd/compile/internal/types2/infer.go

index 0480b7bef415a7cf068c60b2a1f508d599d0e51a..aaef97f58a33baaf525c7ccf3c8033e6bee4e12c 100644 (file)
@@ -41,7 +41,7 @@ func (check *Checker) funcInst(x *operand, inst *syntax.IndexExpr) {
        // if we don't have enough type arguments, try type inference
        inferred := false
        if got < want {
-               targs = check.infer(inst.Pos(), sig.TypeParams().list(), targs, nil, nil, true)
+               targs = check.infer(inst.Pos(), sig.TypeParams().list(), targs, nil, nil)
                if targs == nil {
                        // error was already reported
                        x.mode = invalid
@@ -338,7 +338,7 @@ func (check *Checker) arguments(call *syntax.CallExpr, sig *Signature, targs []T
                }
                // TODO(gri) provide position information for targs so we can feed
                //           it to the instantiate call for better error reporting
-               targs := check.infer(call.Pos(), sig.TypeParams().list(), targs, sigParams, args, true)
+               targs := check.infer(call.Pos(), sig.TypeParams().list(), targs, sigParams, args)
                if targs == nil {
                        return // error already reported
                }
index b98c8211df3d2df48cb210ea6115a7e36f74e9d6..914ee9ea5d907ffe42a0daf2c6fd5ab9349d07aa 100644 (file)
@@ -28,9 +28,7 @@ const useConstraintTypeInference = true
 //   3) Infer type arguments from untyped function arguments.
 //
 // Constraint type inference is used after each step to expand the set of type arguments.
-//
-// TODO(gri): remove the report parameter: is no longer needed.
-func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand, report bool) (result []Type) {
+func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand) (result []Type) {
        if debug {
                defer func() {
                        assert(result == nil || len(result) == len(tparams))
@@ -62,7 +60,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // If we have type arguments, see how far we get with constraint type inference.
        if len(targs) > 0 && useConstraintTypeInference {
                var index int
-               targs, index = check.inferB(tparams, targs, report)
+               targs, index = check.inferB(tparams, targs)
                if targs == nil || index < 0 {
                        return targs
                }
@@ -107,9 +105,6 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        }
 
        errorf := func(kind string, tpar, targ Type, arg *operand) {
-               if !report {
-                       return
-               }
                // provide a better error message if we can
                targs, index := u.x.types()
                if index == 0 {
@@ -176,7 +171,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // Note that even if we don't have any type arguments, constraint type inference
        // may produce results for constraints that explicitly specify a type.
        if useConstraintTypeInference {
-               targs, index = check.inferB(tparams, targs, report)
+               targs, index = check.inferB(tparams, targs)
                if targs == nil || index < 0 {
                        return targs
                }
@@ -214,7 +209,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
 
        // Again, follow up with constraint type inference.
        if useConstraintTypeInference {
-               targs, index = check.inferB(tparams, targs, report)
+               targs, index = check.inferB(tparams, targs)
                if targs == nil || index < 0 {
                        return targs
                }
@@ -223,9 +218,7 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
        // At least one type argument couldn't be inferred.
        assert(targs != nil && index >= 0 && targs[index] == nil)
        tpar := tparams[index]
-       if report {
-               check.errorf(pos, "cannot infer %s (%s) (%s)", tpar.obj.name, tpar.obj.pos, targs)
-       }
+       check.errorf(pos, "cannot infer %s (%s) (%s)", tpar.obj.name, tpar.obj.pos, targs)
        return nil
 }
 
@@ -367,7 +360,7 @@ func (w *tpWalker) isParameterizedTypeList(list []Type) bool {
 // first type argument in that list that couldn't be inferred (and thus is nil). If all
 // type arguments were inferred successfully, index is < 0. The number of type arguments
 // provided may be less than the number of type parameters, but there must be at least one.
-func (check *Checker) inferB(tparams []*TypeParam, targs []Type, report bool) (types []Type, index int) {
+func (check *Checker) inferB(tparams []*TypeParam, targs []Type) (types []Type, index int) {
        assert(len(tparams) >= len(targs) && len(targs) > 0)
 
        // Setup bidirectional unification between those structural bounds
@@ -389,9 +382,7 @@ func (check *Checker) inferB(tparams []*TypeParam, targs []Type, report bool) (t
                sbound := typ.structuralType()
                if sbound != nil {
                        if !u.unify(typ, sbound) {
-                               if report {
-                                       check.errorf(tpar.obj, "%s does not match %s", tpar.obj, sbound)
-                               }
+                               check.errorf(tpar.obj, "%s does not match %s", tpar.obj, sbound)
                                return nil, 0
                        }
                }