dgkf / R

An experimental reimagining of R
https://dgkf.github.io/R
GNU General Public License v3.0
136 stars 5 forks source link

Bug when assigning to vector subset #121

Open sebffischer opened 7 months ago

sebffischer commented 7 months ago

I believe that this is not exactly the same bug as https://github.com/dgkf/R/issues/104, so I am opening a separate issue for it (I might be wrong though). The problem arises when we have a vector subset, where different elements of the subset point to the same elements from the actual vector. I think the culprit are these lines: https://github.com/dgkf/R/blob/c9b14803ccff7075d9651d7376651abce5a10889/src/object/vector/rep.rs#L112.

> x <- 1:3
[1] 1 2 3
> y <- x[c(1, 1)]
[1] 1 1
> y
[1] 1 1
> y[1] <- 10
[1] 10
> y
[1] 10 10
>

PS: Because it feels a little bad that I comment so much on the bugs, I just want to stress that it is amazing how much already does work! 🚀

dgkf commented 7 months ago

I believe that this is not exactly the same bug as https://github.com/dgkf/R/issues/104, so I am opening a separate issue for it (I might be wrong though).

I think these will be the same issue, but I'm happy to have it documented as a separate use case.

I think it's similar because y will be pointing to the same data as x with subset [1, 1]. Assigning to y right now mutates x at position 1 without creating a unique vector.

Once we fix the subset assignment so that it creates a distinct vector upon mutation, then I think this will be resolved.

PS: Because it feels a little bad that I comment so much on the bugs, I just want to stress that it is amazing how much already does work! 🚀

Seriously, do not worry about it at all! Your continued bug reports are evidence that you're invested in the project. Itemizing issues is a lot of work - it's a privilege to have you studiously reporting these things. 🙏