Fix array casting & dispatcher not respecting can_compile flag

Also refactor the function type generation code