Fixing #4213 arrayIndexThenCheck and adding tests