(#22363) Improve error messages from [] operator
There were several cases where errors in arity and type incompatible
in the given keys produced generic error messages, messages without
location, and in a few cases with errors while formatting the error
message.
Test examples added.