Fix a segfault bug in user-defined types