check-cast the return of an invoke when possible