go.tools/go/types: export ConvertibleTo
LGTM=adonovan R=adonovan CC=golang-codereviews https://golang.org/cl/57950043
This commit is contained in:
parent
d0efad3082
commit
83cdd9ba10
|
@ -229,6 +229,12 @@ func AssignableTo(V, T Type) bool {
|
||||||
return x.assignableTo(nil, T) // config not needed for non-constant x
|
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:
|
// 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
|
// 1) For non-interface types V, or if static is set, V implements T if all
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (check *checker) conversion(x *operand, T Type) {
|
||||||
x.val = exact.MakeString(string(codepoint))
|
x.val = exact.MakeString(string(codepoint))
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
case x.isConvertible(check.conf, T):
|
case x.convertibleTo(check.conf, T):
|
||||||
// non-constant conversion
|
// non-constant conversion
|
||||||
x.mode = value
|
x.mode = value
|
||||||
ok = true
|
ok = true
|
||||||
|
@ -63,7 +63,7 @@ func (check *checker) conversion(x *operand, T Type) {
|
||||||
check.updateExprType(x.expr, final, true)
|
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"
|
// "x is assignable to T"
|
||||||
if x.assignableTo(conf, T) {
|
if x.assignableTo(conf, T) {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue