fix type error by resolving types at define; fix and add test cases