From murdoch@dunc@n @end|ng |rom gm@||@com  Fri Apr  5 14:53:08 2024
From: murdoch@dunc@n @end|ng |rom gm@||@com (Duncan Murdoch)
Date: Fri, 5 Apr 2024 08:53:08 -0400
Subject: [Rd] 
 Bug in out-of-bounds assignment of list object to expression()
 vector
In-Reply-To: <CAH54GbXMhcy+JFV7dfBLV0J7+YVoTBB8zdnQqEhrOogZPnM-yQ@mail.gmail.com>
References: <CAH54GbXMhcy+JFV7dfBLV0J7+YVoTBB8zdnQqEhrOogZPnM-yQ@mail.gmail.com>
Message-ID: <614fc33c-8120-4580-a89f-86929b562a50@gmail.com>

Yes, definitely looks like a bug.

Are you able to submit it to bugs.r-project.org?

Duncan Murdoch

On 05/04/2024 8:15 a.m., June Choe wrote:
> There seems to be a bug in out-of-bounds assignment of list objects to an
> expression() vector. Tested on release and devel. (Many thanks to folks
> over at Mastodon for the help narrowing down this bug)
> 
> When assigning a list into an existing index, it correctly errors on
> incompatible type, and the expression vector is unchanged:
> 
> ```
> x <- expression(a,b,c)
> x[[3]] <- list() # Error
> x
> #> expression(a, b, c)
> ```
> 
> When assigning a list to an out of bounds index (ex: the next, n+1 index),
> it errors the same but now changes the values of the vector to NULL:
> 
> ```
> x <- expression(a,b,c)
> x[[4]] <- list() # Error
> x
> #> expression(NULL, NULL, NULL)
> ```
> 
> Curiously, this behavior disappears if a prior attempt is made at assigning
> to the same index, using a different incompatible object that does not
> share this bug (like a function):
> 
> ```
> x <- expression(a,b,c)
> x[[4]] <- base::sum # Error
> x[[4]] <- list() # Error
> x
> #> expression(a, b, c)
> ```
> 
> That "protection" persists until x[[4]] is evaluated, at which point the
> bug can be produced again:
> 
> ```
> x[[4]] # Error
> x[[4]] <- list() # Error
> x
> #> expression(NULL, NULL, NULL)
> ```
> 
> Note that `x` has remained a 3-length vector throughout.
> 
> Best,
> June
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Bug in out-of-bounds assignment of list object to expression() vector
Duncan Murdoch