Properly report errors for failed type assertions

Fixes #97.