janetrs icon indicating copy to clipboard operation
janetrs copied to clipboard

Possible wrong code

Open YichiZhang0613 opened this issue 1 month ago • 0 comments

In janetrs-dev/src/types/array.rs, maybe in code, " if index < 0 || index > self.len() + 1" should be " if index < 0 || index > self.len()" ?

/// # Janet Panics
    /// Janet panics if `index < 0` or `index > len`.
    ///
    /// # Examples
    /// ```
    /// use janetrs::array;
    /// # let _client = janetrs::client::JanetClient::init().unwrap();
    ///
    /// let mut array = array![1, 2];
    /// array.insert(1, 3) // now it's `[1, 3, 2]`
    /// ```
    #[cfg_attr(feature = "inline-more", inline)]
    pub fn insert(&mut self, index: i32, element: impl Into<Janet>) {
        if index < 0 || index > self.len() + 1 {
            crate::jpanic!(
                "insertion index (is {}) should be >= 0 and <= {})",
                index,
                self.len()
            );

YichiZhang0613 avatar May 08 '24 13:05 YichiZhang0613