Check if variant array contains only symbols

Improved, more tested and more secure code for variant assignment change from #14043

/cc @carlosantoniodasilva