fix bugs in inference and resolveType; add more test cases