1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:54:46 -07:00

go/types: remove the report parameter from infer and inferB

The report parameter is now always true, so we can simplify these
functions.

Change-Id: I851adad3011beef9c83172210ff5e93c624372cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/350049
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Findley 2021-09-14 22:09:54 -04:00
parent 6097ebe627
commit fdf2053d52
2 changed files with 9 additions and 18 deletions

View File

@ -40,7 +40,7 @@ func (check *Checker) funcInst(x *operand, ix *typeparams.IndexExpr) {
} }
if got < want { if got < want {
targs = check.infer(ix.Orig, sig.TypeParams().list(), targs, nil, nil, true) targs = check.infer(ix.Orig, sig.TypeParams().list(), targs, nil, nil)
if targs == nil { if targs == nil {
// error was already reported // error was already reported
x.mode = invalid x.mode = invalid
@ -340,7 +340,7 @@ func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type
} }
// TODO(gri) provide position information for targs so we can feed // TODO(gri) provide position information for targs so we can feed
// it to the instantiate call for better error reporting // it to the instantiate call for better error reporting
targs := check.infer(call, sig.TypeParams().list(), targs, sigParams, args, true) targs := check.infer(call, sig.TypeParams().list(), targs, sigParams, args)
if targs == nil { if targs == nil {
return // error already reported return // error already reported
} }

View File

@ -27,9 +27,7 @@ import (
// 3) Infer type arguments from untyped function arguments. // 3) Infer type arguments from untyped function arguments.
// //
// Constraint type inference is used after each step to expand the set of type arguments. // Constraint type inference is used after each step to expand the set of type arguments.
// func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand) (result []Type) {
// TODO(rfindley): remove the report parameter: is no longer needed.
func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand, report bool) (result []Type) {
if debug { if debug {
defer func() { defer func() {
assert(result == nil || len(result) == len(tparams)) assert(result == nil || len(result) == len(tparams))
@ -61,7 +59,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
// If we have type arguments, see how far we get with constraint type inference. // If we have type arguments, see how far we get with constraint type inference.
if len(targs) > 0 { if len(targs) > 0 {
var index int var index int
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs)
if targs == nil || index < 0 { if targs == nil || index < 0 {
return targs return targs
} }
@ -106,9 +104,6 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
} }
errorf := func(kind string, tpar, targ Type, arg *operand) { errorf := func(kind string, tpar, targ Type, arg *operand) {
if !report {
return
}
// provide a better error message if we can // provide a better error message if we can
targs, index := u.x.types() targs, index := u.x.types()
if index == 0 { if index == 0 {
@ -175,7 +170,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
// See how far we get with constraint type inference. // See how far we get with constraint type inference.
// Note that even if we don't have any type arguments, constraint type inference // Note that even if we don't have any type arguments, constraint type inference
// may produce results for constraints that explicitly specify a type. // may produce results for constraints that explicitly specify a type.
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs)
if targs == nil || index < 0 { if targs == nil || index < 0 {
return targs return targs
} }
@ -211,7 +206,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
} }
// Again, follow up with constraint type inference. // Again, follow up with constraint type inference.
targs, index = check.inferB(tparams, targs, report) targs, index = check.inferB(tparams, targs)
if targs == nil || index < 0 { if targs == nil || index < 0 {
return targs return targs
} }
@ -219,9 +214,7 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
// At least one type argument couldn't be inferred. // At least one type argument couldn't be inferred.
assert(index >= 0 && targs[index] == nil) assert(index >= 0 && targs[index] == nil)
tpar := tparams[index] tpar := tparams[index]
if report { check.errorf(posn, _Todo, "cannot infer %s (%v) (%v)", tpar.obj.name, tpar.obj.pos, targs)
check.errorf(posn, _Todo, "cannot infer %s (%v) (%v)", tpar.obj.name, tpar.obj.pos, targs)
}
return nil return nil
} }
@ -362,7 +355,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 // 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 // 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. // 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) assert(len(tparams) >= len(targs) && len(targs) > 0)
// Setup bidirectional unification between those structural bounds // Setup bidirectional unification between those structural bounds
@ -384,9 +377,7 @@ func (check *Checker) inferB(tparams []*TypeParam, targs []Type, report bool) (t
sbound := typ.structuralType() sbound := typ.structuralType()
if sbound != nil { if sbound != nil {
if !u.unify(typ, sbound) { if !u.unify(typ, sbound) {
if report { check.errorf(tpar.obj, _Todo, "%s does not match %s", tpar.obj, sbound)
check.errorf(tpar.obj, _Todo, "%s does not match %s", tpar.obj, sbound)
}
return nil, 0 return nil, 0
} }
} }