From iuc@r @ending from fedor@project@org  Thu Jan  3 20:18:52 2019
From: iuc@r @ending from fedor@project@org (=?UTF-8?Q?I=C3=B1aki_Ucar?=)
Date: Thu, 3 Jan 2019 20:18:52 +0100
Subject: [Rd] Compiler + stopifnot bug
Message-ID: <CALEXWq2CneLqRqaD5H4_-qQEzB3LjhSwoqc=Mg3f9WeHAirmXg@mail.gmail.com>

Hi,

I found the following issue in r-devel (2019-01-02 r75945):

`foo<-` <- function(x, value) {
  bar(x) <- value * x
  x
}

`bar<-` <- function(x, value) {
  stopifnot(all(value / x == 1))
  x + value
}

`foo<-` <- compiler::cmpfun(`foo<-`)
`bar<-` <- compiler::cmpfun(`bar<-`)

x <- c(2, 2)
foo(x) <- 1
x # should be c(4, 4)
#> [1] 3 3

If the functions are not compiled or the stopifnot call is removed,
the snippet works correctly. So it seems that something is messing
around with the references to "value" when the call to stopifnot gets
compiled, and the wrong "value" is modified. Note also that if "x <-
2", then the result is correct, 4.

Regards,
-- 
I?aki ?car



[Rd] Compiler + stopifnot bug
=?UTF-8?Q?I=C3=B1aki_Ucar?=