forcetypeassert icon indicating copy to clipboard operation
forcetypeassert copied to clipboard

Can't detect forced type assertions followed by method calls

Open favonia opened this issue 6 months ago • 0 comments

Consider the following code:

type M struct{}

func (M) F() (bool, bool) { return true, true }
func Test(x any) bool {
	_, ok := x.(M).F()
	return ok
}

The x.(M) is a forced type assertion, but the subsequent .F() masks the problem.

favonia avatar Aug 07 '24 03:08 favonia