fix #6387

This issue is quite involved, and speaks to the need for a rethinking of
the type system code. However for now I'm just happy to fix a segfault.