Use castAs instead of cast in thunk generation

Calling convention attributes can add sugar to methods that we have to
look through.  This fixes an assertion failure in the provided test
case.