fix #857, typechecking for invocations of flattened function