Skip to content

Commit

Permalink
assert: guard CanConvert call in backward compatible wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad committed Jan 17, 2022
1 parent c038d8c commit 54276bb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assert/assertion_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
case reflect.Struct:
{
// All structs enter here. We're not interested in most types.
if !obj1Value.CanConvert(timeType) {
if !canConvert(obj1Value, timeType) {
break
}

Expand Down
11 changes: 11 additions & 0 deletions assert/assertion_compare_can_convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build go1.17

package assert

import "reflect"

// Wrapper around reflect.Value.CanConvert, for compatability
// reasons.
func canConvert(value reflect.Value, to reflect.Type) bool {
return value.CanConvert(to)
}
11 changes: 11 additions & 0 deletions assert/assertion_compare_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build !go1.17

package assert

import "reflect"

// Older versions of Go does not have the reflect.Value.CanConvert
// method.
func canConvert(value reflect.Value, to reflect.Type) bool {
return false
}

0 comments on commit 54276bb

Please sign in to comment.