If the current param is not optional but the previous one is optional, then we need to append "]" in the "else" block and reset pendingOptional to false. issue #4748