Fix `possible-domains' function in TR internals

This fixes type error message generation in some cases
and also the `query-type/result` command on multiple
valued functions.

The latter still does not allow multiple return type
queries (TODO) but it won't crash now.

Closes PR 14493