bug fix: check the type of the 'key' of the two array 'r1' and 'r2'

fix for a little bug found while working on  #3060