Added failing test
Use same algorithm for determining type name.

In particular, use the one from `typeof_term_t`.
Merge branch 'gchpaco_3059' into next

Fixes #3059.