reflect: fix AssignableTo and Implements methods

They both reversed the direction of the check, in a way that mostly
cancelled each other out. Of course they're still mostly unimplemented,
but it's better if they're not wrong.
This commit is contained in:
Ayke van Laethem
2021-03-23 12:24:45 +01:00
committed by Ron Evans
parent 1406453350
commit e9f9a4b750
+6 -6
View File
@@ -609,23 +609,23 @@ func (t rawType) FieldAlign() int {
return t.Align()
}
// AssignableTo returns whether a value of type u can be assigned to a variable
// of type t.
// AssignableTo returns whether a value of type t can be assigned to a variable
// of type u.
func (t rawType) AssignableTo(u Type) bool {
if t == u.(rawType) {
return true
}
if t.Kind() == Interface {
panic("reflect: unimplemented: assigning to interface of different type")
if u.Kind() == Interface {
panic("reflect: unimplemented: AssignableTo with interface")
}
return false
}
func (t rawType) Implements(u Type) bool {
if t.Kind() != Interface {
if u.Kind() != Interface {
panic("reflect: non-interface type passed to Type.Implements")
}
return u.AssignableTo(t)
return t.AssignableTo(u)
}
// Comparable returns whether values of this type can be compared to each other.