From e9f9a4b7509fed26603a6114013209d459b9fa8c Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 23 Mar 2021 12:24:45 +0100 Subject: [PATCH] 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. --- src/reflect/type.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/reflect/type.go b/src/reflect/type.go index 61776150..ad067069 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -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.