Fixes an issue when generating a type erasure exception in TypeExtractor.

The bug has been mentioned in #842.

A additional test case tests the fix.