The value is always 'false'. Brings the code closer in line with go/types.
Follow-up on https://golang.org/cl/304129.
Change-Id: I8bea550033f3187b44e9a54258e0cf642c11c369
Reviewed-on: https://go-review.googlesource.com/c/go/+/304849
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
// AssertableTo reports whether a value of type V can be asserted to have type T.
func AssertableTo(V *Interface, T Type) bool {
- m, _ := (*Checker)(nil).assertableTo(V, T, false)
+ m, _ := (*Checker)(nil).assertableTo(V, T)
return m == nil
}
if T == Typ[Invalid] {
goto Error
}
- check.typeAssertion(posFor(x), x, xtyp, T, false)
+ check.typeAssertion(posFor(x), x, xtyp, T)
x.mode = commaok
x.typ = T
}
// typeAssertion checks that x.(T) is legal; xtyp must be the type of x.
-func (check *Checker) typeAssertion(pos syntax.Pos, x *operand, xtyp *Interface, T Type, strict bool) {
- method, wrongType := check.assertableTo(xtyp, T, strict)
+func (check *Checker) typeAssertion(pos syntax.Pos, x *operand, xtyp *Interface, T Type) {
+ method, wrongType := check.assertableTo(xtyp, T)
if method == nil {
return
}
// method required by V and whether it is missing or just has the wrong type.
// The receiver may be nil if assertableTo is invoked through an exported API call
// (such as AssertableTo), i.e., when all methods have been type-checked.
-// If strict (or the global constant forceStrict) is set, assertions that
-// are known to fail are not permitted.
-func (check *Checker) assertableTo(V *Interface, T Type, strict bool) (method, wrongType *Func) {
+// If the global constant forceStrict is set, assertions that are known to fail
+// are not permitted.
+func (check *Checker) assertableTo(V *Interface, T Type) (method, wrongType *Func) {
// no static check is required if T is an interface
// spec: "If T is an interface type, x.(T) asserts that the
// dynamic type of x implements the interface T."
- if asInterface(T) != nil && !(strict || forceStrict) {
+ if asInterface(T) != nil && !forceStrict {
return
}
return check.missingMethod(T, V, false)
}
}
-func (check *Checker) caseTypes(x *operand, xtyp *Interface, types []syntax.Expr, seen map[Type]syntax.Pos, strict bool) (T Type) {
+func (check *Checker) caseTypes(x *operand, xtyp *Interface, types []syntax.Expr, seen map[Type]syntax.Pos) (T Type) {
L:
for _, e := range types {
T = check.typOrNil(e)
}
seen[T] = e.Pos()
if T != nil {
- check.typeAssertion(e.Pos(), x, xtyp, T, strict)
+ check.typeAssertion(e.Pos(), x, xtyp, T)
}
}
return
}
// Check each type in this type switch case.
cases := unpackExpr(clause.Cases)
- T := check.caseTypes(&x, xtyp, cases, seen, false)
+ T := check.caseTypes(&x, xtyp, cases, seen)
check.openScopeUntil(clause, end, "case")
// If lhs exists, declare a corresponding variable in the case-local scope.
if lhs != nil {