diff --git a/go/types/api.go b/go/types/api.go index 99cf5d2d..bc6bac40 100644 --- a/go/types/api.go +++ b/go/types/api.go @@ -229,6 +229,12 @@ func AssignableTo(V, T Type) bool { return x.assignableTo(nil, T) // config not needed for non-constant x } +// ConvertibleTo reports whether a value of type V is convertible to a value of type T. +func ConvertibleTo(V, T Type) bool { + x := operand{mode: value, typ: V} + return x.convertibleTo(nil, T) // config not needed for non-constant x +} + // Implements reports whether a value of type V implements T, as follows: // // 1) For non-interface types V, or if static is set, V implements T if all diff --git a/go/types/conversions.go b/go/types/conversions.go index a36e6824..6469bc6d 100644 --- a/go/types/conversions.go +++ b/go/types/conversions.go @@ -31,7 +31,7 @@ func (check *checker) conversion(x *operand, T Type) { x.val = exact.MakeString(string(codepoint)) ok = true } - case x.isConvertible(check.conf, T): + case x.convertibleTo(check.conf, T): // non-constant conversion x.mode = value ok = true @@ -63,7 +63,7 @@ func (check *checker) conversion(x *operand, T Type) { check.updateExprType(x.expr, final, true) } -func (x *operand) isConvertible(conf *Config, T Type) bool { +func (x *operand) convertibleTo(conf *Config, T Type) bool { // "x is assignable to T" if x.assignableTo(conf, T) { return true