fix #359 flatten() function with strange type args