Interface behaves different when used as library


I have a library A that provides a datatype Date. The Date has the function

func (s Date) Equal(c Date) bool {
	return s.value.Equal(c.value)

In another library B i have a function Compare. In that function I use the code

 type equaler[T any] interface {
	Equal(T) bool

func Compare[T any](o1 T, o2 T) bool {


 var i1 any = o1
 e1, ok := i1.(equaler[T])

When passing an object of type Date to Compare in library B, the ok is true.

When i use the library B in a project A, and I pass an object of type Date to Compare, the ok is false?

I’ve checked the types with the debugger in library B and in application A. The type of i1 is equal!

Any ideas?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.