Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGotype constraints and comparableSingle-choice MCQ

A constraint uses a union with an underlying-type approximation. Which method-set/operator rule explains why MyInt below is accepted by Number but a method defined on Number's type set cannot be called inside the generic body?

type MyInt int func (m MyInt) Tag() string { return "x" } type Number interface{ ~int } func Sum[T Number](xs []T) T { var t T for _, v := range xs { t += v } return t } // Sum([]MyInt{1,2,3}) is valid